full gamepad support
This commit is contained in:
parent
31ba172123
commit
a57d79e84a
21 changed files with 213 additions and 46 deletions
60
scripts/gui/pause_menu/PauseMenu.cs
Normal file
60
scripts/gui/pause_menu/PauseMenu.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using Godot;
|
||||
using Newlon;
|
||||
using System;
|
||||
|
||||
public partial class PauseMenu : Control
|
||||
{
|
||||
private static PauseMenu Instance;
|
||||
private bool previousPaused;
|
||||
private bool currently_paused = false;
|
||||
private AudioStream pauseSound = ResourceLoader.Load<AudioStream>("uid://ckja8ym50y0d4");
|
||||
private Control stolenFocus;
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
GetViewport().GuiFocusChanged += OnFocusChanged;
|
||||
}
|
||||
|
||||
public void Continue()
|
||||
{
|
||||
GetParent<Control>().Visible = false;
|
||||
GetTree().Paused = previousPaused;
|
||||
currently_paused = false;
|
||||
stolenFocus.GrabFocus();
|
||||
}
|
||||
public void Restart()
|
||||
{
|
||||
GetTree().Paused = false;
|
||||
LevelController.Instance.RestartLevel();
|
||||
currently_paused = false;
|
||||
}
|
||||
public void Exit()
|
||||
{
|
||||
LevelController.Instance.EndLevel();
|
||||
currently_paused = false;
|
||||
}
|
||||
public static void Pause()
|
||||
{
|
||||
if (Instance.currently_paused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Instance.currently_paused = true;
|
||||
Instance.GetNode<Control>("%ContinueButton").GrabFocus();
|
||||
|
||||
Instance.GetParent<Control>().Visible = true;
|
||||
Instance.previousPaused = Instance.GetTree().Paused;
|
||||
Instance.GetTree().Paused = true;
|
||||
AudioSequencer.Play("pause", Instance.pauseSound);
|
||||
}
|
||||
public override void _ExitTree()
|
||||
{
|
||||
GetViewport().GuiFocusChanged -= OnFocusChanged;
|
||||
}
|
||||
|
||||
public void OnFocusChanged(Control to)
|
||||
{
|
||||
if (currently_paused) return;
|
||||
stolenFocus = to;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue