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
This commit is contained in:
Nguyễn Quốc Hưng
2024-10-06 16:57:49 +07:00
parent 1f5a21fec4
commit 9513490cdb
7 changed files with 93 additions and 57 deletions

View File

@@ -20,6 +20,9 @@ MOBILE = CURRENT_OS == "Android" or CURRENT_OS == "iOS"
LILY = require "libs.lily" LILY = require "libs.lily"
---@type table
local sceneStack -- Only use for checking scene stack, not
function love.load() function love.load()
require 'funcs' require 'funcs'
math.randomseed(os.time()) math.randomseed(os.time())
@@ -40,6 +43,7 @@ function love.load()
require "game.vctrl" -- VCTRL require "game.vctrl" -- VCTRL
SCENE = LoadingScene() SCENE = LoadingScene()
sceneStack = {SCENE}
VCTRL.new(SETTINGS.input.virtual) VCTRL.new(SETTINGS.input.virtual)
end end
@@ -305,11 +309,23 @@ function love.run()
end end
end end
love.handlers[name](a,b,c,d,e,f) 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
end end
if SCENE and SCENE.update and love.timer then if SCENE and SCENE.update and love.timer then
SCENE:update() 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 local frame_duration = 1.0 / TARGET_FPS
if time_accumulator < frame_duration then if time_accumulator < frame_duration then
@@ -330,6 +346,12 @@ function love.run()
time_accumulator = time_accumulator - frame_duration time_accumulator = time_accumulator - frame_duration
end end
last_time = love.timer.getTime() 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
end end
@@ -412,7 +434,7 @@ function love.errorhandler(msg)
love.graphics.setColor(1, 1, 1) love.graphics.setColor(1, 1, 1)
love.graphics.draw(screenshot_canva, 0, 0, 0, screenshot_canva_scale) love.graphics.draw(screenshot_canva, 0, 0, 0, screenshot_canva_scale)
if not showScreenshot then if not showScreenshot then
love.graphics.setColor(0, 0, 0, 0.75) love.graphics.setColor(0, 0, 0, 0.75)
love.graphics.rectangle("fill", 0, 0, 640, 480) love.graphics.rectangle("fill", 0, 0, 640, 480)

View File

@@ -71,7 +71,7 @@ function ConfigScene:new(first_time)
secret_code_used = false secret_code_used = false
secret_code_input = {} -- When it matches 88663366 then we will automatically set the special keybind secret_code_input = {} -- When it matches 88663366 then we will automatically set the special keybind
self.menu_state = 1 self.menu_state = 1
if first_time then if first_time then
self.first_time = true self.first_time = true
@@ -84,15 +84,18 @@ function ConfigScene:update() end
function ConfigScene:render() function ConfigScene:render()
MainBackground() MainBackground()
love.graphics.setColor(0, 0, 0, 0.7)
love.graphics.rectangle("fill", 0, 0, 640, 480)
if secret_code_used then if secret_code_used then
if SETTINGS.tvMode then if SETTINGS.tvMode then
drawText("TV mode is ON now! Check keybind below", 80, 40, 1000) drawText("TV mode is ON now! Check keybind below", 80, 40, 1000)
drawText("Which controls do you want to configure?", 80, 70, 1000) drawText("Which controls do you want to configure?", 80, 70, 1000)
drawText( drawText(
"2 - Up 1 - Rotate left 5 - Confirm selection\n".. "2 - Up 1 - Rotate left 5 - Confirm selection\n"..
"8 - Right 3 - Rotate right 0 - Back\n".. "8 - Down 3 - Rotate right 0 - Back\n"..
"4 - Left 7 - Rotate left 2\n".. "4 - Left 7 - Rotate left 2\n"..
"6 - Down 9 - Rotate right 2", 80, 350, 1000 "6 - Right 9 - Rotate right 2", 80, 350, 1000
) )
else else
drawText("TV mode is OFF now!", 80, 40, 1000) 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 secret_code_used then return end
if key:sub(1, 2) == "kp" then if key:sub(1, 2) == "kp" then
table.insert(secret_code_input, key:sub(3,3)) 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) table.insert(secret_code_input, key)
else else
secret_code_input = {} -- Reset secret_code_input = {} -- Reset
@@ -146,14 +149,14 @@ local function checkSecretCodeInput(key)
if current_code == "88663366" then --TVMODEON if current_code == "88663366" then --TVMODEON
-- Set keybind -- Set keybind
SETTINGS.input.keys = { SETTINGS.input.keys = {
["2"] = "up", ["kp2"] = "up", ["2"] = "up", ["kp8"] = "up",
["8"] = "down", ["kp8"] = "down", ["8"] = "down", ["kp2"] = "down",
["4"] = "left", ["kp4"] = "left", ["4"] = "left", ["kp4"] = "left",
["6"] = "right", ["kp6"] = "right", ["6"] = "right", ["kp6"] = "right",
["1"] = "rotate_left", ["kp1"] = "rotate_left", ["1"] = "rotate_left", ["kp7"] = "rotate_left",
["3"] = "rotate_right", ["kp3"] = "rotate_right", ["3"] = "rotate_right", ["kp9"] = "rotate_right",
["7"] = "rotate_left2", ["kp7"] = "rotate_left2", ["7"] = "rotate_left2", ["kp1"] = "rotate_left2",
["9"] = "rotate_right2", ["kp9"] = "rotate_right2", ["9"] = "rotate_right2", ["kp3"] = "rotate_right2",
["5"] = "menu_decide", ["kp5"] = "menu_decide", ["5"] = "menu_decide", ["kp5"] = "menu_decide",
["0"] = "menu_back", ["kp0"] = "menu_back", ["0"] = "menu_back", ["kp0"] = "menu_back",
} }
@@ -161,7 +164,7 @@ local function checkSecretCodeInput(key)
SETTINGS.tvMode = true SETTINGS.tvMode = true
secret_code_used = true secret_code_used = true
updateButtonList(SCENE) updateButtonList(SCENE)
elseif current_code == "........" then elseif current_code == "11111111" then
SETTINGS.input.keys = {} SETTINGS.input.keys = {}
SETTINGS.tvMode = false SETTINGS.tvMode = false
secret_code_used = true secret_code_used = true

