improve Prompt and use it to ask for level and file name when exporting
This commit is contained in:
parent
8cfc6a9d18
commit
edd064c2fd
@ -65,7 +65,21 @@ function stepEditor()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Keybind:CheckPressed(Keybind.debug.reload) then
|
if Keybind:CheckPressed(Keybind.debug.reload) then
|
||||||
ExportLevel("test")
|
Prompt:new({
|
||||||
|
name = "level name",
|
||||||
|
input = "unnamed",
|
||||||
|
func = function(name_prompt)
|
||||||
|
if name_prompt.canceled then return end
|
||||||
|
Prompt:new({
|
||||||
|
name = "filename",
|
||||||
|
input = "level.lua",
|
||||||
|
func = function(file_prompt)
|
||||||
|
if file_prompt.canceled then return end
|
||||||
|
ExportLevel(name_prompt.input, file_prompt.input)
|
||||||
|
end,
|
||||||
|
}):activate()
|
||||||
|
end,
|
||||||
|
}):activate()
|
||||||
end
|
end
|
||||||
|
|
||||||
if Keybind:CheckPressed(Keybind.debug.editor) then
|
if Keybind:CheckPressed(Keybind.debug.editor) then
|
||||||
|
@ -44,6 +44,7 @@ function Keybind:CheckDown(action)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- relies on being called exactly once per frame to be accurate.
|
||||||
function Keybind:CheckPressed(action)
|
function Keybind:CheckPressed(action)
|
||||||
if Keybind:CheckDown(action) then
|
if Keybind:CheckDown(action) then
|
||||||
if not action.pressed then
|
if not action.pressed then
|
||||||
@ -77,6 +78,7 @@ function Keybind:RemoveKeys(action)
|
|||||||
action.keys = {}
|
action.keys = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- this prolly should be used by Prompt:keypressed()
|
||||||
function Keybind:hasKey(action, key)
|
function Keybind:hasKey(action, key)
|
||||||
for _, v in pairs(action.keys) do
|
for _, v in pairs(action.keys) do
|
||||||
if v == key then
|
if v == key then
|
||||||
|
@ -18,6 +18,8 @@ Prompt = {
|
|||||||
pos = { x = 10, y = 10 },
|
pos = { x = 10, y = 10 },
|
||||||
input = "",
|
input = "",
|
||||||
name = "input",
|
name = "input",
|
||||||
|
canceled = false,
|
||||||
|
closing = false,
|
||||||
|
|
||||||
active_prompt = nil,
|
active_prompt = nil,
|
||||||
}
|
}
|
||||||
@ -32,9 +34,12 @@ end
|
|||||||
function Prompt:keypressed(key, scancode, isrepeat)
|
function Prompt:keypressed(key, scancode, isrepeat)
|
||||||
if key == "backspace" then
|
if key == "backspace" then
|
||||||
self.input = backspace(self.input)
|
self.input = backspace(self.input)
|
||||||
elseif key == "return" or key == "kpenter" then
|
elseif key == "return" or key == "kpenter" or key == "escape" then
|
||||||
|
if key == "escape" then
|
||||||
|
self.canceled = true
|
||||||
|
end
|
||||||
|
self.closing = true
|
||||||
self:func()
|
self:func()
|
||||||
Prompt.active_prompt = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
6
main.lua
6
main.lua
@ -98,7 +98,13 @@ function love.update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Prompt.active_prompt then
|
if Prompt.active_prompt then
|
||||||
|
-- try to stop the keypress that closed the menu from spilling into the rest of the game
|
||||||
|
Keybind:CheckPressed(Keybind.menu.pause)
|
||||||
|
if Prompt.active_prompt.closing then
|
||||||
|
Prompt.active_prompt = nil
|
||||||
|
else
|
||||||
Prompt.active_prompt:update()
|
Prompt.active_prompt:update()
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user