Make auto translation inheritable
This commit is contained in:
parent
6f805dee2a
commit
7b42c24550
51 changed files with 284 additions and 136 deletions
|
|
@ -99,6 +99,26 @@ void Node::_notification(int p_notification) {
|
|||
}
|
||||
}
|
||||
|
||||
// Update auto translate mode.
|
||||
if (data.auto_translate_mode == AUTO_TRANSLATE_MODE_INHERIT && !data.parent) {
|
||||
ERR_PRINT("The root node can't be set to Inherit auto translate mode, reverting to Always instead.");
|
||||
data.auto_translate_mode = AUTO_TRANSLATE_MODE_ALWAYS;
|
||||
}
|
||||
data.is_auto_translate_dirty = true;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
// Don't translate UI elements when they're being edited.
|
||||
if (is_part_of_edited_scene()) {
|
||||
set_message_translation(false);
|
||||
} else if (data.auto_translate_mode != AUTO_TRANSLATE_MODE_DISABLED) {
|
||||
notification(NOTIFICATION_TRANSLATION_CHANGED);
|
||||
}
|
||||
#else
|
||||
if (data.auto_translate_mode != AUTO_TRANSLATE_MODE_DISABLED) {
|
||||
notification(NOTIFICATION_TRANSLATION_CHANGED);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (data.input) {
|
||||
add_to_group("_vp_input" + itos(get_viewport()->get_instance_id()));
|
||||
}
|
||||
|
|
@ -136,11 +156,11 @@ void Node::_notification(int p_notification) {
|
|||
remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id()));
|
||||
}
|
||||
|
||||
// Remove from processing first
|
||||
// Remove from processing first.
|
||||
if (_is_any_processing()) {
|
||||
_remove_from_process_thread_group();
|
||||
}
|
||||
// Remove the process group
|
||||
// Remove the process group.
|
||||
if (data.process_thread_group_owner == this) {
|
||||
_remove_process_group();
|
||||
}
|
||||
|
|
@ -217,6 +237,12 @@ void Node::_notification(int p_notification) {
|
|||
memdelete(child);
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_TRANSLATION_CHANGED: {
|
||||
if (data.inside_tree) {
|
||||
data.is_auto_translate_dirty = true;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1149,6 +1175,49 @@ bool Node::is_processing_unhandled_key_input() const {
|
|||
return data.unhandled_key_input;
|
||||
}
|
||||
|
||||
void Node::set_auto_translate_mode(AutoTranslateMode p_mode) {
|
||||
ERR_THREAD_GUARD
|
||||
if (data.auto_translate_mode == p_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_mode == AUTO_TRANSLATE_MODE_INHERIT && data.inside_tree && !data.parent) {
|
||||
ERR_FAIL_MSG("The root node can't be set to Inherit auto translate mode.");
|
||||
}
|
||||
|
||||
data.auto_translate_mode = p_mode;
|
||||
data.is_auto_translating = p_mode != AUTO_TRANSLATE_MODE_DISABLED;
|
||||
data.is_auto_translate_dirty = true;
|
||||
|
||||
propagate_notification(NOTIFICATION_TRANSLATION_CHANGED);
|
||||
}
|
||||
|
||||
Node::AutoTranslateMode Node::get_auto_translate_mode() const {
|
||||
return data.auto_translate_mode;
|
||||
}
|
||||
|
||||
bool Node::can_auto_translate() const {
|
||||
ERR_READ_THREAD_GUARD_V(false);
|
||||
if (!data.is_auto_translate_dirty || data.auto_translate_mode != AUTO_TRANSLATE_MODE_INHERIT) {
|
||||
return data.is_auto_translating;
|
||||
}
|
||||
|
||||
data.is_auto_translate_dirty = false;
|
||||
|
||||
Node *parent = data.parent;
|
||||
while (parent) {
|
||||
if (parent->data.auto_translate_mode == AUTO_TRANSLATE_MODE_INHERIT) {
|
||||
parent = parent->data.parent;
|
||||
continue;
|
||||
}
|
||||
|
||||
data.is_auto_translating = parent->data.auto_translate_mode == AUTO_TRANSLATE_MODE_ALWAYS;
|
||||
break;
|
||||
}
|
||||
|
||||
return data.is_auto_translating;
|
||||
}
|
||||
|
||||
StringName Node::get_name() const {
|
||||
return data.name;
|
||||
}
|
||||
|
|
@ -3488,6 +3557,9 @@ void Node::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_physics_process_internal", "enable"), &Node::set_physics_process_internal);
|
||||
ClassDB::bind_method(D_METHOD("is_physics_processing_internal"), &Node::is_physics_processing_internal);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_auto_translate_mode", "mode"), &Node::set_auto_translate_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_auto_translate_mode"), &Node::get_auto_translate_mode);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_window"), &Node::get_window);
|
||||
ClassDB::bind_method(D_METHOD("get_last_exclusive_window"), &Node::get_last_exclusive_window);
|
||||
ClassDB::bind_method(D_METHOD("get_tree"), &Node::get_tree);
|
||||
|
|
@ -3525,6 +3597,9 @@ void Node::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_unique_name_in_owner", "enable"), &Node::set_unique_name_in_owner);
|
||||
ClassDB::bind_method(D_METHOD("is_unique_name_in_owner"), &Node::is_unique_name_in_owner);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("atr", "message", "context"), &Node::atr, DEFVAL(""));
|
||||
ClassDB::bind_method(D_METHOD("atr_n", "message", "plural_message", "n", "context"), &Node::atr_n, DEFVAL(""));
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
ClassDB::bind_method(D_METHOD("_set_property_pinned", "property", "pinned"), &Node::set_property_pinned);
|
||||
#endif
|
||||
|
|
@ -3635,6 +3710,10 @@ void Node::_bind_methods() {
|
|||
BIND_ENUM_CONSTANT(INTERNAL_MODE_FRONT);
|
||||
BIND_ENUM_CONSTANT(INTERNAL_MODE_BACK);
|
||||
|
||||
BIND_ENUM_CONSTANT(AUTO_TRANSLATE_MODE_INHERIT);
|
||||
BIND_ENUM_CONSTANT(AUTO_TRANSLATE_MODE_ALWAYS);
|
||||
BIND_ENUM_CONSTANT(AUTO_TRANSLATE_MODE_DISABLED);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("ready"));
|
||||
ADD_SIGNAL(MethodInfo("renamed"));
|
||||
ADD_SIGNAL(MethodInfo("tree_entered"));
|
||||
|
|
@ -3657,11 +3736,15 @@ void Node::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Inherit,Pausable,When Paused,Always,Disabled"), "set_process_mode", "get_process_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_priority"), "set_process_priority", "get_process_priority");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_physics_priority"), "set_physics_process_priority", "get_physics_process_priority");
|
||||
|
||||
ADD_SUBGROUP("Thread Group", "process_thread");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_thread_group", PROPERTY_HINT_ENUM, "Inherit,Main Thread,Sub Thread"), "set_process_thread_group", "get_process_thread_group");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_thread_group_order"), "set_process_thread_group_order", "get_process_thread_group_order");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_thread_messages", PROPERTY_HINT_FLAGS, "Process,Physics Process"), "set_process_thread_messages", "get_process_thread_messages");
|
||||
|
||||
ADD_GROUP("Auto Translate", "auto_translate_");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "auto_translate_mode", PROPERTY_HINT_ENUM, "Inherit,Always,Disabled"), "set_auto_translate_mode", "get_auto_translate_mode");
|
||||
|
||||
ADD_GROUP("Editor Description", "editor_");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "editor_description", PROPERTY_HINT_MULTILINE_TEXT), "set_editor_description", "get_editor_description");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue