mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Add touch gesture for replay and input configuration scene
This commit is contained in:
@@ -7,7 +7,45 @@ local menu_screens = {
|
||||
TouchConfigScene
|
||||
}
|
||||
|
||||
local buttonList
|
||||
|
||||
function ConfigScene:new(first_time)
|
||||
buttonList = {
|
||||
BUTTON.new{
|
||||
text = "1", font = FONT_big,
|
||||
x = 75, y = 160, w = 40, h = 40,
|
||||
codeWhenReleased = function()
|
||||
if self.menu_state ~= 1 then
|
||||
self.menu_state = 1
|
||||
else
|
||||
SCENE = KeyConfigScene()
|
||||
end
|
||||
end
|
||||
},
|
||||
BUTTON.new{
|
||||
text = "2", font = FONT_big,
|
||||
x = 75, y = 200, w = 40, h = 40,
|
||||
codeWhenReleased = function()
|
||||
if self.menu_state ~= 2 then
|
||||
self.menu_state = 2
|
||||
else
|
||||
SCENE = StickConfigScene()
|
||||
end
|
||||
end
|
||||
},
|
||||
BUTTON.new{
|
||||
text = "3", font = FONT_big,
|
||||
x = 75, y = 240, w = 40, h = 40,
|
||||
codeWhenReleased = function()
|
||||
if self.menu_state ~= 3 then
|
||||
self.menu_state = 3
|
||||
else
|
||||
SCENE = TouchConfigScene()
|
||||
end
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
self.menu_state = 1
|
||||
if first_time then
|
||||
self.first_time = true
|
||||
@@ -28,12 +66,13 @@ function ConfigScene:render()
|
||||
end
|
||||
|
||||
love.graphics.setColor(1, 1, 1, 0.5)
|
||||
love.graphics.rectangle("fill", 75, 118 + 50 * self.menu_state, 300, 35)
|
||||
love.graphics.rectangle("fill", 75, 120 + 40 * self.menu_state, 300, 40)
|
||||
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
for i, screen in pairs(menu_screens) do
|
||||
drawText(screen.title, 80, 120 + 50 * i, 300, "left")
|
||||
drawText(screen.title, 130, 130 + 40 * i, 300, "left")
|
||||
end
|
||||
BUTTON.draw(buttonList)
|
||||
end
|
||||
|
||||
function ConfigScene:changeOption(rel)
|
||||
@@ -41,8 +80,16 @@ function ConfigScene:changeOption(rel)
|
||||
self.menu_state = (self.menu_state + len + rel - 1) % len + 1
|
||||
end
|
||||
|
||||
function ConfigScene:onInputMove(e)
|
||||
if e.type == "mouse" then
|
||||
BUTTON.checkHovering(buttonList, e.x, e.y)
|
||||
end
|
||||
end
|
||||
|
||||
function ConfigScene:onInputPress(e)
|
||||
if e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then
|
||||
if e.type == "touch" or e.type == "mouse" then
|
||||
BUTTON.press(buttonList, e.x, e.y, e.id)
|
||||
elseif e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then
|
||||
SCENE = menu_screens[self.menu_state]()
|
||||
elseif e.input == "up" or e.scancode == "up" then
|
||||
self:changeOption(-1)
|
||||
@@ -54,5 +101,10 @@ function ConfigScene:onInputPress(e)
|
||||
SCENE = TitleScene()
|
||||
end
|
||||
end
|
||||
function ConfigScene:onInputRelease(e)
|
||||
if e.type == "touch" or e.type == "mouse" then
|
||||
BUTTON.release(buttonList, e.x, e.y, e.id)
|
||||
end
|
||||
end
|
||||
|
||||
return ConfigScene
|
||||
|
||||
105
scene/replay.lua
105
scene/replay.lua
@@ -1,6 +1,34 @@
|
||||
local ReplaySelectScene = SCENE:extend()
|
||||
ReplaySelectScene.title = "Replay"
|
||||
|
||||
local replay_list
|
||||
local buttonList = {
|
||||
BUTTON.new{
|
||||
text = "↑\nUP", font = FONT_big,
|
||||
x = 425, y = 80, w = 80, h = 80,
|
||||
codeWhenPressed = function() SCENE:onInputPress {input = "up"} end,
|
||||
codeWhenReleased = function() SCENE:onInputRelease{input = "up"} end
|
||||
},
|
||||
BUTTON.new{
|
||||
text = "↓\nDOWN", font = FONT_big,
|
||||
x = 425, y = 240, w = 80, h = 80,
|
||||
codeWhenPressed = function() SCENE:onInputPress {input = "down"} end,
|
||||
codeWhenReleased = function() SCENE:onInputRelease{input = "down"} end
|
||||
},
|
||||
BUTTON.new{
|
||||
text = "▶\nPLAY", font = FONT_big,
|
||||
x = 345, y = 160, w = 80, h = 80,
|
||||
codeWhenPressed = function() SCENE:onInputPress {input = "menu_decide"} end,
|
||||
codeWhenReleased = function() SCENE:onInputRelease{input = "menu_decide"} end
|
||||
},
|
||||
BUTTON.new{
|
||||
text = "⌂\nHOME", font = FONT_big,
|
||||
x = 505, y = 160, w = 80, h = 80,
|
||||
codeWhenPressed = function() SCENE:onInputPress {input = "menu_back"} end,
|
||||
codeWhenReleased = function() SCENE:onInputRelease{input = "menu_back"} end
|
||||
},
|
||||
}
|
||||
|
||||
function ReplaySelectScene:new()
|
||||
self:initList()
|
||||
PENTO_MODE = false
|
||||
@@ -13,28 +41,25 @@ function ReplaySelectScene:initList()
|
||||
self.replay_text = {}
|
||||
self.page_flip = 16
|
||||
self.page = 1
|
||||
gradeNames = {
|
||||
"19k", "18k", "17k", "16k", "15k", "14k", "13k", "12k", "11k",
|
||||
local gradeNames = {
|
||||
"19k", "18k", "17k", "16k", "15k", "14k", "13k", "12k", "11k",
|
||||
"10k", "9k", "8k", "7k", "6k", "5k", "4k", "3k", "2k", "1k",
|
||||
"1D", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D"
|
||||
}
|
||||
for i=1, #replay_list do
|
||||
replay_found = string.find(replay_list[i], "_replay.sav")
|
||||
if replay_found ~= nil then
|
||||
if string.find(replay_list[i], "_replay.sav") ~= nil then
|
||||
table.insert(self.replays, replay_list[i])
|
||||
line_components = {}
|
||||
local line_components = {}
|
||||
for str in string.gmatch(replay_list[i], "([^".."_".."]+)") do
|
||||
table.insert(line_components, str)
|
||||
end
|
||||
player_name = line_components[2]
|
||||
player_grade = gradeNames[tonumber(line_components[3])]
|
||||
player_score = line_components[4]
|
||||
local player_name = line_components[2]
|
||||
local player_grade = gradeNames[tonumber(line_components[3])]
|
||||
local player_score = line_components[4]
|
||||
if #player_grade == 2 then player_grade = ' '..player_grade end
|
||||
table.insert(self.replay_text, player_name..' - '..player_grade..' - '..string.format('%6d',player_score))
|
||||
end
|
||||
end
|
||||
self.dialog = false
|
||||
self.dialog_select = 1
|
||||
self.replay_select = 1
|
||||
self.direction = nil
|
||||
self.repeat_limit = 10
|
||||
@@ -43,34 +68,27 @@ end
|
||||
|
||||
function ReplaySelectScene:render()
|
||||
MainBackground()
|
||||
|
||||
love.graphics.setColor(0.4, 1, 1, 0.5)
|
||||
love.graphics.rectangle("fill", 0, 20 + 20 * self.replay_select, 640, 22)
|
||||
|
||||
BUTTON.draw(buttonList)
|
||||
|
||||
drawText('Name - Grade - Score', 40, 20, 1000, "left")
|
||||
drawText(string.format('Page %s', self.page), 20, 440, 1000, "left")
|
||||
drawText(string.format('Page %s/%s', self.page, math.floor(#self.replays / self.page_flip) + 1), 20, 440, 1000, "left")
|
||||
|
||||
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
|
||||
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")
|
||||
end
|
||||
j = j + 1
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
if self.dialog then
|
||||
love.graphics.setColor(0, 0, 0, 0.5)
|
||||
love.graphics.rectangle("fill", 23, 43 + 20 * self.replay_select, 65, 40, 5, 5)
|
||||
love.graphics.setColor(0.3, 0.8, 0.8, 1)
|
||||
love.graphics.rectangle("fill", 20, 40 + 20 * self.replay_select, 65, 40, 5, 5)
|
||||
drawText("Play", 30, 40 + 20 * self.replay_select, 1000, "left")
|
||||
drawText("Delete", 30, 60 + 20 * self.replay_select, 1000, "left")
|
||||
drawText("o", 20, 40+((self.dialog_select-1) * 20) + (20 * self.replay_select), 1000, "left")
|
||||
|
||||
end
|
||||
if self.replays[1] == nil then
|
||||
drawText('No replays yet!', 40, 40, 1000, "left")
|
||||
end
|
||||
@@ -111,35 +129,30 @@ function ReplaySelectScene:changeOption(rel)
|
||||
end
|
||||
end
|
||||
|
||||
function ReplaySelectScene:changeDialog(rel)
|
||||
self.dialog_select = self.dialog_select + rel
|
||||
if self.dialog_select > 2 then self.dialog_select = 1
|
||||
elseif self.dialog_select < 1 then self.dialog_select = 2
|
||||
end
|
||||
end
|
||||
|
||||
function ReplaySelectScene:onInputPress(e)
|
||||
selected_replay = self.replays[self.replay_select + ((self.page-1) * self.page_flip)]
|
||||
selected_replay_text = self.replay_text[self.replay_select + ((self.page-1) * self.page_flip)]
|
||||
if e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then
|
||||
if self.replays[1] == nil then
|
||||
SCENE = TitleScene()
|
||||
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" then
|
||||
BUTTON.press(buttonList, e.x, e.y, e.id)
|
||||
elseif e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then
|
||||
if self.replays[1] == nil then SCENE = TitleScene(); return
|
||||
else
|
||||
line_components = {}
|
||||
local line_components = {}
|
||||
for str in string.gmatch(selected_replay_text, "([^".."-".."]+)") do
|
||||
table.insert(line_components, str)
|
||||
end
|
||||
player_name = line_components[1]
|
||||
player_grade = string.gsub(line_components[2], " ", "")
|
||||
local player_name = line_components[1]
|
||||
local player_grade = string.gsub(line_components[2], " ", "")
|
||||
SCENE = GameScene(player_name, selected_replay, player_grade)
|
||||
end
|
||||
elseif e.input == "rotate_right" then
|
||||
love.system.setClipboardText(love.data.encode("string", "base64", love.filesystem.read('saves/replays/'..selected_replay)))
|
||||
-- elseif e.input == "rotate_right" then -- Will add in future, not now
|
||||
-- love.system.setClipboardText(love.data.encode("string", "base64", love.filesystem.read('saves/replays/'..selected_replay)))
|
||||
elseif e.input == "up" or e.scancode == "up" then
|
||||
if self.replays[1] == nil then scene = TitleScene() end
|
||||
if self.replays[1] == nil then SCENE = TitleScene(); return end
|
||||
self.direction = 'up'
|
||||
elseif e.input == "down" or e.scancode == "down" then
|
||||
if self.replays[1] == nil then scene = TitleScene() end
|
||||
if self.replays[1] == nil then SCENE = TitleScene(); return end
|
||||
self.direction = 'down'
|
||||
elseif e.input == "menu_back" or e.input == "rotate_right" or e.scancode == "backspace" or e.scancode == "delete" then
|
||||
SCENE = TitleScene()
|
||||
@@ -147,10 +160,18 @@ function ReplaySelectScene:onInputPress(e)
|
||||
end
|
||||
|
||||
function ReplaySelectScene:onInputRelease(e)
|
||||
if e.input == "up" or e.scancode == "up" or e.input == "down" or e.scancode == "down" then
|
||||
if e.type == "touch" or e.type == "mouse" then
|
||||
BUTTON.release(buttonList, e.x, e.y, e.id)
|
||||
elseif e.input == "up" or e.scancode == "up" or e.input == "down" or e.scancode == "down" then
|
||||
self.direction = nil
|
||||
self.repeat_counter = self.repeat_limit-1
|
||||
end
|
||||
end
|
||||
|
||||
function ReplaySelectScene:onInputMove(e)
|
||||
if e.type == "mouse" then
|
||||
BUTTON.checkHovering(buttonList, e.x, e.y)
|
||||
end
|
||||
end
|
||||
|
||||
return ReplaySelectScene
|
||||
|
||||
Reference in New Issue
Block a user