| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/input/input_event.h" |
| 34 |
#include "core/object/object.h" |
| 35 |
#include "core/templates/hash_map.h" |
| 36 |
|
| 37 |
template <typename T> |
| 38 |
class TypedArray; |
| 39 |
|
| 40 |
class InputMap : public Object { |
| 41 |
GDCLASS(InputMap, Object); |
| 42 |
|
| 43 |
public: |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
static constexpr int ALL_DEVICES = -1; |
| 48 |
|
| 49 |
struct Action { |
| 50 |
int id; |
| 51 |
float deadzone; |
| 52 |
List<Ref<InputEvent>> inputs; |
| 53 |
}; |
| 54 |
|
| 55 |
static constexpr float DEFAULT_DEADZONE = 0.2f; |
| 56 |
|
| 57 |
static constexpr float DEFAULT_TOGGLE_DEADZONE = 0.5f; |
| 58 |
|
| 59 |
private: |
| 60 |
static inline InputMap *singleton = nullptr; |
| 61 |
|
| 62 |
mutable HashMap<StringName, Action> input_map; |
| 63 |
HashMap<String, List<Ref<InputEvent>>> default_builtin_cache; |
| 64 |
HashMap<String, List<Ref<InputEvent>>> default_builtin_with_overrides_cache; |
| 65 |
|
| 66 |
List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match = false, bool *r_pressed = nullptr, float *r_strength = nullptr, float *r_raw_strength = nullptr, int *r_event_index = nullptr) const; |
| 67 |
|
| 68 |
TypedArray<InputEvent> _action_get_events(const StringName &p_action); |
| 69 |
|
| 70 |
protected: |
| 71 |
static void _bind_methods(); |
| 72 |
|
| 73 |
#ifndef DISABLE_DEPRECATED |
| 74 |
void _add_action_bind_compat_97281(const StringName &p_action, float p_deadzone = 0.5); |
| 75 |
static void _bind_compatibility_methods(); |
| 76 |
#endif |
| 77 |
|
| 78 |
public: |
| 79 |
static _FORCE_INLINE_ InputMap *get_singleton() { return singleton; } |
| 80 |
|
| 81 |
bool has_action(const StringName &p_action) const; |
| 82 |
TypedArray<StringName> get_actions(); |
| 83 |
void add_action(const StringName &p_action, float p_deadzone = DEFAULT_DEADZONE); |
| 84 |
void erase_action(const StringName &p_action); |
| 85 |
|
| 86 |
String get_action_description(const StringName &p_action) const; |
| 87 |
|
| 88 |
float action_get_deadzone(const StringName &p_action); |
| 89 |
void action_set_deadzone(const StringName &p_action, float p_deadzone); |
| 90 |
void action_add_event(const StringName &p_action, RequiredParam<InputEvent> rp_event); |
| 91 |
bool action_has_event(const StringName &p_action, RequiredParam<InputEvent> rp_event); |
| 92 |
void action_erase_event(const StringName &p_action, RequiredParam<InputEvent> rp_event); |
| 93 |
void action_erase_events(const StringName &p_action); |
| 94 |
|
| 95 |
const List<Ref<InputEvent>> *action_get_events(const StringName &p_action); |
| 96 |
bool event_is_action(RequiredParam<InputEvent> rp_event, const StringName &p_action, bool p_exact_match = false) const; |
| 97 |
int event_get_index(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match = false) const; |
| 98 |
bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match = false, bool *r_pressed = nullptr, float *r_strength = nullptr, float *r_raw_strength = nullptr, int *r_event_index = nullptr) const; |
| 99 |
|
| 100 |
const HashMap<StringName, Action> &get_action_map() const; |
| 101 |
void load_from_project_settings(); |
| 102 |
void load_default(); |
| 103 |
|
| 104 |
String suggest_actions(const StringName &p_action) const; |
| 105 |
|
| 106 |
#ifdef TOOLS_ENABLED |
| 107 |
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override; |
| 108 |
#endif |
| 109 |
|
| 110 |
String get_builtin_display_name(const String &p_name) const; |
| 111 |
|
| 112 |
const HashMap<String, List<Ref<InputEvent>>> &get_builtins(); |
| 113 |
const HashMap<String, List<Ref<InputEvent>>> &get_builtins_with_feature_overrides_applied(); |
| 114 |
|
| 115 |
InputMap(); |
| 116 |
~InputMap(); |
| 117 |
}; |