IActionMap

#include

Public Member Functions

virtual void GetMemoryUsage (ICrySizer *) const =0
virtual void Release ()=0
virtual void Clear ()=0
virtual const IActionMapAction * GetAction (const ActionId &actionId) const =0
virtual IActionMapAction * GetAction (const ActionId &actionId)=0
virtual bool CreateAction (const ActionId &actionId)=0
virtual bool RemoveAction (const ActionId &actionId)=0
virtual int GetActionsCount () const =0
virtual bool AddActionInput (const ActionId &actionId, const SActionInput &actionInput, const int iByDeviceIndex=-1)=0
virtual bool AddAndBindActionInput (const ActionId &actionId, const SActionInput &actionInput)=0
virtual bool RemoveActionInput (const ActionId &actionId, const char *szInput)=0
virtual bool ReBindActionInput (const ActionId &actionId, const char *szCurrentInput, const char *szNewInput)=0
virtual bool ReBindActionInput (const ActionId &actionId, const char *szNewInput, const EActionInputDevice device, const int iByDeviceIndex)=0
virtual int GetNumRebindedInputs ()=0
virtual bool Reset ()=0
virtual bool LoadFromXML (const XmlNodeRef &actionMapNode)=0
virtual bool LoadRebindingDataFromXML (const XmlNodeRef &actionMapNode)=0
virtual bool SaveRebindingDataToXML (XmlNodeRef &actionMapNode) const =0
virtual IActionMapActionIteratorPtr CreateActionIterator ()=0
virtual void SetActionListener (EntityId id)=0
virtual EntityId GetActionListener () const =0
virtual const char * GetName ()=0
virtual void Enable (bool enable)=0
virtual bool Enabled () const =0

Detailed Description

Represents an action map group that can be enabled / disabled independently Can contain a larger number of actions that remap raw input either statically (defined by developer) or remapped at runtime by the player

Member Function Documentation

◆ AddAndBindActionInput()

virtual bool IActionMap::AddAndBindActionInput ( const ActionId & actionId,
const SActionInput & actionInput
)
pure virtual

Binds a raw input to the action, ensuring that the action will be triggered when the raw input is detected

Parameters
actionIdIdentifier / name of the action we want to add the input for
actionInputDefinition of the raw input that we want to listen for
#include 

// Example of how action maps can be registered, and how to receive callbacks when their actions are triggered
class CMyActionListener final : public IActionListener
{
    // Define the name of the action map in which our action will reside
    const char* m_szMyActionMapName = "MyActionGroup";
    // Define the identifier of the action we are registering, this should be a constant over the runtime of the application
    const ActionId m_myActionId = ActionId("MyAction");

    virtual ~CMyActionListener()
    {
        // Make sure to remove the listener when we are done
        gEnv->pGameFramework->GetIActionMapManager()->RemoveExtraActionListener(this, m_szMyActionMapName);
    }

    void RegisterAction()
    {
        IActionMapManager* pActionMapManager = gEnv->pGameFramework->GetIActionMapManager();

        // Create the action map in which our action will reside
        IActionMap* pActionMap = pActionMapManager->CreateActionMap(m_szMyActionMapName);
        // Register a listener to receive callbacks when actions in our action map are triggered
        pActionMapManager->AddExtraActionListener(this, m_szMyActionMapName);

        // Register the action in the group
        pActionMap->CreateAction(m_myActionId);

        // Now define the first input with which the user can trigger the input
        SActionInput input;
        // Define that this input is triggered with the keyboard or mouse
        input.inputDevice = eAID_KeyboardMouse;
        // Set the input to "enter"
        // defaultInput is used in case of future rebinding by the end-user at runtime
        input.input = input.defaultInput = "enter";
        // Determine the activation modes we want to listen for
        input.activationMode = eIS_Pressed | eIS_Released;

        // Now bind the input to the action we created earlier
        pActionMap->AddAndBindActionInput(m_myActionId, input);

        // Make sure that the action map is enabled by default
        // This function can also be used to toggle action maps at runtime, for example to disable vehicle inputs when exiting
        pActionMap->Enable(true);
    }

