diff --git a/.luacheckrc b/.luacheckrc index 63d603f..c8dfabd 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -30,6 +30,7 @@ globals = { "MenuWindow", "GameWindow", "PopupWindow", + "ControlsWindow", "AudioTestWindow", "MinigameButtonMashWindow", "MinigameRhythmWindow", diff --git a/impostor.inc b/impostor.inc index af58622..8b09814 100644 --- a/impostor.inc +++ b/impostor.inc @@ -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 diff --git a/inc/system/system.input.lua b/inc/system/system.input.lua index 3c015c2..9fe0ae5 100644 --- a/inc/system/system.input.lua +++ b/inc/system/system.input.lua @@ -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 diff --git a/inc/window/window.controls.lua b/inc/window/window.controls.lua new file mode 100644 index 0000000..1a4cd89 --- /dev/null +++ b/inc/window/window.controls.lua @@ -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 diff --git a/inc/window/window.menu.lua b/inc/window/window.menu.lua index 5903f42..6199db6 100644 --- a/inc/window/window.menu.lua +++ b/inc/window/window.menu.lua @@ -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}) diff --git a/inc/window/window.register.lua b/inc/window/window.register.lua index c293d6c..a3388ac 100644 --- a/inc/window/window.register.lua +++ b/inc/window/window.register.lua @@ -16,6 +16,9 @@ Window.register("game", GameWindow) PopupWindow = {} Window.register("popup", PopupWindow) +ControlsWindow = {} +Window.register("controls", ControlsWindow) + AudioTestWindow = {} Window.register("audiotest", AudioTestWindow)