mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Add buttons to prevent soft-lock in keybind conf.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local StickConfigScene = SCENE:extend()
|
||||
StickConfigScene.title = "Controller 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 StickConfigScene:new()
|
||||
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,
|
||||
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 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,
|
||||
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 StickConfigScene: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
|
||||
@@ -68,8 +104,11 @@ local function addJoystick(input, name)
|
||||
end
|
||||
end
|
||||
|
||||
---@param e SCENE_onInput
|
||||
function StickConfigScene: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)
|
||||
@@ -79,10 +118,7 @@ function StickConfigScene: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
|
||||
else -- Other keys - skip
|
||||
self.set_inputs[configurable_inputs[self.input_state]] = "skipped"
|
||||
@@ -147,4 +183,16 @@ function StickConfigScene:onInputPress(e)
|
||||
end
|
||||
end
|
||||
|
||||
function StickConfigScene:onInputRelease(e)
|
||||
if e.type == "mouse" or e.type == "touch" then
|
||||
BUTTON.release(buttonList, e.x, e.y, e.id)
|
||||
end
|
||||
end
|
||||
|
||||
function StickConfigScene:onInputMove(e)
|
||||
if e.type == "mouse" then
|
||||
BUTTON.checkHovering(buttonList, e.x, e.y)
|
||||
end
|
||||
end
|
||||
|
||||
return StickConfigScene
|
||||
|
||||
Reference in New Issue
Block a user