Update virtual control stuff

This commit is contained in:
SweetSea-ButImNotSweet
2024-04-19 12:53:13 +07:00
parent aefc660dd4
commit cedc6e888e
6 changed files with 96 additions and 81 deletions

View File

@@ -23,7 +23,7 @@ local virtual_quad=setmetatable((function()
empty_quad=gc_newQuad(0,0,1,1,4*w,3*w) empty_quad=gc_newQuad(0,0,1,1,4*w,3*w)
for i,name in next,{ for i,name in next,{
'left','right','up','down', 'left','right','up','down',
'rotate_left','rotate_right','rotate_left2','rotate_right2', 'rotate_right','rotate_left','rotate_right2','rotate_left2',
'menu_deicde','','menu_back' 'menu_deicde','','menu_back'
} do if #name>0 then t[name]=gc_newQuad((i-1)%4*w,math.floor((i-1)/4)*w,w,w,4*w,3*w) end end -- 4x2 is the size of entire texture } do if #name>0 then t[name]=gc_newQuad((i-1)%4*w,math.floor((i-1)/4)*w,w,w,4*w,3*w) end end -- 4x2 is the size of entire texture
return t return t
@@ -134,12 +134,14 @@ function VCTRL.press(x,y,id)
touches[id]=obj touches[id]=obj
obj:press(x,y,id) obj:press(x,y,id)
VCTRL.focus=obj VCTRL.focus=obj
return true
end end
end end
function VCTRL.release(id) function VCTRL.release(id)
if touches[id] then if touches[id] then
touches[id]:release() touches[id]:release()
return true
end end
touches[id]=nil touches[id]=nil
end end

View File

@@ -2,7 +2,7 @@ local bitser = require 'libs.bitser'
local fs = love.filesystem local fs = love.filesystem
function loadSave() function loadSave()
config = loadFromFile(CONFIG_FILE) -- config = loadFromFile(CONFIG_FILE)
end end
function loadFromFile(filename) function loadFromFile(filename)
@@ -13,16 +13,53 @@ function loadFromFile(filename)
end end
function initConfig() function initConfig()
if config.fullscreen == nil then config.fullscreen = false end -- if config.fullscreen == nil then config.fullscreen = false end
if config.music == nil then config.music = true end -- if config.music == nil then config.music = true end
if not config.input then -- if not config.input then
scene = InputConfigScene(true) -- scene = InputConfigScene(true)
else -- else
scene = TitleScene() -- scene = TitleScene()
end -- end
end end
local _config = loadFromFile(CONFIG_FILE) or {}
local _defaultConfig = {
firstTime = true,
fullscreen = false,
music = true,
input = {
keys = {},
mobile = { -- Should not be changed for any reason, used for mobile only
enter = 'menu_decide',
f13 = 'up',
f14 = 'down',
f15 = 'left',
f16 = 'right',
f17 = 'rotate_left',
f18 = 'rotate_left2',
f19 = 'rotate_right',
f20 = 'rotate_right2',
}
}
}
function saveConfig() function saveConfig()
bitser.dumpLoveFile(CONFIG_FILE, config) bitser.dumpLoveFile(CONFIG_FILE, _config)
end end
config = setmetatable(
{},
{
__index = function(_, k)
if _config[k] == nil then _config[k] = _defaultConfig[k] end
return _config[k]
end,
__newindex = function(_, k, v)
_config[k] = v
saveConfig()
end
}
)

View File

@@ -7,7 +7,7 @@ else
end end
require 'funcs' require 'funcs'
DEBUG_showKey=true DEBUG_showKey=false
PENTO_MODE = false PENTO_MODE = false
@@ -27,11 +27,12 @@ function love.load()
require "load.sounds" require "load.sounds"
require "load.save" require "load.save"
require "load.bigint" require "load.bigint"
loadSave()
require "scene" require "scene"
require "game.vctrl" -- VCTRL require "game.vctrl" -- VCTRL
-- love.mouse.setVisible(false) scene = config.firstTime and InputConfigScene() or TitleScene()
love.mouse.setVisible(false)
love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true}); love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true});
GLOBAL_TRANSFORM = love.math.newTransform() GLOBAL_TRANSFORM = love.math.newTransform()
@@ -42,14 +43,22 @@ function love.load()
love.window.setFullscreen(config["fullscreen"]) love.window.setFullscreen(config["fullscreen"])
VCTRL.new{ VCTRL.new{
{type='button',x= 100,y=320,icon= 'up',r=30,iconSize=60,alpha=1}, -- {type='button',x= 100,y=320,key= 'up',icon= 'up',r=35,iconSize=60,alpha=1},
{type='button',x= 160,y=380,icon= 'right',r=30,iconSize=60,alpha=1}, -- {type='button',x= 160,y=380,key='right',icon= 'right',r=35,iconSize=60,alpha=1},
{type='button',x= 100,y=440,icon= 'down',r=30,iconSize=60,alpha=1}, -- {type='button',x= 100,y=440,key= 'down',icon= 'down',r=35,iconSize=60,alpha=1},
{type='button',x= 40,y=380,icon= 'left',r=30,iconSize=60,alpha=1}, -- {type='button',x= 40,y=380,key= 'left',icon= 'left',r=35,iconSize=60,alpha=1},
{type='button',x=640-100,y=320,icon='rotate_right2',r=30,iconSize=60,alpha=1}, -- {type='button',x=640-100,y=320,key= 'f16',icon='rotate_right2',r=35,iconSize=60,alpha=1},
{type='button',x=640-160,y=380,icon= 'rotate_left2',r=30,iconSize=60,alpha=1}, -- {type='button',x=640-160,y=380,key= 'f14',icon= 'rotate_left2',r=35,iconSize=60,alpha=1},
{type='button',x=640-100,y=440,icon= 'rotate_right',r=30,iconSize=60,alpha=1}, -- {type='button',x=640-100,y=440,key= 'f15',icon= 'rotate_right',r=35,iconSize=60,alpha=1},
{type='button',x=640- 40,y=380,icon= 'rotate_left',r=30,iconSize=60,alpha=1}, -- {type='button',x=640- 40,y=380,key= 'f13',icon= 'rotate_left',r=35,iconSize=60,alpha=1},
{type='button',x= 70,y=280,key= 'up',icon= 'up',r=45,iconSize=60,alpha=1},
{type='button',x= 145,y=355,key='right',icon= 'right',r=45,iconSize=60,alpha=1},
{type='button',x= 70,y=430,key= 'down',icon= 'down',r=45,iconSize=60,alpha=1},
{type='button',x= -5,y=355,key= 'left',icon= 'left',r=45,iconSize=60,alpha=1},
{type='button',x=640- 70,y=280,key= 'f16',icon='rotate_right2',r=45,iconSize=60,alpha=1},
{type='button',x=640-145,y=355,key= 'f14',icon= 'rotate_left2',r=45,iconSize=60,alpha=1},
{type='button',x=640- 70,y=430,key= 'f15',icon= 'rotate_right',r=45,iconSize=60,alpha=1},
{type='button',x=640- -5,y=355,key= 'f13',icon= 'rotate_left',r=45,iconSize=60,alpha=1},
} }
end end
@@ -71,9 +80,6 @@ function love.draw()
scene:render() scene:render()
VCTRL.draw() VCTRL.draw()
love.graphics.setLineWidth(3)
love.graphics.rectangle('line',0,0,640,480)
-- -- Grid system -- -- Grid system
-- love.graphics.replaceTransform(GLOBAL_TRANSFORM) -- love.graphics.replaceTransform(GLOBAL_TRANSFORM)
@@ -95,12 +101,25 @@ function love.draw()
end end
end end
function love.mousepressed(x,y,id) local return_scancode, escape_scancode = love.keyboard.getScancodeFromKey('return'), love.keyboard.getScancodeFromKey('escape')
function love.touchpressed(id,x,y)
local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y) local x,y=GLOBAL_TRANSFORM:inverseTransformPoint(x,y)
VCTRL.press(x,y,id) if not VCTRL.press(x,y,id) then
if x >= 320 and x <= 640 then
love.keypressed('escape', escape_scancode)
elseif x >= 0 and x <= 320 then
love.keypressed('return', return_scancode)
end
end
end end
function love.mousereleased(x,y,id) function love.touchreleased(id,x,y)
VCTRL.release(id) if not VCTRL.release(id) then
if x >= 320 and x <= 640 then
love.keyreleased('escape', escape_scancode)
elseif x >= 0 and x <= 320 then
love.keyreleased('return', return_scancode)
end
end
end end
function love.keypressed(key, scancode) function love.keypressed(key, scancode)
@@ -109,12 +128,11 @@ function love.keypressed(key, scancode)
-- global hotkeys -- global hotkeys
if scancode == "f4" then if scancode == "f4" then
config["fullscreen"] = not config["fullscreen"] config["fullscreen"] = not config["fullscreen"]
saveConfig()
love.window.setFullscreen(config["fullscreen"]) love.window.setFullscreen(config["fullscreen"])
elseif scancode == "f2" and scene.title ~= "Input Config" and scene.title ~= "Game" then elseif scancode == "f2" and scene.title ~= "Input Config" and scene.title ~= "Game" then
scene = InputConfigScene() scene = InputConfigScene()
-- function keys are reserved -- function keys are reserved
elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f[1-9][0-9]+$") 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" or scancode == "acback" then
@@ -137,7 +155,7 @@ function love.keyreleased(key, scancode)
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, "^f[1-9][0-9]+$") then elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f1[0-2]+$") then
return return
-- handle all other keys; tab is reserved, but the input config scene keeps it from getting configured as a game input, so pass tab to the scene here -- handle all other keys; tab is reserved, but the input config scene keeps it from getting configured as a game input, so pass tab to the scene here
else else
@@ -201,12 +219,6 @@ function love.joystickaxis(joystick, axis, value)
end end
end end
function love.touchpressed()
love.keyboard.setKeyRepeat(true)
love.keyboard.setTextInput(false)
love.keyboard.setTextInput(true)
end
local last_hat_direction = "" local last_hat_direction = ""
local directions = { local directions = {
["u"] = "up", ["u"] = "up",

View File

@@ -31,17 +31,6 @@ function GameScene:new(player_name, replay_file, replay_grade)
rotate_right2=false, rotate_right2=false,
hold=false, hold=false,
} }
self.inputs_waiting2trigger={ -- Used for buffering the input, in case the input is too fast (1f)
left=false,
right=false,
up=false,
down=false,
rotate_left=false,
rotate_left2=false,
rotate_right=false,
rotate_right2=false,
hold=false,
}
self.paused = false self.paused = false
end end
@@ -53,12 +42,7 @@ function GameScene:update(nosound, tas_update)
end end
end end
for input, value in pairs(self.inputs) do for input, value in pairs(self.inputs) do
if self.inputs_waiting2trigger[input] then inputs[input] = value
inputs[input]=true
self.inputs_waiting2trigger[input]=false
else
inputs[input] = value
end
end end
if tas and tas_update then if tas and tas_update then
self.paused = false self.paused = false
@@ -117,7 +101,6 @@ function GameScene:onInputPress(e)
self.grace_frames = 90 self.grace_frames = 90
elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then
self.inputs[e.input] = true self.inputs[e.input] = true
self.inputs_waiting2trigger[e.input] = true
end end
end end

View File

@@ -31,7 +31,7 @@ local input_names = {
rotate_right='Rotate Clockwise', rotate_right='Rotate Clockwise',
rotate_right2='Rotate Clockwise (2)' rotate_right2='Rotate Clockwise (2)'
} }
local function newSetInputs() local function newSetInputs()
local set_inputs = {} local set_inputs = {}
@@ -73,12 +73,10 @@ function KeyConfigScene:onInputPress(e)
scene = InputConfigScene() scene = InputConfigScene()
elseif self.input_state > table.getn(configurable_inputs) then elseif self.input_state > table.getn(configurable_inputs) then
if e.scancode == "return" then if e.scancode == "return" then
-- save new input, then load next scene
local had_config = config.input ~= nil
if not config.input then config.input = {} end
config.input.keys = self.new_input config.input.keys = self.new_input
saveConfig() saveConfig()
scene = had_config and InputConfigScene() or TitleScene() scene = config.firstTime and TitleScene() or InputConfigScene()
config.firstTime = false
elseif e.scancode == "delete" or e.scancode == "backspace" then elseif e.scancode == "delete" or e.scancode == "backspace" then
-- retry -- retry
self.input_state = 1 self.input_state = 1
@@ -88,7 +86,7 @@ function KeyConfigScene:onInputPress(e)
elseif e.scancode == "tab" then elseif e.scancode == "tab" then
self.set_inputs[configurable_inputs[self.input_state]] = "skipped" self.set_inputs[configurable_inputs[self.input_state]] = "skipped"
self.input_state = self.input_state + 1 self.input_state = self.input_state + 1
elseif e.scancode ~= "escape" and not self.new_input[e.scancode] then elseif not self.new_input[e.scancode] then
-- all other keys can be configured -- all other keys can be configured
self.set_inputs[configurable_inputs[self.input_state]] = "key " .. love.keyboard.getKeyFromScancode(e.scancode) .. " (" .. e.scancode .. ")" self.set_inputs[configurable_inputs[self.input_state]] = "key " .. love.keyboard.getKeyFromScancode(e.scancode) .. " (" .. e.scancode .. ")"
self.new_input[e.scancode] = configurable_inputs[self.input_state] self.new_input[e.scancode] = configurable_inputs[self.input_state]

View File

@@ -28,29 +28,13 @@ function TrainingScene:new()
rotate_right2=false, rotate_right2=false,
hold=false, hold=false,
} }
self.inputs_waiting2trigger={ -- Used for buffering the input, in case the input is too fast (1f)
left=false,
right=false,
up=false,
down=false,
rotate_left=false,
rotate_left2=false,
rotate_right=false,
rotate_right2=false,
hold=false,
}
self.paused = false self.paused = false
end end
function TrainingScene:update() function TrainingScene:update()
local inputs = {} local inputs = {}
for input, value in pairs(self.inputs) do for input, value in pairs(self.inputs) do
if self.inputs_waiting2trigger[input] then inputs[input] = value
inputs[input]=true
self.inputs_waiting2trigger[input]=false
else
inputs[input] = value
end
end end
self.game:update(inputs, self.ruleset) self.game:update(inputs, self.ruleset)
self.game.grid:update() self.game.grid:update()
@@ -67,7 +51,6 @@ function TrainingScene:onInputPress(e)
scene = TitleScene() scene = TitleScene()
elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then
self.inputs[e.input] = true self.inputs[e.input] = true
self.inputs_waiting2trigger[e.input] = true
end end
end end