diff --git a/autoloads/signal_manager.gd b/autoloads/signal_manager.gd index 4d0ce2d..32e012b 100644 --- a/autoloads/signal_manager.gd +++ b/autoloads/signal_manager.gd @@ -2,5 +2,10 @@ extends Node -signal options_menu_opened -signal options_menu_closed +#signal pause_game +signal resume_game + +signal open_pause_menu +signal close_pause_menu +signal open_settings_menu +signal close_settings_menu diff --git a/scenes/ui/pause_menu.gd b/scenes/ui/pause_menu.gd index 8ba1681..97a1dee 100644 --- a/scenes/ui/pause_menu.gd +++ b/scenes/ui/pause_menu.gd @@ -9,13 +9,11 @@ func _unhandled_input(event: InputEvent) -> void: 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() + SignalManager.close_pause_menu.emit() + +func show_menu() -> void: + SignalManager.open_pause_menu.emit() # Signals @@ -34,4 +32,4 @@ func _on_quick_save_pressed() -> void: hide_menu() func _on_settings_button_pressed() -> void: - pass # Replace with function body. + SignalManager.open_settings_menu.emit() diff --git a/scenes/ui/pause_menu.tscn b/scenes/ui/pause_menu.tscn index c23d0bc..226e21a 100644 --- a/scenes/ui/pause_menu.tscn +++ b/scenes/ui/pause_menu.tscn @@ -13,7 +13,7 @@ grow_vertical = 2 theme = ExtResource("1_6tw0m") script = ExtResource("2_0lmf7") -[node name="Background" type="ColorRect" parent="."] +[node name="MenuBody" type="ColorRect" parent="."] custom_minimum_size = Vector2(400, 0) layout_mode = 1 anchors_preset = 13 @@ -24,7 +24,7 @@ grow_horizontal = 2 grow_vertical = 2 color = Color(0.192157, 0.239216, 0.352941, 1) -[node name="MarginContainer" type="MarginContainer" parent="Background"] +[node name="MarginContainer" type="MarginContainer" parent="MenuBody"] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -36,46 +36,45 @@ 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"] +[node name="CenterContainer" type="VBoxContainer" parent="MenuBody/MarginContainer"] layout_mode = 2 size_flags_horizontal = 4 theme_override_constants/separation = 20 -[node name="Title" type="Label" parent="Background/MarginContainer/CenterContainer"] +[node name="Title" type="Label" parent="MenuBody/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"] +[node name="ButtonsContainer" type="VBoxContainer" parent="MenuBody/MarginContainer/CenterContainer"] layout_mode = 2 size_flags_vertical = 6 theme_override_constants/separation = 20 -[node name="ResumeButton" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +[node name="ResumeButton" type="Button" parent="MenuBody/MarginContainer/CenterContainer/ButtonsContainer"] layout_mode = 2 text = "Resume" -[node name="QuickSave" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +[node name="QuickSave" type="Button" parent="MenuBody/MarginContainer/CenterContainer/ButtonsContainer"] layout_mode = 2 text = "Quick Save" -[node name="QuickLoad" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +[node name="QuickLoad" type="Button" parent="MenuBody/MarginContainer/CenterContainer/ButtonsContainer"] layout_mode = 2 text = "Quick Load" -[node name="SettingsButton" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +[node name="SettingsButton" type="Button" parent="MenuBody/MarginContainer/CenterContainer/ButtonsContainer"] layout_mode = 2 -disabled = true text = "Settings" -[node name="ExitGameButton" type="Button" parent="Background/MarginContainer/CenterContainer/ButtonsContainer"] +[node name="ExitGameButton" type="Button" parent="MenuBody/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"] +[connection signal="pressed" from="MenuBody/MarginContainer/CenterContainer/ButtonsContainer/ResumeButton" to="." method="_on_resume_button_pressed"] +[connection signal="pressed" from="MenuBody/MarginContainer/CenterContainer/ButtonsContainer/QuickSave" to="." method="_on_quick_save_pressed"] +[connection signal="pressed" from="MenuBody/MarginContainer/CenterContainer/ButtonsContainer/QuickLoad" to="." method="_on_quick_load_pressed"] +[connection signal="pressed" from="MenuBody/MarginContainer/CenterContainer/ButtonsContainer/SettingsButton" to="." method="_on_settings_button_pressed"] +[connection signal="pressed" from="MenuBody/MarginContainer/CenterContainer/ButtonsContainer/ExitGameButton" to="." method="_on_exit_game_button_pressed"] diff --git a/scenes/ui/settings_menu.gd b/scenes/ui/settings_menu.gd new file mode 100644 index 0000000..697b76e --- /dev/null +++ b/scenes/ui/settings_menu.gd @@ -0,0 +1,13 @@ +class_name SettingsMenu +extends Panel + + +func _on_block_highlighting_toggled(toggled_on: bool) -> void: + Globals.enable_block_highlight = toggled_on + +func _on_enable_waila_toggled(toggled_on: bool) -> void: + Globals.enable_waila = toggled_on + + +func _on_close_button_pressed() -> void: + SignalManager.resume_game.emit() diff --git a/scenes/ui/settings_menu.gd.uid b/scenes/ui/settings_menu.gd.uid new file mode 100644 index 0000000..9866805 --- /dev/null +++ b/scenes/ui/settings_menu.gd.uid @@ -0,0 +1 @@ +uid://37ftrpj14msn diff --git a/scenes/ui/settings_menu.tscn b/scenes/ui/settings_menu.tscn new file mode 100644 index 0000000..7e17aca --- /dev/null +++ b/scenes/ui/settings_menu.tscn @@ -0,0 +1,98 @@ +[gd_scene load_steps=3 format=3 uid="uid://4bdgwwx27m71"] + +[ext_resource type="Script" uid="uid://37ftrpj14msn" path="res://scenes/ui/settings_menu.gd" id="1_qwcqe"] +[ext_resource type="Theme" uid="uid://b5q8b0l6qp1dt" path="res://resources/pause_menu_theme.tres" id="2_mhswj"] + +[node name="SettingsMenu" type="Panel"] +process_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_qwcqe") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -300.0 +offset_right = 300.0 +offset_bottom = 137.0 +grow_horizontal = 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="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 +theme_override_constants/separation = 20 + +[node name="Title" type="Label" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 40 +text = "Settings" +horizontal_alignment = 1 + +[node name="TabContainer" type="TabContainer" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +current_tab = 0 + +[node name="Game" type="VBoxContainer" parent="MarginContainer/VBoxContainer/TabContainer"] +layout_mode = 2 +metadata/_tab_index = 0 + +[node name="BlockHighlighting" type="CheckButton" parent="MarginContainer/VBoxContainer/TabContainer/Game"] +layout_mode = 2 +button_pressed = true +text = "Enable Block Highlighting" + +[node name="EnableWaila" type="CheckButton" parent="MarginContainer/VBoxContainer/TabContainer/Game"] +layout_mode = 2 +button_pressed = true +text = "Enable Waila" + +[node name="Graphics (Todo)" type="VBoxContainer" parent="MarginContainer/VBoxContainer/TabContainer"] +visible = false +layout_mode = 2 +metadata/_tab_index = 1 + +[node name="Audio (TODO)" type="VBoxContainer" parent="MarginContainer/VBoxContainer/TabContainer"] +visible = false +layout_mode = 2 +metadata/_tab_index = 2 + +[node name="Inputs (TODO)" type="VBoxContainer" parent="MarginContainer/VBoxContainer/TabContainer"] +visible = false +layout_mode = 2 +metadata/_tab_index = 3 + +[node name="BottomRow" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +offset_left = -82.5 +offset_top = -40.0 +offset_right = 82.5 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_constants/margin_bottom = 10 + +[node name="HBoxContainer" type="HBoxContainer" parent="BottomRow"] +layout_mode = 2 +theme_override_constants/separation = 20 + +[node name="CloseButton" type="Button" parent="BottomRow/HBoxContainer"] +custom_minimum_size = Vector2(141, 36) +layout_mode = 2 +theme = ExtResource("2_mhswj") +text = "Close Settings" + +[connection signal="toggled" from="MarginContainer/VBoxContainer/TabContainer/Game/BlockHighlighting" to="." method="_on_block_highlighting_toggled"] +[connection signal="toggled" from="MarginContainer/VBoxContainer/TabContainer/Game/EnableWaila" to="." method="_on_enable_waila_toggled"] +[connection signal="pressed" from="BottomRow/HBoxContainer/CloseButton" to="." method="_on_close_button_pressed"] diff --git a/scenes/ui/ui.gd b/scenes/ui/ui.gd index 571e5e5..c25e5cb 100644 --- a/scenes/ui/ui.gd +++ b/scenes/ui/ui.gd @@ -5,28 +5,60 @@ extends CanvasLayer @onready var crosshair: CenterContainer = $Crosshair @onready var inventory: Inventory = $Inventory @onready var quick_slots: MarginContainer = $QuickSlots +@onready var pause_menu: PauseMenu = $PauseMenu +@onready var settings_menu: SettingsMenu = $SettingsMenu @onready var waila: Waila = $Waila func _ready() -> void: - SignalManager.options_menu_closed.connect(_on_options_menu_closed.bind()) - SignalManager.options_menu_opened.connect(_on_options_menu_opened.bind()) + SignalManager.close_pause_menu.connect(_on_close_pause_menu) + SignalManager.open_pause_menu.connect(_on_open_pause_menu) + SignalManager.close_settings_menu.connect(_on_close_settings_menu) + SignalManager.open_settings_menu.connect(_on_open_settings_menu) + SignalManager.resume_game.connect(_on_resume_game) -func _on_options_menu_closed() -> void: - crosshair.visible = true - quick_slots.visible = true - waila.visible = true - - Input.mouse_mode = Input.MOUSE_MODE_CAPTURED - - get_tree().paused = false - -func _on_options_menu_opened() -> void: +func hide_ui_elements() -> void: crosshair.visible = false quick_slots.visible = false waila.visible = false +func hide_menus() -> void: + pause_menu.visible = false + settings_menu.visible = false + inventory.visible = false + + +func _on_close_pause_menu() -> void: + SignalManager.resume_game.emit() + +func _on_close_settings_menu() -> void: + SignalManager.resume_game.emit() + +func _on_open_pause_menu() -> void: + Input.mouse_mode = Input.MOUSE_MODE_VISIBLE + + hide_ui_elements() + hide_menus() + pause_menu.visible = true + + get_tree().paused = true + +func _on_open_settings_menu() -> void: Input.mouse_mode = Input.MOUSE_MODE_VISIBLE + hide_ui_elements() + hide_menus() + settings_menu.visible = true + get_tree().paused = true + +func _on_resume_game() -> void: + Input.mouse_mode = Input.MOUSE_MODE_CAPTURED + + hide_menus() + crosshair.visible = true + quick_slots.visible = true + waila.visible = true + + get_tree().paused = false diff --git a/scenes/ui/ui.tscn b/scenes/ui/ui.tscn index 4138f23..69dc0d3 100644 --- a/scenes/ui/ui.tscn +++ b/scenes/ui/ui.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://c7fj7wla8bd70"] +[gd_scene load_steps=8 format=3 uid="uid://c7fj7wla8bd70"] [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"] @@ -6,6 +6,7 @@ [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"] +[ext_resource type="PackedScene" uid="uid://4bdgwwx27m71" path="res://scenes/ui/settings_menu.tscn" id="7_7vp6q"] [node name="UI" type="CanvasLayer"] script = ExtResource("1_aac20") @@ -37,3 +38,6 @@ inventory_resource = ExtResource("6_pfayw") [node name="PauseMenu" parent="." instance=ExtResource("6_7vp6q")] visible = false + +[node name="SettingsMenu" parent="." instance=ExtResource("7_7vp6q")] +visible = false