From 6c93350f7f607794a779eb3a9b46910f69a0374a Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 13 Nov 2023 19:10:29 +0000 Subject: [PATCH] Add OnGamepadConnected and OnGamepadDisconnected events (#51) Reviewed-on: https://gitea.moonside.games/MoonsideGames/MoonWorks/pulls/51 --- src/Input/Input.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Input/Input.cs b/src/Input/Input.cs index d2ea27e..4700d2c 100644 --- a/src/Input/Input.cs +++ b/src/Input/Input.cs @@ -35,6 +35,22 @@ namespace MoonWorks.Input /// public VirtualButton AnyPressedButton { get; private set; } + public delegate void OnGamepadConnectedFunc(int slot); + + /// + /// Called when a gamepad has been connected. + /// + /// The slot where the connection occurred. + public OnGamepadConnectedFunc OnGamepadConnected; + + public delegate void OnGamepadDisconnectedFunc(int slot); + + /// + /// Called when a gamepad has been disconnected. + /// + /// The slot where the disconnection occurred. + public OnGamepadDisconnectedFunc OnGamepadDisconnected; + internal Inputs() { Keyboard = new Keyboard(); @@ -126,7 +142,9 @@ namespace MoonWorks.Input { Gamepads[slot].Register(openResult); Logger.LogInfo($"Gamepad added to slot {slot}!"); + OnGamepadConnected(slot); } + return; } } @@ -143,6 +161,7 @@ namespace MoonWorks.Input SDL.SDL_GameControllerClose(Gamepads[slot].Handle); Gamepads[slot].Unregister(); Logger.LogInfo($"Removing gamepad from slot {slot}!"); + OnGamepadDisconnected(slot); return; } }