full gamepad support
This commit is contained in:
parent
31ba172123
commit
a57d79e84a
21 changed files with 213 additions and 46 deletions
15
scripts/gui/pause_menu/PM_GamepadFocus.cs
Normal file
15
scripts/gui/pause_menu/PM_GamepadFocus.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class PM_GamepadFocus : Node
|
||||
{
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
1
scripts/gui/pause_menu/PM_GamepadFocus.cs.uid
Normal file
1
scripts/gui/pause_menu/PM_GamepadFocus.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cc8loabsf43m0
|
||||
11
scripts/gui/pause_menu/PauseButton.cs
Normal file
11
scripts/gui/pause_menu/PauseButton.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class PauseButton : Button
|
||||
{
|
||||
public override void _Pressed()
|
||||
{
|
||||
PauseMenu.Pause();
|
||||
}
|
||||
|
||||
}
|
||||
1
scripts/gui/pause_menu/PauseButton.cs.uid
Normal file
1
scripts/gui/pause_menu/PauseButton.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cmfhiun6yrlr6
|
||||
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;
|
||||
}
|
||||
}
|
||||
1
scripts/gui/pause_menu/PauseMenu.cs.uid
Normal file
1
scripts/gui/pause_menu/PauseMenu.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://gvwhpjoame6m
|
||||
Loading…
Add table
Add a link
Reference in a new issue