mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Moving VCTRL related calls and adding buttons for name entry screen
This commit is contained in:
@@ -73,44 +73,48 @@ end
|
||||
function control_type.button:reset()
|
||||
self.pressed=false
|
||||
self.lastPressTime=-1e99
|
||||
self.pressingID=false
|
||||
end
|
||||
function control_type.button:press()
|
||||
function control_type.button:press(_,_,id)
|
||||
self.pressed=true
|
||||
self.lastPressTime=love.timer.getTime()
|
||||
self.pressing=id
|
||||
-- love.keypressed(self.key, love.keyboard.getScancodeFromKey(self.key))
|
||||
SCENE:onInputPress{input=self.key,type="virtual"}
|
||||
end
|
||||
function control_type.button:release()
|
||||
self.pressed=false
|
||||
self.pressingID=false
|
||||
-- love.keyreleased(self.key,love.keyboard.getScancodeFromKey(self.key))
|
||||
SCENE:onInputRelease{input=self.key,type="virtual"}
|
||||
end
|
||||
function control_type.button:drag(dx,dy)
|
||||
self.x,self.y=self.x+dx,self.y+dy
|
||||
end
|
||||
function control_type.button:draw(forceLight)
|
||||
function control_type.button:draw(forceAlpha)
|
||||
local alpha = forceAlpha or self.alpha
|
||||
love.graphics.setLineWidth(4)
|
||||
if self.shape=='circle' then
|
||||
love.graphics.setColor(0,0,0,self.alpha)
|
||||
love.graphics.setColor(0,0,0,alpha)
|
||||
love.graphics.circle('fill',self.x,self.y,self.r-4)
|
||||
|
||||
love.graphics.setColor(1,1,1,self.pressed and .5 or .05)
|
||||
love.graphics.setColor(1,1,1,self.pressed and .5 or 0)
|
||||
love.graphics.circle('fill',self.x,self.y,self.r-4)
|
||||
|
||||
love.graphics.setColor(1,1,1)
|
||||
love.graphics.setColor(1,1,1,alpha)
|
||||
love.graphics.circle('line',self.x,self.y,self.r-2)
|
||||
elseif self.shape=='square' then
|
||||
love.graphics.setColor(0,0,0,self.alpha)
|
||||
love.graphics.setColor(0,0,0,alpha)
|
||||
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
|
||||
|
||||
love.graphics.setColor(1,1,1,self.pressed and .5 or .05)
|
||||
love.graphics.setColor(1,1,1,self.pressed and .5 or 0)
|
||||
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
|
||||
|
||||
love.graphics.setColor(1,1,1)
|
||||
love.graphics.setColor(1,1,1,alpha)
|
||||
love.graphics.rectangle('line',self.x-self.r-2,self.y-self.r-2,self.r*2+4,self.r*2+4)
|
||||
end
|
||||
if self.iconSize>0 and self.quad then
|
||||
love.graphics.setColor(1,1,1,forceLight and 1 or self.alpha)
|
||||
love.graphics.setColor(1,1,1,alpha)
|
||||
local _,_,w,h=self.quad:getViewport()
|
||||
mDrawQ(
|
||||
virtual_texture,
|
||||
@@ -133,8 +137,7 @@ local global_toggle=false
|
||||
VCTRL={}
|
||||
VCTRL.focus=nil -- Focusing buttons
|
||||
|
||||
---@param ... table
|
||||
---@class data
|
||||
---@class VCTRL.data
|
||||
---@field type string
|
||||
---@field x number
|
||||
---@field y number
|
||||
@@ -143,6 +146,8 @@ VCTRL.focus=nil -- Focusing buttons
|
||||
---@field iconSize number
|
||||
---@field alpha number
|
||||
---@field show boolean
|
||||
|
||||
---@param ... VCTRL.data
|
||||
---Adding (multiple) virtual button(s)
|
||||
function VCTRL.new(...)
|
||||
for _,d in pairs(...) do
|
||||
@@ -156,20 +161,28 @@ end
|
||||
---Enabling virtual control or not
|
||||
function VCTRL.toggle(toggle)
|
||||
if not toggle then
|
||||
-- Release all buttons to prevent ghost keys
|
||||
-- Release all buttons to prevent button ghost situation
|
||||
for id, b in pairs(touches) do
|
||||
b:release(id)
|
||||
touches[id]=nil
|
||||
touches[id]=nil
|
||||
end
|
||||
end
|
||||
global_toggle=toggle
|
||||
end
|
||||
|
||||
function VCTRL.clearAll()
|
||||
local toggle = global_toggle
|
||||
VCTRL.toggle(false)
|
||||
global_toggle = toggle
|
||||
|
||||
for i=#VCTRL,1,-1 do VCTRL[i] = nil end
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
function VCTRL.press(x,y,id)
|
||||
if not global_toggle then return end
|
||||
local obj,closestDist=false,1e99
|
||||
for i=1,#VCTRL do
|
||||
local w=VCTRL[i]
|
||||
for _, w in ipairs(VCTRL) do
|
||||
if w.show then
|
||||
local d=w:getDistance(x,y)
|
||||
if d<=1 and d<closestDist then
|
||||
@@ -201,13 +214,14 @@ function VCTRL.drag(dx,dy,id)
|
||||
end
|
||||
end
|
||||
|
||||
function VCTRL.draw(forceLight)
|
||||
function VCTRL.draw(forceAlpha)
|
||||
if not global_toggle then return end
|
||||
for i=1,#VCTRL do
|
||||
if VCTRL[i].show then
|
||||
VCTRL[i]:draw(forceLight)
|
||||
end
|
||||
for _, w in ipairs(VCTRL) do
|
||||
if w.show then w:draw(forceAlpha) end
|
||||
end
|
||||
end
|
||||
|
||||
function VCTRL.export(K) return K:export() end
|
||||
function VCTRL.exportAll()
|
||||
local t = {}
|
||||
for o, k in ipairs(VCTRL) do t[o] = k:export() end
|
||||
end
|
||||
Reference in New Issue
Block a user