Attempt to fix broken button

This commit is contained in:
Nguyễn Quốc Hưng
2024-08-10 14:34:08 +07:00
parent f691f9e75d
commit 0eb274436e

View File

@@ -41,8 +41,8 @@ function StickConfigScene:new()
self.new_input = {}
self.axis_timer = 0
BUTTON.reset(buttonList)
buttonList = { -- Configuring
BUTTON.reset(buttonList1, buttonList2)
buttonList1 = { -- Configuring
BUTTON.new{
text = CHAR.icon.fastForward.." SKIP",
x = 40, y = 300, w = 100, h = 30,
@@ -54,34 +54,31 @@ function StickConfigScene:new()
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "escape"} end
},
}
buttonList2 = { -- Confirming
BUTTON.new{
text = CHAR.icon.checkMark.." CONFIRM",
x = 40, y = 300, w = 100, h = 30,
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "return"} end
},
BUTTON.new{
text = CHAR.icon.retry_spin.." Restart",
x = 150, y = 300, w = 100, h = 30,
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "delete"} end
},
BUTTON.new{
text = CHAR.icon.cross_thick.." Cancel",
x = 260, y = 300, w = 100, h = 30,
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "escape"} end
}
}
end
function StickConfigScene: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,
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "return"} end
},
BUTTON.new{
text = CHAR.icon.retry_spin.." Restart",
x = 150, y = 300, w = 100, h = 30,
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "delete"} end
},
BUTTON.new{
text = CHAR.icon.cross_thick.." Cancel",
x = 260, y = 300, w = 100, h = 30,
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "escape"} end
}
}
end
end
function StickConfigScene:render()
MainBackground()
BUTTON.draw(buttonList)
BUTTON.draw(self.input_state > #configurable_inputs and buttonList2 or buttonList1)
for i, input in ipairs(configurable_inputs) do
drawText(input_names[input], 40, 60 + i * 20, 200, "left")
@@ -107,7 +104,7 @@ end
---@param e SCENE_onInput
function StickConfigScene:onInputPress(e)
if e.type == "mouse" or e.type == "touch" then
BUTTON.press(buttonList, e.x, e.y, e.id)
BUTTON.press(self.input_state > #configurable_inputs and buttonList2 or buttonList1, 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
@@ -185,13 +182,13 @@ end
function StickConfigScene:onInputRelease(e)
if e.type == "mouse" or e.type == "touch" then
BUTTON.release(buttonList, e.x, e.y, e.id)
BUTTON.release(self.input_state > #configurable_inputs and buttonList2 or buttonList1, e.x, e.y, e.id)
end
end
function StickConfigScene:onInputMove(e)
if e.type == "mouse" then
BUTTON.checkHovering(buttonList, e.x, e.y)
BUTTON.checkHovering(self.input_state > #configurable_inputs and buttonList2 or buttonList1, e.x, e.y)
end
end