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:
@@ -15,7 +15,6 @@ local function mDrawQ(obj,quad,x,y,a,k)
|
|||||||
love.graphics.draw(obj,quad,x,y,a,k,nil,w*.5,h*.5)
|
love.graphics.draw(obj,quad,x,y,a,k,nil,w*.5,h*.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
ShowLoadingText('virtual key skin')
|
|
||||||
local empty_quad
|
local empty_quad
|
||||||
-- A table containing quads used to draw icons for virtual control system.
|
-- A table containing quads used to draw icons for virtual control system.
|
||||||
-- local virtual_quad=setmetatable((function()
|
-- local virtual_quad=setmetatable((function()
|
||||||
@@ -42,7 +41,7 @@ local virtual_quad=setmetatable((function()
|
|||||||
empty_quad=gc_newQuad(0,0,1,1,5*w,2*w)
|
empty_quad=gc_newQuad(0,0,1,1,5*w,2*w)
|
||||||
for i,name in next,{
|
for i,name in next,{
|
||||||
'left','right','up','down','restart',
|
'left','right','up','down','restart',
|
||||||
'rotate_right','rotate_left','rotate_right2','rotate_left2','',
|
'rotate_right','rotate_left','rotate_right2','rotate_left2'
|
||||||
} do if #name>0 then t[name]=gc_newQuad((i-1)%5*w,math.floor((i-1)/5)*w,w,w,5*w,2*w) end end
|
} do if #name>0 then t[name]=gc_newQuad((i-1)%5*w,math.floor((i-1)/5)*w,w,w,5*w,2*w) end end
|
||||||
return t
|
return t
|
||||||
end)(),{
|
end)(),{
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ function button:press(x, y, touchID)
|
|||||||
end
|
end
|
||||||
---Trigger release action, don't need ``self._hovering`` to ``true``
|
---Trigger release action, don't need ``self._hovering`` to ``true``
|
||||||
function button:release(x, y, touchID)
|
function button:release(x, y, touchID)
|
||||||
local valid = true
|
local valid
|
||||||
if touchID then
|
if touchID then
|
||||||
valid = touchID == self._touchID
|
valid = touchID == self._touchID
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local KeyConfigScene = SCENE:extend()
|
local KeyConfigScene = SCENE:extend()
|
||||||
KeyConfigScene.title = "Key Config"
|
KeyConfigScene.title = "Key Config"
|
||||||
|
local buttonList = {}
|
||||||
|
|
||||||
local configurable_inputs = {
|
local configurable_inputs = {
|
||||||
"menu_decide",
|
"menu_decide",
|
||||||
@@ -13,7 +14,6 @@ local configurable_inputs = {
|
|||||||
"rotate_right",
|
"rotate_right",
|
||||||
"rotate_right2",
|
"rotate_right2",
|
||||||
}
|
}
|
||||||
|
|
||||||
local input_names = {
|
local input_names = {
|
||||||
menu_decide='Confirm Selection',
|
menu_decide='Confirm Selection',
|
||||||
menu_back = 'Go Back',
|
menu_back = 'Go Back',
|
||||||
@@ -40,13 +40,49 @@ function KeyConfigScene:new()
|
|||||||
self.input_state = 1
|
self.input_state = 1
|
||||||
self.set_inputs = newSetInputs()
|
self.set_inputs = newSetInputs()
|
||||||
self.new_input = {}
|
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
|
end
|
||||||
|
|
||||||
function KeyConfigScene:update()
|
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
|
end
|
||||||
|
|
||||||
function KeyConfigScene:render()
|
function KeyConfigScene:render()
|
||||||
MainBackground()
|
MainBackground()
|
||||||
|
BUTTON.draw(buttonList)
|
||||||
|
|
||||||
for i, input in ipairs(configurable_inputs) do
|
for i, input in ipairs(configurable_inputs) do
|
||||||
drawText(input_names[input], 40, 60 + i * 20, 200, "left")
|
drawText(input_names[input], 40, 60 + i * 20, 200, "left")
|
||||||
if self.set_inputs[input] then
|
if self.set_inputs[input] then
|
||||||
@@ -62,7 +98,9 @@ function KeyConfigScene:render()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function KeyConfigScene:onInputPress(e)
|
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
|
-- 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
|
if e.scancode == "escape" or (self.input_state > #configurable_inputs and e.input == "menu_back") then
|
||||||
SCENE = InputConfigScene(SETTINGS.firstTime)
|
SCENE = InputConfigScene(SETTINGS.firstTime)
|
||||||
@@ -72,10 +110,7 @@ function KeyConfigScene:onInputPress(e)
|
|||||||
SCENE = SETTINGS.firstTime and TitleScene() or InputConfigScene()
|
SCENE = SETTINGS.firstTime and TitleScene() or InputConfigScene()
|
||||||
SETTINGS.firstTime = false
|
SETTINGS.firstTime = false
|
||||||
elseif e.scancode == "delete" or e.scancode == "backspace" then
|
elseif e.scancode == "delete" or e.scancode == "backspace" then
|
||||||
-- retry
|
self:new() -- retry
|
||||||
self.input_state = 1
|
|
||||||
self.set_inputs = newSetInputs()
|
|
||||||
self.new_input = {}
|
|
||||||
end
|
end
|
||||||
elseif e.scancode == "tab" then
|
elseif e.scancode == "tab" then
|
||||||
self.set_inputs[configurable_inputs[self.input_state]] = "skipped"
|
self.set_inputs[configurable_inputs[self.input_state]] = "skipped"
|
||||||
@@ -92,4 +127,16 @@ function KeyConfigScene:onInputPress(e)
|
|||||||
end
|
end
|
||||||
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
|
return KeyConfigScene
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ function NameEntryScene:new()
|
|||||||
self.char_pos = 1
|
self.char_pos = 1
|
||||||
self.name_entry = {'A','A','A'}
|
self.name_entry = {'A','A','A'}
|
||||||
self.entry_pos = 1
|
self.entry_pos = 1
|
||||||
self.entry_chars = self.name_entry[1]..self.name_entry[2]..self.name_entry[3]
|
self.entry_chars = table.concat(self.name_entry, '', 1, 3)
|
||||||
self.grid = Grid(10, 20)
|
self.grid = Grid(10, 20)
|
||||||
self.repeat_limit = 10
|
self.repeat_limit = 10
|
||||||
self.repeat_counter = self.repeat_limit-1
|
self.repeat_counter = self.repeat_limit-1
|
||||||
@@ -130,7 +130,7 @@ function NameEntryScene:update()
|
|||||||
end
|
end
|
||||||
self.repeat_counter = self.repeat_counter + 1
|
self.repeat_counter = self.repeat_counter + 1
|
||||||
end
|
end
|
||||||
self.entry_chars = self.name_entry[1]..self.name_entry[2]..self.name_entry[3]
|
self.entry_chars = table.concat(self.name_entry, '', 1, 3)
|
||||||
end
|
end
|
||||||
|
|
||||||
function NameEntryScene:onInputMove(e)
|
function NameEntryScene:onInputMove(e)
|
||||||
@@ -146,16 +146,15 @@ function NameEntryScene:getPlayInfo(player_name)
|
|||||||
self.wins = grade_history[2]
|
self.wins = grade_history[2]
|
||||||
self.plays = grade_history[4]
|
self.plays = grade_history[4]
|
||||||
else
|
else
|
||||||
self.grade, self.win, self.plays = 0, 0, 0
|
self.grade, self.wins, self.plays = 0, 0, 0
|
||||||
end
|
end
|
||||||
return self.grade, self.win, self.plays
|
|
||||||
end
|
end
|
||||||
function NameEntryScene:onInputPress(e)
|
function NameEntryScene:onInputPress(e)
|
||||||
local name = string.lower(self.name_entry[1]..self.name_entry[2]..self.name_entry[3])
|
local name = string.lower(table.concat(self.name_entry, '', 1, 3))
|
||||||
if e.type == "mouse" or e.type == "touch" then
|
if e.type == "mouse" or e.type == "touch" then
|
||||||
BUTTON.press(buttonList, e.x, e.y, e.id)
|
BUTTON.press(buttonList, e.x, e.y, e.id)
|
||||||
elseif e.key and #e.key == 1 then
|
elseif e.key and #e.key == 1 then
|
||||||
local pos = string.find("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.", string.upper(e.key), 1, true)
|
local pos = string.find(self.chars, string.upper(e.key), 1, true)
|
||||||
if pos then
|
if pos then
|
||||||
if self.entry_pos <= 3 then
|
if self.entry_pos <= 3 then
|
||||||
self.char_pos = pos
|
self.char_pos = pos
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local StickConfigScene = SCENE:extend()
|
local StickConfigScene = SCENE:extend()
|
||||||
StickConfigScene.title = "Controller Config"
|
StickConfigScene.title = "Controller Config"
|
||||||
|
local buttonList = {}
|
||||||
|
|
||||||
local configurable_inputs = {
|
local configurable_inputs = {
|
||||||
"menu_decide",
|
"menu_decide",
|
||||||
@@ -13,7 +14,6 @@ local configurable_inputs = {
|
|||||||
"rotate_right",
|
"rotate_right",
|
||||||
"rotate_right2",
|
"rotate_right2",
|
||||||
}
|
}
|
||||||
|
|
||||||
local input_names = {
|
local input_names = {
|
||||||
menu_decide='Confirm Selection',
|
menu_decide='Confirm Selection',
|
||||||
menu_back = 'Go Back',
|
menu_back = 'Go Back',
|
||||||
@@ -40,13 +40,49 @@ function StickConfigScene:new()
|
|||||||
self.set_inputs = newSetInputs()
|
self.set_inputs = newSetInputs()
|
||||||
self.new_input = {}
|
self.new_input = {}
|
||||||
self.axis_timer = 0
|
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
|
end
|
||||||
|
|
||||||
function StickConfigScene:update()
|
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
|
end
|
||||||
|
|
||||||
function StickConfigScene:render()
|
function StickConfigScene:render()
|
||||||
MainBackground()
|
MainBackground()
|
||||||
|
BUTTON.draw(buttonList)
|
||||||
|
|
||||||
for i, input in ipairs(configurable_inputs) do
|
for i, input in ipairs(configurable_inputs) do
|
||||||
drawText(input_names[input], 40, 60 + i * 20, 200, "left")
|
drawText(input_names[input], 40, 60 + i * 20, 200, "left")
|
||||||
if self.set_inputs[input] then
|
if self.set_inputs[input] then
|
||||||
@@ -68,8 +104,11 @@ local function addJoystick(input, name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param e SCENE_onInput
|
||||||
function StickConfigScene:onInputPress(e)
|
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
|
-- 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
|
if e.scancode == "escape" or (self.input_state > #configurable_inputs and e.input == "menu_back") then
|
||||||
SCENE = InputConfigScene(SETTINGS.firstTime)
|
SCENE = InputConfigScene(SETTINGS.firstTime)
|
||||||
@@ -79,10 +118,7 @@ function StickConfigScene:onInputPress(e)
|
|||||||
SCENE = SETTINGS.firstTime and TitleScene() or InputConfigScene()
|
SCENE = SETTINGS.firstTime and TitleScene() or InputConfigScene()
|
||||||
SETTINGS.firstTime = false
|
SETTINGS.firstTime = false
|
||||||
elseif e.scancode == "delete" or e.scancode == "backspace" then
|
elseif e.scancode == "delete" or e.scancode == "backspace" then
|
||||||
-- retry
|
self:new() -- retry
|
||||||
self.input_state = 1
|
|
||||||
self.set_inputs = newSetInputs()
|
|
||||||
self.new_input = {}
|
|
||||||
end
|
end
|
||||||
else -- Other keys - skip
|
else -- Other keys - skip
|
||||||
self.set_inputs[configurable_inputs[self.input_state]] = "skipped"
|
self.set_inputs[configurable_inputs[self.input_state]] = "skipped"
|
||||||
@@ -147,4 +183,16 @@ function StickConfigScene:onInputPress(e)
|
|||||||
end
|
end
|
||||||
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
|
return StickConfigScene
|
||||||
|
|||||||
Reference in New Issue
Block a user