Final update for touch configuration scene

This commit is contained in:
Squishy (C6H12O6+NaCl+H2O)
2024-05-23 23:44:25 +07:00
parent ffe1bf5049
commit b14fe9c86c
5 changed files with 262 additions and 80 deletions

View File

@@ -62,6 +62,7 @@ local button = {
codeWhenPressed = NULL,
codeWhenReleased = NULL,
update = NULL,
_hovering = false,
_pressed = false,
@@ -121,24 +122,33 @@ function button:press(x, y, touchID)
self._touchID = touchID
self._pressed = true
return true
end
end
---Trigger release action, don't need ``self._hovering`` to ``true``
function button:release(x, y, touchID)
local valid = true
if touchID then valid = touchID == self._touchID end
if touchID then
valid = touchID == self._touchID
elseif x and y then
valid = true
end
if valid then
self.codeWhenReleased()
self._pressed = false
self._touchID = false
if touchID then
self._hovering = false
else
self._hovering = self:isHovering(x, y)
end
if self:isHovering(x, y) then
self.codeWhenReleased()
return true
end
end
end
@@ -243,6 +253,11 @@ end
function BUTTON.draw(list)
for _, v in pairs(list) do v:draw() end
end
---Update all buttons in provided list
---@param list table<any,BUTTON.button>
function BUTTON.update(list)
for _, v in pairs(list) do v:update() end
end
---Check if current mouse position is inside button<br>
---Calling BUTTON.press will trigger this, but you can call it when moving mouse so button can be highlighted when being hovered
@@ -258,13 +273,13 @@ end
---@param x number # Mouse position
---@param y number # Mouse position
function BUTTON.press(list, x, y, touchID)
for _, v in pairs(list) do v:press(x, y, touchID) end
for _, v in pairs(list) do if v:press(x, y, touchID) then return true end end
end
---Trigger the release action
---@param list table<BUTTON.button>
function BUTTON.release(list, x, y, touchID)
for _, v in pairs(list) do v:release(x, y, touchID) end
for _, v in pairs(list) do if v:release(x, y, touchID) then return true end end
end
return BUTTON