Gamepad support

This commit is contained in:
Rendo 2025-07-28 05:07:37 +05:00
commit ed369cf718
24 changed files with 240 additions and 78 deletions

View file

@ -0,0 +1,10 @@
using Godot;
using System;
public partial class ExplosionVibration : Node
{
public override void _EnterTree()
{
Input.StartJoyVibration(GamepadHandler.Instance.CurrentDevice, 0, 1,0.25f);
}
}

View file

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

View file

@ -0,0 +1,52 @@
using Godot;
using Newlon;
using System;
public partial class GamepadHandler : Node
{
public static GamepadHandler Instance { get; private set; }
public int CurrentDevice { get; private set; } = 0;
public bool IsGamepadControlled => focused && controlled;
private bool focused;
private bool controlled;
public override void _EnterTree()
{
Instance = this;
}
public override void _Notification(int what)
{
if (what == NotificationApplicationFocusIn)
{
focused = true;
}
if (what == NotificationApplicationFocusOut)
{
focused = false;
}
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventJoypadButton || @event is InputEventJoypadMotion)
{
SetControlled(true);
}
if ((@event is InputEventMouse && Input.GetVector("cursor_left", "cursor_right", "cursor_up", "cursor_down") == Vector2.Zero) || @event is InputEventKey)
{
SetControlled(false);
}
}
private void SetControlled(bool to)
{
controlled = to;
if (controlled)
{
Cursor.Mode = Cursor.CursorMode.Gamepad;
}
else
{
Cursor.Mode = Cursor.CursorMode.Mouse;
}
}
}

View file

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