mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Small changes on how virtual key call action
This commit is contained in:
@@ -24,12 +24,13 @@ local virtual_quad=setmetatable((function()
|
|||||||
for i,name in next,{
|
for i,name in next,{
|
||||||
'left','right','up','down','',
|
'left','right','up','down','',
|
||||||
'rotate_right','rotate_left','','','',
|
'rotate_right','rotate_left','','','',
|
||||||
'menu_deicde','','menu_back','','',
|
|
||||||
'','','','','',
|
'','','','','',
|
||||||
'','','back','','',
|
|
||||||
'','','','','',
|
'','','','','',
|
||||||
'','','','','select',
|
'','','menu_back','','',
|
||||||
|
'','','','','',
|
||||||
|
'','','','','menu_decide',
|
||||||
} do if #name>0 then t[name]=gc_newQuad((i-1)%5*w,math.floor((i-1)/5)*w,w,w,5*w,7*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,7*w) end end
|
||||||
|
t.rotate_right2, t.rotate_left2 = t.rotate_right, t.rotate_left
|
||||||
return t
|
return t
|
||||||
end)(),{
|
end)(),{
|
||||||
__index=function() return empty_quad end
|
__index=function() return empty_quad end
|
||||||
@@ -52,7 +53,7 @@ function control_type.button:new(data)
|
|||||||
key=data.key or 'X',
|
key=data.key or 'X',
|
||||||
iconSize=data.iconSize or 80,
|
iconSize=data.iconSize or 80,
|
||||||
alpha=data.alpha or 0.75,
|
alpha=data.alpha or 0.75,
|
||||||
quad=virtual_quad[data.icon]
|
quad=virtual_quad[data.key]
|
||||||
},self)
|
},self)
|
||||||
end
|
end
|
||||||
function control_type.button:reset()
|
function control_type.button:reset()
|
||||||
@@ -62,11 +63,13 @@ end
|
|||||||
function control_type.button:press()
|
function control_type.button:press()
|
||||||
self.pressed=true
|
self.pressed=true
|
||||||
self.lastPressTime=love.timer.getTime()
|
self.lastPressTime=love.timer.getTime()
|
||||||
love.keypressed(self.key, love.keyboard.getScancodeFromKey(self.key))
|
-- love.keypressed(self.key, love.keyboard.getScancodeFromKey(self.key))
|
||||||
|
SCENE:onInputPress{input=self.key,type="virtual"}
|
||||||
end
|
end
|
||||||
function control_type.button:release()
|
function control_type.button:release()
|
||||||
self.pressed=false
|
self.pressed=false
|
||||||
love.keyreleased(self.key,love.keyboard.getScancodeFromKey(self.key))
|
-- love.keyreleased(self.key,love.keyboard.getScancodeFromKey(self.key))
|
||||||
|
SCENE:onInputRelease{input=self.key,type="virtual"}
|
||||||
end
|
end
|
||||||
function control_type.button:drag(dx,dy)
|
function control_type.button:drag(dx,dy)
|
||||||
self.x,self.y=self.x+dx,self.y+dy
|
self.x,self.y=self.x+dx,self.y+dy
|
||||||
@@ -74,12 +77,18 @@ end
|
|||||||
function control_type.button:draw(forceLight)
|
function control_type.button:draw(forceLight)
|
||||||
love.graphics.setLineWidth(4)
|
love.graphics.setLineWidth(4)
|
||||||
if self.shape=='circle' then
|
if self.shape=='circle' then
|
||||||
|
love.graphics.setColor(0,0,0,self.alpha*0.5)
|
||||||
|
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 .05)
|
||||||
love.graphics.circle('fill',self.x,self.y,self.r-4)
|
love.graphics.circle('fill',self.x,self.y,self.r-4)
|
||||||
|
|
||||||
love.graphics.setColor(1,1,1)
|
love.graphics.setColor(1,1,1)
|
||||||
love.graphics.circle('line',self.x,self.y,self.r-2)
|
love.graphics.circle('line',self.x,self.y,self.r-2)
|
||||||
elseif self.shape=='square' then
|
elseif self.shape=='square' then
|
||||||
|
love.graphics.setColor(0,0,0,self.alpha*0.5)
|
||||||
|
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 .05)
|
||||||
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
|
love.graphics.rectangle('fill',self.x-self.r-4,self.y-self.r-4,self.r*2+8,self.r*2+8)
|
||||||
|
|
||||||
@@ -125,6 +134,7 @@ end
|
|||||||
---@field key string
|
---@field key string
|
||||||
---@field iconSize number
|
---@field iconSize number
|
||||||
---@field alpha number
|
---@field alpha number
|
||||||
|
---@field show boolean
|
||||||
---Adding (multiple) virtual button(s)
|
---Adding (multiple) virtual button(s)
|
||||||
function VCTRL.new(...)
|
function VCTRL.new(...)
|
||||||
for _,d in pairs(...) do
|
for _,d in pairs(...) do
|
||||||
|
|||||||
80
main.lua
80
main.lua
@@ -66,23 +66,25 @@ function love.load()
|
|||||||
|
|
||||||
SCENE = SETTINGS.firstTime and InputConfigScene(true) or TitleScene()
|
SCENE = SETTINGS.firstTime and InputConfigScene(true) or TitleScene()
|
||||||
VCTRL.toggle(love.system.getOS()=='Android' or true)
|
VCTRL.toggle(love.system.getOS()=='Android' or true)
|
||||||
VCTRL.new{
|
VCTRL.new{ -- up down left right --- right left down up
|
||||||
-- {type='button',x= 100,y=320,key= 'up',icon= 'up',r=35,iconSize=60,alpha=0.75},
|
-- {type='button',x= 100,y=320,key= 'up',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x= 160,y=380,key='right',icon= 'right',r=35,iconSize=60,alpha=0.75},
|
-- {type='button',x= 100,y=440,key= 'down',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x= 100,y=440,key= 'down',icon= 'down',r=35,iconSize=60,alpha=0.75},
|
-- {type='button',x= 40,y=380,key= 'left',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x= 40,y=380,key= 'left',icon= 'left',r=35,iconSize=60,alpha=0.75},
|
-- {type='button',x= 160,y=380,key= 'right',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x=640-100,y=320,key= 'f16',icon='rotate_right2',r=35,iconSize=60,alpha=0.75},
|
-- {type='button',x=640- 40,y=380,key= 'rotate_left',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x=640-160,y=380,key= 'f14',icon= 'rotate_left2',r=35,iconSize=60,alpha=0.75},
|
-- {type='button',x=640-160,y=380,key= 'rotate_left2',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x=640-100,y=440,key= 'f15',icon= 'rotate_right',r=35,iconSize=60,alpha=0.75},
|
-- {type='button',x=640-100,y=440,key= 'rotate_right',r=35,iconSize=60,alpha=0.75},
|
||||||
-- {type='button',x=640- 40,y=380,key= 'f13',icon= 'rotate_left',r=35,iconSize=60,alpha=0.75},
|
-- {type='button',x=640-100,y=320,key='rotate_right2',r=35,iconSize=60,alpha=0.75},
|
||||||
{type='button',x= 70,y=280,key= 'up',icon= 'up',r=45,iconSize=60,alpha=0.75},
|
{type='button',x= 70,y=280,key= 'up',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x= 145,y=355,key='right',icon= 'right',r=45,iconSize=60,alpha=0.75},
|
{type='button',x= 70,y=430,key= 'down',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x= 70,y=430,key= 'down',icon= 'down',r=45,iconSize=60,alpha=0.75},
|
{type='button',x= -5,y=355,key= 'left',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x= -5,y=355,key= 'left',icon= 'left',r=45,iconSize=60,alpha=0.75},
|
{type='button',x= 145,y=355,key= 'right',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x=640- 70,y=280,key= 'f16',icon='rotate_right2',r=45,iconSize=60,alpha=0.75},
|
{type='button',x=640- -5,y=355,key= 'rotate_left',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x=640-145,y=355,key= 'f14',icon= 'rotate_left2',r=45,iconSize=60,alpha=0.75},
|
{type='button',x=640-145,y=355,key= 'rotate_left2',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x=640- 70,y=430,key= 'f15',icon= 'rotate_right',r=45,iconSize=60,alpha=0.75},
|
{type='button',x=640- 70,y=430,key= 'rotate_right',r=45,iconSize=60,alpha=0.75},
|
||||||
{type='button',x=640- -5,y=355,key= 'f13',icon= 'rotate_left',r=45,iconSize=60,alpha=0.75},
|
{type='button',x=640- 70,y=280,key='rotate_right2',r=45,iconSize=60,alpha=0.75},
|
||||||
|
{type='button',x=320- 40,y=420,key= 'menu_decide',r=35,iconSize=60,alpha=0.75},
|
||||||
|
{type='button',x=320+ 40,y=420,key= 'menu_back',r=35,iconSize=60,alpha=0.75},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -105,47 +107,39 @@ function love.draw()
|
|||||||
VCTRL.draw()
|
VCTRL.draw()
|
||||||
|
|
||||||
-- -- Grid system
|
-- -- Grid system
|
||||||
|
-- local grid_width, grid_height = 40, 20
|
||||||
-- love.graphics.replaceTransform(GLOBAL_TRANSFORM)
|
-- love.graphics.replaceTransform(GLOBAL_TRANSFORM)
|
||||||
|
|
||||||
-- love.graphics.setColor(1,1,1,0.5)
|
-- love.graphics.setColor(1,1,1,0.5)
|
||||||
-- love.graphics.setLineWidth(1)
|
-- love.graphics.setLineWidth(1)
|
||||||
-- -- From 0 to X
|
-- -- From 0 to X
|
||||||
-- for ix=1,math.floor(64) do
|
-- for ix=0,math.floor(640 / grid_width) do
|
||||||
-- love.graphics.line(10*ix,0,10*ix,480)
|
-- love.graphics.line(grid_width * ix, 0 , grid_width * ix, 480)
|
||||||
-- end
|
-- end
|
||||||
-- -- From 0 to Y
|
-- -- From 0 to Y
|
||||||
-- for iy=1,math.floor(48) do
|
-- for iy=0,math.floor(480 / grid_height) do
|
||||||
-- love.graphics.line(0,10*iy,640,10*iy)
|
-- love.graphics.line(0, grid_height * iy, 640, grid_height * iy)
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
if DEBUG_showKey then
|
-- drawText(
|
||||||
drawText(
|
-- "Pressed: "..(LastPressedKey or '[NONE]').." | Released: "..(LastReleasedKey or '[NONE]'),
|
||||||
"Pressed: "..(LastPressedKey or '[NONE]').." | Released: "..(LastReleasedKey or '[NONE]'),
|
-- 0,0,1000,"left"
|
||||||
0,0,1000,"left"
|
-- )
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
end
|
end
|
||||||
|
|
||||||
local return_scancode, escape_scancode = love.keyboard.getScancodeFromKey('return'), love.keyboard.getScancodeFromKey('escape')
|
|
||||||
function love.touchpressed(id,x,y)
|
function love.touchpressed(id,x,y)
|
||||||
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
|
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
|
||||||
if not VCTRL.press(x,y,id) then
|
if not VCTRL.press(x,y,id) then
|
||||||
if x >= 320 and x <= 640 then
|
SCENE:onInputPress{type = "touch", x = x, y = y, dx = 0, dy = 0, id = id}
|
||||||
love.keypressed('escape', escape_scancode)
|
|
||||||
elseif x >= 0 and x <= 320 then
|
|
||||||
love.keypressed('return', return_scancode)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function love.touchreleased(id,x,y)
|
function love.touchreleased(id,x,y)
|
||||||
|
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
|
||||||
if not VCTRL.release(id) then
|
if not VCTRL.release(id) then
|
||||||
if x >= 320 and x <= 640 then
|
SCENE:onInputPress{type = "touch", x = x, y = y, dx = 0, dy = 0, id = id}
|
||||||
love.keyreleased('escape', escape_scancode)
|
|
||||||
elseif x >= 0 and x <= 320 then
|
|
||||||
love.keyreleased('return', return_scancode)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -162,14 +156,14 @@ function love.keypressed(key, scancode)
|
|||||||
elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then
|
elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then
|
||||||
return
|
return
|
||||||
-- escape is reserved for menu_back
|
-- escape is reserved for menu_back
|
||||||
elseif scancode == "escape" or scancode == "acback" then
|
elseif scancode == "escape" then
|
||||||
SCENE:onInputPress({input="menu_back", type="key", key=key, scancode=scancode})
|
SCENE:onInputPress{input="menu_back", type="key", key=key, scancode=scancode}
|
||||||
-- pass any other key to the scene, with its configured mapping
|
-- pass any other key to the scene, with its configured mapping
|
||||||
else
|
else
|
||||||
if SETTINGS.input and SETTINGS.input.keys then
|
if SETTINGS.input and SETTINGS.input.keys then
|
||||||
input_pressed = SETTINGS.input.keys[scancode]
|
input_pressed = SETTINGS.input.keys[scancode]
|
||||||
end
|
end
|
||||||
SCENE:onInputPress({input=input_pressed, type="key", key=key, scancode=scancode})
|
SCENE:onInputPress{input=input_pressed, type="key", key=key, scancode=scancode}
|
||||||
end
|
end
|
||||||
|
|
||||||
LastPressedKey = input_pressed or scancode
|
LastPressedKey = input_pressed or scancode
|
||||||
@@ -180,7 +174,7 @@ function love.keyreleased(key, scancode)
|
|||||||
|
|
||||||
-- escape is reserved for menu_back
|
-- escape is reserved for menu_back
|
||||||
if scancode == "escape" or scancode == 'acback' then
|
if scancode == "escape" or scancode == 'acback' then
|
||||||
SCENE:onInputRelease({input="menu_back", type="key", key=key, scancode=scancode})
|
SCENE:onInputRelease{input="menu_back", type="key", key=key, scancode=scancode}
|
||||||
-- function keys are reserved
|
-- function keys are reserved
|
||||||
elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then
|
elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then
|
||||||
return
|
return
|
||||||
@@ -189,7 +183,7 @@ function love.keyreleased(key, scancode)
|
|||||||
if SETTINGS.input and SETTINGS.input.keys then
|
if SETTINGS.input and SETTINGS.input.keys then
|
||||||
input_released = SETTINGS.input.keys[scancode]
|
input_released = SETTINGS.input.keys[scancode]
|
||||||
end
|
end
|
||||||
SCENE:onInputRelease({input=input_released, type="key", key=key, scancode=scancode})
|
SCENE:onInputRelease{input=input_released, type="key", key=key, scancode=scancode}
|
||||||
end
|
end
|
||||||
|
|
||||||
LastReleasedKey = input_released or scancode
|
LastReleasedKey = input_released or scancode
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ require 'settings'
|
|||||||
|
|
||||||
function GameScene:new(player_name, replay_file, replay_grade)
|
function GameScene:new(player_name, replay_file, replay_grade)
|
||||||
game_mode = require 'game.gamemode'
|
game_mode = require 'game.gamemode'
|
||||||
|
|
||||||
|
VCTRL[9].show = false; VCTRL[10].show = false -- Hide SELECT and QUIT button
|
||||||
if PENTO_MODE then
|
if PENTO_MODE then
|
||||||
ruleset = require 'game.rotation_pent'
|
ruleset = require 'game.rotation_pent'
|
||||||
else
|
else
|
||||||
ruleset = require 'game.rotation'
|
ruleset = require 'game.rotation'
|
||||||
end
|
end
|
||||||
|
|
||||||
self.retry_mode = game_mode
|
self.retry_mode = game_mode
|
||||||
self.retry_ruleset = ruleset
|
self.retry_ruleset = ruleset
|
||||||
self.secret_inputs = inputs
|
self.secret_inputs = inputs
|
||||||
@@ -60,6 +63,9 @@ function GameScene:update(nosound, tas_update)
|
|||||||
if not self.paused then
|
if not self.paused then
|
||||||
self.game:update(inputs, self.ruleset)
|
self.game:update(inputs, self.ruleset)
|
||||||
end
|
end
|
||||||
|
if self.game.input_playback or self.game.game_over or self.game.game_completed then
|
||||||
|
VCTRL[9].show = true; VCTRL[10].show = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameScene:render()
|
function GameScene:render()
|
||||||
|
|||||||
@@ -1,42 +1,8 @@
|
|||||||
local TouchConfigScene = SCENE:extend()
|
local TouchConfigScene = SCENE:extend()
|
||||||
TouchConfigScene.title = "Touchscreen config\n(you can tap anywhere on touch screen to select this)"
|
TouchConfigScene.title = "Touchscreen config\n(you can tap anywhere on touch screen to select this)"
|
||||||
|
|
||||||
local origin_touchPressed, origin_touchReleased, origin_touchMoved
|
|
||||||
|
|
||||||
local function onPressed(id, x, y)
|
|
||||||
if not VCTRL.press(x, y, id) then
|
|
||||||
-- TODO
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local function onMoved(id, _, _, dx, dy)
|
|
||||||
VCTRL.drag(dx, dy, id)
|
|
||||||
end
|
|
||||||
local function onReleased(id)
|
|
||||||
if not VCTRL.release(id) then
|
|
||||||
-- TODO
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function TouchConfigScene:new()
|
function TouchConfigScene:new()
|
||||||
-- TODO
|
-- TODO
|
||||||
-- Temproraily hijacking game's touch-related functions
|
|
||||||
origin_touchPressed, origin_touchReleased, origin_touchMoved = love.touchpressed, love.touchreleased, love.touchmoved
|
|
||||||
|
|
||||||
SETTINGS.input.keys = table.merge(
|
|
||||||
SETTINGS.input.keys,
|
|
||||||
{
|
|
||||||
enter = 'menu_decide',
|
|
||||||
acback = 'menu_back',
|
|
||||||
f13 = 'up',
|
|
||||||
f14 = 'down',
|
|
||||||
f15 = 'left',
|
|
||||||
f16 = 'right',
|
|
||||||
f17 = 'rotate_left',
|
|
||||||
f18 = 'rotate_left2',
|
|
||||||
f19 = 'rotate_right',
|
|
||||||
f20 = 'rotate_right2',
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
function TouchConfigScene:update()
|
function TouchConfigScene:update()
|
||||||
-- TODO
|
-- TODO
|
||||||
@@ -46,8 +12,8 @@ function TouchConfigScene:render()
|
|||||||
MainBackground()
|
MainBackground()
|
||||||
end
|
end
|
||||||
|
|
||||||
function TouchConfigScene:onQuit()
|
function TouchConfigScene:onInputPress(e)
|
||||||
love.touchpressed, love.touchreleased, love.touchmoved = origin_touchPressed, origin_touchReleased, origin_touchMoved
|
if e.key == 'menu_back' then SCENE = TitleScene() end
|
||||||
end
|
end
|
||||||
|
|
||||||
return TouchConfigScene
|
return TouchConfigScene
|
||||||
Reference in New Issue
Block a user