---@diagnostic disable: cast-local-type local TouchConfigScene = SCENE:extend() TouchConfigScene.title = "Touchscreen config" local Grid = require 'game.grid' local buttonList local sliderList ---@class VCTRL.data local focusingButton ---@type number local snapUnit = 1 ---@type boolean local hasChanged ---@type function local function exitSceneFunc(saved) VCTRL.release() BUTTON.release(buttonList) if SETTINGS.firstTime and not saved then SCENE = InputConfigScene(true) else SCENE = TitleScene() SETTINGS.firstTime = false end end buttonList = { showToggle = BUTTON.new{ text = function() if focusingButton then return focusingButton.show and "[SHOW]\nHide" or "Show\n[HIDE]" else return "Show\nHide" end end, x = 275, y = 5, w = 50, h = 75, codeWhenReleased = function () 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 = "Preview\nON", x = 570, y = 35, w = 60, h = 40, codeWhenReleased = function() VCTRL.release() BUTTON.release(buttonList) SCENE = TouchConfigPreviewScene() end }, menuScreen = BUTTON.new{ text = "MENU", x = 570, y = 5, w = 60, h = 25, codeWhenReleased = function() if hasChanged or SETTINGS.firstTime 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(true) 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 } } sliderList = {} sliderList.opacity = newSlider( 155, 20+5, 120, 100, 0, 100, function() local v if focusingButton then v = math.roundUnit(sliderList.opacity.value, 0.01) if focusingButton.alpha~=v then focusingButton.alpha = v hasChanged = true end sliderList.opacity.value = v end end, {width = 30} ) sliderList.size = newSlider( 155, 60+2.5, 120, 45, 0, 120, function(v) if focusingButton then local v = math.roundUnit(v, 5) if focusingButton.r ~= v then focusingButton.r = v hasChanged = true end sliderList.size.value = v / 120 end end, {width = 30} ) local gridSizeTable = {1, 2, 5, 10, 20, 50, 100} sliderList.gridSize = newSlider( 405, 50, 100, 1, 1, #gridSizeTable - 1, function() local v = math.roundUnit(sliderList.gridSize.value, 1 / 6) sliderList.gridSize.value = v snapUnit = gridSizeTable[math.roundUnit(v * (#gridSizeTable - 1) + 1)] end, {width = 30} ); sliderList.gridSize.forceLight = true local function sliderList_draw() for _, s in pairs(sliderList) do if s.forceLight then love.graphics.setColor(1, 1, 1) else love.graphics.setColor(focusingButton and {1, 1, 1} or {0.5, 0.5, 0.5}) end love.graphics.setLineWidth(1) s:draw() end end local function sliderList_update() local x, y if #love.touch.getTouches() == 1 then x, y = GLOBAL_TRANSFORM:inverseTransformPoint(love.touch.getPosition(love.touch.getTouches()[1])) else x, y = GLOBAL_TRANSFORM:inverseTransformPoint(love.mouse.getPosition()) end for _, s in pairs(sliderList) do s:update(x, y, #love.touch.getTouches() == 1 or love.mouse.isDown(1)) end end function TouchConfigScene:new(fromPreviewScene) VCTRL.toggle(true) VCTRL.focus = nil focusingButton = nil hasChanged = fromPreviewScene Grid:new(10, 20) -- TODO end function TouchConfigScene:update() -- TODO if VCTRL.focus~=focusingButton then focusingButton = VCTRL.focus sliderList.opacity.value = focusingButton.alpha sliderList.size.value = focusingButton.r / 120 end BUTTON.update(buttonList) sliderList_update() end function TouchConfigScene:render() MainBackground() if snapUnit >= 5 then local x1, y1 = GLOBAL_TRANSFORM:inverseTransformPoint(0, 0) local x2, y2 = GLOBAL_TRANSFORM:inverseTransformPoint(love.graphics.getDimensions()) love.graphics.setColor(1,1,1,math.sin(love.timer.getTime()*4)*.1+.25) love.graphics.setLineWidth(1) -- From 0 to X for i=x1, x2+snapUnit, snapUnit do local x = i - i % snapUnit love.graphics.line(x, y1, x, y2) end -- From 0 to Y for i=y1,y2+snapUnit,snapUnit do local y= i - i % snapUnit love.graphics.line(x1, y, x2, y) end end love.graphics.setColor(0, 0, 0, 0.7) -- Opacity and Size love.graphics.rectangle("fill", 10, 5, 267, 75) -- Snap to grid love.graphics.rectangle("fill", 330, 5, 150, 75) -- Opacity drawText("Opacity", 20, 15, 100, "left") drawText(string.format("%3.1d%%", focusingButton and focusingButton.alpha * 100 or 0), 225, 15, 40, "left") -- Size drawText("Size", 20, 55, 100, "left") drawText(string.format("%3.1dpx", focusingButton and focusingButton.r or 0), 225, 55, 40, "left") -- Snap to grid drawText(string.format("Snap to grid: %3s", snapUnit), 345, 15, 140, "left") 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 1 or 0.5) ) end end if focusingButton then focusingButton:draw( math.clamp( math.sin(love.timer.getTime()*4)*.5+0.1, focusingButton.show and 1 or 0.1, 1 ) ) end sliderList_draw() BUTTON.draw(buttonList) end ---@param e SCENE_onInput function TouchConfigScene:onInputMove(e) if e.type == "touch" or (e.type == "mouse" and love.mouse.isDown(1)) then if VCTRL.drag(e.dx, e.dy, e.id or 1) then hasChanged = true end end if e.type == "mouse" then BUTTON.checkHovering(buttonList, e.x, e.y) end end ---@param e SCENE_onInput function TouchConfigScene:onInputPress(e) if e.type == "mouse" or e.type == "touch" then if not ( VCTRL.press(e.x, e.y, e.id and e.id or 1, true) or BUTTON.press(buttonList, e.x, e.y, e.id) or (e.x >= 80 and e.x <= 230 and e.y >= 10 and e.y <= 77) ) then VCTRL.focus = nil focusingButton = nil end end end ---@param e SCENE_onInput 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 or 1) then focusingButton.x = math.roundUnit(focusingButton.x, snapUnit) focusingButton.y = math.roundUnit(focusingButton.y, snapUnit) end end end end return TouchConfigScene