From 200e05f2dcc8cf3827b29300269b5512f60d215a Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Thu, 8 Oct 2026 07:43:58 +0200 Subject: [PATCH] Improved scene manager history. Added a parent field essentially making a linked list. Allows for better menu traversal. --- src/scene_manager.odin | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/scene_manager.odin b/src/scene_manager.odin index eeb4106..fc9b31b 100644 --- a/src/scene_manager.odin +++ b/src/scene_manager.odin @@ -16,6 +16,7 @@ Scene_Type :: enum { Scene :: struct { type: Scene_Type, + parent: Maybe(Scene_Type), level: Maybe(Level), canvas: Maybe(Canvas), winner_is_player: bool, @@ -26,7 +27,7 @@ push_scene :: proc(game: ^Game, scene: Scene) { } pop_scene :: proc(game: ^Game) { - if len(game.scene_stack) > 1 { + if len(game.scene_stack) > 0 { top_index := len(game.scene_stack) - 1 destroy_scene(&game.scene_stack[top_index]) pop(&game.scene_stack) @@ -227,6 +228,7 @@ make_main_menu :: proc() -> Scene { return Scene{ type = .Main_Menu, + parent = nil, canvas = Canvas{ bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H}, padding = UI_TITLE_PADDING, @@ -296,6 +298,7 @@ make_pause_overlay :: proc() -> Scene { return Scene{ type = .Pause_Menu, + parent = nil, canvas = Canvas{ bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H}, padding = UI_TITLE_PADDING, @@ -363,7 +366,7 @@ update_pause_menu :: proc(scene: ^Scene, input: Input_Event) { // ------------------------------------------------------------------------------ // Settings Menu // ------------------------------------------------------------------------------ -make_settings_menu :: proc(audio: ^Audio_Manager, current_res_label: cstring) -> Scene { +make_settings_menu :: proc(parent: Maybe(Scene_Type), audio: ^Audio_Manager, current_res_label: cstring) -> Scene { ui_items:[8]UI_Item = { 0 = UI_Button{"Back"}, 1 = UI_Selector{ @@ -384,6 +387,7 @@ make_settings_menu :: proc(audio: ^Audio_Manager, current_res_label: cstring) -> return Scene{ type = .Settings_Menu, + parent = parent, canvas = Canvas{ bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H}, padding = UI_TITLE_PADDING, @@ -405,6 +409,12 @@ render_settings_menu :: proc(scene: Scene) { menu, menu_ok := canvas.menu.? assert(menu_ok, "render_settings_menu: Canvas is missing a UI_Menu component") + + if scene.parent != .Main_Menu { + // Draw dark overlay so gameplay/background stays visible behind Settings + rl.DrawRectangleRec(canvas.bounds, rl.Color{0, 0, 0, 200}) + } + t_text: cstring = "SETTINGS" t_width := rl.MeasureText(t_text, UI_TITLE_FONT_SIZE) t_x := i32(canvas.bounds.width * 0.5) - (t_width / 2) @@ -472,6 +482,7 @@ make_game_over_overlay :: proc(winner_is_player: bool) -> Scene { return Scene{ type = .Game_Over, + parent = nil, winner_is_player = winner_is_player, canvas = Canvas{ bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H}, @@ -537,6 +548,7 @@ update_game_over :: proc(scene: ^Scene, input: Input_Event) { make_gameplay_scene :: proc() -> Scene { return Scene{ type = .Gameplay, + parent = nil, level = init_level(), } } \ No newline at end of file