From bda6e1eb616fbceeb591bed8ee192ddc8588b75e Mon Sep 17 00:00:00 2001 From: Cat Date: Wed, 25 Dec 2024 21:25:45 -0700 Subject: [PATCH 01/17] Added level loading screen Created a MasterLevelLoadingMenu class and scene, with added logic to the Master MainMenu. It borrows from the Continue game logic as well as the SceneLister logic. Levels are propagated into an ItemList, with their file names cleaned. Whatever Level is activated, will update the GameStates.current_level to match the level selected. A signal emits which triggers the load action from the main menu. It tried to keep it minimal, and imitate the style of logic already established. --- .../base/scenes/menus/main_menu/main_menu.gd | 19 ++++++++ .../scenes/menus/main_menu/main_menu.tscn | 23 +++++++++- .../master_level_select_menu.gd | 43 +++++++++++++++++++ .../master_level_select_menu.tscn | 41 ++++++++++++++++++ .../main_menu/main_menu_with_animations.tscn | 4 +- 5 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd create mode 100644 addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn diff --git a/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd b/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd index bce0526..6fcd007 100644 --- a/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd +++ b/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd @@ -5,9 +5,11 @@ extends Control @export_file("*.tscn") var game_scene_path : String @export var options_packed_scene : PackedScene @export var credits_packed_scene : PackedScene +@export var level_select_packed_scene: PackedScene var options_scene var credits_scene +var level_select_scene var sub_menu func load_game_scene(): @@ -68,10 +70,24 @@ func _setup_credits(): credits_scene.connect("end_reached", _on_credits_end_reached) %CreditsContainer.call_deferred("add_child", credits_scene) +## If present, adds a level select screen button, and connects siganl triggers to update +## the current level, and load it (borrowing from "continue" button logic) +func _setup_level_select(): + if level_select_packed_scene == null: + %LevelSelectButton.hide() + else: + level_select_scene = level_select_packed_scene.instantiate() + level_select_scene.hide() + %LevelSelectContainer.call_deferred("add_child", level_select_scene) + if level_select_scene.has_signal("level_selected"): + level_select_scene.connect("level_selected", load_game_scene) + + func _ready(): _setup_for_web() _setup_options() _setup_credits() + _setup_level_select() _setup_game_buttons() func _on_new_game_button_pressed(): @@ -93,3 +109,6 @@ func _on_credits_end_reached(): func _on_back_button_pressed(): _close_sub_menu() + +func _on_level_select_button_pressed(): + _open_sub_menu(level_select_scene) diff --git a/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn b/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn index 184d2ec..a4df833 100644 --- a/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn +++ b/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=9 format=3 uid="uid://c6k5nnpbypshi"] +[gd_scene load_steps=10 format=3 uid="uid://c6k5nnpbypshi"] [ext_resource type="Script" path="res://addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd" id="1"] [ext_resource type="PackedScene" uid="uid://hmx6o472ropw" path="res://addons/maaacks_game_template/base/scenes/menus/options_menu/master_options_menu_with_tabs.tscn" id="2_qvrrd"] [ext_resource type="PackedScene" uid="uid://t2dui8ppm3a4" path="res://addons/maaacks_game_template/base/scenes/credits/credits.tscn" id="3_5dhvp"] [ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="4_l1ebe"] +[ext_resource type="PackedScene" uid="uid://dtu0ffm1m5mr7" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn" id="4_p8833"] [ext_resource type="PackedScene" uid="uid://bkcsjsk2ciff" path="res://addons/maaacks_game_template/base/scenes/music_players/background_music_player.tscn" id="4_w8sbm"] [ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/ui_sound_controller.gd" id="6_bs342"] [ext_resource type="Script" path="res://addons/maaacks_game_template/base/scenes/menus/main_menu/config_version_label.gd" id="6_pdiij"] @@ -19,6 +20,7 @@ grow_vertical = 2 script = ExtResource("1") options_packed_scene = ExtResource("2_qvrrd") credits_packed_scene = ExtResource("3_5dhvp") +level_select_packed_scene = ExtResource("4_p8833") [node name="UISoundController" type="Node" parent="."] script = ExtResource("6_bs342") @@ -90,7 +92,7 @@ anchor_right = 1.0 offset_bottom = 67.0 grow_horizontal = 2 theme_override_font_sizes/font_size = 48 -text = "Title" +text = "Game Template" horizontal_alignment = 1 vertical_alignment = 1 script = ExtResource("7_j7612") @@ -150,6 +152,12 @@ custom_minimum_size = Vector2(128, 40) layout_mode = 2 text = "New Game" +[node name="LevelSelectButton" type="Button" parent="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(128, 40) +layout_mode = 2 +text = "Level Select" + [node name="OptionsButton" type="Button" parent="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer"] unique_name_in_owner = true custom_minimum_size = Vector2(128, 40) @@ -189,6 +197,16 @@ theme_override_constants/margin_top = 32 theme_override_constants/margin_right = 16 theme_override_constants/margin_bottom = 32 +[node name="LevelSelectContainer" type="MarginContainer" parent="."] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 + [node name="FlowControlContainer" type="MarginContainer" parent="."] layout_mode = 0 anchor_right = 1.0 @@ -217,6 +235,7 @@ grow_vertical = 0 text = "Back" [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/NewGameButton" to="." method="_on_new_game_button_pressed"] +[connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/LevelSelectButton" to="." method="_on_level_select_button_pressed"] [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"] [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/CreditsButton" to="." method="_on_credits_button_pressed"] [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"] diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd new file mode 100644 index 0000000..7b0413c --- /dev/null +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd @@ -0,0 +1,43 @@ +extends Control +class_name MasterLevelSelectMenu + +## Loads a simple ItemList node within a margin container. SceneLister updates +## the available scenes in the directory provided. Activating a level will update +## the GameState's current_level, and emit a signal. The main menu node will trigger +## a load action from that signal. + +@onready var level_buttons_container: ItemList = %LevelButtonsContainer +@onready var level_buttons_margin: MarginContainer = %LevelButtonsMargin +@onready var scene_lister: SceneLister = $SceneLister + +signal level_selected + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + add_levels_to_container() + +func _unhandled_input(event): + if not is_visible_in_tree(): + return + +## A fresh level list is propgated into the ItemList, and the file names are cleaned +func add_levels_to_container(): + level_buttons_container.clear() + + for file_path in scene_lister.files: + # Extract the file name from the path + var file_name = file_path.get_file() # e.g., "level_1.tscn" + + # Clean up the file name + file_name = file_name.trim_suffix(".tscn") # Remove the ".tscn" extension + file_name = file_name.replace("_", " ") # Replace underscores with spaces + file_name = file_name.capitalize() # Convert to proper case + + var button_name = str(file_name) + level_buttons_container.add_item(button_name) + + +func _on_level_buttons_container_item_activated(index: int) -> void: + GameState.set_current_level(index) + call_deferred("emit_signal","level_selected") + hide() diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn new file mode 100644 index 0000000..1b8b851 --- /dev/null +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn @@ -0,0 +1,41 @@ +[gd_scene load_steps=3 format=3 uid="uid://dtu0ffm1m5mr7"] + +[ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd" id="1_dm7vg"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_g3cvb"] + +[node name="MasterLevelSelectMenu" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_dm7vg") + +[node name="SceneLister" type="Node" parent="."] +script = ExtResource("2_g3cvb") +files = Array[String](["res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_1.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_2.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_3.tscn"]) +directory = "res://addons/maaacks_game_template/examples/scenes/game_scene/levels" + +[node name="LevelButtonsMargin" type="MarginContainer" parent="."] +unique_name_in_owner = true +custom_minimum_size = Vector2(200, 0) +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_top = -17.5 +offset_bottom = 17.5 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="LevelButtonsContainer" type="ItemList" parent="LevelButtonsMargin"] +unique_name_in_owner = true +layout_mode = 2 +auto_height = true +item_count = 1 +item_0/text = "1 - ExampleLevel" + +[connection signal="item_activated" from="LevelButtonsMargin/LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] diff --git a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn index 8434567..e2ed266 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn +++ b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=18 format=3 uid="uid://c63y6b25bs4bk"] +[gd_scene load_steps=19 format=3 uid="uid://c63y6b25bs4bk"] [ext_resource type="PackedScene" uid="uid://c6k5nnpbypshi" path="res://addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn" id="1_0i2sc"] [ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd" id="2_ncvk7"] [ext_resource type="PackedScene" uid="uid://bdvdf5v87mmrr" path="res://addons/maaacks_game_template/examples/scenes/menus/options_menu/master_options_menu_with_tabs.tscn" id="3_tuy3s"] [ext_resource type="PackedScene" uid="uid://c1g50h2avck3w" path="res://addons/maaacks_game_template/examples/scenes/credits/credits.tscn" id="4_lwsll"] +[ext_resource type="PackedScene" uid="uid://dtu0ffm1m5mr7" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn" id="5_4pbct"] [sub_resource type="Animation" id="1"] resource_name = "Intro" @@ -354,6 +355,7 @@ script = ExtResource("2_ncvk7") game_scene_path = "res://addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn" options_packed_scene = ExtResource("3_tuy3s") credits_packed_scene = ExtResource("4_lwsll") +level_select_packed_scene = ExtResource("5_4pbct") [node name="MenuAnimationPlayer" type="AnimationPlayer" parent="." index="1"] libraries = { From 6cf26ec2a6be7db819dcca745552914d4cfbf5f4 Mon Sep 17 00:00:00 2001 From: Cat Date: Sat, 28 Dec 2024 13:12:23 -0700 Subject: [PATCH 02/17] Updated MasterLevelSelect Focus is now grabbed by the auto-capture container. Also the GameState.set_current_level(index) has been changed to "GameStateExample.set_current_level(index)". --- .../master_level_select_menu.gd | 6 +---- .../master_level_select_menu.tscn | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd index 7b0413c..3a4c4d1 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd @@ -16,10 +16,6 @@ signal level_selected func _ready() -> void: add_levels_to_container() -func _unhandled_input(event): - if not is_visible_in_tree(): - return - ## A fresh level list is propgated into the ItemList, and the file names are cleaned func add_levels_to_container(): level_buttons_container.clear() @@ -38,6 +34,6 @@ func add_levels_to_container(): func _on_level_buttons_container_item_activated(index: int) -> void: - GameState.set_current_level(index) + GameStateExample.set_current_level(index) call_deferred("emit_signal","level_selected") hide() diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn index 1b8b851..5ce12c5 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://dtu0ffm1m5mr7"] +[gd_scene load_steps=4 format=3 uid="uid://dtu0ffm1m5mr7"] [ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd" id="1_dm7vg"] [ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_g3cvb"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="3_wl5w3"] [node name="MasterLevelSelectMenu" type="Control"] layout_mode = 3 @@ -17,25 +18,31 @@ script = ExtResource("2_g3cvb") files = Array[String](["res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_1.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_2.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_3.tscn"]) directory = "res://addons/maaacks_game_template/examples/scenes/game_scene/levels" -[node name="LevelButtonsMargin" type="MarginContainer" parent="."] -unique_name_in_owner = true -custom_minimum_size = Vector2(200, 0) +[node name="CaptureFocus" type="Container" parent="."] layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_top = -17.5 -offset_bottom = 17.5 +offset_left = -20.0 +offset_top = -20.0 +offset_right = 20.0 +offset_bottom = 20.0 grow_horizontal = 2 grow_vertical = 2 +script = ExtResource("3_wl5w3") + +[node name="LevelButtonsMargin" type="MarginContainer" parent="CaptureFocus"] +unique_name_in_owner = true +custom_minimum_size = Vector2(200, 0) +layout_mode = 2 -[node name="LevelButtonsContainer" type="ItemList" parent="LevelButtonsMargin"] +[node name="LevelButtonsContainer" type="ItemList" parent="CaptureFocus/LevelButtonsMargin"] unique_name_in_owner = true layout_mode = 2 auto_height = true item_count = 1 item_0/text = "1 - ExampleLevel" -[connection signal="item_activated" from="LevelButtonsMargin/LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] +[connection signal="item_activated" from="CaptureFocus/LevelButtonsMargin/LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] From 4a4700344bed9c691404c803e62677c35c618a9f Mon Sep 17 00:00:00 2001 From: Cat Date: Sat, 28 Dec 2024 13:15:22 -0700 Subject: [PATCH 03/17] Small control sizing tweaks... ... to allow for longer level names. --- .../menus/level_select_menu/master_level_select_menu.tscn | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn index 5ce12c5..fabcc2d 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn @@ -25,9 +25,9 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -20.0 +offset_left = -200.0 offset_top = -20.0 -offset_right = 20.0 +offset_right = 200.0 offset_bottom = 20.0 grow_horizontal = 2 grow_vertical = 2 @@ -35,8 +35,10 @@ script = ExtResource("3_wl5w3") [node name="LevelButtonsMargin" type="MarginContainer" parent="CaptureFocus"] unique_name_in_owner = true -custom_minimum_size = Vector2(200, 0) +custom_minimum_size = Vector2(400, 0) layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 [node name="LevelButtonsContainer" type="ItemList" parent="CaptureFocus/LevelButtonsMargin"] unique_name_in_owner = true From 08fd012f7c8363977ac5ac2aa98f5babf967c85b Mon Sep 17 00:00:00 2001 From: Cat Date: Tue, 31 Dec 2024 10:25:31 -0700 Subject: [PATCH 04/17] Removed auto-capture, and used a more manual method I found on repeat loads-- returning to the main menu and opening the level select scree -- the focus wouldn't grab and options weren't selectable. I replaced it with a simple manual solution to at input detect if visible and lacking focus. I found this worked more consitently with Mouse/Gamepad too. --- .../examples/scenes/game_scene/game_ui.tscn | 1 - .../master_level_select_menu.gd | 15 ++++++-- .../master_level_select_menu.tscn | 37 ++++++------------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn b/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn index dfdaaf2..a3bd79d 100644 --- a/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn +++ b/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn @@ -28,7 +28,6 @@ focused_viewport = NodePath("../ViewportContainer/ConfigurableSubViewport") [node name="LevelLoader" type="Node" parent="." node_paths=PackedStringArray("level_container")] script = ExtResource("6_wd8e4") level_container = NodePath("../ViewportContainer/ConfigurableSubViewport") -files = Array[String](["res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_1.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_2.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_3.tscn"]) directory = "res://addons/maaacks_game_template/examples/scenes/game_scene/levels" [node name="BackgroundMusicPlayer" parent="." instance=ExtResource("7_yr75v")] diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd index 3a4c4d1..acac907 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd @@ -7,15 +7,17 @@ class_name MasterLevelSelectMenu ## a load action from that signal. @onready var level_buttons_container: ItemList = %LevelButtonsContainer -@onready var level_buttons_margin: MarginContainer = %LevelButtonsMargin @onready var scene_lister: SceneLister = $SceneLister signal level_selected - +func _unhandled_input(event: InputEvent) -> void: + if visible && !level_buttons_container.has_focus(): + level_buttons_container.grab_focus() + select_first() # Called when the node enters the scene tree for the first time. func _ready() -> void: add_levels_to_container() - + ## A fresh level list is propgated into the ItemList, and the file names are cleaned func add_levels_to_container(): level_buttons_container.clear() @@ -32,8 +34,13 @@ func add_levels_to_container(): var button_name = str(file_name) level_buttons_container.add_item(button_name) + +func select_first(): + if level_buttons_container.item_count >=1: + level_buttons_container.select(0) + func _on_level_buttons_container_item_activated(index: int) -> void: GameStateExample.set_current_level(index) call_deferred("emit_signal","level_selected") - hide() + #hide() diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn index fabcc2d..cd4bf13 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://dtu0ffm1m5mr7"] +[gd_scene load_steps=3 format=3 uid="uid://dtu0ffm1m5mr7"] [ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd" id="1_dm7vg"] [ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_g3cvb"] -[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="3_wl5w3"] [node name="MasterLevelSelectMenu" type="Control"] layout_mode = 3 @@ -13,38 +12,26 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_dm7vg") -[node name="SceneLister" type="Node" parent="."] -script = ExtResource("2_g3cvb") -files = Array[String](["res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_1.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_2.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_3.tscn"]) -directory = "res://addons/maaacks_game_template/examples/scenes/game_scene/levels" - -[node name="CaptureFocus" type="Container" parent="."] +[node name="LevelButtonsContainer" type="ItemList" parent="."] +unique_name_in_owner = true +custom_minimum_size = Vector2(400, 0) layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -200.0 -offset_top = -20.0 -offset_right = 200.0 -offset_bottom = 20.0 +offset_top = -17.5 +offset_bottom = 17.5 grow_horizontal = 2 grow_vertical = 2 -script = ExtResource("3_wl5w3") - -[node name="LevelButtonsMargin" type="MarginContainer" parent="CaptureFocus"] -unique_name_in_owner = true -custom_minimum_size = Vector2(400, 0) -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_vertical = 3 - -[node name="LevelButtonsContainer" type="ItemList" parent="CaptureFocus/LevelButtonsMargin"] -unique_name_in_owner = true -layout_mode = 2 auto_height = true item_count = 1 item_0/text = "1 - ExampleLevel" -[connection signal="item_activated" from="CaptureFocus/LevelButtonsMargin/LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] +[node name="SceneLister" type="Node" parent="."] +script = ExtResource("2_g3cvb") +files = Array[String](["res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_1.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_2.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_3.tscn"]) +directory = "res://addons/maaacks_game_template/examples/scenes/game_scene/levels" + +[connection signal="item_activated" from="LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] From 2b4b45677594a8d2dc6b61fd934f868c3af9063a Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 10:52:06 -0800 Subject: [PATCH 05/17] Removes changes from base main menu files. --- .../base/scenes/menus/main_menu/main_menu.gd | 19 --------------- .../scenes/menus/main_menu/main_menu.tscn | 23 ++----------------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd b/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd index 6fcd007..bce0526 100644 --- a/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd +++ b/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd @@ -5,11 +5,9 @@ extends Control @export_file("*.tscn") var game_scene_path : String @export var options_packed_scene : PackedScene @export var credits_packed_scene : PackedScene -@export var level_select_packed_scene: PackedScene var options_scene var credits_scene -var level_select_scene var sub_menu func load_game_scene(): @@ -70,24 +68,10 @@ func _setup_credits(): credits_scene.connect("end_reached", _on_credits_end_reached) %CreditsContainer.call_deferred("add_child", credits_scene) -## If present, adds a level select screen button, and connects siganl triggers to update -## the current level, and load it (borrowing from "continue" button logic) -func _setup_level_select(): - if level_select_packed_scene == null: - %LevelSelectButton.hide() - else: - level_select_scene = level_select_packed_scene.instantiate() - level_select_scene.hide() - %LevelSelectContainer.call_deferred("add_child", level_select_scene) - if level_select_scene.has_signal("level_selected"): - level_select_scene.connect("level_selected", load_game_scene) - - func _ready(): _setup_for_web() _setup_options() _setup_credits() - _setup_level_select() _setup_game_buttons() func _on_new_game_button_pressed(): @@ -109,6 +93,3 @@ func _on_credits_end_reached(): func _on_back_button_pressed(): _close_sub_menu() - -func _on_level_select_button_pressed(): - _open_sub_menu(level_select_scene) diff --git a/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn b/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn index a4df833..184d2ec 100644 --- a/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn +++ b/addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn @@ -1,10 +1,9 @@ -[gd_scene load_steps=10 format=3 uid="uid://c6k5nnpbypshi"] +[gd_scene load_steps=9 format=3 uid="uid://c6k5nnpbypshi"] [ext_resource type="Script" path="res://addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.gd" id="1"] [ext_resource type="PackedScene" uid="uid://hmx6o472ropw" path="res://addons/maaacks_game_template/base/scenes/menus/options_menu/master_options_menu_with_tabs.tscn" id="2_qvrrd"] [ext_resource type="PackedScene" uid="uid://t2dui8ppm3a4" path="res://addons/maaacks_game_template/base/scenes/credits/credits.tscn" id="3_5dhvp"] [ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="4_l1ebe"] -[ext_resource type="PackedScene" uid="uid://dtu0ffm1m5mr7" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn" id="4_p8833"] [ext_resource type="PackedScene" uid="uid://bkcsjsk2ciff" path="res://addons/maaacks_game_template/base/scenes/music_players/background_music_player.tscn" id="4_w8sbm"] [ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/ui_sound_controller.gd" id="6_bs342"] [ext_resource type="Script" path="res://addons/maaacks_game_template/base/scenes/menus/main_menu/config_version_label.gd" id="6_pdiij"] @@ -20,7 +19,6 @@ grow_vertical = 2 script = ExtResource("1") options_packed_scene = ExtResource("2_qvrrd") credits_packed_scene = ExtResource("3_5dhvp") -level_select_packed_scene = ExtResource("4_p8833") [node name="UISoundController" type="Node" parent="."] script = ExtResource("6_bs342") @@ -92,7 +90,7 @@ anchor_right = 1.0 offset_bottom = 67.0 grow_horizontal = 2 theme_override_font_sizes/font_size = 48 -text = "Game Template" +text = "Title" horizontal_alignment = 1 vertical_alignment = 1 script = ExtResource("7_j7612") @@ -152,12 +150,6 @@ custom_minimum_size = Vector2(128, 40) layout_mode = 2 text = "New Game" -[node name="LevelSelectButton" type="Button" parent="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer"] -unique_name_in_owner = true -custom_minimum_size = Vector2(128, 40) -layout_mode = 2 -text = "Level Select" - [node name="OptionsButton" type="Button" parent="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer"] unique_name_in_owner = true custom_minimum_size = Vector2(128, 40) @@ -197,16 +189,6 @@ theme_override_constants/margin_top = 32 theme_override_constants/margin_right = 16 theme_override_constants/margin_bottom = 32 -[node name="LevelSelectContainer" type="MarginContainer" parent="."] -unique_name_in_owner = true -layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -mouse_filter = 2 - [node name="FlowControlContainer" type="MarginContainer" parent="."] layout_mode = 0 anchor_right = 1.0 @@ -235,7 +217,6 @@ grow_vertical = 0 text = "Back" [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/NewGameButton" to="." method="_on_new_game_button_pressed"] -[connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/LevelSelectButton" to="." method="_on_level_select_button_pressed"] [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"] [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/CreditsButton" to="." method="_on_credits_button_pressed"] [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"] From 820c5778d81ad9400131013d69b9dd48d18fa5c4 Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 11:23:29 -0800 Subject: [PATCH 06/17] Fix to example level list state manager. --- .../examples/scripts/level_list_state_manager.gd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/maaacks_game_template/examples/scripts/level_list_state_manager.gd b/addons/maaacks_game_template/examples/scripts/level_list_state_manager.gd index 9a45ae1..001d2ac 100644 --- a/addons/maaacks_game_template/examples/scripts/level_list_state_manager.gd +++ b/addons/maaacks_game_template/examples/scripts/level_list_state_manager.gd @@ -5,7 +5,8 @@ func set_current_level_id(value): GameStateExample.level_reached(value) func get_current_level_id() -> int: - return GameStateExample.get_current_level() if force_level == -1 else force_level + current_level_id = GameStateExample.get_current_level() if force_level == -1 else force_level + return current_level_id func _advance_level(): super._advance_level() From 9e8b0dc3d000e248d69639079130b87fc4afa5c7 Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 11:24:17 -0800 Subject: [PATCH 07/17] Adds level files to example game UI for testing. --- .../examples/scenes/game_scene/game_ui.tscn | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn b/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn index a3bd79d..dfdaaf2 100644 --- a/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn +++ b/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn @@ -28,6 +28,7 @@ focused_viewport = NodePath("../ViewportContainer/ConfigurableSubViewport") [node name="LevelLoader" type="Node" parent="." node_paths=PackedStringArray("level_container")] script = ExtResource("6_wd8e4") level_container = NodePath("../ViewportContainer/ConfigurableSubViewport") +files = Array[String](["res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_1.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_2.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_3.tscn"]) directory = "res://addons/maaacks_game_template/examples/scenes/game_scene/levels" [node name="BackgroundMusicPlayer" parent="." instance=ExtResource("7_yr75v")] From 8a391ce64e31ed66d89b6777350ed72a4170472b Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 11:25:15 -0800 Subject: [PATCH 08/17] Moves main menu changes to example main menu. --- .../main_menu/main_menu_with_animations.gd | 18 ++++++++++++++ .../main_menu/main_menu_with_animations.tscn | 24 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd index 307579a..8cde25c 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd +++ b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd @@ -1,5 +1,8 @@ extends MainMenu +@export var level_select_packed_scene: PackedScene + +var level_select_scene var animation_state_machine : AnimationNodeStateMachinePlayback func load_game_scene(): @@ -33,6 +36,17 @@ func _close_sub_menu(): super._close_sub_menu() animation_state_machine.travel("OpenMainMenu") +func _setup_level_select(): + if level_select_packed_scene == null: + %LevelSelectButton.hide() + else: + %LevelSelectButton.show() + level_select_scene = level_select_packed_scene.instantiate() + level_select_scene.hide() + %LevelSelectContainer.call_deferred("add_child", level_select_scene) + if level_select_scene.has_signal("level_selected"): + level_select_scene.connect("level_selected", load_game_scene) + func _input(event): if _is_in_intro() and _event_skips_intro(event): intro_done() @@ -41,6 +55,7 @@ func _input(event): func _ready(): super._ready() + _setup_level_select() animation_state_machine = $MenuAnimationTree.get("parameters/playback") func _setup_game_buttons(): @@ -50,3 +65,6 @@ func _setup_game_buttons(): func _on_continue_game_button_pressed(): load_game_scene() + +func _on_level_select_button_pressed(): + _open_sub_menu(level_select_scene) diff --git a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn index e2ed266..b5323e5 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn +++ b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn @@ -352,10 +352,10 @@ graph_offset = Vector2(-180.277, 49) [node name="MainMenu" instance=ExtResource("1_0i2sc")] script = ExtResource("2_ncvk7") +level_select_packed_scene = ExtResource("5_4pbct") game_scene_path = "res://addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn" options_packed_scene = ExtResource("3_tuy3s") credits_packed_scene = ExtResource("4_lwsll") -level_select_packed_scene = ExtResource("5_4pbct") [node name="MenuAnimationPlayer" type="AnimationPlayer" parent="." index="1"] libraries = { @@ -373,6 +373,9 @@ modulate = Color(1, 1, 1, 0) [node name="TitleContainer" parent="MenuContainer/TitleMargin" index="0"] modulate = Color(1, 1, 1, 0) +[node name="TitleLabel" parent="MenuContainer/TitleMargin/TitleContainer" index="0"] +text = "Game Template" + [node name="SubTitleContainer" parent="MenuContainer/SubTitleMargin" index="0"] modulate = Color(1, 1, 1, 0) @@ -389,4 +392,23 @@ custom_minimum_size = Vector2(128, 40) layout_mode = 2 text = "Continue" +[node name="LevelSelectButton" type="Button" parent="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer" index="2"] +unique_name_in_owner = true +visible = false +custom_minimum_size = Vector2(128, 40) +layout_mode = 2 +text = "Level Select" + +[node name="LevelSelectContainer" type="MarginContainer" parent="." index="9"] +unique_name_in_owner = true +layout_mode = 0 +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 32 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 32 + [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/ContinueGameButton" to="." method="_on_continue_game_button_pressed"] +[connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/LevelSelectButton" to="." method="_on_level_select_button_pressed"] From c9566e901dcf54e44779645ac2690482811b0b3e Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 11:37:18 -0800 Subject: [PATCH 09/17] Renames level select menu, master doesn't apply. --- .../{master_level_select_menu.gd => level_select_menu.gd} | 2 +- .../{master_level_select_menu.tscn => level_select_menu.tscn} | 4 ++-- .../scenes/menus/main_menu/main_menu_with_animations.tscn | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename addons/maaacks_game_template/examples/scenes/menus/level_select_menu/{master_level_select_menu.gd => level_select_menu.gd} (98%) rename addons/maaacks_game_template/examples/scenes/menus/level_select_menu/{master_level_select_menu.tscn => level_select_menu.tscn} (90%) diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd similarity index 98% rename from addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd rename to addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd index acac907..c6d85e1 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd @@ -1,5 +1,5 @@ extends Control -class_name MasterLevelSelectMenu +class_name LevelSelectMenu ## Loads a simple ItemList node within a margin container. SceneLister updates ## the available scenes in the directory provided. Activating a level will update diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn similarity index 90% rename from addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn rename to addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn index cd4bf13..dadc464 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn @@ -1,9 +1,9 @@ [gd_scene load_steps=3 format=3 uid="uid://dtu0ffm1m5mr7"] -[ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.gd" id="1_dm7vg"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd" id="1_dm7vg"] [ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_g3cvb"] -[node name="MasterLevelSelectMenu" type="Control"] +[node name="LevelSelectMenu" type="Control"] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 diff --git a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn index b5323e5..3e8da46 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn +++ b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn @@ -4,7 +4,7 @@ [ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd" id="2_ncvk7"] [ext_resource type="PackedScene" uid="uid://bdvdf5v87mmrr" path="res://addons/maaacks_game_template/examples/scenes/menus/options_menu/master_options_menu_with_tabs.tscn" id="3_tuy3s"] [ext_resource type="PackedScene" uid="uid://c1g50h2avck3w" path="res://addons/maaacks_game_template/examples/scenes/credits/credits.tscn" id="4_lwsll"] -[ext_resource type="PackedScene" uid="uid://dtu0ffm1m5mr7" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/master_level_select_menu.tscn" id="5_4pbct"] +[ext_resource type="PackedScene" uid="uid://dtu0ffm1m5mr7" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn" id="5_4pbct"] [sub_resource type="Animation" id="1"] resource_name = "Intro" From 92c18fc45bd118100a393b21c3e1617f98ac6246 Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 11:43:14 -0800 Subject: [PATCH 10/17] Changes condition for showing level select button. --- .../scenes/menus/main_menu/main_menu_with_animations.gd | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd index 8cde25c..7099292 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd +++ b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd @@ -37,10 +37,7 @@ func _close_sub_menu(): animation_state_machine.travel("OpenMainMenu") func _setup_level_select(): - if level_select_packed_scene == null: - %LevelSelectButton.hide() - else: - %LevelSelectButton.show() + if level_select_packed_scene != null: level_select_scene = level_select_packed_scene.instantiate() level_select_scene.hide() %LevelSelectContainer.call_deferred("add_child", level_select_scene) @@ -62,6 +59,7 @@ func _setup_game_buttons(): super._setup_game_buttons() if GameStateExample.has_game_state(): %ContinueGameButton.show() + %LevelSelectButton.show() func _on_continue_game_button_pressed(): load_game_scene() From 5f35d25a175cdf5926dfcc4aa9dfe1c44f7dabf5 Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 11:51:10 -0800 Subject: [PATCH 11/17] Only lists levels that have been reached. --- .../scenes/menus/level_select_menu/level_select_menu.gd | 6 +++++- addons/maaacks_game_template/examples/scripts/game_state.gd | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd index c6d85e1..74e43d8 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd @@ -21,8 +21,12 @@ func _ready() -> void: ## A fresh level list is propgated into the ItemList, and the file names are cleaned func add_levels_to_container(): level_buttons_container.clear() - + + var max_level_reached := GameStateExample.get_max_level_reached() + var level_iter := 0 for file_path in scene_lister.files: + if level_iter > max_level_reached : break + level_iter += 1 # Extract the file name from the path var file_name = file_path.get_file() # e.g., "level_1.tscn" diff --git a/addons/maaacks_game_template/examples/scripts/game_state.gd b/addons/maaacks_game_template/examples/scripts/game_state.gd index 8fb19bc..1f7c540 100644 --- a/addons/maaacks_game_template/examples/scripts/game_state.gd +++ b/addons/maaacks_game_template/examples/scripts/game_state.gd @@ -31,6 +31,12 @@ static func get_current_level() -> int: return 0 return game_state.current_level +static func get_max_level_reached() -> int: + var game_state = get_game_state() + if not game_state: + return 0 + return game_state.max_level_reached + static func level_reached(level_number): var game_state = get_game_state() if not game_state: From 7d95824cae8e46e758e1cba443875390a1f4fafa Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 11:55:33 -0800 Subject: [PATCH 12/17] Updates condition for showing level select to have >1 level. --- .../scenes/menus/main_menu/main_menu_with_animations.gd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd index 7099292..0689b31 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd +++ b/addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.gd @@ -59,7 +59,8 @@ func _setup_game_buttons(): super._setup_game_buttons() if GameStateExample.has_game_state(): %ContinueGameButton.show() - %LevelSelectButton.show() + if GameStateExample.get_max_level_reached() > 0: + %LevelSelectButton.show() func _on_continue_game_button_pressed(): load_game_scene() From 57bc4760ccda45b1e548e3e4358e0ad3d0b1fa2f Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 14:11:03 -0800 Subject: [PATCH 13/17] Fixes class name conflicts after copying, unused... warnings, and linting. --- .../level_select_menu/level_select_menu.gd | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd index 74e43d8..bd03242 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd @@ -1,5 +1,4 @@ extends Control -class_name LevelSelectMenu ## Loads a simple ItemList node within a margin container. SceneLister updates ## the available scenes in the directory provided. Activating a level will update @@ -10,18 +9,17 @@ class_name LevelSelectMenu @onready var scene_lister: SceneLister = $SceneLister signal level_selected -func _unhandled_input(event: InputEvent) -> void: - if visible && !level_buttons_container.has_focus(): +func _unhandled_input(_event: InputEvent) -> void: + if visible and !level_buttons_container.has_focus(): level_buttons_container.grab_focus() select_first() -# Called when the node enters the scene tree for the first time. + func _ready() -> void: add_levels_to_container() ## A fresh level list is propgated into the ItemList, and the file names are cleaned func add_levels_to_container(): level_buttons_container.clear() - var max_level_reached := GameStateExample.get_max_level_reached() var level_iter := 0 for file_path in scene_lister.files: @@ -29,22 +27,17 @@ func add_levels_to_container(): level_iter += 1 # Extract the file name from the path var file_name = file_path.get_file() # e.g., "level_1.tscn" - # Clean up the file name file_name = file_name.trim_suffix(".tscn") # Remove the ".tscn" extension file_name = file_name.replace("_", " ") # Replace underscores with spaces file_name = file_name.capitalize() # Convert to proper case - var button_name = str(file_name) level_buttons_container.add_item(button_name) - - + func select_first(): if level_buttons_container.item_count >=1: level_buttons_container.select(0) - func _on_level_buttons_container_item_activated(index: int) -> void: GameStateExample.set_current_level(index) - call_deferred("emit_signal","level_selected") - #hide() + level_selected.emit() From df9e0b1d8dd1f86ad658488b9d433db49032a498 Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 14:14:20 -0800 Subject: [PATCH 14/17] Copies examples into project root. --- .../level_select_menu/level_select_menu.gd | 43 +++++++++++++++++++ .../level_select_menu/level_select_menu.tscn | 37 ++++++++++++++++ .../main_menu/main_menu_with_animations.gd | 17 ++++++++ .../main_menu/main_menu_with_animations.tscn | 39 +++++++++++++---- scripts/game_state.gd | 6 +++ scripts/level_list_state_manager.gd | 3 +- 6 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 scenes/menus/level_select_menu/level_select_menu.gd create mode 100644 scenes/menus/level_select_menu/level_select_menu.tscn diff --git a/scenes/menus/level_select_menu/level_select_menu.gd b/scenes/menus/level_select_menu/level_select_menu.gd new file mode 100644 index 0000000..793836e --- /dev/null +++ b/scenes/menus/level_select_menu/level_select_menu.gd @@ -0,0 +1,43 @@ +extends Control + +## Loads a simple ItemList node within a margin container. SceneLister updates +## the available scenes in the directory provided. Activating a level will update +## the GameState's current_level, and emit a signal. The main menu node will trigger +## a load action from that signal. + +@onready var level_buttons_container: ItemList = %LevelButtonsContainer +@onready var scene_lister: SceneLister = $SceneLister + +signal level_selected +func _unhandled_input(_event: InputEvent) -> void: + if visible and !level_buttons_container.has_focus(): + level_buttons_container.grab_focus() + select_first() + +func _ready() -> void: + add_levels_to_container() + +## A fresh level list is propgated into the ItemList, and the file names are cleaned +func add_levels_to_container(): + level_buttons_container.clear() + var max_level_reached := GameState.get_max_level_reached() + var level_iter := 0 + for file_path in scene_lister.files: + if level_iter > max_level_reached : break + level_iter += 1 + # Extract the file name from the path + var file_name = file_path.get_file() # e.g., "level_1.tscn" + # Clean up the file name + file_name = file_name.trim_suffix(".tscn") # Remove the ".tscn" extension + file_name = file_name.replace("_", " ") # Replace underscores with spaces + file_name = file_name.capitalize() # Convert to proper case + var button_name = str(file_name) + level_buttons_container.add_item(button_name) + +func select_first(): + if level_buttons_container.item_count >=1: + level_buttons_container.select(0) + +func _on_level_buttons_container_item_activated(index: int) -> void: + GameState.set_current_level(index) + level_selected.emit() diff --git a/scenes/menus/level_select_menu/level_select_menu.tscn b/scenes/menus/level_select_menu/level_select_menu.tscn new file mode 100644 index 0000000..04c96df --- /dev/null +++ b/scenes/menus/level_select_menu/level_select_menu.tscn @@ -0,0 +1,37 @@ +[gd_scene load_steps=3 format=3 uid="uid://cvhipghsnttqv"] + +[ext_resource type="Script" path="res://scenes/menus/level_select_menu/level_select_menu.gd" id="1_f1amo"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_ljb5a"] + +[node name="LevelSelectMenu" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_f1amo") + +[node name="LevelButtonsContainer" type="ItemList" parent="."] +unique_name_in_owner = true +custom_minimum_size = Vector2(400, 0) +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_top = -17.5 +offset_bottom = 17.5 +grow_horizontal = 2 +grow_vertical = 2 +auto_height = true +item_count = 1 +item_0/text = "1 - ExampleLevel" + +[node name="SceneLister" type="Node" parent="."] +script = ExtResource("2_ljb5a") +files = Array[String](["res://scenes/game_scene/levels/level_1.tscn", "res://scenes/game_scene/levels/level_2.tscn", "res://scenes/game_scene/levels/level_3.tscn"]) +directory = "res://scenes/game_scene/levels" + +[connection signal="item_activated" from="LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] diff --git a/scenes/menus/main_menu/main_menu_with_animations.gd b/scenes/menus/main_menu/main_menu_with_animations.gd index 9aafd8f..d86adb1 100644 --- a/scenes/menus/main_menu/main_menu_with_animations.gd +++ b/scenes/menus/main_menu/main_menu_with_animations.gd @@ -1,5 +1,8 @@ extends MainMenu +@export var level_select_packed_scene: PackedScene + +var level_select_scene var animation_state_machine : AnimationNodeStateMachinePlayback func load_game_scene(): @@ -33,6 +36,14 @@ func _close_sub_menu(): super._close_sub_menu() animation_state_machine.travel("OpenMainMenu") +func _setup_level_select(): + if level_select_packed_scene != null: + level_select_scene = level_select_packed_scene.instantiate() + level_select_scene.hide() + %LevelSelectContainer.call_deferred("add_child", level_select_scene) + if level_select_scene.has_signal("level_selected"): + level_select_scene.connect("level_selected", load_game_scene) + func _input(event): if _is_in_intro() and _event_skips_intro(event): intro_done() @@ -41,12 +52,18 @@ func _input(event): func _ready(): super._ready() + _setup_level_select() animation_state_machine = $MenuAnimationTree.get("parameters/playback") func _setup_game_buttons(): super._setup_game_buttons() if GameState.has_game_state(): %ContinueGameButton.show() + if GameState.get_max_level_reached() > 0: + %LevelSelectButton.show() func _on_continue_game_button_pressed(): load_game_scene() + +func _on_level_select_button_pressed(): + _open_sub_menu(level_select_scene) diff --git a/scenes/menus/main_menu/main_menu_with_animations.tscn b/scenes/menus/main_menu/main_menu_with_animations.tscn index 43b37c4..c6439ba 100644 --- a/scenes/menus/main_menu/main_menu_with_animations.tscn +++ b/scenes/menus/main_menu/main_menu_with_animations.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=18 format=3 uid="uid://8ymyrorpy02h"] +[gd_scene load_steps=19 format=3 uid="uid://cctjxrnxut1t7"] -[ext_resource type="PackedScene" path="res://addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn" id="1_ol417"] -[ext_resource type="Script" path="res://scenes/menus/main_menu/main_menu_with_animations.gd" id="2_0jb1p"] -[ext_resource type="PackedScene" path="res://scenes/menus/options_menu/master_options_menu_with_tabs.tscn" id="3_v43e6"] -[ext_resource type="PackedScene" path="res://scenes/credits/credits.tscn" id="4_58732"] +[ext_resource type="PackedScene" path="res://addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn" id="1_6btwc"] +[ext_resource type="Script" path="res://scenes/menus/main_menu/main_menu_with_animations.gd" id="2_qyyu4"] +[ext_resource type="PackedScene" path="res://scenes/menus/level_select_menu/level_select_menu.tscn" id="3_lmrqr"] +[ext_resource type="PackedScene" path="res://scenes/menus/options_menu/master_options_menu_with_tabs.tscn" id="4_p1xti"] +[ext_resource type="PackedScene" path="res://scenes/credits/credits.tscn" id="5_svaqx"] [sub_resource type="Animation" id="1"] resource_name = "Intro" @@ -349,11 +350,12 @@ states/Start/position = Vector2(82, 123) transitions = ["Intro", "OpenMainMenu", SubResource("11"), "OpenMainMenu", "OpenSubMenu", SubResource("14"), "Start", "Intro", SubResource("AnimationNodeStateMachineTransition_j0orr"), "OpenSubMenu", "OpenMainMenu", SubResource("AnimationNodeStateMachineTransition_63dxc")] graph_offset = Vector2(-180.277, 49) -[node name="MainMenu" instance=ExtResource("1_ol417")] -script = ExtResource("2_0jb1p") +[node name="MainMenu" instance=ExtResource("1_6btwc")] +script = ExtResource("2_qyyu4") +level_select_packed_scene = ExtResource("3_lmrqr") game_scene_path = "res://scenes/game_scene/game_ui.tscn" -options_packed_scene = ExtResource("3_v43e6") -credits_packed_scene = ExtResource("4_58732") +options_packed_scene = ExtResource("4_p1xti") +credits_packed_scene = ExtResource("5_svaqx") [node name="MenuAnimationPlayer" type="AnimationPlayer" parent="." index="1"] libraries = { @@ -387,4 +389,23 @@ custom_minimum_size = Vector2(128, 40) layout_mode = 2 text = "Continue" +[node name="LevelSelectButton" type="Button" parent="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer" index="2"] +unique_name_in_owner = true +visible = false +custom_minimum_size = Vector2(128, 40) +layout_mode = 2 +text = "Level Select" + +[node name="LevelSelectContainer" type="MarginContainer" parent="." index="9"] +unique_name_in_owner = true +layout_mode = 0 +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 32 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 32 + [connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/ContinueGameButton" to="." method="_on_continue_game_button_pressed"] +[connection signal="pressed" from="MenuContainer/MenuButtonsMargin/MenuButtonsContainer/MenuButtonsBoxContainer/LevelSelectButton" to="." method="_on_level_select_button_pressed"] diff --git a/scripts/game_state.gd b/scripts/game_state.gd index 608642f..dd0597f 100644 --- a/scripts/game_state.gd +++ b/scripts/game_state.gd @@ -31,6 +31,12 @@ static func get_current_level() -> int: return 0 return game_state.current_level +static func get_max_level_reached() -> int: + var game_state = get_game_state() + if not game_state: + return 0 + return game_state.max_level_reached + static func level_reached(level_number): var game_state = get_game_state() if not game_state: diff --git a/scripts/level_list_state_manager.gd b/scripts/level_list_state_manager.gd index b348ae7..e6238b8 100644 --- a/scripts/level_list_state_manager.gd +++ b/scripts/level_list_state_manager.gd @@ -5,7 +5,8 @@ func set_current_level_id(value): GameState.level_reached(value) func get_current_level_id() -> int: - return GameState.get_current_level() if force_level == -1 else force_level + current_level_id = GameState.get_current_level() if force_level == -1 else force_level + return current_level_id func _advance_level(): super._advance_level() From 683d339f2e336e1fabdbdcd2d12cc5a87d9dabd8 Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 14:30:10 -0800 Subject: [PATCH 15/17] Fixes level select grabbing focus from back button. --- .../base/scripts/capture_focus.gd | 4 +++- .../level_select_menu/level_select_menu.gd | 8 ------- .../level_select_menu/level_select_menu.tscn | 21 +++++++++++++++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/addons/maaacks_game_template/base/scripts/capture_focus.gd b/addons/maaacks_game_template/base/scripts/capture_focus.gd index 575eb28..2fd0cd1 100644 --- a/addons/maaacks_game_template/base/scripts/capture_focus.gd +++ b/addons/maaacks_game_template/base/scripts/capture_focus.gd @@ -1,5 +1,5 @@ class_name CaptureFocus -extends Container +extends Control ## Node that captures UI focus for games with a hidden mouse or joypad enabled. ## ## This script assists with capturing UI focus when @@ -27,6 +27,8 @@ func _focus_first_search(control_node : Control, levels : int = 1): return false if control_node.focus_mode == FOCUS_ALL: control_node.grab_focus() + if control_node is ItemList: + control_node.select(0) return true if levels < 1: return false diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd index bd03242..7dc3293 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd @@ -9,10 +9,6 @@ extends Control @onready var scene_lister: SceneLister = $SceneLister signal level_selected -func _unhandled_input(_event: InputEvent) -> void: - if visible and !level_buttons_container.has_focus(): - level_buttons_container.grab_focus() - select_first() func _ready() -> void: add_levels_to_container() @@ -34,10 +30,6 @@ func add_levels_to_container(): var button_name = str(file_name) level_buttons_container.add_item(button_name) -func select_first(): - if level_buttons_container.item_count >=1: - level_buttons_container.select(0) - func _on_level_buttons_container_item_activated(index: int) -> void: GameStateExample.set_current_level(index) level_selected.emit() diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn index dadc464..1ba86da 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://dtu0ffm1m5mr7"] +[gd_scene load_steps=4 format=3 uid="uid://dtu0ffm1m5mr7"] [ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd" id="1_dm7vg"] -[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_g3cvb"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="2_88qak"] +[ext_resource type="Script" uid="uid://wjq7li836lwj" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_g3cvb"] [node name="LevelSelectMenu" type="Control"] layout_mode = 3 @@ -12,7 +13,17 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_dm7vg") -[node name="LevelButtonsContainer" type="ItemList" parent="."] +[node name="Control" type="Control" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("2_88qak") +enabled = true + +[node name="LevelButtonsContainer" type="ItemList" parent="Control"] unique_name_in_owner = true custom_minimum_size = Vector2(400, 0) layout_mode = 1 @@ -21,7 +32,9 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 +offset_left = -200.0 offset_top = -17.5 +offset_right = 200.0 offset_bottom = 17.5 grow_horizontal = 2 grow_vertical = 2 @@ -34,4 +47,4 @@ script = ExtResource("2_g3cvb") files = Array[String](["res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_1.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_2.tscn", "res://addons/maaacks_game_template/examples/scenes/game_scene/levels/level_3.tscn"]) directory = "res://addons/maaacks_game_template/examples/scenes/game_scene/levels" -[connection signal="item_activated" from="LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] +[connection signal="item_activated" from="Control/LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] From 5b87ddef6d8f2d4ae5776115deea7d0dcd03e986 Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 14:33:15 -0800 Subject: [PATCH 16/17] Recopies examples into project root. --- .../level_select_menu/level_select_menu.gd | 8 ------ .../level_select_menu/level_select_menu.tscn | 27 ++++++++++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/scenes/menus/level_select_menu/level_select_menu.gd b/scenes/menus/level_select_menu/level_select_menu.gd index 793836e..8274453 100644 --- a/scenes/menus/level_select_menu/level_select_menu.gd +++ b/scenes/menus/level_select_menu/level_select_menu.gd @@ -9,10 +9,6 @@ extends Control @onready var scene_lister: SceneLister = $SceneLister signal level_selected -func _unhandled_input(_event: InputEvent) -> void: - if visible and !level_buttons_container.has_focus(): - level_buttons_container.grab_focus() - select_first() func _ready() -> void: add_levels_to_container() @@ -34,10 +30,6 @@ func add_levels_to_container(): var button_name = str(file_name) level_buttons_container.add_item(button_name) -func select_first(): - if level_buttons_container.item_count >=1: - level_buttons_container.select(0) - func _on_level_buttons_container_item_activated(index: int) -> void: GameState.set_current_level(index) level_selected.emit() diff --git a/scenes/menus/level_select_menu/level_select_menu.tscn b/scenes/menus/level_select_menu/level_select_menu.tscn index 04c96df..7d5aecc 100644 --- a/scenes/menus/level_select_menu/level_select_menu.tscn +++ b/scenes/menus/level_select_menu/level_select_menu.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=3 uid="uid://cvhipghsnttqv"] +[gd_scene load_steps=4 format=3 uid="uid://crgwq4t7ljint"] -[ext_resource type="Script" path="res://scenes/menus/level_select_menu/level_select_menu.gd" id="1_f1amo"] -[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_ljb5a"] +[ext_resource type="Script" path="res://scenes/menus/level_select_menu/level_select_menu.gd" id="1_h6hut"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="2_c723y"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="3_odcm1"] [node name="LevelSelectMenu" type="Control"] layout_mode = 3 @@ -10,9 +11,19 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -script = ExtResource("1_f1amo") +script = ExtResource("1_h6hut") -[node name="LevelButtonsContainer" type="ItemList" parent="."] +[node name="Control" type="Control" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("2_c723y") +enabled = true + +[node name="LevelButtonsContainer" type="ItemList" parent="Control"] unique_name_in_owner = true custom_minimum_size = Vector2(400, 0) layout_mode = 1 @@ -21,7 +32,9 @@ anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 +offset_left = -200.0 offset_top = -17.5 +offset_right = 200.0 offset_bottom = 17.5 grow_horizontal = 2 grow_vertical = 2 @@ -30,8 +43,8 @@ item_count = 1 item_0/text = "1 - ExampleLevel" [node name="SceneLister" type="Node" parent="."] -script = ExtResource("2_ljb5a") +script = ExtResource("3_odcm1") files = Array[String](["res://scenes/game_scene/levels/level_1.tscn", "res://scenes/game_scene/levels/level_2.tscn", "res://scenes/game_scene/levels/level_3.tscn"]) directory = "res://scenes/game_scene/levels" -[connection signal="item_activated" from="LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] +[connection signal="item_activated" from="Control/LevelButtonsContainer" to="." method="_on_level_buttons_container_item_activated"] From 3046e335ee9d1bdd893dee49def4226842f432fd Mon Sep 17 00:00:00 2001 From: Marek Belski Date: Thu, 9 Jan 2025 14:59:29 -0800 Subject: [PATCH 17/17] Fixes capturing focus in other instances. --- .../scenes/menus/options_menu/input/input_options_menu.tscn | 2 +- addons/maaacks_game_template/base/scripts/capture_focus.gd | 2 ++ .../scenes/menus/level_select_menu/level_select_menu.tscn | 3 +-- scenes/menus/level_select_menu/level_select_menu.tscn | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/maaacks_game_template/base/scenes/menus/options_menu/input/input_options_menu.tscn b/addons/maaacks_game_template/base/scenes/menus/options_menu/input/input_options_menu.tscn index 835789c..d93a5f1 100644 --- a/addons/maaacks_game_template/base/scenes/menus/options_menu/input/input_options_menu.tscn +++ b/addons/maaacks_game_template/base/scenes/menus/options_menu/input/input_options_menu.tscn @@ -22,7 +22,7 @@ size_flags_horizontal = 4 size_flags_vertical = 4 theme_override_constants/separation = 8 script = ExtResource("2_wft4x") -search_depth = 2 +search_depth = 4 [node name="InputMappingContainer" type="VBoxContainer" parent="VBoxContainer"] layout_mode = 2 diff --git a/addons/maaacks_game_template/base/scripts/capture_focus.gd b/addons/maaacks_game_template/base/scripts/capture_focus.gd index 2fd0cd1..11daf6a 100644 --- a/addons/maaacks_game_template/base/scripts/capture_focus.gd +++ b/addons/maaacks_game_template/base/scripts/capture_focus.gd @@ -11,6 +11,7 @@ extends Control ## Hierarchical depth to search in the scene tree. @export var search_depth : int = 1 @export var enabled : bool = false +@export var null_focus_enabled : bool = true @export var joypad_enabled : bool = true @export var mouse_hidden_enabled : bool = true @@ -47,6 +48,7 @@ func update_focus(): func _should_capture_focus(): return enabled or \ + (get_viewport().gui_get_focus_owner() == null and null_focus_enabled) or \ (Input.get_connected_joypads().size() > 0 and joypad_enabled) or \ (Input.mouse_mode not in [Input.MOUSE_MODE_VISIBLE, Input.MOUSE_MODE_CONFINED] and mouse_hidden_enabled) diff --git a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn index 1ba86da..79fef08 100644 --- a/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn +++ b/addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.tscn @@ -2,7 +2,7 @@ [ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/menus/level_select_menu/level_select_menu.gd" id="1_dm7vg"] [ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="2_88qak"] -[ext_resource type="Script" uid="uid://wjq7li836lwj" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_g3cvb"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/scene_lister.gd" id="2_g3cvb"] [node name="LevelSelectMenu" type="Control"] layout_mode = 3 @@ -21,7 +21,6 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("2_88qak") -enabled = true [node name="LevelButtonsContainer" type="ItemList" parent="Control"] unique_name_in_owner = true diff --git a/scenes/menus/level_select_menu/level_select_menu.tscn b/scenes/menus/level_select_menu/level_select_menu.tscn index 7d5aecc..e130a54 100644 --- a/scenes/menus/level_select_menu/level_select_menu.tscn +++ b/scenes/menus/level_select_menu/level_select_menu.tscn @@ -21,7 +21,6 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("2_c723y") -enabled = true [node name="LevelButtonsContainer" type="ItemList" parent="Control"] unique_name_in_owner = true