diff options
Diffstat (limited to 'core/object.cpp')
-rw-r--r-- | core/object.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/core/object.cpp b/core/object.cpp index ff6d4a666f..0d9e5c5116 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1315,9 +1315,10 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co Callable target = p_callable; - if (s->slot_map.has(target)) { + //compare with the base callable, so binds can be ignored + if (s->slot_map.has(*target.get_base_comparator())) { if (p_flags & CONNECT_REFERENCE_COUNTED) { - s->slot_map[target].reference_count++; + s->slot_map[*target.get_base_comparator()].reference_count++; return OK; } else { ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, "Signal '" + p_signal + "' is already connected to given callable '" + p_callable + "' in that object."); @@ -1337,7 +1338,8 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co slot.reference_count = 1; } - s->slot_map[target] = slot; + //use callable version as key, so binds can be ignored + s->slot_map[*target.get_base_comparator()] = slot; return OK; } @@ -1364,7 +1366,7 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable Callable target = p_callable; - return s->slot_map.has(target); + return s->slot_map.has(*target.get_base_comparator()); //const Map<Signal::Target,Signal::Slot>::Element *E = s->slot_map.find(target); //return (E!=nullptr ); } @@ -1386,7 +1388,7 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, SignalData *s = signal_map.getptr(p_signal); ERR_FAIL_COND_MSG(!s, vformat("Nonexistent signal '%s' in %s.", p_signal, to_string())); - ERR_FAIL_COND_MSG(!s->slot_map.has(p_callable), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + "."); + ERR_FAIL_COND_MSG(!s->slot_map.has(*p_callable.get_base_comparator()), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + "."); SignalData::Slot *slot = &s->slot_map[p_callable]; @@ -1398,7 +1400,7 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, } target_object->connections.erase(slot->cE); - s->slot_map.erase(p_callable); + s->slot_map.erase(*p_callable.get_base_comparator()); if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(), p_signal)) { //not user signal, delete @@ -1432,12 +1434,22 @@ void Object::initialize_class() { initialized = true; } -StringName Object::tr(const StringName &p_message) const { +String Object::tr(const StringName &p_message, const StringName &p_context) const { if (!_can_translate || !TranslationServer::get_singleton()) { return p_message; } + return TranslationServer::get_singleton()->translate(p_message, p_context); +} - return TranslationServer::get_singleton()->translate(p_message); +String Object::tr_n(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const { + if (!_can_translate || !TranslationServer::get_singleton()) { + // Return message based on English plural rule if translation is not possible. + if (p_n == 1) { + return p_message; + } + return p_message_plural; + } + return TranslationServer::get_singleton()->translate_plural(p_message, p_message_plural, p_n, p_context); } void Object::_clear_internal_resource_paths(const Variant &p_var) { @@ -1578,7 +1590,8 @@ void Object::_bind_methods() { ClassDB::bind_method(D_METHOD("set_message_translation", "enable"), &Object::set_message_translation); ClassDB::bind_method(D_METHOD("can_translate_messages"), &Object::can_translate_messages); - ClassDB::bind_method(D_METHOD("tr", "message"), &Object::tr); + ClassDB::bind_method(D_METHOD("tr", "message", "context"), &Object::tr, DEFVAL("")); + ClassDB::bind_method(D_METHOD("tr_n", "message", "plural_message", "n", "context"), &Object::tr_n, DEFVAL("")); ClassDB::bind_method(D_METHOD("is_queued_for_deletion"), &Object::is_queued_for_deletion); |