mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Update of touch configuration scene
This commit is contained in:
@@ -2,22 +2,16 @@
|
||||
local TouchConfigScene = SCENE:extend()
|
||||
TouchConfigScene.title = "Touchscreen config"
|
||||
|
||||
--[[
|
||||
TODO:
|
||||
1. Can import and export data
|
||||
2. Add behaviors
|
||||
]]
|
||||
local Grid = require 'game.grid'
|
||||
|
||||
local buttonList
|
||||
local sliderList
|
||||
---@class VCTRL.data
|
||||
local focusingButton
|
||||
---@type boolean
|
||||
local previewMode
|
||||
---@type boolean
|
||||
local isSelectingButton
|
||||
---@type number
|
||||
local gridSize = 1
|
||||
---@type boolean
|
||||
local hasChanged
|
||||
|
||||
---@type function
|
||||
local exitSceneFunc = function()
|
||||
@@ -37,41 +31,45 @@ buttonList = {
|
||||
end,
|
||||
x = 240, y = 5, w = 90, h = 50,
|
||||
codeWhenReleased = function ()
|
||||
if focusingButton then focusingButton.show = not focusingButton.show end
|
||||
if focusingButton then
|
||||
focusingButton.show = not focusingButton.show
|
||||
hasChanged = true
|
||||
end
|
||||
end,
|
||||
update = function(self) self.textColor = focusingButton and {1, 1, 1} or {0.5, 0.5, 0.5} end
|
||||
},
|
||||
previewToggle = BUTTON.new{
|
||||
text = function ()
|
||||
return string.format("Preview\n[%s]", previewMode and "On" or "Off")
|
||||
end,
|
||||
text = "Preview\nON",
|
||||
x = 520, y = 5, w = 60, h = 50,
|
||||
codeWhenReleased = function() previewMode = not previewMode end
|
||||
codeWhenReleased = function()
|
||||
VCTRL.release()
|
||||
BUTTON.release(buttonList)
|
||||
SCENE = TouchConfigPreviewScene()
|
||||
end
|
||||
},
|
||||
menuScreen = BUTTON.new{
|
||||
text = "MENU",
|
||||
x = 585, y = 5, w = 50, h = 50,
|
||||
codeWhenReleased = function()
|
||||
local selection = love.window.showMessageBox(
|
||||
"Save config?",
|
||||
"Are you sure you want to save your changes?",
|
||||
{
|
||||
"Save", "Discard", "Cont. editing",
|
||||
escapebutton = 2, enterbutton = 1
|
||||
},
|
||||
"info",
|
||||
true
|
||||
)
|
||||
if selection == 1 then
|
||||
SETTINGS.input.virtual = VCTRL.exportAll()
|
||||
love.window.showMessageBox("Saved!", "Your changes was saved!")
|
||||
|
||||
exitSceneFunc()
|
||||
elseif selection == 2 then
|
||||
VCTRL.clearAll()
|
||||
VCTRL.new(SETTINGS.input.virtual)
|
||||
love.window.showMessageBox("Discarded!", "Your changes was discarded!")
|
||||
if hasChanged then
|
||||
local selection = love.window.showMessageBox(
|
||||
"Save config?", "Do you want to save your changes before exiting?",
|
||||
{"Save", "Discard", "Keep editing", escapebutton = 2, enterbutton = 1},
|
||||
"info", true
|
||||
)
|
||||
if selection == 1 then
|
||||
SETTINGS.input.virtual = VCTRL.exportAll()
|
||||
-- love.window.showMessageBox("Saved!", "Your changes was saved!")
|
||||
|
||||
exitSceneFunc()
|
||||
elseif selection == 2 then
|
||||
VCTRL.clearAll()
|
||||
VCTRL.new(SETTINGS.input.virtual)
|
||||
-- love.window.showMessageBox("Discarded!", "Your changes was discarded!")
|
||||
|
||||
exitSceneFunc()
|
||||
end
|
||||
else
|
||||
exitSceneFunc()
|
||||
end
|
||||
end
|
||||
@@ -84,7 +82,10 @@ sliderList.opacity = newSlider(
|
||||
local v
|
||||
if focusingButton then
|
||||
v = math.roundUnit(sliderList.opacity.value, 0.01)
|
||||
focusingButton.alpha = v
|
||||
if focusingButton.alpha~=v then
|
||||
focusingButton.alpha = v
|
||||
hasChanged = true
|
||||
end
|
||||
sliderList.opacity.value = v
|
||||
end
|
||||
end,
|
||||
@@ -95,7 +96,10 @@ sliderList.size = newSlider(
|
||||
function(v)
|
||||
if focusingButton then
|
||||
local v = math.roundUnit(v, 5)
|
||||
focusingButton.r = v
|
||||
if focusingButton.r ~= v then
|
||||
focusingButton.r = v
|
||||
hasChanged = true
|
||||
end
|
||||
sliderList.size.value = v / 120
|
||||
end
|
||||
end,
|
||||
@@ -125,17 +129,24 @@ local function sliderList_draw()
|
||||
end
|
||||
|
||||
local function sliderList_update()
|
||||
local x, y = GLOBAL_TRANSFORM:inverseTransformPoint(love.mouse.getPosition())
|
||||
local x, y
|
||||
if love.mouse.isDown(1) then
|
||||
x, y = GLOBAL_TRANSFORM:inverseTransformPoint(love.mouse.getPosition())
|
||||
elseif #love.touch.getTouches() == 1 then
|
||||
x, y = love.touch.getPosition(love.touch.getTouches()[1])
|
||||
end
|
||||
for _, s in pairs(sliderList) do
|
||||
s:update(x, y)
|
||||
s:update(x, y, x and y)
|
||||
end
|
||||
end
|
||||
|
||||
function TouchConfigScene:new()
|
||||
VCTRL.toggle(true)
|
||||
|
||||
VCTRL.focus = nil
|
||||
focusingButton = nil
|
||||
previewMode = false
|
||||
hasChanged = false
|
||||
Grid:new(10, 20)
|
||||
-- TODO
|
||||
end
|
||||
function TouchConfigScene:update()
|
||||
@@ -153,7 +164,7 @@ end
|
||||
function TouchConfigScene:render()
|
||||
MainBackground()
|
||||
|
||||
if gridSize >= 10 then
|
||||
if gridSize >= 5 then
|
||||
love.graphics.setColor(1,1,1,0.5)
|
||||
love.graphics.setLineWidth(1)
|
||||
-- From 0 to X
|
||||
@@ -181,37 +192,34 @@ function TouchConfigScene:render()
|
||||
-- Snap to grid
|
||||
drawText(string.format("Snap to grid: %3s", gridSize), 340, 10, 140, "left")
|
||||
|
||||
if previewMode then
|
||||
VCTRL.draw()
|
||||
else
|
||||
for _, v in ipairs(VCTRL) do
|
||||
if v ~= focusingButton then
|
||||
v:draw(
|
||||
focusingButton and
|
||||
(v.show and 0.5 or 0.1) or
|
||||
(v.show and 0.5 or 0.25)
|
||||
)
|
||||
end
|
||||
end
|
||||
if focusingButton then
|
||||
focusingButton:draw(
|
||||
math.clamp(
|
||||
math.abs(math.sin(love.timer.getTime()*4)),
|
||||
focusingButton.show and 0.5 or 0.1, 1
|
||||
)
|
||||
for _, v in ipairs(VCTRL) do
|
||||
if v ~= focusingButton then
|
||||
v:draw(
|
||||
focusingButton and
|
||||
(v.show and 0.5 or 0.1) or
|
||||
(v.show and 0.5 or 0.25)
|
||||
)
|
||||
end
|
||||
end
|
||||
if focusingButton then
|
||||
focusingButton:draw(
|
||||
math.clamp(
|
||||
math.abs(math.sin(love.timer.getTime()*4)),
|
||||
focusingButton.show and 0.5 or 0.1, 1
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
sliderList_draw()
|
||||
BUTTON.draw(buttonList)
|
||||
VCTRL.draw()
|
||||
end
|
||||
|
||||
---@param e SCENE_onInput
|
||||
function TouchConfigScene:onInputMove(e)
|
||||
if e.type == "mouse" or e.type == "touch" then
|
||||
if love.mouse.isDown(1) then
|
||||
VCTRL.drag(e.dx, e.dy, e.id or 1)
|
||||
if VCTRL.drag(e.dx, e.dy, e.id or 1) then hasChanged = true end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -237,8 +245,7 @@ end
|
||||
function TouchConfigScene:onInputRelease(e)
|
||||
if e.type == "mouse" or e.type == "touch" then
|
||||
if not BUTTON.release(buttonList, e.x, e.y, e.id) then
|
||||
if focusingButton and VCTRL.release(e.id) then
|
||||
love.window.showMessageBox("Okay","")
|
||||
if focusingButton and VCTRL.release(e.id or 1) then
|
||||
focusingButton.x = math.roundUnit(focusingButton.x, gridSize)
|
||||
focusingButton.y = math.roundUnit(focusingButton.y, gridSize)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user