summaryrefslogtreecommitdiff
path: root/core/input
diff options
context:
space:
mode:
Diffstat (limited to 'core/input')
-rw-r--r--core/input/input.cpp10
-rw-r--r--core/input/shortcut.cpp84
-rw-r--r--core/input/shortcut.h12
3 files changed, 79 insertions, 27 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 05b02408a1..f9a361c761 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -35,10 +35,6 @@
#include "core/input/input_map.h"
#include "core/os/os.h"
-#ifdef TOOLS_ENABLED
-#include "editor/editor_settings.h"
-#endif
-
static const char *_joy_buttons[JOY_BUTTON_SDL_MAX] = {
"a",
"b",
@@ -162,9 +158,6 @@ void Input::_bind_methods() {
}
void Input::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
-#ifdef TOOLS_ENABLED
- const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
-
String pf = p_function;
if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" ||
pf == "is_action_just_pressed" || pf == "is_action_just_released" ||
@@ -179,10 +172,9 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
}
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
- r_options->push_back(name.quote(quote_style));
+ r_options->push_back(name.quote());
}
}
-#endif
}
void Input::SpeedTrack::update(const Vector2 &p_delta_p) {
diff --git a/core/input/shortcut.cpp b/core/input/shortcut.cpp
index d0cb08724e..30e35190e4 100644
--- a/core/input/shortcut.cpp
+++ b/core/input/shortcut.cpp
@@ -31,14 +31,26 @@
#include "shortcut.h"
#include "core/os/keyboard.h"
-void Shortcut::set_event(const Ref<InputEvent> &p_event) {
- ERR_FAIL_COND_MSG(Object::cast_to<InputEventShortcut>(*p_event), "Cannot set a shortcut event to an instance of InputEventShortcut.");
- event = p_event;
+void Shortcut::set_events(const Array &p_events) {
+ for (int i = 0; i < p_events.size(); i++) {
+ Ref<InputEventShortcut> ies = p_events[i];
+ ERR_FAIL_COND_MSG(ies.is_valid(), "Cannot set a shortcut event to an instance of InputEventShortcut.");
+ }
+
+ events = p_events;
emit_changed();
}
-Ref<InputEvent> Shortcut::get_event() const {
- return event;
+void Shortcut::set_events_list(const List<Ref<InputEvent>> *p_events) {
+ events.clear();
+
+ for (const Ref<InputEvent> &ie : *p_events) {
+ events.push_back(ie);
+ }
+}
+
+Array Shortcut::get_events() const {
+ return events;
}
bool Shortcut::matches_event(const Ref<InputEvent> &p_event) const {
@@ -48,29 +60,73 @@ bool Shortcut::matches_event(const Ref<InputEvent> &p_event) const {
return true;
}
}
- return event.is_valid() && event->is_match(p_event, true);
+
+ for (int i = 0; i < events.size(); i++) {
+ Ref<InputEvent> ie = events[i];
+ bool valid = ie.is_valid() && ie->is_match(p_event);
+
+ // Stop on first valid event - don't need to check further.
+ if (valid) {
+ return true;
+ }
+ }
+
+ return false;
}
String Shortcut::get_as_text() const {
- if (event.is_valid()) {
- return event->as_text();
- } else {
- return "None";
+ for (int i = 0; i < events.size(); i++) {
+ Ref<InputEvent> ie = events[i];
+ // Return first shortcut which is valid
+ if (ie.is_valid()) {
+ return ie->as_text();
+ }
}
+
+ return "None";
}
bool Shortcut::has_valid_event() const {
- return event.is_valid();
+ // Tests if there is ANY input event which is valid.
+ for (int i = 0; i < events.size(); i++) {
+ Ref<InputEvent> ie = events[i];
+ if (ie.is_valid()) {
+ return true;
+ }
+ }
+
+ return false;
}
void Shortcut::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_event", "event"), &Shortcut::set_event);
- ClassDB::bind_method(D_METHOD("get_event"), &Shortcut::get_event);
+ ClassDB::bind_method(D_METHOD("set_events", "events"), &Shortcut::set_events);
+ ClassDB::bind_method(D_METHOD("get_events"), &Shortcut::get_events);
ClassDB::bind_method(D_METHOD("has_valid_event"), &Shortcut::has_valid_event);
ClassDB::bind_method(D_METHOD("matches_event", "event"), &Shortcut::matches_event);
ClassDB::bind_method(D_METHOD("get_as_text"), &Shortcut::get_as_text);
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), "set_event", "get_event");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "events", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")), "set_events", "get_events");
+}
+
+bool Shortcut::is_event_array_equal(const Array &p_event_array1, const Array &p_event_array2) {
+ if (p_event_array1.size() != p_event_array2.size()) {
+ return false;
+ }
+
+ bool is_same = true;
+ for (int i = 0; i < p_event_array1.size(); i++) {
+ Ref<InputEvent> ie_1 = p_event_array1[i];
+ Ref<InputEvent> ie_2 = p_event_array2[i];
+
+ is_same = ie_1->is_match(ie_2);
+
+ // Break on the first that doesn't match - don't need to check further.
+ if (!is_same) {
+ break;
+ }
+ }
+
+ return is_same;
}
diff --git a/core/input/shortcut.h b/core/input/shortcut.h
index 249dd1971f..a989b10626 100644
--- a/core/input/shortcut.h
+++ b/core/input/shortcut.h
@@ -37,18 +37,22 @@
class Shortcut : public Resource {
GDCLASS(Shortcut, Resource);
- Ref<InputEvent> event;
+ Array events;
protected:
static void _bind_methods();
public:
- void set_event(const Ref<InputEvent> &p_shortcut);
- Ref<InputEvent> get_event() const;
+ void set_events(const Array &p_events);
+ Array get_events() const;
+
+ void set_events_list(const List<Ref<InputEvent>> *p_events);
+
bool matches_event(const Ref<InputEvent> &p_event) const;
bool has_valid_event() const;
String get_as_text() const;
-};
+ static bool is_event_array_equal(const Array &p_event_array1, const Array &p_event_array2);
+};
#endif // SHORTCUT_H