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

@@ -46,7 +46,7 @@ control_type.button.__index=control_type.button
function control_type.button:new(data)
local data=data or {}
return setmetatable({
show=data.show or true,
show=data.show~=nil and data.show or true,
x=data.x or 320,
y=data.y or 240,
r=data.r or 80, -- size
@@ -137,7 +137,6 @@ local global_toggle=false
VCTRL={}
VCTRL.focus=nil -- Focusing buttons
---@type table
---@class VCTRL.data
---@field type 'button'
---@field x number
@@ -148,14 +147,10 @@ VCTRL.focus=nil -- Focusing buttons
---@field alpha? number
---@field show? boolean
---@param ... VCTRL.data
---@param ... VCTRL.data[]
---Adding (multiple) virtual button(s)
function VCTRL.new(...)
for _,d in pairs(...) do
local t=d.type
d.type=nil
table.insert(VCTRL,control_type[t]:new(d))
end
for _,d in pairs(...) do table.insert(VCTRL,control_type[d.type]:new(d)) end
end
---@param toggle boolean|false
@@ -180,11 +175,12 @@ function VCTRL.clearAll()
collectgarbage()
end
function VCTRL.press(x,y,id)
---@param force? boolean Forcing click on hidden widgets?
function VCTRL.press(x,y,id,force)
if not global_toggle then return end
local obj,closestDist=false,1e99
for _, w in ipairs(VCTRL) do
if w.show then
if w.show or force then
local d=w:getDistance(x,y)
if d<=1 and d<closestDist then
obj,closestDist=w,d
@@ -212,6 +208,7 @@ function VCTRL.drag(dx,dy,id)
if not global_toggle then return end
if touches[id] then
touches[id]:drag(dx,dy)
return true
end
end