This commit is contained in:
@@ -30,9 +30,15 @@ function EndWindow.draw()
|
||||
Print.text(yes_text, centerX - 40, y, yes_color)
|
||||
Print.text(no_text, centerX + 10, y, no_color)
|
||||
elseif Context._end.state == "ending" then
|
||||
Print.text_center("Game over -- good ending.", Config.screen.width / 2, 50, Config.colors.light_blue)
|
||||
Print.text_center("Congratulations!", Config.screen.width / 2, 70, Config.colors.white)
|
||||
Print.text_center("Press Z to return to menu", Config.screen.width / 2, 110, Config.colors.light_grey)
|
||||
local cx = Config.screen.width / 2
|
||||
local name = Context.player_name or "AAA"
|
||||
local code = CodeGenerator.encrypt(name)
|
||||
Print.text_center("Game over -- good ending.", cx, 40, Config.colors.light_blue)
|
||||
Print.text_center("Congrats " .. name .. "!", cx, 54, Config.colors.white)
|
||||
Print.text_center("Your personal code:", cx, 72, Config.colors.light_grey)
|
||||
Print.text_center(code, cx, 84, Config.colors.white, false, 3)
|
||||
Print.text_center("Write it down!", cx, 112, Config.colors.item)
|
||||
Print.text_center("Press Z to return to menu", cx, 126, Config.colors.dark_grey)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -102,17 +102,13 @@ function MenuWindow.update()
|
||||
end
|
||||
end
|
||||
|
||||
--- Starts a new game from the menu.
|
||||
--- Opens player name entry then starts a new game.
|
||||
--- @within MenuWindow
|
||||
function MenuWindow.new_game()
|
||||
Context.new_game()
|
||||
end
|
||||
|
||||
--- Loads a game from the menu.
|
||||
--- @within MenuWindow
|
||||
function MenuWindow.load_game()
|
||||
Context.load_game()
|
||||
GameWindow.set_state("game")
|
||||
PlayerNameWindow.init(function()
|
||||
Context.new_game()
|
||||
end)
|
||||
Window.set_current("player_name")
|
||||
end
|
||||
|
||||
--- Saves the current game from the menu.
|
||||
@@ -139,6 +135,21 @@ function MenuWindow.controls()
|
||||
Window.set_current("controls")
|
||||
end
|
||||
|
||||
--- Opens the player name entry screen (test mode shortcut).
|
||||
--- @within MenuWindow
|
||||
function MenuWindow.player_name()
|
||||
PlayerNameWindow.init()
|
||||
Window.set_current("player_name")
|
||||
end
|
||||
|
||||
--- Opens the credits screen.
|
||||
--- @within MenuWindow
|
||||
function MenuWindow.credits()
|
||||
CreditsWindow.init()
|
||||
Window.set_current("credits")
|
||||
end
|
||||
|
||||
|
||||
--- Opens the audio test menu.
|
||||
--- @within MenuWindow
|
||||
function MenuWindow.audio_test()
|
||||
@@ -153,6 +164,14 @@ function MenuWindow.continued()
|
||||
GameWindow.set_state("continued")
|
||||
end
|
||||
|
||||
--- Opens the end screen for testing.
|
||||
--- @within MenuWindow
|
||||
function MenuWindow.end_screen()
|
||||
Context._end.state = "ending"
|
||||
Context._end.selection = 1
|
||||
GameWindow.set_state("end")
|
||||
end
|
||||
|
||||
--- Opens the DDR minigame test.
|
||||
--- @within MenuWindow
|
||||
function MenuWindow.ddr_test()
|
||||
@@ -171,13 +190,15 @@ function MenuWindow.refresh_menu_items()
|
||||
end
|
||||
|
||||
table.insert(_menu_items, {label = "New Game", decision = MenuWindow.new_game})
|
||||
table.insert(_menu_items, {label = "Load Game", decision = MenuWindow.load_game})
|
||||
table.insert(_menu_items, {label = "Controls", decision = MenuWindow.controls})
|
||||
table.insert(_menu_items, {label = "Credits", decision = MenuWindow.credits})
|
||||
|
||||
if Context.test_mode then
|
||||
table.insert(_menu_items, {label = "Audio Test", decision = MenuWindow.audio_test})
|
||||
table.insert(_menu_items, {label = "To Be Continued...", decision = MenuWindow.continued})
|
||||
table.insert(_menu_items, {label = "DDR Test", decision = MenuWindow.ddr_test})
|
||||
table.insert(_menu_items, {label = "End Screen", decision = MenuWindow.end_screen})
|
||||
table.insert(_menu_items, {label = "Player Name", decision = MenuWindow.player_name})
|
||||
end
|
||||
|
||||
table.insert(_menu_items, {label = "Exit", decision = MenuWindow.exit})
|
||||
|
||||
115
inc/window/window.player_name.lua
Normal file
115
inc/window/window.player_name.lua
Normal file
@@ -0,0 +1,115 @@
|
||||
--- @section PlayerNameWindow
|
||||
|
||||
local _frame = 0
|
||||
local _on_confirm = nil
|
||||
local MAX_LEN = 3
|
||||
local BOX_W = 24
|
||||
local BOX_H = 24
|
||||
local BOX_GAP = 12
|
||||
local BOX_Y = 50
|
||||
local WARN_Y = 104
|
||||
|
||||
local function box_start_x()
|
||||
return math.floor((Config.screen.width - (MAX_LEN * BOX_W + (MAX_LEN - 1) * BOX_GAP)) / 2)
|
||||
end
|
||||
|
||||
local function box_x(i)
|
||||
return box_start_x() + (i - 1) * (BOX_W + BOX_GAP)
|
||||
end
|
||||
|
||||
--- Initialises the player name window.
|
||||
--- @within PlayerNameWindow
|
||||
--- @param on_confirm function Called with the entered name when the player saves.
|
||||
function PlayerNameWindow.init(on_confirm)
|
||||
_frame = 0
|
||||
_on_confirm = on_confirm
|
||||
TextInput.init(MAX_LEN)
|
||||
end
|
||||
|
||||
local function draw_boxes()
|
||||
local cursor = TextInput.get_position()
|
||||
local blink = math.floor(_frame / 18) % 2 == 0
|
||||
|
||||
for i = 1, MAX_LEN do
|
||||
local x = box_x(i)
|
||||
local is_cur = (i == cursor)
|
||||
local done = TextInput.is_done()
|
||||
|
||||
local fill = (is_cur and not done) and Config.colors.blue or Config.colors.black
|
||||
local border = (is_cur and not done) and Config.colors.white
|
||||
or done and Config.colors.light_blue
|
||||
or Config.colors.dark_grey
|
||||
|
||||
rect (x, BOX_Y, BOX_W, BOX_H, fill)
|
||||
rectb(x, BOX_Y, BOX_W, BOX_H, border)
|
||||
|
||||
local show = not (is_cur and blink and not done)
|
||||
if show then
|
||||
local ch = TextInput.get_letter(i)
|
||||
local cw = print(ch, 0, -100, 0, false, 2)
|
||||
local cx = x + math.floor((BOX_W - cw) / 2)
|
||||
local cy = BOX_Y + math.floor((BOX_H - 11) / 2)
|
||||
local col = (is_cur and not done) and Config.colors.white or Config.colors.light_grey
|
||||
print(ch, cx, cy, col, false, 2)
|
||||
end
|
||||
end
|
||||
|
||||
-- caret arrow below active box
|
||||
if not TextInput.is_done() then
|
||||
local cx = box_x(cursor) + math.floor(BOX_W / 2)
|
||||
local ay = BOX_Y + BOX_H + 4
|
||||
line(cx - 4, ay, cx, ay + 4, Config.colors.white)
|
||||
line(cx + 4, ay, cx, ay + 4, Config.colors.white)
|
||||
end
|
||||
end
|
||||
|
||||
--- Draws the player name window.
|
||||
--- @within PlayerNameWindow
|
||||
function PlayerNameWindow.draw()
|
||||
cls(Config.colors.black)
|
||||
|
||||
Print.text_center("Player Name", Config.screen.width / 2, 14, Config.colors.white, false, 2)
|
||||
|
||||
draw_boxes()
|
||||
|
||||
if TextInput.is_done() then
|
||||
Print.text_center("Z: save name B: edit", Config.screen.width / 2, BOX_Y + BOX_H + 12, Config.colors.light_blue)
|
||||
else
|
||||
Print.text_center("Up/Dn: letter Lft/Rgt: move Z: ok", Config.screen.width / 2, BOX_Y + BOX_H + 12, Config.colors.dark_grey)
|
||||
end
|
||||
|
||||
-- Warning section
|
||||
rect(0, WARN_Y, Config.screen.width, Config.screen.height - WARN_Y, Config.colors.blue)
|
||||
rectb(0, WARN_Y, Config.screen.width, Config.screen.height - WARN_Y, Config.colors.light_blue)
|
||||
Print.text_center("Remember your name!", Config.screen.width / 2, WARN_Y + 8, Config.colors.white)
|
||||
Print.text_center("You will need it to load the game.", Config.screen.width / 2, WARN_Y + 20, Config.colors.light_grey)
|
||||
end
|
||||
|
||||
--- Updates player name window logic.
|
||||
--- @within PlayerNameWindow
|
||||
function PlayerNameWindow.update()
|
||||
_frame = _frame + 1
|
||||
|
||||
if TextInput.is_done() then
|
||||
if Input.select() then
|
||||
Context.player_name = TextInput.get_name()
|
||||
if _on_confirm then _on_confirm() else Window.set_current("menu") end
|
||||
elseif Input.back() then
|
||||
TextInput.prev_position()
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if Input.up_repeat() then TextInput.next_letter() end
|
||||
if Input.down_repeat() then TextInput.prev_letter() end
|
||||
if Input.right() then TextInput.next_position() end
|
||||
if Input.select() then TextInput.select_letter() end
|
||||
|
||||
if Input.left() or Input.back() then
|
||||
if TextInput.get_position() > 1 then
|
||||
TextInput.prev_position()
|
||||
else
|
||||
Window.set_current("menu")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -39,3 +39,9 @@ Window.register("discussion", DiscussionWindow)
|
||||
|
||||
ContinuedWindow = {}
|
||||
Window.register("continued", ContinuedWindow)
|
||||
|
||||
CreditsWindow = {}
|
||||
Window.register("credits", CreditsWindow)
|
||||
|
||||
PlayerNameWindow = {}
|
||||
Window.register("player_name", PlayerNameWindow)
|
||||
|
||||
Reference in New Issue
Block a user