From 62bb2f3772bbd13ecae0b1c51c413f8b2fbf5743 Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Sat, 22 Mar 2025 16:04:46 -0400 Subject: [PATCH] Replaced existing options menu with Pause Menu (missing settings currently) --- autoloads/signal_manager.gd | 6 ++ autoloads/signal_manager.gd.uid | 1 + project.godot | 1 + resources/pause_menu_theme.tres | 6 ++ save_load/autoloads/save_game_manager.gd | 8 +-- scenes/ui/options_menu.tscn | 89 ------------------------ scenes/ui/pause_menu.gd | 37 ++++++++++ scenes/ui/pause_menu.gd.uid | 1 + scenes/ui/pause_menu.tscn | 81 +++++++++++++++++++++ scenes/ui/ui.gd | 41 ++++------- scenes/ui/ui.tscn | 13 +--- 11 files changed, 155 insertions(+), 129 deletions(-) create mode 100644 autoloads/signal_manager.gd create mode 100644 autoloads/signal_manager.gd.uid create mode 100644 resources/pause_menu_theme.tres delete mode 100644 scenes/ui/options_menu.tscn create mode 100644 scenes/ui/pause_menu.gd create mode 100644 scenes/ui/pause_menu.gd.uid create mode 100644 scenes/ui/pause_menu.tscn diff --git a/autoloads/signal_manager.gd b/autoloads/signal_manager.gd new file mode 100644 index 0000000..4d0ce2d --- /dev/null +++ b/autoloads/signal_manager.gd @@ -0,0 +1,6 @@ +## General Purpose signals +extends Node + + +signal options_menu_opened +signal options_menu_closed diff --git a/autoloads/signal_manager.gd.uid b/autoloads/signal_manager.gd.uid new file mode 100644 index 0000000..818e812 --- /dev/null +++ b/autoloads/signal_manager.gd.uid @@ -0,0 +1 @@ +uid://biwce2o15q44g diff --git a/project.godot b/project.godot index d298b9d..398611d 100644 --- a/project.godot +++ b/project.godot @@ -23,6 +23,7 @@ EntityManager="*res://autoloads/entity_manager.gd" InventoryManager="*res://autoloads/inventory_manager.gd" DBItems="*res://autoloads/db_items.gd" SaveGameManager="*res://save_load/autoloads/save_game_manager.gd" +SignalManager="*res://autoloads/signal_manager.gd" [debug] diff --git a/resources/pause_menu_theme.tres b/resources/pause_menu_theme.tres new file mode 100644 index 0000000..af3d5d8 --- /dev/null +++ b/resources/pause_menu_theme.tres @@ -0,0 +1,6 @@ +[gd_resource type="Theme" format=3 uid="uid://b5q8b0l6qp1dt"] + +[resource] +Button/colors/font_color = Color(0.839216, 0.933333, 1, 1) +Button/constants/outline_size = 2 +Button/font_sizes/font_size = 20 diff --git a/save_load/autoloads/save_game_manager.gd b/save_load/autoloads/save_game_manager.gd index 3a2a1e0..dae42bf 100644 --- a/save_load/autoloads/save_game_manager.gd +++ b/save_load/autoloads/save_game_manager.gd @@ -13,12 +13,12 @@ signal game_loaded func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("quick_save"): - _save_game() + save_game() if event.is_action_pressed("quick_load"): - _load_game() + load_game() -func _save_game() -> void: +func save_game() -> void: var save_level_data_component: SaveLevelDataComponent = get_tree().get_first_node_in_group("save_level_data_component") if save_level_data_component == null: @@ -28,7 +28,7 @@ func _save_game() -> void: save_level_data_component.save_game() game_saved.emit() -func _load_game() -> void: +func load_game() -> void: EntityManager.reset_world.emit() var save_level_data_component: SaveLevelDataComponent = get_tree().get_first_node_in_group("save_level_data_component") diff --git a/scenes/ui/options_menu.tscn b/scenes/ui/options_menu.tscn deleted file mode 100644 index 9a8fd08..0000000 --- a/scenes/ui/options_menu.tscn +++ /dev/null @@ -1,89 +0,0 @@ -[gd_scene format=3 uid="uid://w6wtjosjn1qu"] - -[node name="OptionsMenu" type="MarginContainer"] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="PanelContainer" type="PanelContainer" parent="."] -layout_mode = 2 - -[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] -layout_mode = 2 -theme_override_constants/margin_left = 20 -theme_override_constants/margin_top = 20 -theme_override_constants/margin_right = 20 -theme_override_constants/margin_bottom = 20 - -[node name="LeftContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer"] -layout_mode = 2 - -[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer/LeftContainer"] -layout_mode = 2 -size_flags_horizontal = 3 - -[node name="Label" type="Label" parent="PanelContainer/MarginContainer/LeftContainer/VBoxContainer"] -layout_mode = 2 -size_flags_vertical = 0 -theme_type_variation = &"HeaderLarge" -text = "Options Menu" -horizontal_alignment = 1 - -[node name="BlockHighlights" type="HBoxContainer" parent="PanelContainer/MarginContainer/LeftContainer/VBoxContainer"] -layout_mode = 2 - -[node name="CheckButton" type="CheckButton" parent="PanelContainer/MarginContainer/LeftContainer/VBoxContainer/BlockHighlights"] -layout_mode = 2 -button_pressed = true -text = "Enable Block Highlighting" - -[node name="Waila" type="HBoxContainer" parent="PanelContainer/MarginContainer/LeftContainer/VBoxContainer"] -layout_mode = 2 - -[node name="CheckButton" type="CheckButton" parent="PanelContainer/MarginContainer/LeftContainer/VBoxContainer/Waila"] -layout_mode = 2 -button_pressed = true -text = "Enable Waila" - -[node name="BottomRightContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer"] -layout_mode = 2 -size_flags_horizontal = 8 -size_flags_vertical = 8 - -[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer/BottomRightContainer"] -layout_mode = 2 -size_flags_horizontal = 8 - -[node name="ControlsLabel" type="Label" parent="PanelContainer/MarginContainer/BottomRightContainer/VBoxContainer"] -layout_mode = 2 -theme_type_variation = &"HeaderSmall" -text = "Controls" -horizontal_alignment = 1 - -[node name="Controls" type="Label" parent="PanelContainer/MarginContainer/BottomRightContainer/VBoxContainer"] -layout_mode = 2 -text = "Left Click - Create Block -Right Click - Delete Block -Scoll Wheel - Change Block -Ctrl - Crouch -Shift - Sprint (until stop or toggled)" - -[node name="CenterContainer" type="CenterContainer" parent="PanelContainer/MarginContainer"] -layout_mode = 2 -size_flags_vertical = 8 - -[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/CenterContainer"] -layout_mode = 2 -theme_override_constants/separation = 10 - -[node name="CloseButton" type="Button" parent="PanelContainer/MarginContainer/CenterContainer/HBoxContainer"] -layout_mode = 2 -theme_override_font_sizes/font_size = 20 -text = "Close Menu" - -[node name="ExitButton" type="Button" parent="PanelContainer/MarginContainer/CenterContainer/HBoxContainer"] -layout_mode = 2 -theme_override_font_sizes/font_size = 20 -text = "Exit Game" diff --git a/scenes/ui/pause_menu.gd b/scenes/ui/pause_menu.gd new file mode 100644 index 0000000..8ba1681 --- /dev/null +++ b/scenes/ui/pause_menu.gd @@ -0,0 +1,37 @@ +class_name PauseMenu +extends Panel + + +func _unhandled_input(event: InputEvent) -> void: + if event.is_action_pressed("ui_cancel") and self.visible: + hide_menu() + elif event.is_action_pressed("ui_cancel") and !self.visible: + show_menu() + + +func show_menu() -> void: + self.visible = true + SignalManager.options_menu_opened.emit() + +func hide_menu() -> void: + self.visible = false + SignalManager.options_menu_closed.emit() + + +# Signals +func _on_exit_game_button_pressed() -> void: + get_tree().quit() + +func _on_resume_button_pressed() -> void: + hide_menu() + +func _on_quick_load_pressed() -> void: + SaveGameManager.load_game() + hide_menu() + +func _on_quick_save_pressed() -> void: + SaveGameManager.save_game() + hide_menu() + +func _on_settings_button_pressed() -> void: + pass # Replace with function body. diff --git a/scenes/ui/pause_menu.gd.uid b/scenes/ui/pause_menu.gd.uid new file mode 100644 index 0000000..9c7340d --- /dev/null +++ b/scenes/ui/pause_menu.gd.uid @@ -0,0 +1 @@ +uid://d3ysjgxxmyqpw diff --git a/scenes/ui/pause_menu.tscn b/scenes/ui/pause_menu.tscn new file mode 100644 index 0000000..c23d0bc --- /dev/null +++ b/scenes/ui/pause_menu.tscn @@ -0,0 +1,81 @@ +[gd_scene load_steps=3 format=3 uid="uid://bopvfwcgnnawg"] + +[ext_resource type="Theme" uid="uid://b5q8b0l6qp1dt" path="res://resources/pause_menu_theme.tres" id="1_6tw0m"] +[ext_resource type="Script" uid="uid://d3ysjgxxmyqpw" path="res://scenes/ui/pause_menu.gd" id="2_0lmf7"] + +[node name="PauseMenu" type="Panel"] +process_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = ExtResource("1_6tw0m") +script = ExtResource("2_0lmf7") + +[node name="Background" type="ColorRect" parent="."] +custom_minimum_size = Vector2(400, 0) +layout_mode = 1 +anchors_preset = 13 +anchor_left = 0.5 +anchor_right = 0.5 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.192157, 0.239216, 0.352941, 1) + +[node name="MarginContainer" type="MarginContainer" parent="Background"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="CenterContainer" type="VBoxContainer" parent="Background/MarginContainer"] +layout_mode = 2 +size_flags_horizontal = 4 +theme_override_constants/separation = 20 + +[node name="Title" type="Label" parent="Background/MarginContainer/CenterContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 40 +text = "Paused" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ButtonsContainer" type="VBoxContainer" parent="Background/MarginContainer/CenterContainer"] +layout_mode = 2 +size_flags_vertical = 6 +theme_override_constants/separation = 20 + +[node name="ResumeButton" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +layout_mode = 2 +text = "Resume" + +[node name="QuickSave" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +layout_mode = 2 +text = "Quick Save" + +[node name="QuickLoad" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +layout_mode = 2 +text = "Quick Load" + +[node name="SettingsButton" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +layout_mode = 2 +disabled = true +text = "Settings" + +[node name="ExitGameButton" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +layout_mode = 2 +text = "Exit Game" + +[connection signal="pressed" from="Background/MarginContainer/CenterContainer/ButtonsContainer/ResumeButton" to="." method="_on_resume_button_pressed"] +[connection signal="pressed" from="Background/MarginContainer/CenterContainer/ButtonsContainer/QuickSave" to="." method="_on_quick_save_pressed"] +[connection signal="pressed" from="Background/MarginContainer/CenterContainer/ButtonsContainer/QuickLoad" to="." method="_on_quick_load_pressed"] +[connection signal="pressed" from="Background/MarginContainer/CenterContainer/ButtonsContainer/SettingsButton" to="." method="_on_settings_button_pressed"] +[connection signal="pressed" from="Background/MarginContainer/CenterContainer/ButtonsContainer/ExitGameButton" to="." method="_on_exit_game_button_pressed"] diff --git a/scenes/ui/ui.gd b/scenes/ui/ui.gd index 5c99e97..571e5e5 100644 --- a/scenes/ui/ui.gd +++ b/scenes/ui/ui.gd @@ -4,40 +4,29 @@ extends CanvasLayer @onready var crosshair: CenterContainer = $Crosshair @onready var inventory: Inventory = $Inventory -@onready var options_menu: MarginContainer = $OptionsMenu @onready var quick_slots: MarginContainer = $QuickSlots @onready var waila: Waila = $Waila -func _process(_delta: float) -> void: - if Input.is_action_just_pressed("ui_cancel"): - toggle_options_menu() +func _ready() -> void: + SignalManager.options_menu_closed.connect(_on_options_menu_closed.bind()) + SignalManager.options_menu_opened.connect(_on_options_menu_opened.bind()) -func toggle_options_menu() -> void: - options_menu.visible = !options_menu.visible - Globals.is_options_menu_active = options_menu.visible - crosshair.visible = !options_menu.visible - quick_slots.visible = !options_menu.visible +func _on_options_menu_closed() -> void: + crosshair.visible = true + quick_slots.visible = true + waila.visible = true - if options_menu.visible: - waila.visible = false - Input.mouse_mode = Input.MOUSE_MODE_VISIBLE - else: - Input.mouse_mode = Input.MOUSE_MODE_CAPTURED + Input.mouse_mode = Input.MOUSE_MODE_CAPTURED + get_tree().paused = false -# Options -func _on_block_highlights_toggled(toggled_on: bool) -> void: - Globals.enable_block_highlight = toggled_on +func _on_options_menu_opened() -> void: + crosshair.visible = false + quick_slots.visible = false + waila.visible = false -func _on_waila_toggled(toggled_on: bool) -> void: - Globals.enable_waila = toggled_on + Input.mouse_mode = Input.MOUSE_MODE_VISIBLE - -# Signals -func _on_close_button_pressed() -> void: - toggle_options_menu() - -func _on_exit_button_pressed() -> void: - get_tree().quit() + get_tree().paused = true diff --git a/scenes/ui/ui.tscn b/scenes/ui/ui.tscn index a1c506d..4138f23 100644 --- a/scenes/ui/ui.tscn +++ b/scenes/ui/ui.tscn @@ -2,9 +2,9 @@ [ext_resource type="Script" uid="uid://bslimr2y4lnvq" path="res://scenes/ui/ui.gd" id="1_aac20"] [ext_resource type="PackedScene" uid="uid://dvogu3djluqsn" path="res://scenes/ui/waila.tscn" id="1_u7n8c"] -[ext_resource type="PackedScene" uid="uid://w6wtjosjn1qu" path="res://scenes/ui/options_menu.tscn" id="2_f5cxw"] [ext_resource type="PackedScene" uid="uid://cbiygbgpfk220" path="res://scenes/ui/quick_slots.tscn" id="4_g5kmx"] [ext_resource type="PackedScene" uid="uid://dcr25y1lw4wjp" path="res://scenes/ui/inventory/inventory.tscn" id="5_0dwhk"] +[ext_resource type="PackedScene" uid="uid://bopvfwcgnnawg" path="res://scenes/ui/pause_menu.tscn" id="6_7vp6q"] [ext_resource type="Resource" uid="uid://blfp6tiir282o" path="res://resources/inventory/player_inventory_testing.tres" id="6_pfayw"] [node name="UI" type="CanvasLayer"] @@ -29,18 +29,11 @@ mouse_filter = 2 [node name="Waila" parent="." instance=ExtResource("1_u7n8c")] -[node name="OptionsMenu" parent="." instance=ExtResource("2_f5cxw")] -visible = false - [node name="QuickSlots" parent="." instance=ExtResource("4_g5kmx")] [node name="Inventory" parent="." instance=ExtResource("5_0dwhk")] visible = false inventory_resource = ExtResource("6_pfayw") -[connection signal="toggled" from="OptionsMenu/PanelContainer/MarginContainer/LeftContainer/VBoxContainer/BlockHighlights/CheckButton" to="." method="_on_block_highlights_toggled"] -[connection signal="toggled" from="OptionsMenu/PanelContainer/MarginContainer/LeftContainer/VBoxContainer/Waila/CheckButton" to="." method="_on_waila_toggled"] -[connection signal="pressed" from="OptionsMenu/PanelContainer/MarginContainer/CenterContainer/HBoxContainer/CloseButton" to="." method="_on_close_button_pressed"] -[connection signal="pressed" from="OptionsMenu/PanelContainer/MarginContainer/CenterContainer/HBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"] - -[editable path="OptionsMenu"] +[node name="PauseMenu" parent="." instance=ExtResource("6_7vp6q")] +visible = false