Update both key and stick configuration scenes

This commit is contained in:
Nguyễn Quốc Hưng
2024-08-10 17:13:43 +07:00
parent e6388c79bc
commit 78501f368c
2 changed files with 25 additions and 36 deletions

View File

@@ -27,7 +27,6 @@ local input_names = {
rotate_right2='Rotate Clockwise (2)'
}
local function newSetInputs()
local set_inputs = {}
for i, input in ipairs(configurable_inputs) do
@@ -40,43 +39,34 @@ function KeyConfigScene:new()
self.input_state = 1
self.set_inputs = newSetInputs()
self.new_input = {}
self.axis_timer = 0
BUTTON.reset(buttonList)
buttonList = { -- Configuring
BUTTON.new{
text = CHAR.icon.fastForward.." SKIP",
x = 40, y = 300, w = 100, h = 30,
text = CHAR.key.tab.."\nTab",
x = 40, y = 300, w = 100, h = 50,
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "tab"} end
},
BUTTON.new{
text = CHAR.icon.cross_thick.." Cancel",
x = 150, y = 300, w = 100, h = 30,
text = CHAR.key.enter_or_return.."\nEnter/Return",
x = 150, y = 300, w = 100, h = 50,
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "return"} end
},
BUTTON.new{
text = CHAR.key.del.."\nDelete",
x = 260, y = 300, w = 100, h = 50,
codeWhenReleased = function() self:onInputPress{type = "key", scancode = "delete"} end
},
BUTTON.new{
text = CHAR.key.esc.."\nEscape",
x = 370, y = 300, w = 100, h = 50,
codeWhenReleased = 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,
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 KeyConfigScene:render()
@@ -90,10 +80,10 @@ function KeyConfigScene:render()
end
end
if self.input_state > #configurable_inputs then
drawText("Press Enter/Confirm Selection to confirm, delete/backspace to retry" .. (SETTINGS.input.keys and ", esc/Go Back to cancel" or ""),0,0,1000)
drawText("Press Enter/Confirm Selection to confirm, Delete/Backspace to retry" .. (SETTINGS.input.keys and ", Esc/Go Back to cancel" or ""), 0, 0, 1000)
else
drawText("Press key input for " .. input_names[configurable_inputs[self.input_state]] .. ", escape to cancel\nPress tab on keyboard, or any key from other inputs, to skip",0,0,1000)
drawText("Function keys (F1, F2, etc.), escape, and tab can't be changed", 0, 35,1000)
drawText("Function keys (F1, F2, etc.), Escape, and Tab can't be changed", 0, 35,1000)
end
end

View File

@@ -1,6 +1,6 @@
local StickConfigScene = SCENE:extend()
StickConfigScene.title = "Controller Config"
local buttonList1 = {}
local buttonList = {}
local configurable_inputs = {
"menu_decide",
@@ -41,8 +41,8 @@ function StickConfigScene:new()
self.new_input = {}
self.axis_timer = 0
BUTTON.reset(buttonList1)
buttonList1 = { -- Configuring
BUTTON.reset(buttonList)
buttonList = { -- Configuring
BUTTON.new{
text = CHAR.key.tab.."\nTab",
x = 40, y = 300, w = 100, h = 50,
@@ -71,7 +71,7 @@ end
function StickConfigScene:render()
MainBackground()
BUTTON.draw(buttonList1)
BUTTON.draw(buttonList)
for i, input in ipairs(configurable_inputs) do
drawText(input_names[input], 40, 60 + i * 20, 200, "left")
@@ -80,7 +80,7 @@ function StickConfigScene:render()
end
end
if self.input_state > #configurable_inputs then
drawText("Press enter/Confirm Selection to confirm, delete/backspace to retry" .. (SETTINGS.input.joysticks and ", esc/Go Back to cancel" or ""), 0, 0, 1000)
drawText("Press Enter/Confirm Selection to confirm, Delete/Backspace to retry" .. (SETTINGS.input.joysticks and ", Esc/Go Back to cancel" or ""), 0, 0, 1000)
else
drawText("Press joystick input for " .. input_names[configurable_inputs[self.input_state]] .. ", tab to skip, escape to cancel", 0, 0, 1000)
end
@@ -94,10 +94,9 @@ local function addJoystick(input, name)
end
end
---@param e SCENE_onInput
function StickConfigScene:onInputPress(e)
if e.type == "mouse" or e.type == "touch" then
BUTTON.press(buttonList1, e.x, e.y, e.id)
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
@@ -175,13 +174,13 @@ end
function StickConfigScene:onInputRelease(e)
if e.type == "mouse" or e.type == "touch" then
BUTTON.release(buttonList1, e.x, e.y, e.id)
BUTTON.release(buttonList, e.x, e.y, e.id)
end
end
function StickConfigScene:onInputMove(e)
if e.type == "mouse" then
BUTTON.checkHovering(buttonList1, e.x, e.y)
BUTTON.checkHovering(buttonList, e.x, e.y)
end
end