Add Resume/Exit buttons to pause menu, handle logic for returning to main menu and starting a new game
This commit is contained in:
@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
public interface IPauseMenu : IControl
|
||||
@@ -10,6 +11,8 @@ public interface IPauseMenu : IControl
|
||||
void FadeOut();
|
||||
event PauseMenu.UnpauseButtonPressedEventHandler UnpauseButtonPressed;
|
||||
event PauseMenu.TransitionCompletedEventHandler TransitionCompleted;
|
||||
|
||||
public event Action ExitGamePressed;
|
||||
}
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
@@ -24,14 +27,32 @@ public partial class PauseMenu : Control, IPauseMenu
|
||||
|
||||
[Node] public IAnimationPlayer AnimationPlayer { get; set; } = default!;
|
||||
|
||||
[Node] public Button ResumeButton { get; set; } = default!;
|
||||
[Node] public Button ExitButton { get; set; } = default!;
|
||||
|
||||
public event Action ExitGamePressed;
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
||||
ResumeButton.Pressed += ResumeButton_Pressed;
|
||||
ExitButton.Pressed += ExitButton_Pressed;
|
||||
}
|
||||
|
||||
public void FadeIn() => AnimationPlayer.Play("fade_in");
|
||||
private void ExitButton_Pressed() => ExitGamePressed?.Invoke();
|
||||
private void ResumeButton_Pressed() => FadeOut();
|
||||
public void FadeIn()
|
||||
{
|
||||
ResumeButton.GrabFocus();
|
||||
AnimationPlayer.Play("fade_in");
|
||||
}
|
||||
|
||||
public void FadeOut() => AnimationPlayer.Play("fade_out");
|
||||
public void FadeOut()
|
||||
{
|
||||
ResumeButton.ReleaseFocus();
|
||||
ExitButton.ReleaseFocus();
|
||||
AnimationPlayer.Play("fade_out");
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
@@ -41,5 +62,7 @@ public partial class PauseMenu : Control, IPauseMenu
|
||||
|
||||
public void OnAnimationFinished(StringName name)
|
||||
{
|
||||
if (name == "fade_out")
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://blbqgw3wosc1w"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://blbqgw3wosc1w"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cbal5oeaha4nx" path="res://src/ui/pause_menu/PauseMenu.cs" id="1_1mfd6"]
|
||||
[ext_resource type="FontFile" uid="uid://beh6d5lo5ihq0" path="res://src/ui/fonts/georgiai.ttf" id="2_o1qdr"]
|
||||
[ext_resource type="StyleBox" uid="uid://bxuy4tnftibfq" path="res://src/options/SelectedOptionsBox.tres" id="2_xhp56"]
|
||||
[ext_resource type="StyleBox" uid="uid://bl15q835s4ene" path="res://src/options/UnselectedOptionsBox.tres" id="3_o1qdr"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_f1eqn"]
|
||||
length = 0.001
|
||||
@@ -62,6 +67,7 @@ anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_1mfd6")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
@@ -77,3 +83,53 @@ anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 10
|
||||
|
||||
[node name="ResumeButton" type="Button" parent="CenterContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("2_o1qdr")
|
||||
theme_override_font_sizes/font_size = 38
|
||||
theme_override_styles/focus = ExtResource("2_xhp56")
|
||||
theme_override_styles/disabled_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/disabled = ExtResource("3_o1qdr")
|
||||
theme_override_styles/hover_pressed_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/hover_pressed = ExtResource("3_o1qdr")
|
||||
theme_override_styles/hover_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/hover = ExtResource("3_o1qdr")
|
||||
theme_override_styles/pressed_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/pressed = ExtResource("3_o1qdr")
|
||||
theme_override_styles/normal_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/normal = ExtResource("3_o1qdr")
|
||||
text = "Resume"
|
||||
flat = true
|
||||
|
||||
[node name="ExitButton" type="Button" parent="CenterContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("2_o1qdr")
|
||||
theme_override_font_sizes/font_size = 38
|
||||
theme_override_styles/focus = ExtResource("2_xhp56")
|
||||
theme_override_styles/disabled_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/disabled = ExtResource("3_o1qdr")
|
||||
theme_override_styles/hover_pressed_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/hover_pressed = ExtResource("3_o1qdr")
|
||||
theme_override_styles/hover_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/hover = ExtResource("3_o1qdr")
|
||||
theme_override_styles/pressed_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/pressed = ExtResource("3_o1qdr")
|
||||
theme_override_styles/normal_mirrored = ExtResource("3_o1qdr")
|
||||
theme_override_styles/normal = ExtResource("3_o1qdr")
|
||||
text = "Exit Game"
|
||||
flat = true
|
||||
|
||||
Reference in New Issue
Block a user