Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AFM #867

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/FuseItems/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Lib:init()
end
end

function Lib:postInit()
function Lib:afmPostInit()
Game:setFlag("fuse_items_data", {})
end

Expand Down
2 changes: 1 addition & 1 deletion libraries/LevelingSystem/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Lib:init()
end
end

function Lib:postInit(new_file)
function Lib:afmPostInit(new_file)
if new_file then
Game:setFlag("library_love", 1)
Game:setFlag("library_experience", 0)
Expand Down
2 changes: 1 addition & 1 deletion libraries/Questline/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Lib:onKeyPressed(key)
end
end

function Lib:postInit(new_file)
function Lib:afmPostInit(new_file)
if Game:getFlag("quest_menu_ever_opened") == nil then
Game:setFlag("quest_menu_ever_opened", false)
end
Expand Down
Binary file added libraries/afilemenu/assets/music/menu.ogg
Binary file not shown.
Binary file added libraries/afilemenu/assets/sounds/squeak.wav
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions libraries/afilemenu/fileselect.tiled-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"automappingRulesFile": "",
"commands": [
],
"extensionsPath": "extensions",
"folders": [
"scripts/world"
],
"objectTypesFile": "",
"propertyTypes": [
]
}
19 changes: 19 additions & 0 deletions libraries/afilemenu/lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"id": "afilemenu",
"name": "File Select",
"authors": [
"Hyperboid",
],
"config": {
// What map to load on a new file
"map": null,
"music": null,
"style": "DEVICE",
// Prevents the special color palette on the Options menu
"noStyledOptions": false,
// Set to false if you are hooking DarkConfigMenu yourself.
"configButtonOverride": true,
// Experimental. Makes holding ESC in-game bring you to the file select.
"hookOverlay": false,
}
}
93 changes: 93 additions & 0 deletions libraries/afilemenu/lib.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
local lib = {}

function lib:init()
if Kristal.getLibConfig("afilemenu", "hookOverlay") then
Utils.hook(Kristal.Overlay, "update", function (orig, self)
local do_orig = true
if love.keyboard.isDown("escape") and not self.quit_release then
if Kristal.Config and Kristal.Config["instantQuit"] then
if Mod ~= nil then
self.quit_release = true
if Kristal.getModOption("hardReset") then
love.event.quit("restart")
else
Kristal.returnToMenu()
end
else
love.event.quit()
end
else
if self.quit_alpha < 1 then
self.quit_alpha = math.min(1, self.quit_alpha + DT / 0.75)
end
self.quit_timer = self.quit_timer + DT
if self.quit_timer > 1.2 then
if Game.world and Game.world.map and Game.world.map.id == "fileselect" then
if Kristal.getModOption("hardReset") then
love.event.quit("restart")
else
Kristal.returnToMenu()
end
else
Game:load(nil,nil,true)
end
self.quit_timer = 0
self.quit_alpha = 0
self.quit_release = true
do_orig = false
else
self.quit_timer = self.quit_timer - DT
end
end
else
self.quit_timer = 0
if self.quit_alpha > 0 then
self.quit_alpha = math.max(0, self.quit_alpha - DT / 0.25)
end
end

if self.quit_release and not love.keyboard.isDown("escape") then
self.quit_release = false
end
if do_orig then
orig(self)
end
end)
end
end

function lib:getPaletteColor(key)
local style = "normal"
if Game.world and Game.world.map then
style = Game.world.map.menustyle
end
local function bystyle(table)
return table[style] or table.default
end
if key == "filemenu_deselected" then
return bystyle{
default = {0.6, 0.6, 0.7},
DEVICE = {0, 0.5, 0},
greatdoor = {.7, .6, .6},
}
elseif key == "filemenu_selected" then
return bystyle {
default = {1, 1, 1},
DEVICE = {0,1,0}
}
elseif key == "filemenu_copy" then
return bystyle {
default = {1, 1, 0.4},
DEVICE = {0.5,1,0.5}
}
elseif key == "filemenu_settings" then
return bystyle {
default = {1, 1, 1},
DEVICE = {0.4,1.0,0.2}
}
end
MUSIC_PITCHES.menu = 0.95
MUSIC_PITCHES.mod_menu = 0.95
end

return lib
30 changes: 30 additions & 0 deletions libraries/afilemenu/scripts/hooks/DarkConfigMenu.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if not Kristal.getLibConfig("afilemenu", "configMenuOverride") then
return DarkConfigMenu
end

local DarkConfigMenu, super = Class(DarkConfigMenu)

function DarkConfigMenu:update()
if self.state == "MAIN" then
if Input.pressed("confirm") then
if self.currently_selected == 6 then
Game.fader:fadeOut(function ()
Game:load(nil, nil, true)
end, {})
self.fadeout = true
return
end
end
end
super.update(self)
end

function DarkConfigMenu:draw()
if self.fadeout then
super.super.draw(self)
return
end
super.draw(self)
end

return DarkConfigMenu
25 changes: 25 additions & 0 deletions libraries/afilemenu/scripts/hooks/Draw.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---@type metatable
local _mt = {__index = Draw}

---@class Draw
local Draw = setmetatable({}, _mt)

