Controls menu

This commit is contained in:
2026-04-02 18:51:17 +02:00
parent 589b225ab0
commit 10316d3075
6 changed files with 60 additions and 3 deletions

View File

@@ -30,6 +30,7 @@ globals = {
"MenuWindow",
"GameWindow",
"PopupWindow",
"ControlsWindow",
"AudioTestWindow",
"MinigameButtonMashWindow",
"MinigameRhythmWindow",

View File

@@ -70,6 +70,7 @@ window/window.intro.title.lua
window/window.intro.ttg.lua
window/window.intro.brief.lua
window/window.menu.lua
window/window.controls.lua
window/window.audiotest.lua
window/window.popup.lua
window/window.minigame.mash.lua

View File

@@ -3,7 +3,8 @@ local INPUT_KEY_UP = 0
local INPUT_KEY_DOWN = 1
local INPUT_KEY_LEFT = 2
local INPUT_KEY_RIGHT = 3
local INPUT_KEY_Y = 7
local INPUT_KEY_A = 4
local INPUT_KEY_B = 5
local INPUT_KEY_SPACE = 48
local INPUT_KEY_BACKSPACE = 51
@@ -21,7 +22,7 @@ function Input.left() return btnp(INPUT_KEY_LEFT) end
function Input.right() return btnp(INPUT_KEY_RIGHT) end
--- Checks if Select is pressed.
--- @within Input
function Input.select() return btnp(INPUT_KEY_Y) or keyp(INPUT_KEY_SPACE) or Mouse.clicked() end
function Input.select() return btnp(INPUT_KEY_A) or keyp(INPUT_KEY_SPACE) or Mouse.clicked() end
--- Checks if Back is pressed.
--- @within Input
function Input.back() return keyp(INPUT_KEY_BACKSPACE) end
function Input.back() return btnp(INPUT_KEY_B) or keyp(INPUT_KEY_BACKSPACE) end

View File

@@ -0,0 +1,44 @@
--- @section ControlsWindow
local _controls = {
{ action = "Navigate", keyboard = "Arrow keys", gamepad = "D-pad" },
{ action = "Select / OK", keyboard = "Space", gamepad = "Z button" },
{ action = "Back", keyboard = "Backspace", gamepad = "B button" },
{ action = "Click", keyboard = "Mouse", gamepad = "" },
}
--- Draws the controls window.
--- @within ControlsWindow
function ControlsWindow.draw()
UI.draw_top_bar("Controls")
local col_action = 4
local col_keyboard = 80
local col_gamepad = 170
local row_h = 10
local y_header = 18
local y_start = 30
Print.text("Action", col_action, y_header, Config.colors.light_grey)
Print.text("Keyboard", col_keyboard, y_header, Config.colors.light_grey)
Print.text("Gamepad", col_gamepad, y_header, Config.colors.light_grey)
line(col_action, y_header + 8, Config.screen.width - 4, y_header + 8, Config.colors.dark_grey)
for i, entry in ipairs(_controls) do
local y = y_start + (i - 1) * row_h
Print.text(entry.action, col_action, y, Config.colors.white)
Print.text(entry.keyboard, col_keyboard, y, Config.colors.light_blue)
if entry.gamepad ~= "" then
Print.text(entry.gamepad, col_gamepad, y, Config.colors.light_blue)
end
end
Print.text("Space / Z button or click to go back", col_action, Config.screen.height - 10, Config.colors.light_grey)
end
--- Updates the controls window logic.
--- @within ControlsWindow
function ControlsWindow.update()
if Input.back() or Input.select() then
Window.set_current("menu")
end
end

View File

@@ -84,6 +84,12 @@ function MenuWindow.exit()
exit()
end
--- Opens the controls screen.
--- @within MenuWindow
function MenuWindow.controls()
Window.set_current("controls")
end
--- Opens the audio test menu.
--- @within MenuWindow
function MenuWindow.audio_test()
@@ -117,6 +123,7 @@ function MenuWindow.refresh_menu_items()
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})
if Context.test_mode then
table.insert(_menu_items, {label = "Audio Test", decision = MenuWindow.audio_test})

View File

@@ -16,6 +16,9 @@ Window.register("game", GameWindow)
PopupWindow = {}
Window.register("popup", PopupWindow)
ControlsWindow = {}
Window.register("controls", ControlsWindow)
AudioTestWindow = {}
Window.register("audiotest", AudioTestWindow)