View File

@@ -71,6 +71,8 @@ end
function KeyConfigScene:render() function KeyConfigScene:render()
MainBackground() MainBackground()
love.graphics.setColor(0, 0, 0, 0.7)
love.graphics.rectangle("fill", 0, 0, 640, 480)
BUTTON.draw(buttonList) BUTTON.draw(buttonList)
for i, input in ipairs(configurable_inputs) do 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.new_input[e.scancode] = configurable_inputs[self.input_state]
self.input_state = self.input_state + 1 self.input_state = self.input_state + 1
end 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.set_inputs[configurable_inputs[self.input_state]] = "skipped"
self.input_state = self.input_state + 1 self.input_state = self.input_state + 1
end end

View File

@@ -37,7 +37,7 @@ local Grid = require 'game.grid'
function NameEntryScene:new() function NameEntryScene:new()
VCTRL.toggle(false) VCTRL.toggle(false)
self.chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890." self.chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890."
self.char_pos = 1 self.char_pos = 1
self.name_entry = {'A','A','A'} self.name_entry = {'A','A','A'}
@@ -79,7 +79,7 @@ end
function NameEntryScene:render() function NameEntryScene:render()
MainBackground() MainBackground()
BUTTON.draw(buttonList) BUTTON.draw(buttonList)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.line(216,80,216,80+(16*self.grid.height)) 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)) 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)) local name = string.lower(table.concat(self.name_entry, '', 1, 3))
if e.type == "mouse" or e.type == "touch" then if e.type == "mouse" or e.type == "touch" then
BUTTON.press(buttonList, e.x, e.y, e.id) 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 elseif e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then
if self.entry_pos == 4 then if self.entry_pos == 4 then
BUTTON.release(buttonList, e.x, e.y, e.id) 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.entry_pos = self.entry_pos - 1
self.grade = 0 self.grade = 0
end 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
end end

View File

