full gamepad support

This commit is contained in:
Rendo 2025-07-28 18:03:26 +05:00
commit a57d79e84a
21 changed files with 213 additions and 46 deletions

View 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)
{
}
}

View file

@ -0,0 +1 @@
uid://cc8loabsf43m0

View file

@ -0,0 +1,11 @@
using Godot;
using System;
public partial class PauseButton : Button
{
public override void _Pressed()
{
PauseMenu.Pause();
}
}

View file

@ -0,0 +1 @@
uid://cmfhiun6yrlr6

View 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;
}
}

View file

@ -0,0 +1 @@
uid://gvwhpjoame6m