diff --git a/Facepunch.Steamworks/Generated/SteamEnums.cs b/Facepunch.Steamworks/Generated/SteamEnums.cs index f7264c806..29db30fb2 100644 --- a/Facepunch.Steamworks/Generated/SteamEnums.cs +++ b/Facepunch.Steamworks/Generated/SteamEnums.cs @@ -1057,7 +1057,7 @@ public enum InputSourceMode : int // // EInputActionOrigin // - internal enum InputActionOrigin : int + public enum InputActionOrigin : int { None = 0, SteamController_A = 1, diff --git a/Facepunch.Steamworks/SteamInput.cs b/Facepunch.Steamworks/SteamInput.cs index f4c8dc3df..28a269acc 100644 --- a/Facepunch.Steamworks/SteamInput.cs +++ b/Facepunch.Steamworks/SteamInput.cs @@ -51,27 +51,58 @@ public static IEnumerable Controllers } - /// - /// 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 - /// maintain your own list of loaded PNG assets. - /// - /// - /// - /// - public static string GetDigitalActionGlyph( Controller controller, string action ) - { - InputActionOrigin origin = InputActionOrigin.None; - - Internal.GetDigitalActionOrigins( - controller.Handle, - Internal.GetCurrentActionSet(controller.Handle), - GetDigitalActionHandle(action), - ref origin - ); - - return Internal.GetGlyphForActionOrigin_Legacy(origin); - } + /// + /// 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 + /// maintain your own list of loaded PNG assets. + /// + /// Valve recommends that you continuously check the action origins using + /// in case the bindings have changed. When that happens you can update the prompts displayed in your game. + /// + /// + /// + /// + /// + public static string GetDigitalActionGlyph( Controller controller, string action ) + { + InputActionOrigin origin = InputActionOrigin.None; + + Internal.GetDigitalActionOrigins( + controller.Handle, + Internal.GetCurrentActionSet( controller.Handle ), + GetDigitalActionHandle( action ), + ref origin + ); + + return Internal.GetGlyphForActionOrigin_Legacy( origin ); + } + + + /// + /// Return an absolute path to the PNG image glyph for the provided analog action name. The current + /// action set in use for the controller will be used for the lookup. You should cache the result and + /// maintain your own list of loaded PNG assets. + /// + /// Valve recommends that you continuously check the action origins using + /// in case the bindings have changed. When that happens you can update the prompts displayed in your game. + /// + /// + /// + /// + /// + public static string GetAnalogActionGlyph( Controller controller, string action ) + { + InputActionOrigin origin = InputActionOrigin.None; + + Internal.GetAnalogActionOrigins( + controller.Handle, + Internal.GetCurrentActionSet( controller.Handle ), + GetAnalogActionHandle( action ), + ref origin + ); + + return Internal.GetGlyphForActionOrigin_Legacy( origin ); + } /// diff --git a/Facepunch.Steamworks/Structs/Controller.cs b/Facepunch.Steamworks/Structs/Controller.cs index f694ecd2c..67098c999 100644 --- a/Facepunch.Steamworks/Structs/Controller.cs +++ b/Facepunch.Steamworks/Structs/Controller.cs @@ -1,5 +1,6 @@ using Steamworks.Data; using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; namespace Steamworks @@ -30,6 +31,40 @@ public string ActionSet public void ActivateLayer( string layer ) => SteamInput.Internal.ActivateActionSetLayer( Handle, SteamInput.Internal.GetActionSetHandle( layer ) ); public void ClearLayers() => SteamInput.Internal.DeactivateAllActionSetLayers( Handle ); + #region Action Origins + + internal const int STEAM_INPUT_MAX_ORIGINS = 8; + internal InputActionSetHandle_t ActionSetHandle => SteamInput.Internal.GetCurrentActionSet( Handle ); + + /// + /// Get the origin(s) for an analog action within an action set. + /// Use this to display the appropriate on-screen prompt for the action. + /// + /// This is cheap, and Valve recommends you re-gather the origins each frame to update your ingame prompts in case they have changed. + /// + /// + public IEnumerable GetAnalogActionOrigins( string actionName ) + { + InputActionOrigin[] actionOrigins = new InputActionOrigin[STEAM_INPUT_MAX_ORIGINS]; + int numOrigins = SteamInput.Internal.GetAnalogActionOrigins( Handle, ActionSetHandle, SteamInput.Internal.GetAnalogActionHandle( actionName ), ref actionOrigins[0] ); + return actionOrigins.Take( numOrigins ); + } + + /// + /// Get the origin(s) for a digital action within an action set. + /// Use this to display the appropriate on-screen prompt for the action. + /// + /// This is cheap, and Valve recommends you re-gather the origins each frame to update your ingame prompts in case they have changed. + /// + /// + public IEnumerable GetDigitalActionOrigins( string actionName ) + { + InputActionOrigin[] actionOrigins = new InputActionOrigin[STEAM_INPUT_MAX_ORIGINS]; + int numOrigins = SteamInput.Internal.GetDigitalActionOrigins( Handle, ActionSetHandle, SteamInput.Internal.GetDigitalActionHandle( actionName ), ref actionOrigins[0] ); + return actionOrigins.Take( numOrigins ); + } + + #endregion Action Origins /// /// Returns the current state of the supplied digital game action @@ -65,6 +100,9 @@ public struct AnalogState public float X; // x float public float Y; // y float internal byte BActive; // bActive byte + /// + /// Whether or not this action is currently available to be bound in the active action set. If it is not available, OR does not belong to the active action set, this will be false. + /// public bool Active => BActive != 0; } @@ -91,7 +129,13 @@ public struct DigitalState [MarshalAs( UnmanagedType.I1 )] internal byte BActive; // bActive byte + /// + /// The current state of this action; true if the action is currently pressed, otherwise false. + /// public bool Pressed => BState != 0; + /// + /// Whether or not this action is currently available to be bound in the active action set. + /// public bool Active => BActive != 0; } } \ No newline at end of file diff --git a/Generator/Cleanup.cs b/Generator/Cleanup.cs index 3414c58d0..21bac2d12 100644 --- a/Generator/Cleanup.cs +++ b/Generator/Cleanup.cs @@ -152,6 +152,7 @@ internal static string Expose( string name ) if ( name == "TextFilteringContext" ) return "public"; if ( name == "GlyphSize" ) return "public"; if ( name == "TextInputMode" ) return "public"; + if ( name == "InputActionOrigin" ) return "public"; return "internal"; }