    // Called when any action is triggered
    virtual void OnAction(const ActionId &actionId, int activationMode, float value) override
    {
        const bool isInputPressed = (activationMode & eIS_Pressed) != 0;
        const bool isInputReleased = (activationMode & eIS_Released) != 0;

        // Check if the triggered action
        if (actionId == m_myActionId)
        {
            if (isInputPressed)
            {
                CryLogAlways("Action pressed!");
            }
            else if (isInputReleased)
            {
                CryLogAlways("Action released!");
            }
        }
    }
};

◆ CreateAction()

virtual bool IActionMap::CreateAction ( const ActionId & actionId)
pure virtual

Creates an abstracted action that can be triggered by one or more input state changes

Parameters
actionIdIdentifier / name of the action we want to create
#include 

// Example of how action maps can be registered, and how to receive callbacks when their actions are triggered
class CMyActionListener final : public IActionListener
{
    // Define the name of the action map in which our action will reside
    const char* m_szMyActionMapName = "MyActionGroup";
    // Define the identifier of the action we are registering, this should be a constant over the runtime of the application
    const ActionId m_myActionId = ActionId("MyAction");

    virtual ~CMyActionListener()
    {
        // Make sure to remove the listener when we are done
        gEnv->pGameFramework->GetIActionMapManager()->RemoveExtraActionListener(this, m_szMyActionMapName);
    }

    void RegisterAction()
    {
        IActionMapManager* pActionMapManager = gEnv->pGameFramework->GetIActionMapManager();

        // Create the action map in which our action will reside
        IActionMap* pActionMap = pActionMapManager->CreateActionMap(m_szMyActionMapName);
        // Register a listener to receive callbacks when actions in our action map are triggered
        pActionMapManager->AddExtraActionListener(this, m_szMyActionMapName);

        // Register the action in the group
        pActionMap->CreateAction(m_myActionId);

        // Now define the first input with which the user can trigger the input
        SActionInput input;
        // Define that this input is triggered with the keyboard or mouse
        input.inputDevice = eAID_KeyboardMouse;
        // Set the input to "enter"
        // defaultInput is used in case of future rebinding by the end-user at runtime
        input.input = input.defaultInput = "enter";
        // Determine the activation modes we want to listen for
        input.activationMode = eIS_Pressed | eIS_Released;

        // Now bind the input to the action we created earlier
        pActionMap->AddAndBindActionInput(m_myActionId, input);

        // Make sure that the action map is enabled by default
        // This function can also be used to toggle action maps at runtime, for example to disable vehicle inputs when exiting
        pActionMap->Enable(true);
    }

    // Called when any action is triggered
    virtual void OnAction(const ActionId &actionId, int activationMode, float value) override
    {
        const bool isInputPressed = (activationMode & eIS_Pressed) != 0;
        const bool isInputReleased = (activationMode & eIS_Released) != 0;

        // Check if the triggered action
        if (actionId == m_myActionId)
        {
            if (isInputPressed)
            {
                CryLogAlways("Action pressed!");
            }
            else if (isInputReleased)
            {
                CryLogAlways("Action released!");
            }
        }
    }
};

◆ ReBindActionInput() [1/2]

virtual bool IActionMap::ReBindActionInput ( const ActionId & actionId,
const char * szCurrentInput,
const char * szNewInput
)
pure virtual

Rebinds the specified action from the current input to a new input of the same device type

Parameters
actionIdIdentifier / name of the action we want to rebind
szCurrentInputThe input that the action is currently bound to, note that this will traverse all inputs regardless of input device
szNewInputThe input that we want to bind to, has to remain the same device as szCurrentInput!
#include 

