Add buttons to prevent soft-lock in keybind conf.

This commit is contained in:
Nguyễn Quốc Hưng
2024-08-09 23:40:07 +07:00
parent 1a99de7435
commit 91100883fe
5 changed files with 116 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
local KeyConfigScene = SCENE:extend()
KeyConfigScene.title = "Key Config"
local buttonList = {}
local configurable_inputs = {
"menu_decide",
@@ -13,7 +14,6 @@ local configurable_inputs = {
"rotate_right",
"rotate_right2",
}
local input_names = {
menu_decide='Confirm Selection',
menu_back = 'Go Back',
@@ -40,13 +40,49 @@ function KeyConfigScene:new()
self.input_state = 1
self.set_inputs = newSetInputs()
self.new_input = {}
BUTTON.reset(buttonList)
buttonList = { -- Configuring
BUTTON.new{
text = CHAR.icon.fastForward.." SKIP",
x = 40, y = 300, w = 100, h = 30,
codeWhenPressed = function() self:onInputPress{type = "key", scancode = "tab"} end
},
BUTTON.new{
text = CHAR.icon.cross_thick.." Cancel",
x = 150, y = 300, w = 100, h = 30,
codeWhenPressed = function() self:onInputPress{type = "key", scancode = "escape"} end
},
}
end
function KeyConfigScene:update()
if self.input_state > #configurable_inputs then
BUTTON.reset(buttonList)
buttonList = { -- Confirming
BUTTON.new{
text = CHAR.icon.checkMark.." CONFIRM",
x = 40, y = 300, w = 100, h = 30,
codeWhenPressed = function() self:onInputPress{type = "key", scancode = "return"} end
},
BUTTON.new{
text = CHAR.icon.retry_spin.." Restart",
x = 150, y = 300, w = 100, h = 30,
codeWhenPressed = function() self:onInputPress{type = "key", scancode = "delete"} end
},
BUTTON.new{
text = CHAR.icon.cross_thick.." Cancel",
x = 260, y = 300, w = 100, h = 30,
codeWhenPressed = function() self:onInputPress{type = "key", scancode = "escape"} end
}
}
end
end
function KeyConfigScene:render()
MainBackground()
BUTTON.draw(buttonList)
for i, input in ipairs(configurable_inputs) do
drawText(input_names[input], 40, 60 + i * 20, 200, "left")
if self.set_inputs[input] then
@@ -62,7 +98,9 @@ function KeyConfigScene:render()
end
function KeyConfigScene:onInputPress(e)
if e.type == "key" then
if e.type == "mouse" or e.type == "touch" then
BUTTON.press(buttonList, e.x, e.y, e.id)
elseif e.type == "key" then
-- function keys, escape, and tab are reserved and can't be remapped
if e.scancode == "escape" or (self.input_state > #configurable_inputs and e.input == "menu_back") then
SCENE = InputConfigScene(SETTINGS.firstTime)
@@ -72,10 +110,7 @@ function KeyConfigScene:onInputPress(e)
SCENE = SETTINGS.firstTime and TitleScene() or InputConfigScene()
SETTINGS.firstTime = false
elseif e.scancode == "delete" or e.scancode == "backspace" then
-- retry
self.input_state = 1
self.set_inputs = newSetInputs()
self.new_input = {}
self:new() -- retry
end
elseif e.scancode == "tab" then
self.set_inputs[configurable_inputs[self.input_state]] = "skipped"
@@ -92,4 +127,16 @@ function KeyConfigScene:onInputPress(e)
end
end
function KeyConfigScene:onInputRelease(e)
if e.type == "mouse" or e.type == "touch" then
BUTTON.release(buttonList, e.x, e.y, e.id)
end
end
function KeyConfigScene:onInputMove(e)
if e.type == "mouse" then
BUTTON.checkHovering(buttonList, e.x, e.y)
end
end
return KeyConfigScene