summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/input/input_event.cpp106
-rw-r--r--core/input/input_event.h12
-rw-r--r--core/input/input_map.cpp42
-rw-r--r--core/input/input_map.h4
-rw-r--r--core/io/resource_loader.cpp2
-rw-r--r--core/string/locales.h1
-rw-r--r--core/string/translation.cpp16
-rw-r--r--core/variant/variant_call.cpp1
8 files changed, 88 insertions, 96 deletions
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index c608076a21..4e18efde81 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -86,7 +86,7 @@ Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2
return Ref<InputEvent>((InputEvent *)this);
}
-bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
+bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
return false;
}
@@ -412,35 +412,32 @@ Ref<InputEventKey> InputEventKey::create_reference(Key p_keycode) {
return ie;
}
-bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
+bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
Ref<InputEventKey> key = p_event;
if (key.is_null()) {
return false;
}
- bool match = false;
- if (get_keycode() == Key::NONE) {
- Key code = get_physical_keycode_with_modifiers();
- Key event_code = key->get_physical_keycode_with_modifiers();
-
- match = get_physical_keycode() == key->get_physical_keycode() && (!key->is_pressed() || (code & event_code) == code);
+ bool match;
+ if (keycode != Key::NONE) {
+ match = keycode == key->keycode;
} else {
- Key code = get_keycode_with_modifiers();
- Key event_code = key->get_keycode_with_modifiers();
-
- match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code);
+ match = get_physical_keycode() == key->get_physical_keycode();
+ }
+ if (p_exact_match) {
+ match &= get_modifiers_mask() == key->get_modifiers_mask();
}
if (match) {
bool pressed = key->is_pressed();
- if (p_pressed != nullptr) {
- *p_pressed = pressed;
+ if (r_pressed != nullptr) {
+ *r_pressed = pressed;
}
float strength = pressed ? 1.0f : 0.0f;
- if (p_strength != nullptr) {
- *p_strength = strength;
+ if (r_strength != nullptr) {
+ *r_strength = strength;
}
- if (p_raw_strength != nullptr) {
- *p_raw_strength = strength;
+ if (r_raw_strength != nullptr) {
+ *r_raw_strength = strength;
}
}
return match;
@@ -585,24 +582,27 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co
return mb;
}
-bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
+bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_null()) {
return false;
}
- bool match = mb->button_index == button_index;
+ bool match = button_index == mb->button_index;
+ if (p_exact_match) {
+ match &= get_modifiers_mask() == mb->get_modifiers_mask();
+ }
if (match) {
bool pressed = mb->is_pressed();
- if (p_pressed != nullptr) {
- *p_pressed = pressed;
+ if (r_pressed != nullptr) {
+ *r_pressed = pressed;
}
float strength = pressed ? 1.0f : 0.0f;
- if (p_strength != nullptr) {
- *p_strength = strength;
+ if (r_strength != nullptr) {
+ *r_strength = strength;
}
- if (p_raw_strength != nullptr) {
- *p_raw_strength = strength;
+ if (r_raw_strength != nullptr) {
+ *r_raw_strength = strength;
}
}
@@ -887,36 +887,40 @@ bool InputEventJoypadMotion::is_pressed() const {
return Math::abs(axis_value) >= 0.5f;
}
-bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
+bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
Ref<InputEventJoypadMotion> jm = p_event;
if (jm.is_null()) {
return false;
}
- bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
+ // Matches even if not in the same direction, but returns a "not pressed" event.
+ bool match = axis == jm->axis;
+ if (p_exact_match) {
+ match &= (axis_value < 0) == (jm->axis_value < 0);
+ }
if (match) {
float jm_abs_axis_value = Math::abs(jm->get_axis_value());
bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
bool pressed = same_direction && jm_abs_axis_value >= p_deadzone;
- if (p_pressed != nullptr) {
- *p_pressed = pressed;
+ if (r_pressed != nullptr) {
+ *r_pressed = pressed;
}
- if (p_strength != nullptr) {
+ if (r_strength != nullptr) {
if (pressed) {
if (p_deadzone == 1.0f) {
- *p_strength = 1.0f;
+ *r_strength = 1.0f;
} else {
- *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, jm_abs_axis_value), 0.0f, 1.0f);
+ *r_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, jm_abs_axis_value), 0.0f, 1.0f);
}
} else {
- *p_strength = 0.0f;
+ *r_strength = 0.0f;
}
}
- if (p_raw_strength != nullptr) {
+ if (r_raw_strength != nullptr) {
if (same_direction) { // NOT pressed, because we want to ignore the deadzone.
- *p_raw_strength = jm_abs_axis_value;
+ *r_raw_strength = jm_abs_axis_value;
} else {
- *p_raw_strength = 0.0f;
+ *r_raw_strength = 0.0f;
}
}
}
@@ -994,7 +998,7 @@ float InputEventJoypadButton::get_pressure() const {
return pressure;
}
-bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
+bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
Ref<InputEventJoypadButton> jb = p_event;
if (jb.is_null()) {
return false;
@@ -1003,15 +1007,15 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *
bool match = button_index == jb->button_index;
if (match) {
bool pressed = jb->is_pressed();
- if (p_pressed != nullptr) {
- *p_pressed = pressed;
+ if (r_pressed != nullptr) {
+ *r_pressed = pressed;
}
float strength = pressed ? 1.0f : 0.0f;
- if (p_strength != nullptr) {
- *p_strength = strength;
+ if (r_strength != nullptr) {
+ *r_strength = strength;
}
- if (p_raw_strength != nullptr) {
- *p_raw_strength = strength;
+ if (r_raw_strength != nullptr) {
+ *r_raw_strength = strength;
}
}
@@ -1288,7 +1292,7 @@ bool InputEventAction::is_action(const StringName &p_action) const {
return action == p_action;
}
-bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
+bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
Ref<InputEventAction> act = p_event;
if (act.is_null()) {
return false;
@@ -1297,15 +1301,15 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pres
bool match = action == act->action;
if (match) {
bool pressed = act->pressed;
- if (p_pressed != nullptr) {
- *p_pressed = pressed;
+ if (r_pressed != nullptr) {
+ *r_pressed = pressed;
}
float strength = pressed ? 1.0f : 0.0f;
- if (p_strength != nullptr) {
- *p_strength = strength;
+ if (r_strength != nullptr) {
+ *r_strength = strength;
}
- if (p_raw_strength != nullptr) {
- *p_raw_strength = strength;
+ if (r_raw_strength != nullptr) {
+ *r_raw_strength = strength;
}
}
return match;
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 29450dfc52..114db46623 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -79,7 +79,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const;
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const;
virtual bool is_action_type() const;
@@ -192,7 +192,7 @@ public:
Key get_keycode_with_modifiers() const;
Key get_physical_keycode_with_modifiers() const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
@@ -255,7 +255,7 @@ public:
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
@@ -315,7 +315,7 @@ public:
virtual bool is_pressed() const override;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
@@ -344,7 +344,7 @@ public:
void set_pressure(float p_pressure);
float get_pressure() const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
@@ -437,7 +437,7 @@ public:
virtual bool is_action(const StringName &p_action) const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
virtual bool is_action_type() const override { return true; }
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index 753ac72ab6..41083b4c47 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -126,15 +126,13 @@ List<StringName> InputMap::get_actions() const {
return actions;
}
-List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength) const {
+List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
ERR_FAIL_COND_V(!p_event.is_valid(), nullptr);
for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) {
int device = E->get()->get_device();
if (device == ALL_DEVICES || device == p_event->get_device()) {
- if (p_exact_match && E->get()->is_match(p_event, true)) {
- return E;
- } else if (!p_exact_match && E->get()->action_match(p_event, p_pressed, p_strength, p_raw_strength, p_action.deadzone)) {
+ if (E->get()->action_match(p_event, p_exact_match, p_action.deadzone, r_pressed, r_strength, r_raw_strength)) {
return E;
}
}
@@ -217,40 +215,28 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName
return event_get_action_status(p_event, p_action, p_exact_match);
}
-bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength) const {
+bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength) const {
OrderedHashMap<StringName, Action>::Element E = input_map.find(p_action);
ERR_FAIL_COND_V_MSG(!E, false, suggest_actions(p_action));
Ref<InputEventAction> input_event_action = p_event;
if (input_event_action.is_valid()) {
- bool pressed = input_event_action->is_pressed();
- if (p_pressed != nullptr) {
- *p_pressed = pressed;
+ const bool pressed = input_event_action->is_pressed();
+ if (r_pressed != nullptr) {
+ *r_pressed = pressed;
+ }
+ const float strength = pressed ? input_event_action->get_strength() : 0.0f;
+ if (r_strength != nullptr) {
+ *r_strength = strength;
}
- if (p_strength != nullptr) {
- *p_strength = pressed ? input_event_action->get_strength() : 0.0f;
+ if (r_raw_strength != nullptr) {
+ *r_raw_strength = strength;
}
return input_event_action->get_action() == p_action;
}
- bool pressed;
- float strength;
- float raw_strength;
- List<Ref<InputEvent>>::Element *event = _find_event(E.get(), p_event, p_exact_match, &pressed, &strength, &raw_strength);
- if (event != nullptr) {
- if (p_pressed != nullptr) {
- *p_pressed = pressed;
- }
- if (p_strength != nullptr) {
- *p_strength = strength;
- }
- if (p_raw_strength != nullptr) {
- *p_raw_strength = raw_strength;
- }
- return true;
- } else {
- return false;
- }
+ List<Ref<InputEvent>>::Element *event = _find_event(E.get(), p_event, p_exact_match, r_pressed, r_strength, r_raw_strength);
+ return event != nullptr;
}
const OrderedHashMap<StringName, InputMap::Action> &InputMap::get_action_map() const {
diff --git a/core/input/input_map.h b/core/input/input_map.h
index e896d1f679..79b4d1038f 100644
--- a/core/input/input_map.h
+++ b/core/input/input_map.h
@@ -58,7 +58,7 @@ private:
OrderedHashMap<String, List<Ref<InputEvent>>> default_builtin_cache;
OrderedHashMap<String, List<Ref<InputEvent>>> default_builtin_with_overrides_cache;
- List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match = false, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const;
+ 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) const;
Array _action_get_events(const StringName &p_action);
Array _get_actions();
@@ -83,7 +83,7 @@ public:
const List<Ref<InputEvent>> *action_get_events(const StringName &p_action);
bool event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match = false) const;
- bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match = false, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const;
+ 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) const;
const OrderedHashMap<StringName, Action> &get_action_map() const;
void load_from_project_settings();
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 3e1c9d2e4a..21bf566b1b 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -820,7 +820,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
}
String l = res_remaps[i].substr(split + 1).strip_edges();
int score = TranslationServer::get_singleton()->compare_locales(locale, l);
- if (score > best_score) {
+ if (score > 0 && score >= best_score) {
new_path = res_remaps[i].left(split);
best_score = score;
if (score == 10) {
diff --git a/core/string/locales.h b/core/string/locales.h
index 9ef6dee5ac..32d6608ec2 100644
--- a/core/string/locales.h
+++ b/core/string/locales.h
@@ -42,6 +42,7 @@ static const char *locale_renames[][2] = {
{ "in", "id" }, // Indonesian
{ "iw", "he" }, // Hebrew
{ "no", "nb" }, // Norwegian Bokmål
+ { "C", "en" }, // Locale is not set, fallback to English.
{ nullptr, nullptr }
};
diff --git a/core/string/translation.cpp b/core/string/translation.cpp
index 674098b06c..355ee238e8 100644
--- a/core/string/translation.cpp
+++ b/core/string/translation.cpp
@@ -544,7 +544,7 @@ Ref<Translation> TranslationServer::get_translation_object(const String &p_local
String l = t->get_locale();
int score = compare_locales(p_locale, l);
- if (score > best_score) {
+ if (score > 0 && score >= best_score) {
res = t;
best_score = score;
if (score == 10) {
@@ -566,8 +566,6 @@ StringName TranslationServer::translate(const StringName &p_message, const Strin
return p_message;
}
- ERR_FAIL_COND_V_MSG(locale.length() < 2, p_message, "Could not translate message as configured locale '" + locale + "' is invalid.");
-
StringName res = _get_message_from_translations(p_message, p_context, locale, false);
if (!res && fallback.length() >= 2) {
@@ -589,8 +587,6 @@ StringName TranslationServer::translate_plural(const StringName &p_message, cons
return p_message_plural;
}
- ERR_FAIL_COND_V_MSG(locale.length() < 2, p_message, "Could not translate message as configured locale '" + locale + "' is invalid.");
-
StringName res = _get_message_from_translations(p_message, p_context, locale, true, p_message_plural, p_n);
if (!res && fallback.length() >= 2) {
@@ -617,13 +613,17 @@ StringName TranslationServer::_get_message_from_translations(const StringName &p
String l = t->get_locale();
int score = compare_locales(p_locale, l);
- if (score > best_score) {
+ if (score > 0 && score >= best_score) {
StringName r;
if (!plural) {
- res = t->get_message(p_message, p_context);
+ r = t->get_message(p_message, p_context);
} else {
- res = t->get_plural_message(p_message, p_message_plural, p_n, p_context);
+ r = t->get_plural_message(p_message, p_message_plural, p_n, p_context);
+ }
+ if (!r) {
+ continue;
}
+ res = r;
best_score = score;
if (score == 10) {
break; // Exact match, skip the rest.
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 62964fba80..aecc6e9a26 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -1789,6 +1789,7 @@ static void _register_variant_builtin_methods() {
bind_method(Transform3D, scaled, sarray("scale"), varray());
bind_method(Transform3D, translated, sarray("offset"), varray());
bind_method(Transform3D, looking_at, sarray("target", "up"), varray(Vector3(0, 1, 0)));
+ bind_method(Transform3D, sphere_interpolate_with, sarray("xform", "weight"), varray());
bind_method(Transform3D, interpolate_with, sarray("xform", "weight"), varray());
bind_method(Transform3D, is_equal_approx, sarray("xform"), varray());