diff --git a/core/input_map.cpp b/core/input_map.cpp index 17e98902a15..0506233116c 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -36,6 +36,7 @@ void InputMap::_bind_methods() { 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_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("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]; } +Array InputMap::_get_actions() { + + Array ret; + List actions = get_actions(); + if(actions.empty()) + return ret; + + for(const List::Element *E=actions.front();E;E=E->next()) { + + ret.push_back(E->get()); + } + + return ret; +} + +List InputMap::get_actions() const { + + List actions = List(); + if(input_map.empty()){ + return actions; + } + + for (Map::Element *E=input_map.front();E;E=E->next()) { + actions.push_back(E->key()); + } + + return actions; +} + List::Element *InputMap::_find_event(List &p_list,const InputEvent& p_event) const { for (List::Element *E=p_list.front();E;E=E->next()) { diff --git a/core/input_map.h b/core/input_map.h index 5cd1e419224..82b650516ee 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -47,6 +47,7 @@ class InputMap : public Object { List::Element *_find_event(List &p_list,const InputEvent& p_event) const; Array _get_action_list(const StringName& p_action); + Array _get_actions(); protected: @@ -59,6 +60,7 @@ public: bool has_action(const StringName& p_action) const; int get_action_id(const StringName& p_action) const; StringName get_action_from_id(int p_id) const; + List get_actions() const; void add_action(const StringName& p_action); void erase_action(const StringName& p_action); diff --git a/doc/base/classes.xml b/doc/base/classes.xml index ef71f1c8169..ce3d61594d1 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -15375,6 +15375,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) + Whether this InputMap has an action with name "action". @@ -15383,6 +15384,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) + Return the id of an action. @@ -15391,18 +15393,28 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) + Return the action from an id. + + + + + + + Return an [Array] of all actions in the [InputMap]. + Add an action to the [InputMap]. + Remove an action from the [InputMap]. @@ -15411,6 +15423,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) + Add an [InputEvent] to action. This [InputEvent] will trigger the action. @@ -15421,6 +15434,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) + Whether an action has an [InputEvent] associated with it. @@ -15429,6 +15443,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) + Remove an [InputEvent] from an action. @@ -15437,6 +15452,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) + Return an [Array] of [InputEvent]s associated with an action. @@ -15451,6 +15467,7 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) + Clears the [InputMap] and loads it from [Globals].