From 99b178262f9a5f777e4584614bbacd8cdd264bd0 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 20:36:04 +0100 Subject: [PATCH] DesitionSelector --- inc/init/init.context.lua | 22 ++++++++++++++++ inc/init/init.modules.lua | 2 +- inc/system/system.desitions.lua | 1 - inc/system/system.ui.lua | 39 +++++++++++++++++++++++++--- inc/window/window.game.lua | 46 +++++++++++++++++++++++++++++---- 5 files changed, 100 insertions(+), 10 deletions(-) diff --git a/inc/init/init.context.lua b/inc/init/init.context.lua index 1ae5635..a916b88 100644 --- a/inc/init/init.context.lua +++ b/inc/init/init.context.lua @@ -43,16 +43,38 @@ local function get_initial_data() }, menu_items = {}, selected_menu_item = 1, + selected_desition_index = 1, -- New desition index game_in_progress = false, -- New flag screens = clone_table({ { name = "Screen 1", + decisions = { + Util.create_decision( + "play_button_mash", + "Play Button Mash", + function() Desitions.start_minigame_mash() end + ), + } }, { name = "Screen 2", + decisions = { + Util.create_decision( + "play_rhythm", + "Play Rhythm Game", + function() Desitions.start_minigame_rhythm() end + ), + } }, { name = "Screen 3", + decisions = { + Util.create_decision( + "play_ddr", + "Play DDR (Random)", + function() Desitions.start_minigame_ddr(nil) end + ), + } } }) } diff --git a/inc/init/init.modules.lua b/inc/init/init.modules.lua index d93f72a..098e38a 100644 --- a/inc/init/init.modules.lua +++ b/inc/init/init.modules.lua @@ -11,9 +11,9 @@ local MinigameDDRWindow = {} local Util = {} local Context = {} +local Desitions = {} local UI = {} local Print = {} local Input = {} local Player = {} local Audio = {} -local Desitions = {} diff --git a/inc/system/system.desitions.lua b/inc/system/system.desitions.lua index 7467807..2d311ea 100644 --- a/inc/system/system.desitions.lua +++ b/inc/system/system.desitions.lua @@ -1,4 +1,3 @@ - function Desitions.start_minigame_mash() MinigameButtonMashWindow.start(WINDOW_GAME) end diff --git a/inc/system/system.ui.lua b/inc/system/system.ui.lua index 4f21ee1..4ebc1ad 100644 --- a/inc/system/system.ui.lua +++ b/inc/system/system.ui.lua @@ -80,10 +80,43 @@ function UI.create_numeric_stepper(label, value_getter, value_setter, min, max, } end -function UI.create_desition_item(label, desition) +function UI.create_action_item(label, action) return { label = label, - desition = desition, - type = "desition_item" + action = action, + type = "action_item" } end + +function UI.draw_desition_selector(desitions, selected_desition_index) + local bar_height = 16 + local bar_y = Config.screen.height - bar_height + + rect(0, bar_y, Config.screen.width, bar_height, Config.colors.dark_grey) + + if #desitions > 0 then + local selected_desition = desitions[selected_desition_index] + local desition_label = selected_desition.label + local text_width = #desition_label * 4 -- Assuming 4 pixels per char + local text_x = (Config.screen.width - text_width) / 2 + local text_y = bar_y + 4 + + -- Draw left arrow + Print.text("<", text_x - 10, text_y, Config.colors.green) + -- Draw selected desition label + Print.text(desition_label, text_x, text_y, Config.colors.item) -- Highlight color + -- Draw right arrow + Print.text(">", text_x + text_width + 6, text_y, Config.colors.green) + end +end + +function UI.update_desition_selector(desitions, selected_desition_index) + if Input.left() then + Audio.sfx_beep() + selected_desition_index = Util.safeindex(desitions, selected_desition_index - 1) + elseif Input.right() then + Audio.sfx_beep() + selected_desition_index = Util.safeindex(desitions, selected_desition_index + 1) + end + return selected_desition_index +end diff --git a/inc/window/window.game.lua b/inc/window/window.game.lua index 4af01c0..35c675f 100644 --- a/inc/window/window.game.lua +++ b/inc/window/window.game.lua @@ -2,6 +2,10 @@ function GameWindow.draw() local currentScreenData = Context.screens[Context.current_screen] UI.draw_top_bar(currentScreenData.name) + + if currentScreenData and currentScreenData.decisions and #currentScreenData.decisions > 0 then + UI.draw_desition_selector(currentScreenData.decisions, Context.selected_desition_index) + end end function GameWindow.update() @@ -10,11 +14,43 @@ function GameWindow.update() MenuWindow.refresh_menu_items() return end - if Input.select() then - if Context.current_screen == #Context.screens then + + -- Handle screen changing using up/down + if Input.up() then + Context.current_screen = Context.current_screen - 1 + if Context.current_screen < 1 then + Context.current_screen = #Context.screens + end + Context.selected_desition_index = 1 -- Reset selected decision on screen change + elseif Input.down() then + Context.current_screen = Context.current_screen + 1 + if Context.current_screen > #Context.screens then Context.current_screen = 1 - else - Context.current_screen = Context.current_screen + 1 + end + Context.selected_desition_index = 1 -- Reset selected decision on screen change + end + + local currentScreenData = Context.screens[Context.current_screen] + + if currentScreenData and currentScreenData.decisions and #currentScreenData.decisions > 0 then + -- Update selected decision using left/right inputs + local new_selected_desition_index = UI.update_desition_selector( + currentScreenData.decisions, + Context.selected_desition_index + ) + + -- Only update Context if the selection actually changed to avoid unnecessary re-assignment + if new_selected_desition_index ~= Context.selected_desition_index then + Context.selected_desition_index = new_selected_desition_index + end + + -- Execute selected decision on Input.select() + if Input.select() then + local selected_desition = currentScreenData.decisions[Context.selected_desition_index] + if selected_desition and selected_desition.handler then + Audio.sfx_select() -- Play sound for selection + selected_desition.handler() + end end end end @@ -22,4 +58,4 @@ end function GameWindow.set_state(new_state) Context.active_window = new_state -- Add any state-specific initialization/cleanup here later if needed -end \ No newline at end of file +end