function Draw.coolRectangle(x, y, w, h)
-- Make sure the line is a single pixel wide
love.graphics.setLineWidth(1)
love.graphics.setLineStyle("rough")
if Game.world.map.menustyle == "DEVICE" then
love.graphics.rectangle("line", x, y, w, h)
return
end
-- Draw the rectangles
love.graphics.rectangle("line", x, y, w + 1, h + 1)
-- Increase the width and height by one instead of two to produce the broken effect
love.graphics.rectangle("line", x - 1, y - 1, w + 2, h + 2)
love.graphics.rectangle("line", x - 2, y - 2, w + 5, h + 5)
-- Here too
love.graphics.rectangle("line", x - 3, y - 3, w + 6, h + 6)
end

_mt.__newindex = _mt.__index
return Draw
107 changes: 107 additions & 0 deletions libraries/afilemenu/scripts/hooks/FileButton.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
local FileButton, super = Class(FileButton)

function FileButton:getDrawColor()
local copy = self.color[3] < 0.7 -- TODO: detect better
local delete = Utils.equal(self.color, {1, 0, 0})
if delete then
return Utils.unpackColor{1,0,0}
end
if copy then return PALETTE["filemenu_copy"] end
if self.selected then
return PALETTE["filemenu_selected"]
end
return PALETTE["filemenu_deselected"]
-- return Utils.unpackColor{ 0, 0.5, 0 }
-- return super.super.getDrawColor(self)
end

function FileButton:drawCoolRectangle(x, y, w, h)
if Game.world.map.menustyle == "DEVICE" then
love.graphics.setLineWidth(1)
love.graphics.setLineStyle("rough")
-- Set the color
Draw.setColor(self:getDrawColor())
love.graphics.rectangle("line", x, y, w, h)
else
super.drawCoolRectangle(self, x, y, w, h)
end
end

function FileButton:draw()
-- Draw the transparent background
Draw.setColor(0, 0, 0, 0.5)
love.graphics.rectangle("fill", 0, 0, self.width, self.height)

-- Draw the rectangle outline
self:drawCoolRectangle(0, 0, self.width, self.height)

-- Draw text inside the button rectangle
Draw.pushScissor()
Draw.scissor(0, 0, self.width, self.height)

if not self.prompt then
-- Draw the name shadow
Draw.setColor(0, 0, 0)
love.graphics.print(self.name, 50 + 2, 10 + 2)
-- Draw the name
Draw.setColor(self:getDrawColor())
love.graphics.print(self.name, 50, 10)

-- Draw the time shadow
local time_x = self.width-64-self.font:getWidth(self.time) + 2
Draw.setColor(0, 0, 0)
love.graphics.print(self.time, time_x + 2, 10 + 2)
-- Draw the time
Draw.setColor(self:getDrawColor())
love.graphics.print(self.time, time_x, 10)
else
-- Draw the prompt shadow
Draw.setColor(0, 0, 0)
love.graphics.print(self.prompt, 50 + 2, 10 + 2)
-- Draw the prompt
Draw.setColor(self:getDrawColor())
love.graphics.print(self.prompt, 50, 10)
end

if not self.choices then
-- Draw the area shadow
Draw.setColor(0, 0, 0)
love.graphics.print(self.area, 50 + 2, 44 + 2)
-- Draw the area
Draw.setColor(self:getDrawColor())
love.graphics.print(self.area, 50, 44)
else
-- Draw the shadow for choice 1
Draw.setColor(0, 0, 0)
love.graphics.print(self.choices[1], 70+2, 44+2)
-- Draw choice 1
if self.selected_choice == 1 then
Draw.setColor(PALETTE["filemenu_selected"])
else
Draw.setColor(PALETTE["filemenu_deselected"])
end
love.graphics.print(self.choices[1], 70, 44)

-- Draw the shadow for choice 2
Draw.setColor(0, 0, 0)
love.graphics.print(self.choices[2], 250+2, 44+2)
-- Draw choice 2
if self.selected_choice == 2 then
Draw.setColor(1, 1, 1)
else
Draw.setColor(PALETTE["filemenu_deselected"])
end
if Game.world.map.menustyle == "DEVICE" then
if self.selected_choice == 2 then
Draw.setColor(0, 1, 0)
else
Draw.setColor(0, 0.5, 0)
end
end
love.graphics.print(self.choices[2], 250, 44)
end

Draw.popScissor()
end

return FileButton
10 changes: 10 additions & 0 deletions libraries/afilemenu/scripts/hooks/Map.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---@class Map : Map
---@field menustyle string?
local Map, super = Class(Map)

function Map:init(world,data)
super.init(self,world,data)
self.menustyle = nil
end

return Map
15 changes: 15 additions & 0 deletions libraries/afilemenu/scripts/objects/CompletionFileButton.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---@class CompletionFileButton : FileButton
---@overload fun(): CompletionFileButton
local CompletionFileButton, super = Class(FileButton)

function CompletionFileButton:setData(data)
super.setData(self, data)
self.name = data and data.name or "Completion FILE not found."
if not(data and data.playtime) then
self.time = ""
end
self.area = data and data.room_name or "[Made on seeing credits.]"
end


return CompletionFileButton
Loading