This commit is contained in:
Squishy (C6H12O6+NaCl+H2O)
2024-05-19 22:24:21 +07:00
parent c0f06b9694
commit 62dc4b1abf
3 changed files with 30 additions and 21 deletions

View File

@@ -87,7 +87,7 @@ end
---Round a number with specified unit
---@param n number
---@param u number # Default: 10
---@param u? number # Default: 10
---@return number
function math.roundUnit(n,u)
local u = u or 10

View File

@@ -161,6 +161,7 @@ function love.keypressed(key, scancode)
love.window.setFullscreen(SETTINGS["fullscreen"])
elseif scancode == "f2" and SCENE.title ~= "Input Config" and SCENE.title ~= "Game" then
SCENE = InputConfigScene()
elseif scancode == "f12" then REQUEST_BREAK()
-- function keys are reserved
elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then
return

View File

@@ -1,6 +1,28 @@
local TouchConfigScene = SCENE:extend()
TouchConfigScene.title = "Touchscreen config\n(you can tap anywhere on touch screen to select this)"
local widgetList = {
BUTTON.new{
text = "Select widget\nLoading...",
x = 10, y = 10, w = 120, h = 50
}
}
local function widgetList_update()
for _, v in pairs(widgetList) do v:update() end
end
local function widgetList_draw()
for _, v in pairs(widgetList) do v:draw() end
end
local function widgetList_isHovering(x, y)
for _, v in pairs(widgetList) do v:isHovering(x, y) end
end
local function widgetList_press()
for _, v in pairs(widgetList) do v:press() end
end
local function widgetList_release()
for _, v in pairs(widgetList) do v:release() end
end
function TouchConfigScene:new()
-- TODO
end
@@ -8,38 +30,24 @@ function TouchConfigScene:update()
-- TODO
end
local test_button = BUTTON.new{
name = 'PHÍM THỬ - Chọn widget',
x = 50, y = 50, w = 200, h = 30, textColor = {1,1,1,1},
codeWhenPressed = function() PlaySE("promote") end,
codeWhenReleased = function() PlaySE("lock") end,
}
local function drawButtons()
-- drawText('Select button', 10, 10, 100, 'center')
-- love.graphics.setColor(1,1,1)
-- love.graphics.setLineWidth(3)
-- love.graphics.rectangle('line',0,0,120,40)
test_button:draw()
end
function TouchConfigScene:render()
MainBackground()
drawButtons()
widgetList_draw()
end
---@param e SCENE_onInput
function TouchConfigScene:onInputMove(e)
if e.type == "mouse" then
test_button:isHovering(e.x, e.y)
widgetList_isHovering(e.x, e.y)
end
end
---@param e SCENE_onInput
function TouchConfigScene:onInputPress(e)
if e.input == 'menu_back' then SCENE = InputConfigScene() end
if e.type == 'mouse' then test_button:press() end
if e.type == 'touch' then test_button:press(true) end
if e.type =="mouse" then widgetList_press() end
end
function TouchConfigScene:onInputRelease(e)
if e.type == 'mouse' then test_button:press() end
if e.type =="mouse" then widgetList_release() end
end
return TouchConfigScene