summaryrefslogtreecommitdiff
path: root/core/input
diff options
context:
space:
mode:
authorEric M <itsjusteza@gmail.com>2020-09-29 00:23:51 +1000
committerEric M <itsjusteza@gmail.com>2020-11-19 21:05:45 +1000
commitc92f83d3ca90c49594c9ed79748c0bf5225563d8 (patch)
tree2047b7d246ebe15bb47fdd150ea053292e922ba0 /core/input
parent593e35346ab182c36068c3dcfc741eeb7311a19e (diff)
Made serialization of Command toggleable when saving InputEvents.
Made serialization of Command optional. If command is serialized, Control (On Win/Linux) or Meta (on Mac) are not. Example use case: You are on Windows and you set a shortcut to be Control + E. This would serialize as Command=true and Control=true. If you then run this project on Mac, you would need to press Command AND Control to activate the shortcut - which is not what is intended. Now, you can set store_command to true, and it will only serialize to Command = true (no Control serialized). On Windows, this means Control. On Mac, it means only command.
Diffstat (limited to 'core/input')
-rw-r--r--core/input/input_event.cpp34
-rw-r--r--core/input/input_event.h6
2 files changed, 40 insertions, 0 deletions
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 6ba082f86f..240f8c57d8 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -138,6 +138,14 @@ int64_t InputEventFromWindow::get_window_id() const {
///////////////////////////////////
+void InputEventWithModifiers::set_store_command(bool p_enabled) {
+ store_command = p_enabled;
+}
+
+bool InputEventWithModifiers::is_storing_command() const {
+ return store_command;
+}
+
void InputEventWithModifiers::set_shift(bool p_enabled) {
shift = p_enabled;
}
@@ -186,6 +194,9 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif
}
void InputEventWithModifiers::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_store_command", "enable"), &InputEventWithModifiers::set_store_command);
+ ClassDB::bind_method(D_METHOD("is_storing_command"), &InputEventWithModifiers::is_storing_command);
+
ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
@@ -201,6 +212,7 @@ void InputEventWithModifiers::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command);
ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command);
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "store_command"), "set_store_command", "is_storing_command");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control");
@@ -208,6 +220,28 @@ void InputEventWithModifiers::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
}
+void InputEventWithModifiers::_validate_property(PropertyInfo &property) const {
+ if (store_command) {
+ // If we only want to Store "Command".
+#ifdef APPLE_STYLE_KEYS
+ // Don't store "Meta" on Mac.
+ if (property.name == "meta") {
+ property.usage ^= PROPERTY_USAGE_STORAGE;
+ }
+#else
+ // Don't store "Control".
+ if (property.name == "control") {
+ property.usage ^= PROPERTY_USAGE_STORAGE;
+ }
+#endif
+ } else {
+ // We don't want to store command, only control or meta (on mac).
+ if (property.name == "command") {
+ property.usage ^= PROPERTY_USAGE_STORAGE;
+ }
+ }
+}
+
///////////////////////////////////
void InputEventKey::set_pressed(bool p_pressed) {
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 8b58cf08c2..969dc149e5 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -209,6 +209,8 @@ public:
class InputEventWithModifiers : public InputEventFromWindow {
GDCLASS(InputEventWithModifiers, InputEventFromWindow);
+ bool store_command = true;
+
bool shift = false;
bool alt = false;
#ifdef APPLE_STYLE_KEYS
@@ -228,8 +230,12 @@ class InputEventWithModifiers : public InputEventFromWindow {
protected:
static void _bind_methods();
+ virtual void _validate_property(PropertyInfo &property) const override;
public:
+ void set_store_command(bool p_enabled);
+ bool is_storing_command() const;
+
void set_shift(bool p_enabled);
bool get_shift() const;