Added InputMap.get_actions()

get_actions() lists all actions in the InputMap.

(cherry picked from commit 1a80b2a04a)
This commit is contained in:
J08nY 2016-06-04 17:55:09 +02:00 committed by Rémi Verschelde
parent bed17e98c8
commit 845a0e2566
3 changed files with 49 additions and 0 deletions

View File

@ -36,6 +36,7 @@ void InputMap::_bind_methods() {
ObjectTypeDB::bind_method(_MD("has_action","action"),&InputMap::has_action); ObjectTypeDB::bind_method(_MD("has_action","action"),&InputMap::has_action);
ObjectTypeDB::bind_method(_MD("get_action_id","action"),&InputMap::get_action_id); ObjectTypeDB::bind_method(_MD("get_action_id","action"),&InputMap::get_action_id);
ObjectTypeDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id); ObjectTypeDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id);
ObjectTypeDB::bind_method(_MD("get_actions"),&InputMap::_get_actions);
ObjectTypeDB::bind_method(_MD("add_action","action"),&InputMap::add_action); ObjectTypeDB::bind_method(_MD("add_action","action"),&InputMap::add_action);
ObjectTypeDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action); ObjectTypeDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action);
@ -75,6 +76,35 @@ StringName InputMap::get_action_from_id(int p_id) const {
return input_id_map[p_id]; return input_id_map[p_id];
} }
Array InputMap::_get_actions() {
Array ret;
List<StringName> actions = get_actions();
if(actions.empty())
return ret;
for(const List<StringName>::Element *E=actions.front();E;E=E->next()) {
ret.push_back(E->get());
}
return ret;
}
List<StringName> InputMap::get_actions() const {
List<StringName> actions = List<StringName>();
if(input_map.empty()){
return actions;
}
for (Map<StringName, Action>::Element *E=input_map.front();E;E=E->next()) {
actions.push_back(E->key());
}
return actions;
}
List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const { List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const {
for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) { for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) {

View File

@ -47,6 +47,7 @@ class InputMap : public Object {
List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const; List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const;
Array _get_action_list(const StringName& p_action); Array _get_action_list(const StringName& p_action);
Array _get_actions();
protected: protected:
@ -59,6 +60,7 @@ public:
bool has_action(const StringName& p_action) const; bool has_action(const StringName& p_action) const;
int get_action_id(const StringName& p_action) const; int get_action_id(const StringName& p_action) const;
StringName get_action_from_id(int p_id) const; StringName get_action_from_id(int p_id) const;
List<StringName> get_actions() const;
void add_action(const StringName& p_action); void add_action(const StringName& p_action);
void erase_action(const StringName& p_action); void erase_action(const StringName& p_action);

View File

@ -15375,6 +15375,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8)
<argument index="0" name="action" type="String"> <argument index="0" name="action" type="String">
</argument> </argument>
<description> <description>
Whether this InputMap has an action with name "action".
</description> </description>
</method> </method>
<method name="get_action_id" qualifiers="const"> <method name="get_action_id" qualifiers="const">
@ -15383,6 +15384,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8)
<argument index="0" name="action" type="String"> <argument index="0" name="action" type="String">
</argument> </argument>
<description> <description>
Return the id of an action.
</description> </description>
</method> </method>
<method name="get_action_from_id" qualifiers="const"> <method name="get_action_from_id" qualifiers="const">
@ -15391,18 +15393,28 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8)
<argument index="0" name="id" type="int"> <argument index="0" name="id" type="int">
</argument> </argument>
<description> <description>
Return the action from an id.
</description>
</method>
<method name="get_actions">
<return type="Array">
</return>
<description>
Return an [Array] of all actions in the [InputMap].
</description> </description>
</method> </method>
<method name="add_action"> <method name="add_action">
<argument index="0" name="action" type="String"> <argument index="0" name="action" type="String">
</argument> </argument>
<description> <description>
Add an action to the [InputMap].
</description> </description>
</method> </method>
<method name="erase_action"> <method name="erase_action">
<argument index="0" name="action" type="String"> <argument index="0" name="action" type="String">
</argument> </argument>
<description> <description>
Remove an action from the [InputMap].
</description> </description>
</method> </method>
<method name="action_add_event"> <method name="action_add_event">
@ -15411,6 +15423,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8)
<argument index="1" name="event" type="InputEvent"> <argument index="1" name="event" type="InputEvent">
</argument> </argument>
<description> <description>
Add an [InputEvent] to action. This [InputEvent] will trigger the action.
</description> </description>
</method> </method>
<method name="action_has_event"> <method name="action_has_event">
@ -15421,6 +15434,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8)
<argument index="1" name="event" type="InputEvent"> <argument index="1" name="event" type="InputEvent">
</argument> </argument>
<description> <description>
Whether an action has an [InputEvent] associated with it.
</description> </description>
</method> </method>
<method name="action_erase_event"> <method name="action_erase_event">
@ -15429,6 +15443,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8)
<argument index="1" name="event" type="InputEvent"> <argument index="1" name="event" type="InputEvent">
</argument> </argument>
<description> <description>
Remove an [InputEvent] from an action.
</description> </description>
</method> </method>
<method name="get_action_list"> <method name="get_action_list">
@ -15437,6 +15452,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8)
<argument index="0" name="action" type="String"> <argument index="0" name="action" type="String">
</argument> </argument>
<description> <description>
Return an [Array] of [InputEvent]s associated with an action.
</description> </description>
</method> </method>
<method name="event_is_action" qualifiers="const"> <method name="event_is_action" qualifiers="const">
@ -15451,6 +15467,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8)
</method> </method>
<method name="load_from_globals"> <method name="load_from_globals">
<description> <description>
Clears the [InputMap] and loads it from [Globals].
</description> </description>
</method> </method>
</methods> </methods>