---@diagnostic disable: cast-local-type local TouchConfigScene = SCENE:extend() TouchConfigScene.title = "Touchscreen config" --[[ TODO: 1. Can import and export data 2. Add behaviors ]] local buttonList local sliderList ---@class VCTRL.data local focusingButton ---@type boolean local previewMode ---@type boolean local isSelectingButton ---@type number local gridSize = 1 ---@type function local exitSceneFunc = function() VCTRL.release() BUTTON.release(buttonList) SCENE = TitleScene() end buttonList = { showToggle = BUTTON.new{ text = function() if focusingButton then return string.format("Show / Hide\n[%s]", focusingButton.show and "Show" or "Hide") else return "Show / Hide\n[----]" end end, x = 240, y = 5, w = 90, h = 50, codeWhenReleased = function () if focusingButton then focusingButton.show = not focusingButton.show 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, x = 520, y = 5, w = 60, h = 50, codeWhenReleased = function() previewMode = not previewMode 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!") exitSceneFunc() end end } } sliderList = {} sliderList.opacity = newSlider( 130, 20-1, 100, 100, 0, 100, function() local v if focusingButton then v = math.roundUnit(sliderList.opacity.value, 0.01) focusingButton.alpha = v sliderList.opacity.value = v end end, {width = 10, knob = 'circle', track = 'roundrect'} ) sliderList.size = newSlider( 130, 40-1, 100, 45, 0, 120, function(v) if focusingButton then local v = math.roundUnit(v, 5) focusingButton.r = v sliderList.size.value = v / 120 end end, {width = 10, knob = 'circle', track = 'roundrect'} ) local gridSizeTable = {1, 2, 5, 10, 20, 50, 100} sliderList.gridSize = newSlider( 400, 40-1, 100, 1, 1, #gridSizeTable - 1, function() local v = math.roundUnit(sliderList.gridSize.value, 1 / 6) sliderList.gridSize.value = v gridSize = gridSizeTable[math.roundUnit(v * (#gridSizeTable - 1) + 1, 1)] end, {width = 10, knob = 'circle', track = 'roundrect'} ); 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 = GLOBAL_TRANSFORM:inverseTransformPoint(love.mouse.getPosition()) for _, s in pairs(sliderList) do s:update(x, y) end end function TouchConfigScene:new() VCTRL.toggle(true) VCTRL.focus = nil focusingButton = nil previewMode = false -- 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 gridSize >= 10 then love.graphics.setColor(1,1,1,0.5) love.graphics.setLineWidth(1) -- From 0 to X for ix=0,math.floor(640 / gridSize) do love.graphics.line(gridSize * ix, 0 , gridSize * ix, 480) end -- From 0 to Y for iy=0,math.floor(480 / gridSize) do love.graphics.line(0, gridSize * iy, 640, gridSize * iy) end end love.graphics.setColor(0, 0, 0, 0.7) -- Opacity and Size love.graphics.rectangle("fill", 10, 5, 227, 50) -- Snap to grid love.graphics.rectangle("fill", 335, 5, 130, 50) -- Opacity drawText("Opacity", 20, 10, 100, "left") drawText(string.format("%3.1d%%", focusingButton and focusingButton.alpha * 100 or 0), 190, 10, 40, "left") -- Size drawText("Size", 20, 30, 100, "left") drawText(string.format("%3.1dpx", focusingButton and focusingButton.r or 0), 190, 30, 40, "left") -- 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 ) ) end end sliderList_draw() BUTTON.draw(buttonList) 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) 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 ~= "virtual" and e.input == 'menu_back' then SCENE = InputConfigScene() end 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 >= 75 and e.x <= 185 and e.y >= 12 and e.y <= 44) ) 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) then love.window.showMessageBox("Okay","") focusingButton.x = math.roundUnit(focusingButton.x, gridSize) focusingButton.y = math.roundUnit(focusingButton.y, gridSize) end end end end return TouchConfigScene