From d9b5c588fbb4ac07306b3b5ca8c0721677a2b294 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 13 Nov 2023 10:54:31 -0800 Subject: [PATCH 1/3] OnGamepadConnected and OnGamepadDisconnected --- src/Input/Input.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Input/Input.cs b/src/Input/Input.cs index d2ea27e..44434e4 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(); + + /// + /// Called when a game pad has been connected. + /// + /// The slot where the connection occurred. + public OnGamepadConnectedFunc OnGamepadConnected; + + public delegate void OnGamepadDisconnectedFunc(); + + /// + /// Called when a game pad has been disconnected. + /// + /// The slot where the disconnection occurred. + public OnGamepadDisconnectedFunc OnGamepadDisconnected; + internal Inputs() { Keyboard = new Keyboard(); -- 2.25.1 From 41382d4054698de3e54ffa5f0f649196bf391a4f Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 13 Nov 2023 11:06:39 -0800 Subject: [PATCH 2/3] add slot to gamepad events --- src/Input/Input.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Input/Input.cs b/src/Input/Input.cs index 44434e4..dcc25da 100644 --- a/src/Input/Input.cs +++ b/src/Input/Input.cs @@ -35,7 +35,7 @@ namespace MoonWorks.Input /// public VirtualButton AnyPressedButton { get; private set; } - public delegate void OnGamepadConnectedFunc(); + public delegate void OnGamepadConnectedFunc(int slot); /// /// Called when a game pad has been connected. @@ -43,7 +43,7 @@ namespace MoonWorks.Input /// The slot where the connection occurred. public OnGamepadConnectedFunc OnGamepadConnected; - public delegate void OnGamepadDisconnectedFunc(); + public delegate void OnGamepadDisconnectedFunc(int slot); /// /// Called when a game pad has been disconnected. @@ -142,7 +142,9 @@ namespace MoonWorks.Input { Gamepads[slot].Register(openResult); Logger.LogInfo($"Gamepad added to slot {slot}!"); + OnGamepadConnected(slot); } + return; } } @@ -159,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; } } -- 2.25.1 From fc174c35aeb07c6d6c58c19dc6654d67df9d423c Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 13 Nov 2023 11:10:11 -0800 Subject: [PATCH 3/3] tweak comment --- src/Input/Input.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Input/Input.cs b/src/Input/Input.cs index dcc25da..4700d2c 100644 --- a/src/Input/Input.cs +++ b/src/Input/Input.cs @@ -38,7 +38,7 @@ namespace MoonWorks.Input public delegate void OnGamepadConnectedFunc(int slot); /// - /// Called when a game pad has been connected. + /// Called when a gamepad has been connected. /// /// The slot where the connection occurred. public OnGamepadConnectedFunc OnGamepadConnected; @@ -46,7 +46,7 @@ namespace MoonWorks.Input public delegate void OnGamepadDisconnectedFunc(int slot); /// - /// Called when a game pad has been disconnected. + /// Called when a gamepad has been disconnected. /// /// The slot where the disconnection occurred. public OnGamepadDisconnectedFunc OnGamepadDisconnected; -- 2.25.1