Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SteamInput: Add missing API calls for retrieving InputActionOrigins #713

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Facepunch.Steamworks/Generated/SteamEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ public enum InputSourceMode : int
//
// EInputActionOrigin
//
internal enum InputActionOrigin : int
public enum InputActionOrigin : int
{
None = 0,
SteamController_A = 1,
Expand Down
73 changes: 52 additions & 21 deletions Facepunch.Steamworks/SteamInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,58 @@ public static IEnumerable<Controller> Controllers
}


/// <summary>
/// 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.
/// </summary>
/// <param name="controller"></param>
/// <param name="action"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 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.
/// <para>
/// Valve recommends that you continuously check the action origins using <see cref="Controller.GetDigitalActionOrigins(string)"/>
/// in case the bindings have changed. When that happens you can update the prompts displayed in your game.
/// </para>
/// </summary>
/// <param name="controller"></param>
/// <param name="action"></param>
/// <returns></returns>
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 );
}


/// <summary>
/// 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.
/// <para>
/// Valve recommends that you continuously check the action origins using <see cref="Controller.GetAnalogActionOrigins(string)"/>
/// in case the bindings have changed. When that happens you can update the prompts displayed in your game.
/// </para>
/// </summary>
/// <param name="controller"></param>
/// <param name="action"></param>
/// <returns></returns>
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 );
}


/// <summary>
Expand Down
44 changes: 44 additions & 0 deletions Facepunch.Steamworks/Structs/Controller.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Steamworks.Data;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

namespace Steamworks
Expand Down Expand Up @@ -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 );

/// <summary>
/// Get the origin(s) for an analog action within an action set.
/// Use this to display the appropriate on-screen prompt for the action.
/// <para>
/// This is cheap, and Valve recommends you re-gather the origins each frame to update your ingame prompts in case they have changed.
/// </para>
/// </summary>
public IEnumerable<InputActionOrigin> 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 );
}

/// <summary>
/// Get the origin(s) for a digital action within an action set.
/// Use this to display the appropriate on-screen prompt for the action.
/// <para>
/// This is cheap, and Valve recommends you re-gather the origins each frame to update your ingame prompts in case they have changed.
/// </para>
/// </summary>
public IEnumerable<InputActionOrigin> 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

/// <summary>
/// Returns the current state of the supplied digital game action
Expand Down Expand Up @@ -65,6 +100,9 @@ public struct AnalogState
public float X; // x float
public float Y; // y float
internal byte BActive; // bActive byte
/// <summary>
/// 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.
/// </summary>
public bool Active => BActive != 0;
}

Expand All @@ -91,7 +129,13 @@ public struct DigitalState
[MarshalAs( UnmanagedType.I1 )]
internal byte BActive; // bActive byte

/// <summary>
/// The current state of this action; true if the action is currently pressed, otherwise false.
/// </summary>
public bool Pressed => BState != 0;
/// <summary>
/// Whether or not this action is currently available to be bound in the active action set.
/// </summary>
public bool Active => BActive != 0;
}
}
1 change: 1 addition & 0 deletions Generator/Cleanup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down