diff --git a/libs/simple-button.lua b/libs/simple-button.lua index a26c1a2..d262e1e 100644 --- a/libs/simple-button.lua +++ b/libs/simple-button.lua @@ -93,6 +93,7 @@ function button:draw() end ---Check if current position is hovering the button, if yes, set ``self._hovering`` to true and return true function button:isHovering(x,y) + if not y then self._hovering = false; return false end if x >= self.x and y >= self.y and @@ -111,7 +112,10 @@ function button:press() end ---Trigger release action, don't need ``self._hovering`` to ``true`` function button:release() - self.codeWhenReleased() + if self._hovering then + self.codeWhenReleased() + self._hovering = false + end end @@ -122,18 +126,19 @@ local BUTTON = {} ---@return nil ---Validate the provided data, will be called by ``BUTTON.new`` and ``BUTTON.setDefaultOption``
---***WARNING! THIS FUNCTION WILL RAISE EXCEPTION IF DATA IS INVALID!*** -function BUTTON.checkDataValidation(D) - -- - assert(type(D.text) == "string" == "string","[text] is missing, or you just passed an empty data?") - - assert(type(D.x) == "number" , "[x] must be a integer") - assert(type(D.y) == "number" , "[y] must be a integer") - assert(type(D.w) == "number" and D.w > 0, "[w] must be a positive integer") - assert(type(D.h) == "number" and D.h > 0, "[h] must be a positive integer") - -- +function BUTTON.checkDataValidation(D, safe) + if not safe then + assert(type(D.text) == "string","[text] is missing, or you just passed an empty data?") + + assert(type(D.x) == "number" , "[x] must be a integer") + assert(type(D.y) == "number" , "[y] must be a integer") + assert(type(D.w) == "number" and D.w > 0, "[w] must be a positive integer") + assert(type(D.h) == "number" and D.h > 0, "[h] must be a positive integer") + assert((type(D.r) == "number" and D.r >= 0 and D.r <= D.w * 0.5 and D.r <= D.h * 0.5) or D.r == nil, "[r] must be a positive integer and cannot larger than half of button's width and half of button's height") + else + assert(type(D.r) == "number" and D.r >= 0 or D.r == nil, "[r] must be a positive integer (CAUTION: a extra condition is temproraily ignored because you are setting default option)") + end assert(table.contains({"center","justify","left","right"}, D.textOrientation) or D.textOrientation == nil, "[borderJoin] must be 'bevel', 'miter' or 'none") - - assert((type(D.r) == "number" and D.r >= 0 and D.r <= D.w * 0.5 and D.r <= D.h * 0.5) or D.r == nil, "[r] must be a positive integer and cannot larger than half of button's width and half of button's height") assert((type(D.borderWidth) == "number" and D.borderWidth > 0) or D.borderWidth == nil, "[borderWidth] must be a postive integer") assert(table.contains({"bevel", "miter", "none"}, D.borderJoin) or D.borderJoin == nil, "[borderJoin] must be 'bevel', 'miter' or 'none") assert(table.contains({"rough", "smooth"}, D.borderStyle) or D.borderStyle == nil, "[borderStyle] must be 'rough' or 'smooth'") diff --git a/main.lua b/main.lua index ad177ea..677a606 100644 --- a/main.lua +++ b/main.lua @@ -22,7 +22,6 @@ LOADING_IMAGE_FILE = love.graphics.newImage('res/loading.png') --- Show the loading text while we are loading resources
--- **WARNING**: should only be used while loading the game! function ShowLoadingText(thing) - love.graphics.replaceTransform(GLOBAL_TRANSFORM) love.graphics.setFont(love.graphics.newFont(20)) love.graphics.clear() diff --git a/scene/input_config.lua b/scene/input_config.lua index da66dbc..a382a10 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -28,11 +28,11 @@ function ConfigScene:render() end love.graphics.setColor(1, 1, 1, 0.5) - love.graphics.rectangle("fill", 75, 118 + 50 * self.menu_state, 400, 35) + love.graphics.rectangle("fill", 75, 118 + 50 * self.menu_state, 300, 35) love.graphics.setColor(1, 1, 1, 1) for i, screen in pairs(menu_screens) do - drawText(screen.title, 80, 120 + 50 * i, 400, "left") + drawText(screen.title, 80, 120 + 50 * i, 300, "left") end end diff --git a/scene/title.lua b/scene/title.lua index 5d0a94a..65ad81b 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -55,32 +55,31 @@ end function TitleScene:render() MainBackground() - love.graphics.setColor(0,0,0,0.7) - love.graphics.rectangle("fill", 14, 174, 260, 220, 10, 10) - love.graphics.setColor(0,0,0,0.7) - love.graphics.rectangle("fill", 14, 400, 605, 75, 10, 10) + love.graphics.setColor(0,0,0,0.7) + love.graphics.rectangle("fill", 14, 174, 260, 210, 10, 10) love.graphics.setColor(0.4, 1, 1, 0.5) + love.graphics.rectangle("fill", 14, 40, 260, 120, 10, 10) love.graphics.rectangle("fill", 20, 198 + 20 * self.main_menu_state, 240, 22) + -- drawBigText('Tromi', 30, 180, 120, "left") drawText('version 2', 110, 193, 120, "left") - self:drawCredits(300, 40) - drawText(tostring(self.main_menu_state), 20, 405, 1000) - drawText("Based on Cambridge - t-sp.in/cambridge", 20, 420, 1000) - drawText("Music for Tromi by Jerry Martin, all rights reserved - jerrymartinmusic.com", 20, 435, 1000) - drawText("Game backgrounds by Pixabay users Joe_hackney, yokim, Favorisxp, Any_Ann, VisualSkyFX ", 20, 450, 1000) - if SETTINGS["music"] == true then - drawText("On", 230, 320, 1000) - else - drawText("Off", 230, 320, 1000) - end - if SETTINGS["lines"] == true then - drawText("On", 230, 340, 1000) - else - drawText("Off", 230, 340, 1000) - end + -- for i, screen in pairs(main_menu_screens) do drawText(screen.title, 40, 200 + 20 * i, 1200, "left") end + -- + drawText(SETTINGS["music"] and "On" or "Off", 230, 320, 1000) + drawText(SETTINGS["lines"] and "On" or "Off", 230, 340, 1000) + + love.graphics.setColor(0,0,0,0.7) + love.graphics.rectangle("fill", 14, 400, 605, 75, 10, 10) + -- + drawText("mycophobia.org", 20, 405, 1000) + drawText("Based on Cambridge - t-sp.in/cambridge", 20, 420, 1000) + drawText("Music for Tromi by Jerry Martin, all rights reserved - jerrymartinmusic.com", 20, 435, 1000) + drawText("Game backgrounds by Pixabay users Joe_hackney, yokim, Favorisxp, Any_Ann, VisualSkyFX ", 20, 450, 1000) + self:drawCredits(300, 40) + if table.concat(self.code, ',') == '1,1,1,1,-1,-1,-1,-1' then PENTO_MODE = true end if PENTO_MODE then drawBigText('PENT MODE', 30, 100, 120, "left") @@ -95,13 +94,15 @@ end function TitleScene:onInputPress(e) if e.type == "touch" then local selecting = math.floor((e.y - 198) / 20) - if selecting > 0 and selecting <= #main_menu_screens then + if (e.x >= 20 and e.x <= 260) and (selecting > 0 and selecting <= #main_menu_screens) then if self.main_menu_state ~= selecting then self.main_menu_state = selecting else VCTRL.toggle(true) SCENE = main_menu_screens[selecting]() end + elseif e.x >= 14 and e.y >= 40 and e.x <= 274 and e.y <= 170 then + end else if e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then diff --git a/scene/touch_config.lua b/scene/touch_config.lua index 3457c24..f106961 100644 --- a/scene/touch_config.lua +++ b/scene/touch_config.lua @@ -2,10 +2,53 @@ local TouchConfigScene = SCENE:extend() TouchConfigScene.title = "Touchscreen config\n(you can tap anywhere on touch screen to select this)" local widgetList = { + select_widget = BUTTON.new{ + text = "Select key\n[Rotate right 2]", + x = 10, y = 10, w = 120, h = 110 + }, + BUTTON.new{ - text = "Select widget\nLoading...", - x = 10, y = 10, w = 120, h = 50 - } + text = "[—]\nSmaller", + x = 140, y = 10, w = 70, h = 50, + }, + BUTTON.new{ + text = "Size: 50\nTap to reset", + x = 220, y = 10, w = 110, h = 50, + }, + BUTTON.new{ + text = "[+]\nBigger", + x = 340, y = 10, w = 70, h = 50, + }, + + BUTTON.new{ + text = "[—]\nBlurrier", + x = 140, y = 70, w = 70, h = 50, + }, + BUTTON.new{ + text = "Opacity: 50%\nTap to reset", + x = 220, y = 70, w = 110, h = 50, + }, + BUTTON.new{ + text = "[+]\nClearer", + x = 340, y = 70, w = 70, h = 50, + }, + + BUTTON.new{ + text = "SAVE and\nback to MENU", + x = 480, y = 10, w = 150, h = 50, + codeWhenReleased = function() SCENE = TitleScene() end + }, + BUTTON.new{ + text = "DISCARD\nchanges", + x = 480, y = 70, w = 70, h = 50, + codeWhenReleased = function() SCENE = TitleScene() end + }, + BUTTON.new{ + text = "RESET to\nDEFAULT", + x = 560, y = 70, w = 70, h = 50, + codeWhenReleased = function() SCENE = TitleScene() end + }, + } local function widgetList_update() for _, v in pairs(widgetList) do v:update() end @@ -44,10 +87,19 @@ end ---@param e SCENE_onInput function TouchConfigScene:onInputPress(e) if e.input == 'menu_back' then SCENE = InputConfigScene() end - if e.type =="mouse" then widgetList_press() end + if e.type == "mouse" then widgetList_press() end + if e.type == "touch" then + widgetList_isHovering(e.x,e.y) + widgetList_press() + end end function TouchConfigScene:onInputRelease(e) - if e.type =="mouse" then widgetList_release() end + if e.type == "mouse" then + widgetList_release() + widgetList_isHovering(x, y) + elseif e.type == "touch" then + widgetList_release() + end end return TouchConfigScene \ No newline at end of file