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:
@@ -175,27 +175,27 @@ function Grid:update()
|
||||
end
|
||||
|
||||
function Grid:draw(greyscale, timer)
|
||||
love.graphics.setColor(0,0,0,1)
|
||||
love.graphics.rectangle("fill", 256, 31, 80, 45, 0, 0)
|
||||
love.graphics.setColor(0.3, 0.3, 0.3, 1)
|
||||
love.graphics.line(256,31,256,31+45)
|
||||
love.graphics.line(256,31,256+80,31)
|
||||
love.graphics.line(256+80,31,256+80,31+45)
|
||||
love.graphics.line(256,31+45,256+80,31+45)
|
||||
love.graphics.setColor(0,0,0,1)
|
||||
love.graphics.rectangle("fill", 256, 31, 80, 45, 0, 0)
|
||||
love.graphics.setColor(0.3, 0.3, 0.3, 1)
|
||||
love.graphics.line(256,31,256,31+45)
|
||||
love.graphics.line(256,31,256+80,31)
|
||||
love.graphics.line(256+80,31,256+80,31+45)
|
||||
love.graphics.line(256,31+45,256+80,31+45)
|
||||
for y = 1, self.height do
|
||||
for x = 1, self.width do
|
||||
if BLOCKS[self.grid[y][x].skin] and
|
||||
BLOCKS[self.grid[y][x].skin][self.grid[y][x].colour] then
|
||||
if self.grid[y][x].flash ~= nil then
|
||||
if self.grid[y][x].flash > 0 then
|
||||
love.graphics.setColor(0.4+(self.grid[y][x].flash*0.1), 0.4+(self.grid[y][x].flash*0.1), 0.4+(self.grid[y][x].flash*0.1), 1)
|
||||
love.graphics.draw(BLOCKS[self.grid[y][x].skin]['W'], 200+x*16, 64+y*16)
|
||||
self.grid[y][x].flash = self.grid[y][x].flash - 1
|
||||
else
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.draw(BLOCKS[self.grid[y][x].skin][self.grid[y][x].colour..'_d'], 200+x*16, 64+y*16)
|
||||
end
|
||||
end
|
||||
if self.grid[y][x].flash ~= nil then
|
||||
if self.grid[y][x].flash > 0 then
|
||||
love.graphics.setColor(0.4+(self.grid[y][x].flash*0.1), 0.4+(self.grid[y][x].flash*0.1), 0.4+(self.grid[y][x].flash*0.1), 1)
|
||||
love.graphics.draw(BLOCKS[self.grid[y][x].skin]['W'], 200+x*16, 64+y*16)
|
||||
self.grid[y][x].flash = self.grid[y][x].flash - 1
|
||||
else
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.draw(BLOCKS[self.grid[y][x].skin][self.grid[y][x].colour..'_d'], 200+x*16, 64+y*16)
|
||||
end
|
||||
end
|
||||
if greyscale then
|
||||
if timer > 1 then timer = 1 end
|
||||
love.graphics.setColor(0.7, 0.7, 0.7, 0+timer)
|
||||
|
||||
@@ -177,7 +177,7 @@ end
|
||||
|
||||
---@param force? boolean Forcing click on hidden widgets?
|
||||
function VCTRL.press(x,y,id,force)
|
||||
if not global_toggle then return end
|
||||
if not (global_toggle and id) then return end
|
||||
local obj,closestDist=false,1e99
|
||||
for _, w in ipairs(VCTRL) do
|
||||
if w.show or force then
|
||||
@@ -196,7 +196,7 @@ function VCTRL.press(x,y,id,force)
|
||||
end
|
||||
|
||||
function VCTRL.release(id)
|
||||
if not global_toggle then return end
|
||||
if not (global_toggle and id) then return end
|
||||
if touches[id] then
|
||||
touches[id]:release()
|
||||
touches[id]=nil
|
||||
|
||||
@@ -41,6 +41,7 @@ NameEntryScene = require "scene.name_entry"
|
||||
KeyConfigScene = require "scene.key_config"
|
||||
StickConfigScene = require "scene.stick_config"
|
||||
TouchConfigScene = require "scene.touch_config"
|
||||
TouchConfigPreviewScene = require "scene.touch_config_preview"
|
||||
InputConfigScene = require "scene.input_config"
|
||||
|
||||
ReplaySelectScene = require "scene.replay"
|
||||
|
||||
@@ -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
|
||||
|
||||
93
scene/touch_config_preview.lua
Normal file
93
scene/touch_config_preview.lua
Normal file
@@ -0,0 +1,93 @@
|
||||
local TouchConfigPreviewScene = SCENE:extend()
|
||||
TouchConfigPreviewScene.title = "Touchscreen config (Preview)"
|
||||
|
||||
local Grid = require 'game.grid'
|
||||
local GameMode = require 'game.gamemode'
|
||||
|
||||
local buttonList
|
||||
buttonList = {
|
||||
previewToggle = BUTTON.new{
|
||||
text = "Preview\nOFF",
|
||||
x = 520, y = 5, w = 60, h = 50,
|
||||
codeWhenReleased = function()
|
||||
VCTRL.release()
|
||||
BUTTON.release(buttonList)
|
||||
SCENE = TouchConfigScene()
|
||||
end
|
||||
},
|
||||
}
|
||||
local sliderList = {}
|
||||
|
||||
local secret_grade_grid = {}
|
||||
do
|
||||
local colour_names = {'R', 'O', 'Y', 'G', 'C', 'B', 'M'}
|
||||
local color_blocks = {E = {colour = "", flash = 0, skin = "2tie"}}
|
||||
for _, v in pairs(colour_names) do
|
||||
color_blocks[v] = {colour = v, flash = 0, skin = "2tie"}
|
||||
end
|
||||
|
||||
for y = 20, 1, -1 do
|
||||
local hole_pos = (y > 10 and 21 - y) or (y > 1 and y - 1) or 2
|
||||
local current_colour_name = colour_names[(20 - y)%7+1]
|
||||
local row = {}
|
||||
for x = 1, 10 do
|
||||
if x == hole_pos then
|
||||
row[x] = color_blocks.E
|
||||
else
|
||||
row[x] = color_blocks[current_colour_name]
|
||||
end
|
||||
end
|
||||
secret_grade_grid[y] = row
|
||||
end
|
||||
end
|
||||
|
||||
function TouchConfigPreviewScene:new()
|
||||
VCTRL.toggle(true)
|
||||
|
||||
VCTRL.focus = nil
|
||||
Grid:new(10, 20)
|
||||
Grid.grid = secret_grade_grid
|
||||
-- TODO
|
||||
end
|
||||
function TouchConfigPreviewScene:update()
|
||||
BUTTON.update(buttonList)
|
||||
end
|
||||
|
||||
function TouchConfigPreviewScene:render()
|
||||
if not BACKGROUNDS[0]:isPlaying() then
|
||||
BACKGROUNDS[0]:play()
|
||||
end
|
||||
if BACKGROUNDS[0]:tell() >= 0.5 then
|
||||
BACKGROUNDS[0]:rewind()
|
||||
end
|
||||
love.graphics.setColor(0.7, 0.7, 0.7)
|
||||
love.graphics.draw(BACKGROUNDS[0])
|
||||
|
||||
GameMode.drawFrame{grid = {width = 10, height = 20}}
|
||||
Grid:draw(false, 1)
|
||||
|
||||
BUTTON.draw(buttonList)
|
||||
VCTRL.draw()
|
||||
end
|
||||
|
||||
---@param e SCENE_onInput
|
||||
function TouchConfigPreviewScene:onInputMove(e)
|
||||
if e.type == "mouse" then
|
||||
BUTTON.checkHovering(buttonList, e.x, e.y)
|
||||
end
|
||||
end
|
||||
---@param e SCENE_onInput
|
||||
function TouchConfigPreviewScene:onInputPress(e)
|
||||
if e.type ~= "virtual" and e.input == 'menu_back' then SCENE = InputConfigScene() end
|
||||
if e.type == "mouse" or e.type == "touch" then
|
||||
BUTTON.press(buttonList, e.x, e.y, e.id)
|
||||
end
|
||||
end
|
||||
---@param e SCENE_onInput
|
||||
function TouchConfigPreviewScene:onInputRelease(e)
|
||||
if e.type == "mouse" or e.type == "touch" then
|
||||
BUTTON.release(buttonList, e.x, e.y, e.id)
|
||||
end
|
||||
end
|
||||
|
||||
return TouchConfigPreviewScene
|
||||
Reference in New Issue
Block a user