@@ -4,41 +4,41 @@ ReplaySelectScene.title = "Replay"
local replay_list local replay_list
local buttonList = { local buttonList = {
BUTTON.new{ BUTTON.new{
x = 325, y = 385, w = 100, h = 30, x = 325, y = 375, w = 100, h = 30,
text = CHAR.key.up.." Page up", text = CHAR.key.up.." Page up",
codeWhenReleased = function() SCENE:onInputPress{input = "left"} end codeWhenReleased = function() SCENE:onInputPress{input = "left"} end
}, },
BUTTON.new{ BUTTON.new{
x = 435, y = 385, w = 100, h = 30, x = 435, y = 375, w = 100, h = 30,
text = CHAR.key.down.." Page down", text = CHAR.key.down.." Page down",
codeWhenReleased = function() SCENE:onInputPress{input = "right"} end codeWhenReleased = function() SCENE:onInputPress{input = "right"} end
}, },
BUTTON.new{ BUTTON.new{
x = 105, y = 385, w = 100, h = 30, x = 105, y = 375, w = 100, h = 30,
text = CHAR.icon.play.." Play", text = CHAR.icon.play.." Play",
codeWhenPressed = function() SCENE:onInputPress {input = "menu_decide"} end, codeWhenPressed = function() SCENE:onInputPress {input = "menu_decide"} end,
codeWhenReleased = function() SCENE:onInputRelease{input = "menu_decide"} end codeWhenReleased = function() SCENE:onInputRelease{input = "menu_decide"} end
}, },
BUTTON.new{ BUTTON.new{
x = 105, y = 425, w = 100, h = 30, x = 105, y = 415, w = 100, h = 45,
text = CHAR.icon.home.." Home", text = CHAR.icon.home.." Home",
codeWhenPressed = function() SCENE:onInputPress {input = "menu_back"} end, codeWhenPressed = function() SCENE:onInputPress {input = "menu_back"} end,
codeWhenReleased = function() SCENE:onInputRelease{input = "menu_back"} end codeWhenReleased = function() SCENE:onInputRelease{input = "menu_back"} end
}, },
BUTTON.new{ BUTTON.new{
x = 215, y = 425, w = 100, h = 30, x = 215, y = 415, w = 100, h = 45,
text = CHAR.icon.save.." Converter", text = CHAR.icon.save.." Converter",
codeWhenReleased = function() love.system.openURL("https://sweetsea-butimnotsweet.github.io/tromi_replay_converter/") end codeWhenReleased = function() love.system.openURL("https://sweetsea-butimnotsweet.github.io/tromi_replay_converter/") end
}, },
BUTTON.new{ BUTTON.new{
x = 325, y = 425, w = 100, h = 30, x = 325, y = 415, w = 100, h = 45,
text = CHAR.icon.export.." Export", text = CHAR.icon.export.." Export\n(R.Left)",
codeWhenPressed = function() SCENE:onInputPress {input = "rotate_left"} end, codeWhenPressed = function() SCENE:onInputPress {input = "rotate_left"} end,
codeWhenReleased = function() SCENE:onInputRelease{input = "rotate_left"} end codeWhenReleased = function() SCENE:onInputRelease{input = "rotate_left"} end
}, },
BUTTON.new{ BUTTON.new{
x = 435, y = 425, w = 100, h = 30, x = 435, y = 415, w = 100, h = 45,
text = CHAR.icon.import.." Import", text = CHAR.icon.import.." Import\n(R.Right)",
codeWhenPressed = function() SCENE:onInputPress {input = "rotate_right"} end, codeWhenPressed = function() SCENE:onInputPress {input = "rotate_right"} end,
codeWhenReleased = function() SCENE:onInputRelease{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.setColor(0, 0, 0, 0.7)
love.graphics.rectangle("fill", 0, 0, 640, 480) 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('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(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 local i, j = 1, 1
while i <= #self.replay_text do while i <= #self.replay_text do
if j > self.page_flip then j = 1 if j > self.page_flip then j = 1
elseif j < 1 then j = self.page_flip 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 end
if i > (self.page-1) * self.page_flip and i <= self.page * self.page_flip then else
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
drawText('No replays yet!', 40, 40, 1000, "left") drawText('No replays yet!', 40, 40, 1000, "left")
end end
BUTTON.draw(buttonList)
end end
function ReplaySelectScene:update() 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 = 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)] 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) local selection = math.floor((e.y - 15) / 30)
if ( if (
selection >= 1 and selection >= 1 and
@@ -198,14 +203,16 @@ function ReplaySelectScene:onInputPress(e)
if self.replays[1] == nil then SCENE = TitleScene(); return end if self.replays[1] == nil then SCENE = TitleScene(); return end
self.direction = 'down' self.direction = 'down'
elseif e.input == "left" or e.scancode == "left" then elseif e.input == "left" or e.scancode == "left" then
if self.replays[1] == nil then SCENE = TitleScene(); return end
if self.page == 1 then 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 else
self.page = self.page - 1 self.page = self.page - 1
end end
self.replay_select = 1; self.replay_select = 1;
elseif e.input == "right" or e.scancode == "right" then 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 self.page = self.page + 1
else else
self.page = 1 self.page = 1

View File

@@ -12,7 +12,7 @@ local settings_explaination = {
"Enable music?\nThis does not apply to sound effects.", "Enable music?\nThis does not apply to sound effects.",
"Show level and lines counter?\nThis setting is ignored when replaying.", "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.", "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" "Back to main menu"
} }

View File

@@ -71,6 +71,8 @@ end
function StickConfigScene:render() function StickConfigScene:render()
MainBackground() MainBackground()
love.graphics.setColor(0, 0, 0, 0.7)
love.graphics.rectangle("fill", 0, 0, 640, 480)
BUTTON.draw(buttonList) BUTTON.draw(buttonList)
for i, input in ipairs(configurable_inputs) do for i, input in ipairs(configurable_inputs) do