void ReBindActionInput()
{
    // Define the name of the action map in which our action resides
    const char* szMyActionMapName = "MyActionGroup";
    // Define the identifier of the action we are rebinding
    const ActionId myActionId = ActionId("MyAction");

    IActionMapManager* pActionMapManager = gEnv->pGameFramework->GetIActionMapManager();

    // Query the action map manager for our action map
    if (IActionMap* pActionMap = pActionMapManager->GetActionMap(szMyActionMapName))
    {
        // Specify the input that the action is currently triggered by
        const char* szCurrentInput = "enter";
        // Now specify the new input that the action should be triggered by
        const char* szNewInput = "space";

        // Rebind the action
        pActionMap->ReBindActionInput(myActionId, szCurrentInput, szNewInput);
    }
}

void ReBindActionInputWithDevice()
{
    // Define the name of the action map in which our action resides
    const char* szMyActionMapName = "MyActionGroup";
    // Define the identifier of the action we are rebinding
    const ActionId myActionId = ActionId("MyAction");

    IActionMapManager* pActionMapManager = gEnv->pGameFramework->GetIActionMapManager();

    // Query the action map manager for our action map
    if (IActionMap* pActionMap = pActionMapManager->GetActionMap(szMyActionMapName))
    {
        // Specify the device for which we want to rebind the input
        const EActionInputDevice inputDevice = eAID_KeyboardMouse;
        // Specify the device index, in case of multiple devices of the same type
        const int inputDeviceIndex = 0;
        // Now specify the new input that the action should be triggered by
        const char* szNewInput = "space";

        // Rebind the action
        pActionMap->ReBindActionInput(myActionId, szNewInput, inputDevice, inputDeviceIndex);
    }
}

◆ ReBindActionInput() [2/2]

virtual bool IActionMap::ReBindActionInput ( const ActionId & actionId,
const char * szNewInput,
const EActionInputDevice device,
const int iByDeviceIndex
)
pure virtual

Rebinds the specified action from the current input to a new input of a specific device type

Parameters
actionIdIdentifier / name of the action we want to rebind
szNewInputNew input we want to bind to
deviceDevice type that we want to remap
iByDeviceIndexIndex of the device that we want to remap, typically 0 but can be used in case of multiple devices of the same type
#include 

void ReBindActionInput()
{
    // Define the name of the action map in which our action resides
    const char* szMyActionMapName = "MyActionGroup";
    // Define the identifier of the action we are rebinding
    const ActionId myActionId = ActionId("MyAction");

    IActionMapManager* pActionMapManager = gEnv->pGameFramework->GetIActionMapManager();

    // Query the action map manager for our action map
    if (IActionMap* pActionMap = pActionMapManager->GetActionMap(szMyActionMapName))
    {
        // Specify the input that the action is currently triggered by
        const char* szCurrentInput = "enter";
        // Now specify the new input that the action should be triggered by
        const char* szNewInput = "space";

        // Rebind the action
        pActionMap->ReBindActionInput(myActionId, szCurrentInput, szNewInput);
    }
}

void ReBindActionInputWithDevice()
{
    // Define the name of the action map in which our action resides
    const char* szMyActionMapName = "MyActionGroup";
    // Define the identifier of the action we are rebinding
    const ActionId myActionId = ActionId("MyAction");

    IActionMapManager* pActionMapManager = gEnv->pGameFramework->GetIActionMapManager();

    // Query the action map manager for our action map
    if (IActionMap* pActionMap = pActionMapManager->GetActionMap(szMyActionMapName))
    {
        // Specify the device for which we want to rebind the input
        const EActionInputDevice inputDevice = eAID_KeyboardMouse;
        // Specify the device index, in case of multiple devices of the same type
        const int inputDeviceIndex = 0;
        // Now specify the new input that the action should be triggered by
        const char* szNewInput = "space";

        // Rebind the action
        pActionMap->ReBindActionInput(myActionId, szNewInput, inputDevice, inputDeviceIndex);
    }
}