gd: added menu template
This commit is contained in:
@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cikf3o5omnunl"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bqqngki8bm3iq" path="res://addons/maaacks_game_template/base/scenes/overlaid_menu/overlaid_menu_container.tscn" id="1_kverk"]
|
||||
[ext_resource type="PackedScene" uid="uid://vh1ucj2rfbby" path="res://addons/maaacks_game_template/base/scenes/menus/options_menu/mini_options_menu.tscn" id="2_ihtu5"]
|
||||
|
||||
[node name="OverlaidMenuContainer" instance=ExtResource("1_kverk")]
|
||||
menu_scene = ExtResource("2_ihtu5")
|
||||
|
||||
[node name="TitleLabel" parent="MenuPanelContainer/MarginContainer/BoxContainer/TitleMargin" index="0"]
|
||||
text = "Options"
|
@ -0,0 +1,81 @@
|
||||
class_name PauseMenu
|
||||
extends OverlaidMenu
|
||||
|
||||
@export var options_packed_scene : PackedScene
|
||||
@export_file("*.tscn") var main_menu_scene : String
|
||||
|
||||
var popup_open : Node
|
||||
|
||||
func close_popup() -> void:
|
||||
if popup_open != null:
|
||||
popup_open.hide()
|
||||
popup_open = null
|
||||
|
||||
func _disable_focus() -> void:
|
||||
for child in %MenuButtons.get_children():
|
||||
if child is Control:
|
||||
child.focus_mode = FOCUS_NONE
|
||||
|
||||
func _enable_focus() -> void:
|
||||
for child in %MenuButtons.get_children():
|
||||
if child is Control:
|
||||
child.focus_mode = FOCUS_ALL
|
||||
|
||||
func _load_scene(scene_path: String) -> void:
|
||||
_scene_tree.paused = false
|
||||
SceneLoader.load_scene(scene_path)
|
||||
|
||||
func open_options_menu() -> void:
|
||||
var options_scene := options_packed_scene.instantiate()
|
||||
add_child(options_scene)
|
||||
_disable_focus.call_deferred()
|
||||
await options_scene.tree_exiting
|
||||
_enable_focus.call_deferred()
|
||||
|
||||
func _handle_cancel_input() -> void:
|
||||
if popup_open != null:
|
||||
close_popup()
|
||||
else:
|
||||
super._handle_cancel_input()
|
||||
|
||||
func _hide_exit_for_web() -> void:
|
||||
if OS.has_feature("web"):
|
||||
%ExitButton.hide()
|
||||
|
||||
func _hide_options_if_unset() -> void:
|
||||
if options_packed_scene == null:
|
||||
%OptionsButton.hide()
|
||||
|
||||
func _hide_main_menu_if_unset() -> void:
|
||||
if main_menu_scene.is_empty():
|
||||
%MainMenuButton.hide()
|
||||
|
||||
func _ready() -> void:
|
||||
_hide_exit_for_web()
|
||||
_hide_options_if_unset()
|
||||
_hide_main_menu_if_unset()
|
||||
|
||||
func _on_restart_button_pressed() -> void:
|
||||
%ConfirmRestart.popup_centered()
|
||||
popup_open = %ConfirmRestart
|
||||
|
||||
func _on_options_button_pressed() -> void:
|
||||
open_options_menu()
|
||||
|
||||
func _on_main_menu_button_pressed() -> void:
|
||||
%ConfirmMainMenu.popup_centered()
|
||||
popup_open = %ConfirmMainMenu
|
||||
|
||||
func _on_exit_button_pressed() -> void:
|
||||
%ConfirmExit.popup_centered()
|
||||
popup_open = %ConfirmExit
|
||||
|
||||
func _on_confirm_restart_confirmed() -> void:
|
||||
SceneLoader.reload_current_scene()
|
||||
close()
|
||||
|
||||
func _on_confirm_main_menu_confirmed() -> void:
|
||||
_load_scene(main_menu_scene)
|
||||
|
||||
func _on_confirm_exit_confirmed() -> void:
|
||||
get_tree().quit()
|
@ -0,0 +1 @@
|
||||
uid://uidwhqh4fyhj
|
@ -0,0 +1,68 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://b5cd6sa8qq4vc"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://wny2d8dvp3ok" path="res://addons/maaacks_game_template/base/scenes/overlaid_menu/overlaid_menu.tscn" id="1_gm3uv"]
|
||||
[ext_resource type="Script" uid="uid://uidwhqh4fyhj" path="res://addons/maaacks_game_template/base/scenes/overlaid_menu/menus/pause_menu.gd" id="2_0ln3r"]
|
||||
[ext_resource type="PackedScene" uid="uid://cikf3o5omnunl" path="res://addons/maaacks_game_template/base/scenes/overlaid_menu/menus/mini_options_overlaid_menu.tscn" id="3_kv70e"]
|
||||
|
||||
[node name="PauseMenu" instance=ExtResource("1_gm3uv")]
|
||||
process_mode = 3
|
||||
script = ExtResource("2_0ln3r")
|
||||
options_packed_scene = ExtResource("3_kv70e")
|
||||
main_menu_scene = "res://addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn"
|
||||
pauses_game = true
|
||||
|
||||
[node name="MarginContainer" parent="MenuPanelContainer" index="0"]
|
||||
theme_override_constants/margin_left = 64
|
||||
theme_override_constants/margin_right = 64
|
||||
|
||||
[node name="TitleLabel" parent="MenuPanelContainer/MarginContainer/BoxContainer/TitleMargin" index="0"]
|
||||
text = "Paused"
|
||||
|
||||
[node name="MenuButtonsMargin" parent="MenuPanelContainer/MarginContainer/BoxContainer" index="2"]
|
||||
theme_override_constants/margin_top = 16
|
||||
theme_override_constants/margin_bottom = 16
|
||||
|
||||
[node name="CloseButton" parent="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons" index="0"]
|
||||
text = "Resume"
|
||||
|
||||
[node name="RestartButton" type="Button" parent="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons" index="1"]
|
||||
layout_mode = 2
|
||||
text = "Restart"
|
||||
|
||||
[node name="OptionsButton" type="Button" parent="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons" index="2"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Options"
|
||||
|
||||
[node name="MainMenuButton" type="Button" parent="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons" index="3"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Main Menu"
|
||||
|
||||
[node name="ExitButton" type="Button" parent="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons" index="4"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Exit Game"
|
||||
|
||||
[node name="ConfirmRestart" type="ConfirmationDialog" parent="." index="2"]
|
||||
unique_name_in_owner = true
|
||||
auto_translate_mode = 1
|
||||
dialog_text = "Restart the game?"
|
||||
|
||||
[node name="ConfirmMainMenu" type="ConfirmationDialog" parent="." index="3"]
|
||||
unique_name_in_owner = true
|
||||
auto_translate_mode = 1
|
||||
dialog_text = "Go back to main menu?"
|
||||
|
||||
[node name="ConfirmExit" type="ConfirmationDialog" parent="." index="4"]
|
||||
unique_name_in_owner = true
|
||||
auto_translate_mode = 1
|
||||
dialog_text = "Quit the game?"
|
||||
|
||||
[connection signal="pressed" from="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons/RestartButton" to="." method="_on_restart_button_pressed"]
|
||||
[connection signal="pressed" from="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons/OptionsButton" to="." method="_on_options_button_pressed"]
|
||||
[connection signal="pressed" from="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons/MainMenuButton" to="." method="_on_main_menu_button_pressed"]
|
||||
[connection signal="pressed" from="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons/ExitButton" to="." method="_on_exit_button_pressed"]
|
||||
[connection signal="confirmed" from="ConfirmRestart" to="." method="_on_confirm_restart_confirmed"]
|
||||
[connection signal="confirmed" from="ConfirmMainMenu" to="." method="_on_confirm_main_menu_confirmed"]
|
||||
[connection signal="confirmed" from="ConfirmExit" to="." method="_on_confirm_exit_confirmed"]
|
@ -0,0 +1,49 @@
|
||||
@tool
|
||||
class_name OverlaidMenu
|
||||
extends Control
|
||||
|
||||
@export var pauses_game : bool = false :
|
||||
set(value):
|
||||
pauses_game = value
|
||||
if pauses_game:
|
||||
process_mode = PROCESS_MODE_ALWAYS
|
||||
else:
|
||||
process_mode = PROCESS_MODE_INHERIT
|
||||
@export var makes_mouse_visible : bool = true
|
||||
|
||||
var _initial_pause_state : bool = false
|
||||
var _initial_focus_mode : FocusMode = FOCUS_ALL
|
||||
var _initial_mouse_mode : Input.MouseMode
|
||||
var _initial_focus_control
|
||||
var _scene_tree : SceneTree
|
||||
|
||||
func close() -> void:
|
||||
_scene_tree.paused = _initial_pause_state
|
||||
Input.set_mouse_mode(_initial_mouse_mode)
|
||||
if is_instance_valid(_initial_focus_control) and _initial_focus_control.is_inside_tree():
|
||||
_initial_focus_control.focus_mode = _initial_focus_mode
|
||||
_initial_focus_control.grab_focus()
|
||||
queue_free()
|
||||
|
||||
func _handle_cancel_input() -> void:
|
||||
close()
|
||||
|
||||
func _unhandled_input(event : InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
_handle_cancel_input()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
func _on_close_button_pressed() -> void:
|
||||
close()
|
||||
|
||||
func _enter_tree() -> void:
|
||||
_scene_tree = get_tree()
|
||||
_initial_pause_state = _scene_tree.paused
|
||||
_initial_mouse_mode = Input.get_mouse_mode()
|
||||
_initial_focus_control = get_viewport().gui_get_focus_owner()
|
||||
if _initial_focus_control:
|
||||
_initial_focus_mode = _initial_focus_control.focus_mode
|
||||
if Engine.is_editor_hint(): return
|
||||
_scene_tree.paused = pauses_game or _initial_pause_state
|
||||
if makes_mouse_visible:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
@ -0,0 +1 @@
|
||||
uid://xfugmpspqbcc
|
@ -0,0 +1,88 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://wny2d8dvp3ok"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://xfugmpspqbcc" path="res://addons/maaacks_game_template/base/scenes/overlaid_menu/overlaid_menu.gd" id="1_euyj1"]
|
||||
[ext_resource type="Script" uid="uid://1nf36h0gms3q" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="2_6ani0"]
|
||||
|
||||
[node name="OverlaidMenu" 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_euyj1")
|
||||
|
||||
[node name="BackgroundColor" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
color = Color(0, 0, 0, 0.12549)
|
||||
|
||||
[node name="MenuPanelContainer" type="PanelContainer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
process_mode = 3
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -16.0
|
||||
offset_top = -16.0
|
||||
offset_right = 16.0
|
||||
offset_bottom = 16.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="MenuPanelContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 16
|
||||
theme_override_constants/margin_top = 16
|
||||
theme_override_constants/margin_right = 16
|
||||
theme_override_constants/margin_bottom = 16
|
||||
|
||||
[node name="BoxContainer" type="BoxContainer" parent="MenuPanelContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
vertical = true
|
||||
|
||||
[node name="TitleMargin" type="MarginContainer" parent="MenuPanelContainer/MarginContainer/BoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TitleLabel" type="Label" parent="MenuPanelContainer/MarginContainer/BoxContainer/TitleMargin"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 24
|
||||
text = "Menu"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="DescriptionMargin" type="MarginContainer" parent="MenuPanelContainer/MarginContainer/BoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="DescriptionLabel" type="RichTextLabel" parent="MenuPanelContainer/MarginContainer/BoxContainer/DescriptionMargin"]
|
||||
layout_mode = 2
|
||||
bbcode_enabled = true
|
||||
|
||||
[node name="MenuButtonsMargin" type="MarginContainer" parent="MenuPanelContainer/MarginContainer/BoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MenuButtons" type="BoxContainer" parent="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(128, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/separation = 16
|
||||
alignment = 1
|
||||
vertical = true
|
||||
script = ExtResource("2_6ani0")
|
||||
|
||||
[node name="CloseButton" type="Button" parent="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons"]
|
||||
layout_mode = 2
|
||||
text = "Close"
|
||||
|
||||
[connection signal="pressed" from="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons/CloseButton" to="." method="_on_close_button_pressed"]
|
@ -0,0 +1,14 @@
|
||||
@tool
|
||||
class_name OverlaidMenuContainer
|
||||
extends OverlaidMenu
|
||||
|
||||
@export var menu_scene : PackedScene :
|
||||
set(value):
|
||||
var _value_changed = menu_scene != value
|
||||
menu_scene = value
|
||||
if _value_changed:
|
||||
for child in %MenuContainer.get_children():
|
||||
child.queue_free()
|
||||
if menu_scene:
|
||||
var _instance = menu_scene.instantiate()
|
||||
%MenuContainer.add_child(_instance)
|
@ -0,0 +1 @@
|
||||
uid://droejgtv8bu0s
|
@ -0,0 +1,21 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://bqqngki8bm3iq"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://wny2d8dvp3ok" path="res://addons/maaacks_game_template/base/scenes/overlaid_menu/overlaid_menu.tscn" id="1_xgkve"]
|
||||
[ext_resource type="Script" uid="uid://droejgtv8bu0s" path="res://addons/maaacks_game_template/base/scenes/overlaid_menu/overlaid_menu_container.gd" id="2_owcue"]
|
||||
|
||||
[node name="OverlaidMenuContainer" instance=ExtResource("1_xgkve")]
|
||||
script = ExtResource("2_owcue")
|
||||
menu_scene = null
|
||||
|
||||
[node name="MenuContainer" type="MarginContainer" parent="MenuPanelContainer/MarginContainer/BoxContainer" index="2"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="MenuButtonsMargin" parent="MenuPanelContainer/MarginContainer/BoxContainer" index="3"]
|
||||
theme_override_constants/margin_top = 16
|
||||
theme_override_constants/margin_bottom = 16
|
||||
|
||||
[node name="CloseButton" parent="MenuPanelContainer/MarginContainer/BoxContainer/MenuButtonsMargin/MenuButtons" index="0"]
|
||||
size_flags_horizontal = 4
|
||||
text = "Back"
|
Reference in New Issue
Block a user