From c0089fc4a5323cf85915455d4faa34d4cf65e007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Qu=E1=BB=91c=20H=C6=B0ng?= <106439598+SweetSea-ButImNotSweet@users.noreply.github.com> Date: Sun, 6 Oct 2024 16:57:49 +0700 Subject: [PATCH] Multiple changes - Fix softlock in Name entry - Wrong page count in Replay scene - Last key can't be ignored by other controllers - Small B.T.S changes --- main.lua | 24 +++++++++++++++- scene/input_config.lua | 27 ++++++++++-------- scene/key_config.lua | 4 ++- scene/name_entry.lua | 26 ++++++++--------- scene/replay.lua | 65 +++++++++++++++++++++++------------------- scene/settings.lua | 2 +- scene/stick_config.lua | 2 ++ 7 files changed, 93 insertions(+), 57 deletions(-) diff --git a/main.lua b/main.lua index f929f57..8330f18 100644 --- a/main.lua +++ b/main.lua @@ -20,6 +20,9 @@ MOBILE = CURRENT_OS == "Android" or CURRENT_OS == "iOS" LILY = require "libs.lily" +---@type table +local sceneStack -- Only use for checking scene stack, not + function love.load() require 'funcs' math.randomseed(os.time()) @@ -40,6 +43,7 @@ function love.load() require "game.vctrl" -- VCTRL SCENE = LoadingScene() + sceneStack = {SCENE} VCTRL.new(SETTINGS.input.virtual) end @@ -305,11 +309,23 @@ function love.run() end end love.handlers[name](a,b,c,d,e,f) + + -- Checking for new scene and add it to the end of scene stack + if SCENE ~= sceneStack[1] then + table.insert(sceneStack, SCENE) + SCENE = sceneStack[1] + end end end + if SCENE and SCENE.update and love.timer then SCENE:update() + -- Checking for new scene and add it to the end of scene stack + if SCENE ~= sceneStack[1] then + table.insert(sceneStack, SCENE) + SCENE = sceneStack[1] + end local frame_duration = 1.0 / TARGET_FPS if time_accumulator < frame_duration then @@ -330,6 +346,12 @@ function love.run() time_accumulator = time_accumulator - frame_duration end last_time = love.timer.getTime() + + -- Finally, changing to the latest scene in scene stack + if #sceneStack > 1 then + SCENE = sceneStack[#sceneStack] + sceneStack = {SCENE} + end end end @@ -412,7 +434,7 @@ function love.errorhandler(msg) love.graphics.setColor(1, 1, 1) love.graphics.draw(screenshot_canva, 0, 0, 0, screenshot_canva_scale) - + if not showScreenshot then love.graphics.setColor(0, 0, 0, 0.75) love.graphics.rectangle("fill", 0, 0, 640, 480) diff --git a/scene/input_config.lua b/scene/input_config.lua index 974d570..3d56fb9 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -71,7 +71,7 @@ function ConfigScene:new(first_time) secret_code_used = false secret_code_input = {} -- When it matches 88663366 then we will automatically set the special keybind - + self.menu_state = 1 if first_time then self.first_time = true @@ -84,15 +84,18 @@ function ConfigScene:update() end function ConfigScene:render() MainBackground() + love.graphics.setColor(0, 0, 0, 0.7) + love.graphics.rectangle("fill", 0, 0, 640, 480) + if secret_code_used then if SETTINGS.tvMode then drawText("TV mode is ON now! Check keybind below", 80, 40, 1000) drawText("Which controls do you want to configure?", 80, 70, 1000) drawText( "2 - Up 1 - Rotate left 5 - Confirm selection\n".. - "8 - Right 3 - Rotate right 0 - Back\n".. - "4 - Left 7 - Rotate left 2\n".. - "6 - Down 9 - Rotate right 2", 80, 350, 1000 + "8 - Down 3 - Rotate right 0 - Back\n".. + "4 - Left 7 - Rotate left 2\n".. + "6 - Right 9 - Rotate right 2", 80, 350, 1000 ) else drawText("TV mode is OFF now!", 80, 40, 1000) @@ -132,7 +135,7 @@ local function checkSecretCodeInput(key) if secret_code_used then return end if key:sub(1, 2) == "kp" then table.insert(secret_code_input, key:sub(3,3)) - elseif key:find("[0-9.]") == 1 then + elseif key:find("[0-9]") == 1 then table.insert(secret_code_input, key) else secret_code_input = {} -- Reset @@ -146,14 +149,14 @@ local function checkSecretCodeInput(key) if current_code == "88663366" then --TVMODEON -- Set keybind SETTINGS.input.keys = { - ["2"] = "up", ["kp2"] = "up", - ["8"] = "down", ["kp8"] = "down", + ["2"] = "up", ["kp8"] = "up", + ["8"] = "down", ["kp2"] = "down", ["4"] = "left", ["kp4"] = "left", ["6"] = "right", ["kp6"] = "right", - ["1"] = "rotate_left", ["kp1"] = "rotate_left", - ["3"] = "rotate_right", ["kp3"] = "rotate_right", - ["7"] = "rotate_left2", ["kp7"] = "rotate_left2", - ["9"] = "rotate_right2", ["kp9"] = "rotate_right2", + ["1"] = "rotate_left", ["kp7"] = "rotate_left", + ["3"] = "rotate_right", ["kp9"] = "rotate_right", + ["7"] = "rotate_left2", ["kp1"] = "rotate_left2", + ["9"] = "rotate_right2", ["kp3"] = "rotate_right2", ["5"] = "menu_decide", ["kp5"] = "menu_decide", ["0"] = "menu_back", ["kp0"] = "menu_back", } @@ -161,7 +164,7 @@ local function checkSecretCodeInput(key) SETTINGS.tvMode = true secret_code_used = true updateButtonList(SCENE) - elseif current_code == "........" then + elseif current_code == "11111111" then SETTINGS.input.keys = {} SETTINGS.tvMode = false secret_code_used = true diff --git a/scene/key_config.lua b/scene/key_config.lua index 8b0fbc2..153c890 100644 --- a/scene/key_config.lua +++ b/scene/key_config.lua @@ -71,6 +71,8 @@ end function KeyConfigScene:render() MainBackground() + love.graphics.setColor(0, 0, 0, 0.7) + love.graphics.rectangle("fill", 0, 0, 640, 480) BUTTON.draw(buttonList) for i, input in ipairs(configurable_inputs) do @@ -111,7 +113,7 @@ function KeyConfigScene:onInputPress(e) self.new_input[e.scancode] = configurable_inputs[self.input_state] self.input_state = self.input_state + 1 end - elseif self.input_state < #configurable_inputs then + elseif self.input_state <= #configurable_inputs then self.set_inputs[configurable_inputs[self.input_state]] = "skipped" self.input_state = self.input_state + 1 end diff --git a/scene/name_entry.lua b/scene/name_entry.lua index 5fdf0b4..78e6198 100644 --- a/scene/name_entry.lua +++ b/scene/name_entry.lua @@ -37,7 +37,7 @@ local Grid = require 'game.grid' function NameEntryScene:new() VCTRL.toggle(false) - + self.chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890." self.char_pos = 1 self.name_entry = {'A','A','A'} @@ -79,7 +79,7 @@ end function NameEntryScene:render() MainBackground() BUTTON.draw(buttonList) - + love.graphics.setColor(1, 1, 1, 1) love.graphics.line(216,80,216,80+(16*self.grid.height)) love.graphics.line(216+(16*self.grid.width),80,216+(16*self.grid.width),80+(16*self.grid.height)) @@ -153,17 +153,6 @@ function NameEntryScene:onInputPress(e) local name = string.lower(table.concat(self.name_entry, '', 1, 3)) if e.type == "mouse" or e.type == "touch" then BUTTON.press(buttonList, e.x, e.y, e.id) - elseif e.key and #e.key == 1 then - local pos = string.find(self.chars, string.upper(e.key), 1, true) - if pos then - if self.entry_pos <= 3 then - self.char_pos = pos - self.name_entry[self.entry_pos] = string.upper(e.key) - self.name_entry[self.entry_pos + 1] = string.upper(e.key) - end - self.entry_pos = math.min(self.entry_pos + 1, 4) - if self.entry_pos == 4 then self:getPlayInfo(string.lower(table.concat(self.name_entry, '', 1, 3))) end - end elseif e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then if self.entry_pos == 4 then BUTTON.release(buttonList, e.x, e.y, e.id) @@ -190,6 +179,17 @@ function NameEntryScene:onInputPress(e) self.entry_pos = self.entry_pos - 1 self.grade = 0 end + elseif e.key and #e.key == 1 then + local pos = string.find(self.chars, string.upper(e.key), 1, true) + if pos then + if self.entry_pos <= 3 then + self.char_pos = pos + self.name_entry[self.entry_pos] = string.upper(e.key) + self.name_entry[self.entry_pos + 1] = string.upper(e.key) + end + self.entry_pos = math.min(self.entry_pos + 1, 4) + if self.entry_pos == 4 then self:getPlayInfo(string.lower(table.concat(self.name_entry, '', 1, 3))) end + end end end diff --git a/scene/replay.lua b/scene/replay.lua index 7250ceb..6666013 100644 --- a/scene/replay.lua +++ b/scene/replay.lua @@ -4,41 +4,41 @@ ReplaySelectScene.title = "Replay" local replay_list local buttonList = { BUTTON.new{ - x = 325, y = 385, w = 100, h = 30, + x = 325, y = 375, w = 100, h = 30, text = CHAR.key.up.." Page up", codeWhenReleased = function() SCENE:onInputPress{input = "left"} end }, BUTTON.new{ - x = 435, y = 385, w = 100, h = 30, + x = 435, y = 375, w = 100, h = 30, text = CHAR.key.down.." Page down", codeWhenReleased = function() SCENE:onInputPress{input = "right"} end }, BUTTON.new{ - x = 105, y = 385, w = 100, h = 30, + x = 105, y = 375, w = 100, h = 30, text = CHAR.icon.play.." Play", codeWhenPressed = function() SCENE:onInputPress {input = "menu_decide"} end, codeWhenReleased = function() SCENE:onInputRelease{input = "menu_decide"} end }, BUTTON.new{ - x = 105, y = 425, w = 100, h = 30, + x = 105, y = 415, w = 100, h = 45, text = CHAR.icon.home.." Home", codeWhenPressed = function() SCENE:onInputPress {input = "menu_back"} end, codeWhenReleased = function() SCENE:onInputRelease{input = "menu_back"} end }, BUTTON.new{ - x = 215, y = 425, w = 100, h = 30, + x = 215, y = 415, w = 100, h = 45, text = CHAR.icon.save.." Converter", codeWhenReleased = function() love.system.openURL("https://sweetsea-butimnotsweet.github.io/tromi_replay_converter/") end }, BUTTON.new{ - x = 325, y = 425, w = 100, h = 30, - text = CHAR.icon.export.." Export", + x = 325, y = 415, w = 100, h = 45, + text = CHAR.icon.export.." Export\n(R.Left)", codeWhenPressed = function() SCENE:onInputPress {input = "rotate_left"} end, codeWhenReleased = function() SCENE:onInputRelease{input = "rotate_left"} end }, BUTTON.new{ - x = 435, y = 425, w = 100, h = 30, - text = CHAR.icon.import.." Import", + x = 435, y = 415, w = 100, h = 45, + text = CHAR.icon.import.." Import\n(R.Right)", codeWhenPressed = function() SCENE:onInputPress {input = "rotate_right"} end, codeWhenReleased = function() SCENE:onInputRelease{input = "rotate_right"} end }, @@ -88,29 +88,30 @@ function ReplaySelectScene:render() love.graphics.setColor(0, 0, 0, 0.7) love.graphics.rectangle("fill", 0, 0, 640, 480) - love.graphics.setColor(0.4, 1, 1, 0.5) - love.graphics.rectangle("fill", 0, 15 + 30 * self.replay_select, 640, 27) - BUTTON.draw(buttonList) + if #self.replays > 0 then + love.graphics.setColor(0.4, 1, 1, 0.5) + love.graphics.rectangle("fill", 0, 15 + 30 * self.replay_select, 640, 27) - drawText('Name - Grade - Score', 40, 20, 1000, "left") - drawText(string.format('Page %s/%s', self.page, math.floor(#self.replays / self.page_flip) + 1), 215, 390, 100, "center") + drawText('Name - Grade - Score', 40, 20, 1000, "left") + drawText(string.format('Page %s/%s', self.page, 1 + math.floor((#self.replays - 1) / self.page_flip)), 215, 380, 100, "center") - local i, j = 1, 1 - while i <= #self.replay_text do - if j > self.page_flip then j = 1 - elseif j < 1 then j = self.page_flip + local i, j = 1, 1 + while i <= #self.replay_text do + if j > self.page_flip then j = 1 + elseif j < 1 then j = self.page_flip + end + if i > (self.page-1) * self.page_flip and i <= self.page * self.page_flip then + drawText(self.replay_text[i], 40, 20 + 30 * j, 1000, "left") + end + j = j + 1 + i = i + 1 end - if i > (self.page-1) * self.page_flip and i <= self.page * self.page_flip then - drawText(self.replay_text[i], 40, 20 + 30 * j, 1000, "left") - end - j = j + 1 - i = i + 1 - end - - if self.replays[1] == nil then + else drawText('No replays yet!', 40, 40, 1000, "left") end + + BUTTON.draw(buttonList) end function ReplaySelectScene:update() @@ -152,7 +153,11 @@ function ReplaySelectScene:onInputPress(e) local selected_replay = self.replays[self.replay_select + ((self.page-1) * self.page_flip)] local selected_replay_text = self.replay_text[self.replay_select + ((self.page-1) * self.page_flip)] - if (e.type == "touch" or e.type == "mouse") and not BUTTON.press(buttonList, e.x, e.y, e.id) then + if ( + e.type == "touch" or e.type == "mouse") and + not BUTTON.press(buttonList, e.x, e.y, e.id and + #self.replays > 0 + ) then local selection = math.floor((e.y - 15) / 30) if ( selection >= 1 and @@ -198,14 +203,16 @@ function ReplaySelectScene:onInputPress(e) if self.replays[1] == nil then SCENE = TitleScene(); return end self.direction = 'down' elseif e.input == "left" or e.scancode == "left" then + if self.replays[1] == nil then SCENE = TitleScene(); return end if self.page == 1 then - self.page = 1 + math.floor(#self.replays / self.page_flip) + self.page = math.floor((#self.replays - 1) / self.page_flip) else self.page = self.page - 1 end self.replay_select = 1; elseif e.input == "right" or e.scancode == "right" then - if self.page < 1 + math.floor(#self.replays / self.page_flip) then + if self.replays[1] == nil then SCENE = TitleScene(); return end + if self.page < 1 + math.floor((#self.replays - 1) / self.page_flip) then self.page = self.page + 1 else self.page = 1 diff --git a/scene/settings.lua b/scene/settings.lua index 68ed80a..bf96a7a 100644 --- a/scene/settings.lua +++ b/scene/settings.lua @@ -12,7 +12,7 @@ local settings_explaination = { "Enable music?\nThis does not apply to sound effects.", "Show level and lines counter?\nThis setting is ignored when replaying.", "Enter or leave fullscreen\nYou can press F4 key at any screen to do this quick.", - "This is where you can re-configure your keybinds.\nYou can press F2 on the keyboard to open this quick\n\nTip for TV:\n\t88663366: enable TV mode.\n\t........: disable TV mode", + "This is where you can re-configure your keybinds.\nYou can press F2 on the keyboard to open this quick\n\nTip for TV:\n\t88663366: enable TV mode.\n\t11111111 disable TV mode", "Back to main menu" } diff --git a/scene/stick_config.lua b/scene/stick_config.lua index acb4b0e..2ce2ec7 100644 --- a/scene/stick_config.lua +++ b/scene/stick_config.lua @@ -71,6 +71,8 @@ end function StickConfigScene:render() MainBackground() + love.graphics.setColor(0, 0, 0, 0.7) + love.graphics.rectangle("fill", 0, 0, 640, 480) BUTTON.draw(buttonList) for i, input in ipairs(configurable_inputs) do