Improved scene manager history.

Added a parent field essentially making a linked list.
Allows for better menu traversal.
This commit is contained in:
2026-10-08 07:43:58 +02:00
parent 404c320973
commit 200e05f2dc
+14 -2
View File
@@ -16,6 +16,7 @@ Scene_Type :: enum {
Scene :: struct { Scene :: struct {
type: Scene_Type, type: Scene_Type,
parent: Maybe(Scene_Type),
level: Maybe(Level), level: Maybe(Level),
canvas: Maybe(Canvas), canvas: Maybe(Canvas),
winner_is_player: bool, winner_is_player: bool,
@@ -26,7 +27,7 @@ push_scene :: proc(game: ^Game, scene: Scene) {
} }
pop_scene :: proc(game: ^Game) { pop_scene :: proc(game: ^Game) {
if len(game.scene_stack) > 1 { if len(game.scene_stack) > 0 {
top_index := len(game.scene_stack) - 1 top_index := len(game.scene_stack) - 1
destroy_scene(&game.scene_stack[top_index]) destroy_scene(&game.scene_stack[top_index])
pop(&game.scene_stack) pop(&game.scene_stack)
@@ -227,6 +228,7 @@ make_main_menu :: proc() -> Scene {
return Scene{ return Scene{
type = .Main_Menu, type = .Main_Menu,
parent = nil,
canvas = Canvas{ canvas = Canvas{
bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H}, bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H},
padding = UI_TITLE_PADDING, padding = UI_TITLE_PADDING,
@@ -296,6 +298,7 @@ make_pause_overlay :: proc() -> Scene {
return Scene{ return Scene{
type = .Pause_Menu, type = .Pause_Menu,
parent = nil,
canvas = Canvas{ canvas = Canvas{
bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H}, bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H},
padding = UI_TITLE_PADDING, padding = UI_TITLE_PADDING,
@@ -363,7 +366,7 @@ update_pause_menu :: proc(scene: ^Scene, input: Input_Event) {
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Settings Menu // 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 = { ui_items:[8]UI_Item = {
0 = UI_Button{"Back"}, 0 = UI_Button{"Back"},
1 = UI_Selector{ 1 = UI_Selector{
@@ -384,6 +387,7 @@ make_settings_menu :: proc(audio: ^Audio_Manager, current_res_label: cstring) ->
return Scene{ return Scene{
type = .Settings_Menu, type = .Settings_Menu,
parent = parent,
canvas = Canvas{ canvas = Canvas{
bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H}, bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H},
padding = UI_TITLE_PADDING, padding = UI_TITLE_PADDING,
@@ -405,6 +409,12 @@ render_settings_menu :: proc(scene: Scene) {
menu, menu_ok := canvas.menu.? menu, menu_ok := canvas.menu.?
assert(menu_ok, "render_settings_menu: Canvas is missing a UI_Menu component") 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_text: cstring = "SETTINGS"
t_width := rl.MeasureText(t_text, UI_TITLE_FONT_SIZE) t_width := rl.MeasureText(t_text, UI_TITLE_FONT_SIZE)
t_x := i32(canvas.bounds.width * 0.5) - (t_width / 2) 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{ return Scene{
type = .Game_Over, type = .Game_Over,
parent = nil,
winner_is_player = winner_is_player, winner_is_player = winner_is_player,
canvas = Canvas{ canvas = Canvas{
bounds = rl.Rectangle{0, 0, VIEWPORT_W, VIEWPORT_H}, 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 { make_gameplay_scene :: proc() -> Scene {
return Scene{ return Scene{
type = .Gameplay, type = .Gameplay,
parent = nil,
level = init_level(), level = init_level(),
} }
} }