From 0c3f4ec5fc7a61a0e43cdc15ce06ff1f5fa340e2 Mon Sep 17 00:00:00 2001 From: David Tootill Date: Mon, 26 Feb 2024 17:08:42 -0800 Subject: [PATCH] Add SteamInput Get(Analog|Digital)ActionOrigin; SteamUtils ShowFloatingKeyboardTextInput --- .../Generated/Interfaces/ISteamInput.cs | 2 +- Facepunch.Steamworks/Generated/SteamEnums.cs | 4 +- Facepunch.Steamworks/SteamInput.cs | 54 ++++++++++++++++++- Facepunch.Steamworks/SteamUtils.cs | 18 +++++-- 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamInput.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamInput.cs index 3d1ab52..e70086d 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamInput.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamInput.cs @@ -216,7 +216,7 @@ namespace Steamworks var returnValue = _GetDigitalActionOrigins( Self, inputHandle, actionSetHandle, digitalActionHandle, ref originsOut ); return returnValue; } - + #region FunctionMeta [DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamInput_GetStringForDigitalActionName", CallingConvention = Platform.CC)] private static extern Utf8StringPointer _GetStringForDigitalActionName( IntPtr self, InputDigitalActionHandle_t eActionHandle ); diff --git a/Facepunch.Steamworks/Generated/SteamEnums.cs b/Facepunch.Steamworks/Generated/SteamEnums.cs index b45ca27..49a454a 100644 --- a/Facepunch.Steamworks/Generated/SteamEnums.cs +++ b/Facepunch.Steamworks/Generated/SteamEnums.cs @@ -1048,7 +1048,7 @@ namespace Steamworks // // EInputActionOrigin // - internal enum InputActionOrigin : int + public enum InputActionOrigin : int { None = 0, SteamController_A = 1, @@ -1996,7 +1996,7 @@ namespace Steamworks Count = 386, MaximumPossibleValue = 32767, } - + // // ESteamControllerLEDFlag // diff --git a/Facepunch.Steamworks/SteamInput.cs b/Facepunch.Steamworks/SteamInput.cs index e90a4f2..6414be1 100644 --- a/Facepunch.Steamworks/SteamInput.cs +++ b/Facepunch.Steamworks/SteamInput.cs @@ -1,6 +1,9 @@ using System; using Steamworks.Data; using System.Collections.Generic; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Diagnostics; namespace Steamworks { @@ -11,6 +14,8 @@ namespace Steamworks { internal static ISteamInput Internal => Interface as ISteamInput; + internal static int STEAM_INPUT_MAX_ORIGINS = 16; + internal override bool InitializeInterface( bool server ) { SetInterface( server, new ISteamInput( server ) ); @@ -82,6 +87,24 @@ namespace Steamworks } + /// + /// Return an array of all origins mapped to the provided analog action + /// + /// + public static InputActionOrigin[] GetAnalogActionOrigins( Controller controller, string action ) + { + InputActionOrigin[] origins = new InputActionOrigin[STEAM_INPUT_MAX_ORIGINS]; + + Internal.GetAnalogActionOrigins( + controller.Handle, + Internal.GetCurrentActionSet( controller.Handle ), + GetAnalogActionHandle( action ), + ref origins[0] + ); + return origins; + } + + /// /// Return an absolute path to the PNG image glyph for the provided digital action name. The current /// action set in use for the controller will be used for the lookup. You should cache the result and @@ -93,18 +116,37 @@ namespace Steamworks public static string GetDigitalActionGlyph( Controller controller, string action ) { InputActionOrigin origin = InputActionOrigin.None; + InputActionOrigin[] origins = new InputActionOrigin[16]; - Internal.GetDigitalActionOrigins( + int originCount = Internal.GetDigitalActionOrigins( controller.Handle, Internal.GetCurrentActionSet(controller.Handle), GetDigitalActionHandle(action), ref origin ); - return Internal.GetGlyphForActionOrigin_Legacy(origin); + return Internal.GetGlyphForActionOrigin_Legacy(origin); } + /// + /// Return an array of all origins mapped to the provided digital action + /// + /// + public static InputActionOrigin[] GetDigitalActionOrigins( Controller controller, string action ) + { + InputActionOrigin[] origins = new InputActionOrigin[STEAM_INPUT_MAX_ORIGINS]; + + Internal.GetDigitalActionOrigins( + controller.Handle, + Internal.GetCurrentActionSet( controller.Handle ), + GetDigitalActionHandle( action ), + ref origins[0] + ); + return origins; + } + + /// /// Return an absolute path to the PNG image glyph for the provided digital action name. The current /// action set in use for the controller will be used for the lookup. You should cache the result and @@ -119,6 +161,14 @@ namespace Steamworks return Internal.GetGlyphPNGForActionOrigin( origin, size, 0 ); } + /// + /// Return an absolute path to the PNG image glyph for the provided action origin + /// + public static string GetPngActionGlyphForOrigin( InputActionOrigin origin, GlyphSize size ) + { + return Internal.GetGlyphPNGForActionOrigin( origin, size, 0 ); + } + /// /// Return an absolute path to the SVF image glyph for the provided digital action name. The current /// action set in use for the controller will be used for the lookup. You should cache the result and diff --git a/Facepunch.Steamworks/SteamUtils.cs b/Facepunch.Steamworks/SteamUtils.cs index 8d2c45e..d077c9f 100644 --- a/Facepunch.Steamworks/SteamUtils.cs +++ b/Facepunch.Steamworks/SteamUtils.cs @@ -30,6 +30,7 @@ namespace Steamworks Dispatch.Install( x => OnLowBatteryPower?.Invoke( x.MinutesBatteryLeft ), server ); Dispatch.Install( x => SteamClosed(), server ); Dispatch.Install( x => OnGamepadTextInputDismissed?.Invoke( x.Submitted ), server ); + Dispatch.Install( x => OnFloatingGamepadTextInputDismissed?.Invoke(), server ); } private static void SteamClosed() @@ -60,6 +61,10 @@ namespace Steamworks /// public static event Action OnGamepadTextInputDismissed; + /// + /// Invoked when floating keyboard invoked from ShowFloatingGamepadTextInput has been closed. + public static event Action OnFloatingGamepadTextInputDismissed; + /// /// Returns the number of seconds since the application was active. /// @@ -191,6 +196,14 @@ namespace Steamworks return Internal.ShowGamepadTextInput( inputMode, lineInputMode, description, (uint)maxChars, existingText ); } + /// + /// Opens a floating keyboard over the game content and sends OS keyboard keys directly to the game + /// + public static bool ShowFloatingGamepadTextInput( TextInputMode mode, int left, int top, int width, int height ) + { + return Internal.ShowFloatingGamepadTextInput( mode, left, top, width, height ); + } + /// /// Returns previously entered text. /// @@ -295,10 +308,5 @@ namespace Steamworks /// Steam Input translate the controller input into mouse/kb to navigate the launcher /// public static void SetGameLauncherMode( bool mode ) => Internal.SetGameLauncherMode( mode ); - - //public void ShowFloatingGamepadTextInput( TextInputMode mode, int left, int top, int width, int height ) - //{ - // Internal.ShowFloatingGamepadTextInput( mode, left, top, width, height ); - //} } }