DesitionSelector
This commit is contained in:
@@ -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
|
||||
),
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ local MinigameDDRWindow = {}
|
||||
|
||||
local Util = {}
|
||||
local Context = {}
|
||||
local Desitions = {}
|
||||
local UI = {}
|
||||
local Print = {}
|
||||
local Input = {}
|
||||
local Player = {}
|
||||
local Audio = {}
|
||||
local Desitions = {}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
function Desitions.start_minigame_mash()
|
||||
MinigameButtonMashWindow.start(WINDOW_GAME)
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user