add slot to gamepad events

pull/51/head
cosmonaut 2023-11-13 11:06:39 -08:00
parent d9b5c588fb
commit 41382d4054
1 changed files with 5 additions and 2 deletions

View File

@ -35,7 +35,7 @@ namespace MoonWorks.Input
/// </summary> /// </summary>
public VirtualButton AnyPressedButton { get; private set; } public VirtualButton AnyPressedButton { get; private set; }
public delegate void OnGamepadConnectedFunc(); public delegate void OnGamepadConnectedFunc(int slot);
/// <summary> /// <summary>
/// Called when a game pad has been connected. /// Called when a game pad has been connected.
@ -43,7 +43,7 @@ namespace MoonWorks.Input
/// <param name="slot">The slot where the connection occurred.</param> /// <param name="slot">The slot where the connection occurred.</param>
public OnGamepadConnectedFunc OnGamepadConnected; public OnGamepadConnectedFunc OnGamepadConnected;
public delegate void OnGamepadDisconnectedFunc(); public delegate void OnGamepadDisconnectedFunc(int slot);
/// <summary> /// <summary>
/// Called when a game pad has been disconnected. /// Called when a game pad has been disconnected.
@ -142,7 +142,9 @@ namespace MoonWorks.Input
{ {
Gamepads[slot].Register(openResult); Gamepads[slot].Register(openResult);
Logger.LogInfo($"Gamepad added to slot {slot}!"); Logger.LogInfo($"Gamepad added to slot {slot}!");
OnGamepadConnected(slot);
} }
return; return;
} }
} }
@ -159,6 +161,7 @@ namespace MoonWorks.Input
SDL.SDL_GameControllerClose(Gamepads[slot].Handle); SDL.SDL_GameControllerClose(Gamepads[slot].Handle);
Gamepads[slot].Unregister(); Gamepads[slot].Unregister();
Logger.LogInfo($"Removing gamepad from slot {slot}!"); Logger.LogInfo($"Removing gamepad from slot {slot}!");
OnGamepadDisconnected(slot);
return; return;
} }
} }