Update replay screen

This commit is contained in:
Squishy (C6H12O6+NaCl+H2O)
2024-06-13 11:38:17 +07:00
parent 1d6643448e
commit 0a2fd20075

View File

@@ -1,48 +1,60 @@
local ReplaySelectScene = SCENE:extend() local ReplaySelectScene = SCENE:extend()
ReplaySelectScene.title = "Replay" ReplaySelectScene.title = "Replay"
local scene_self
local replay_list local replay_list
local buttonList = { local buttonList = {
BUTTON.new{ BUTTON.new{
text = CHAR.key.up.."\nUP", font = FONT_big, x = 325, y = 385, w = 100, h = 30,
x = 425, y = 80, w = 80, h = 80, text = CHAR.key.up.." Page up",
codeWhenPressed = function() SCENE:onInputPress {input = "up"} end, codeWhenReleased = function()
codeWhenReleased = function() SCENE:onInputRelease{input = "up"} end scene_self.page = math.max(scene_self.page - 1, 0)
scene_self.replay_select = 1;
end
}, },
BUTTON.new{ BUTTON.new{
text = CHAR.key.down.."\nDOWN", font = FONT_big, x = 435, y = 385, w = 100, h = 30,
x = 425, y = 240, w = 80, h = 80, text = CHAR.key.down.." Page down",
codeWhenPressed = function() SCENE:onInputPress {input = "down"} end, codeWhenReleased = function()
codeWhenReleased = function() SCENE:onInputRelease{input = "down"} end scene_self.page = math.max(scene_self.page - 1, 1+(math.floor(#scene_self.replays / scene_self.page_flip)))
scene_self.replay_select = 1;
end
}, },
BUTTON.new{ BUTTON.new{
text = CHAR.icon.play.."\nPLAY", font = FONT_big, x = 105, y = 385, w = 100, h = 30,
x = 345, y = 160, w = 80, h = 80, text = CHAR.icon.play.." Play",
codeWhenPressed = function() SCENE:onInputPress {input = "menu_decide"} end, codeWhenPressed = function() scene_self:onInputPress {input = "menu_decide"} end,
codeWhenReleased = function() SCENE:onInputRelease{input = "menu_decide"} end codeWhenReleased = function() scene_self:onInputRelease{input = "menu_decide"} end
}, },
BUTTON.new{ BUTTON.new{
text = CHAR.icon.home.."\nHOME", font = FONT_big, x = 105, y = 425, w = 100, h = 30,
x = 505, y = 160, w = 80, h = 80, text = CHAR.icon.home.." Home",
codeWhenPressed = function() SCENE:onInputPress {input = "menu_back"} end, codeWhenPressed = function() scene_self:onInputPress {input = "menu_back"} end,
codeWhenReleased = function() SCENE:onInputRelease{input = "menu_back"} end codeWhenReleased = function() scene_self:onInputRelease{input = "menu_back"} end
}, },
BUTTON.new{ BUTTON.new{
text = CHAR.icon.export.."\nEXP.", font = FONT_big, x = 215, y = 425, w = 100, h = 30,
x = 345, y = 320, w = 80, h = 80, text = CHAR.icon.save.." Converter",
codeWhenPressed = function() SCENE:onInputPress {input = "rotate_left"} end, codeWhenReleased = function() love.system.openURL("https://sweetsea-butimnotsweet.github.io/tromi_replay_converter/") end
codeWhenReleased = function() SCENE:onInputRelease{input = "rotate_left"} end
}, },
BUTTON.new{ BUTTON.new{
text = CHAR.icon.import.."\nIMP.", font = FONT_big, x = 325, y = 425, w = 100, h = 30,
x = 505, y = 320, w = 80, h = 80, text = CHAR.icon.export.." Export",
codeWhenPressed = function() SCENE:onInputPress {input = "rotate_right"} end, codeWhenPressed = function() scene_self:onInputPress {input = "rotate_left"} end,
codeWhenReleased = function() SCENE:onInputRelease{input = "rotate_right"} end codeWhenReleased = function() scene_self:onInputRelease{input = "rotate_left"} end
},
BUTTON.new{
x = 435, y = 425, w = 100, h = 30,
text = CHAR.icon.import.." Import",
codeWhenPressed = function() scene_self:onInputPress {input = "rotate_right"} end,
codeWhenReleased = function() scene_self:onInputRelease{input = "rotate_right"} end
}, },
} }
function ReplaySelectScene:new() function ReplaySelectScene:new()
self:initList() self:initList()
scene_self = self
BUTTON.reset(buttonList)
PENTO_MODE = false PENTO_MODE = false
end end
@@ -51,7 +63,7 @@ function ReplaySelectScene:initList()
replay_list = love.filesystem.getDirectoryItems('saves/replays/') replay_list = love.filesystem.getDirectoryItems('saves/replays/')
table.sort(replay_list, function(a,b) return a > b end) table.sort(replay_list, function(a,b) return a > b end)
self.replay_text = {} self.replay_text = {}
self.page_flip = 16 self.page_flip = 10
self.page = 1 self.page = 1
local gradeNames = { local gradeNames = {
"19k", "18k", "17k", "16k", "15k", "14k", "13k", "12k", "11k", "19k", "18k", "17k", "16k", "15k", "14k", "13k", "12k", "11k",
@@ -81,13 +93,15 @@ end
function ReplaySelectScene:render() function ReplaySelectScene:render()
MainBackground() MainBackground()
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.setColor(0.4, 1, 1, 0.5)
love.graphics.rectangle("fill", 0, 20 + 20 * self.replay_select, 640, 22) love.graphics.rectangle("fill", 0, 15 + 30 * self.replay_select, 640, 27)
BUTTON.draw(buttonList) BUTTON.draw(buttonList)
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), 20, 440, 1000, "left") drawText(string.format('Page %s/%s', self.page, math.floor(#self.replays / self.page_flip) + 1), 215, 390, 100, "center")
local i, j = 1, 1 local i, j = 1, 1
while i <= #self.replay_text do while i <= #self.replay_text do
@@ -95,7 +109,7 @@ function ReplaySelectScene:render()
elseif j < 1 then j = self.page_flip elseif j < 1 then j = self.page_flip
end end
if i > (self.page-1) * self.page_flip and i <= self.page * self.page_flip then if i > (self.page-1) * self.page_flip and i <= self.page * self.page_flip then
drawText(self.replay_text[i], 40, 20 + 20 * j, 1000, "left") drawText(self.replay_text[i], 40, 20 + 30 * j, 1000, "left")
end end
j = j + 1 j = j + 1
i = i + 1 i = i + 1
@@ -145,8 +159,15 @@ 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" then if (e.type == "touch" or e.type == "mouse") and not BUTTON.press(buttonList, e.x, e.y, e.id) then
BUTTON.press(buttonList, e.x, e.y, e.id) local selection = math.floor((e.y - 15) / 30)
if (
selection >= 1 and
selection <= self.repeat_limit and
selection + ((self.page-1) * self.page_flip) <= #replay_list
) then
self.replay_select = selection
end
elseif e.input == "menu_decide" or e.scancode == "return" then elseif e.input == "menu_decide" or e.scancode == "return" then
if self.replays[1] == nil then SCENE = TitleScene(); return if self.replays[1] == nil then SCENE = TitleScene(); return
else else