From d83e3b4d8258c4e330aaf0465ba5a3d2c4a4a88e Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 19 Mar 2026 03:22:17 +0100 Subject: [PATCH] feat: add InputDeviceManager autoload for input device tracking --- Autoloads/InputDeviceManager.cs | 50 +++++++++++++++++++++++++++++++++ project.godot | 1 + 2 files changed, 51 insertions(+) create mode 100644 Autoloads/InputDeviceManager.cs diff --git a/Autoloads/InputDeviceManager.cs b/Autoloads/InputDeviceManager.cs new file mode 100644 index 0000000..76241d1 --- /dev/null +++ b/Autoloads/InputDeviceManager.cs @@ -0,0 +1,50 @@ +using Godot; + +namespace Mr.BrickAdventures.Autoloads; + +public enum InputDevice { Mouse, Keyboard, Gamepad } + +public partial class InputDeviceManager : Node +{ + public static InputDeviceManager Instance { get; private set; } + + public InputDevice CurrentDevice { get; private set; } = InputDevice.Mouse; + + public bool IsPointerless => CurrentDevice is InputDevice.Keyboard or InputDevice.Gamepad; + + [Signal] public delegate void DeviceChangedEventHandler(int device); + + public override void _Ready() + { + Instance = this; + Input.MouseMode = Input.MouseModeEnum.Visible; + } + + public override void _ExitTree() + { + if (Instance == this) Instance = null; + } + + public override void _Input(InputEvent @event) + { + InputDevice detected; + + if (@event is InputEventMouseMotion or InputEventMouseButton) + detected = InputDevice.Mouse; + else if (@event is InputEventKey) + detected = InputDevice.Keyboard; + else if (@event is InputEventJoypadButton or InputEventJoypadMotion) + detected = InputDevice.Gamepad; + else + return; + + if (detected == CurrentDevice) return; + + CurrentDevice = detected; + Input.MouseMode = CurrentDevice == InputDevice.Mouse + ? Input.MouseModeEnum.Visible + : Input.MouseModeEnum.Hidden; + + EmitSignal(SignalName.DeviceChanged, (int)CurrentDevice); + } +} diff --git a/project.godot b/project.godot index 35d8795..5293142 100644 --- a/project.godot +++ b/project.godot @@ -38,6 +38,7 @@ AudioController="*res://objects/audio_controller.tscn" UIManager="*res://Autoloads/UIManager.cs" ConfigFileHandler="*res://Autoloads/ConfigFileHandler.cs" SettingsManager="*res://Autoloads/SettingsManager.cs" +InputDeviceManager="*res://Autoloads/InputDeviceManager.cs" SaveSystem="*res://Autoloads/SaveSystem.cs" ConsoleManager="*res://Autoloads/ConsoleManager.cs" LimboConsole="*uid://dyxornv8vwibg"