Implement override of get_message

This commit is contained in:
O01eg 2021-09-29 14:06:57 +03:00
parent 047108a4ca
commit cddabf2a8b
No known key found for this signature in database
GPG Key ID: 1B9D1643A461AA2A
2 changed files with 13 additions and 0 deletions

View File

@ -871,6 +871,10 @@ void Translation::add_message(const StringName &p_src_text, const StringName &p_
translation_map[p_src_text] = p_xlated_text; translation_map[p_src_text] = p_xlated_text;
} }
StringName Translation::get_message(const StringName &p_src_text) const { StringName Translation::get_message(const StringName &p_src_text) const {
if (get_script_instance()) {
return get_script_instance()->call("_get_message", p_src_text);
}
const Map<StringName, StringName>::Element *E = translation_map.find(p_src_text); const Map<StringName, StringName>::Element *E = translation_map.find(p_src_text);
if (!E) { if (!E) {
return StringName(); return StringName();
@ -904,6 +908,8 @@ void Translation::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_messages"), &Translation::_set_messages); ClassDB::bind_method(D_METHOD("_set_messages"), &Translation::_set_messages);
ClassDB::bind_method(D_METHOD("_get_messages"), &Translation::_get_messages); ClassDB::bind_method(D_METHOD("_get_messages"), &Translation::_get_messages);
BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_message", PropertyInfo(Variant::STRING, "src_message")));
ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "messages", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_messages", "_get_messages"); ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "messages", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_messages", "_get_messages");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "locale"), "set_locale", "get_locale"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "locale"), "set_locale", "get_locale");
} }

View File

@ -11,6 +11,13 @@
<link>https://docs.godotengine.org/en/3.4/tutorials/i18n/locales.html</link> <link>https://docs.godotengine.org/en/3.4/tutorials/i18n/locales.html</link>
</tutorials> </tutorials>
<methods> <methods>
<method name="_get_message" qualifiers="virtual">
<return type="String" />
<argument index="0" name="src_message" type="String" />
<description>
Virtual method to override [method get_message].
</description>
</method>
<method name="add_message"> <method name="add_message">
<return type="void" /> <return type="void" />
<argument index="0" name="src_message" type="String" /> <argument index="0" name="src_message" type="String" />