You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-12 13:20:55 +00:00
Optimize StringName usage
* Added a new macro SNAME() that constructs and caches a local stringname. * Subsequent usages use the cached version. * Since these use a global static variable, a second refcounter of static usages need to be kept for cleanup time. * Replaced all theme usages by this new macro. * Replace all signal emission usages by this new macro. * Replace all call_deferred usages by this new macro. This is part of ongoing work to optimize GUI and the editor.
This commit is contained in:
@@ -63,15 +63,15 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
|
||||
if (p_id == BUTTON_SUBSCENE) {
|
||||
if (n == get_scene_node()) {
|
||||
if (n && n->get_scene_inherited_state().is_valid()) {
|
||||
emit_signal("open", n->get_scene_inherited_state()->get_path());
|
||||
emit_signal(SNAME("open"), n->get_scene_inherited_state()->get_path());
|
||||
}
|
||||
} else {
|
||||
emit_signal("open", n->get_filename());
|
||||
emit_signal(SNAME("open"), n->get_filename());
|
||||
}
|
||||
} else if (p_id == BUTTON_SCRIPT) {
|
||||
Ref<Script> script_typed = n->get_script();
|
||||
if (!script_typed.is_null()) {
|
||||
emit_signal("open_script", script_typed);
|
||||
emit_signal(SNAME("open_script"), script_typed);
|
||||
}
|
||||
|
||||
} else if (p_id == BUTTON_VISIBILITY) {
|
||||
@@ -197,19 +197,19 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
item->set_metadata(0, p_node->get_path());
|
||||
|
||||
if (connect_to_script_mode) {
|
||||
Color accent = get_theme_color("accent_color", "Editor");
|
||||
Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor"));
|
||||
|
||||
Ref<Script> script = p_node->get_script();
|
||||
if (!script.is_null() && EditorNode::get_singleton()->get_object_custom_type_base(p_node) != script) {
|
||||
//has script
|
||||
item->add_button(0, get_theme_icon("Script", "EditorIcons"), BUTTON_SCRIPT);
|
||||
item->add_button(0, get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), BUTTON_SCRIPT);
|
||||
} else {
|
||||
//has no script (or script is a custom type)
|
||||
item->set_custom_color(0, get_theme_color("disabled_font_color", "Editor"));
|
||||
item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
|
||||
item->set_selectable(0, false);
|
||||
|
||||
if (!script.is_null()) { // make sure to mark the script if a custom type
|
||||
item->add_button(0, get_theme_icon("Script", "EditorIcons"), BUTTON_SCRIPT);
|
||||
item->add_button(0, get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), BUTTON_SCRIPT);
|
||||
item->set_button_disabled(0, item->get_button_count(0) - 1, true);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
}
|
||||
} else if (part_of_subscene) {
|
||||
if (valid_types.size() == 0) {
|
||||
item->set_custom_color(0, get_theme_color("disabled_font_color", "Editor"));
|
||||
item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
|
||||
}
|
||||
} else if (marked.has(p_node)) {
|
||||
String node_name = p_node->get_name();
|
||||
@@ -235,15 +235,15 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
}
|
||||
item->set_text(0, node_name);
|
||||
item->set_selectable(0, marked_selectable);
|
||||
item->set_custom_color(0, get_theme_color("accent_color", "Editor"));
|
||||
item->set_custom_color(0, get_theme_color(SNAME("accent_color"), SNAME("Editor")));
|
||||
} else if (!p_node->can_process()) {
|
||||
item->set_custom_color(0, get_theme_color("disabled_font_color", "Editor"));
|
||||
item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
|
||||
} else if (!marked_selectable && !marked_children_selectable) {
|
||||
Node *node = p_node;
|
||||
while (node) {
|
||||
if (marked.has(node)) {
|
||||
item->set_selectable(0, false);
|
||||
item->set_custom_color(0, get_theme_color("error_color", "Editor"));
|
||||
item->set_custom_color(0, get_theme_color(SNAME("error_color"), SNAME("Editor")));
|
||||
break;
|
||||
}
|
||||
node = node->get_parent();
|
||||
@@ -254,7 +254,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
|
||||
String warning = p_node->get_configuration_warnings_as_string();
|
||||
if (!warning.is_empty()) {
|
||||
item->add_button(0, get_theme_icon("NodeWarning", "EditorIcons"), BUTTON_WARNING, false, TTR("Node configuration warning:") + "\n" + warning);
|
||||
item->add_button(0, get_theme_icon(SNAME("NodeWarning"), SNAME("EditorIcons")), BUTTON_WARNING, false, TTR("Node configuration warning:") + "\n" + warning);
|
||||
}
|
||||
|
||||
int num_connections = p_node->get_persistent_signal_connection_count();
|
||||
@@ -279,11 +279,11 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
Ref<Texture2D> icon_temp;
|
||||
SceneTreeEditorButton signal_temp = BUTTON_SIGNALS;
|
||||
if (num_connections >= 1 && num_groups >= 1) {
|
||||
icon_temp = get_theme_icon("SignalsAndGroups", "EditorIcons");
|
||||
icon_temp = get_theme_icon(SNAME("SignalsAndGroups"), SNAME("EditorIcons"));
|
||||
} else if (num_connections >= 1) {
|
||||
icon_temp = get_theme_icon("Signals", "EditorIcons");
|
||||
icon_temp = get_theme_icon(SNAME("Signals"), SNAME("EditorIcons"));
|
||||
} else if (num_groups >= 1) {
|
||||
icon_temp = get_theme_icon("Groups", "EditorIcons");
|
||||
icon_temp = get_theme_icon(SNAME("Groups"), SNAME("EditorIcons"));
|
||||
signal_temp = BUTTON_GROUPS;
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
}
|
||||
|
||||
if (p_node == get_scene_node() && p_node->get_scene_inherited_state().is_valid()) {
|
||||
item->add_button(0, get_theme_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Open in Editor"));
|
||||
item->add_button(0, get_theme_icon(SNAME("InstanceOptions"), SNAME("EditorIcons")), BUTTON_SUBSCENE, false, TTR("Open in Editor"));
|
||||
|
||||
String tooltip = TTR("Inherits:") + " " + p_node->get_scene_inherited_state()->get_path() + "\n" + TTR("Type:") + " " + p_node->get_class();
|
||||
if (p_node->get_editor_description() != String()) {
|
||||
@@ -302,7 +302,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
|
||||
item->set_tooltip(0, tooltip);
|
||||
} else if (p_node != get_scene_node() && p_node->get_filename() != "" && can_open_instance) {
|
||||
item->add_button(0, get_theme_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Open in Editor"));
|
||||
item->add_button(0, get_theme_icon(SNAME("InstanceOptions"), SNAME("EditorIcons")), BUTTON_SUBSCENE, false, TTR("Open in Editor"));
|
||||
|
||||
String tooltip = TTR("Instance:") + " " + p_node->get_filename() + "\n" + TTR("Type:") + " " + p_node->get_class();
|
||||
if (p_node->get_editor_description() != String()) {
|
||||
@@ -332,7 +332,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
|
||||
Ref<Script> script = p_node->get_script();
|
||||
if (!script.is_null()) {
|
||||
item->add_button(0, get_theme_icon("Script", "EditorIcons"), BUTTON_SCRIPT, false, TTR("Open Script:") + " " + script->get_path());
|
||||
item->add_button(0, get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), BUTTON_SCRIPT, false, TTR("Open Script:") + " " + script->get_path());
|
||||
if (EditorNode::get_singleton()->get_object_custom_type_base(p_node) == script) {
|
||||
item->set_button_color(0, item->get_button_count(0) - 1, Color(1, 1, 1, 0.5));
|
||||
}
|
||||
@@ -341,19 +341,19 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
if (p_node->is_class("CanvasItem")) {
|
||||
bool is_locked = p_node->has_meta("_edit_lock_"); //_edit_group_
|
||||
if (is_locked) {
|
||||
item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
|
||||
item->add_button(0, get_theme_icon(SNAME("Lock"), SNAME("EditorIcons")), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
|
||||
}
|
||||
|
||||
bool is_grouped = p_node->has_meta("_edit_group_");
|
||||
if (is_grouped) {
|
||||
item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
|
||||
item->add_button(0, get_theme_icon(SNAME("Group"), SNAME("EditorIcons")), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
|
||||
}
|
||||
|
||||
bool v = p_node->call("is_visible");
|
||||
if (v) {
|
||||
item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
|
||||
item->add_button(0, get_theme_icon(SNAME("GuiVisibilityVisible"), SNAME("EditorIcons")), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
|
||||
} else {
|
||||
item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
|
||||
item->add_button(0, get_theme_icon(SNAME("GuiVisibilityHidden"), SNAME("EditorIcons")), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
|
||||
}
|
||||
|
||||
if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) {
|
||||
@@ -364,19 +364,19 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
} else if (p_node->is_class("Node3D")) {
|
||||
bool is_locked = p_node->has_meta("_edit_lock_");
|
||||
if (is_locked) {
|
||||
item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
|
||||
item->add_button(0, get_theme_icon(SNAME("Lock"), SNAME("EditorIcons")), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
|
||||
}
|
||||
|
||||
bool is_grouped = p_node->has_meta("_edit_group_");
|
||||
if (is_grouped) {
|
||||
item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
|
||||
item->add_button(0, get_theme_icon(SNAME("Group"), SNAME("EditorIcons")), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
|
||||
}
|
||||
|
||||
bool v = p_node->call("is_visible");
|
||||
if (v) {
|
||||
item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
|
||||
item->add_button(0, get_theme_icon(SNAME("GuiVisibilityVisible"), SNAME("EditorIcons")), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
|
||||
} else {
|
||||
item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
|
||||
item->add_button(0, get_theme_icon(SNAME("GuiVisibilityHidden"), SNAME("EditorIcons")), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
|
||||
}
|
||||
|
||||
if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) {
|
||||
@@ -388,7 +388,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
bool is_pinned = AnimationPlayerEditor::singleton->get_player() == p_node && AnimationPlayerEditor::singleton->is_pinned();
|
||||
|
||||
if (is_pinned) {
|
||||
item->add_button(0, get_theme_icon("Pin", "EditorIcons"), BUTTON_PIN, false, TTR("AnimationPlayer is pinned.\nClick to unpin."));
|
||||
item->add_button(0, get_theme_icon(SNAME("Pin"), SNAME("EditorIcons")), BUTTON_PIN, false, TTR("AnimationPlayer is pinned.\nClick to unpin."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,7 +429,7 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent, bool p_scroll
|
||||
|
||||
if (!valid) {
|
||||
//item->set_selectable(0,marked_selectable);
|
||||
item->set_custom_color(0, get_theme_color("disabled_font_color", "Editor"));
|
||||
item->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), SNAME("Editor")));
|
||||
item->set_selectable(0, false);
|
||||
}
|
||||
}
|
||||
@@ -475,9 +475,9 @@ void SceneTreeEditor::_node_visibility_changed(Node *p_node) {
|
||||
}
|
||||
|
||||
if (visible) {
|
||||
item->set_button(0, idx, get_theme_icon("GuiVisibilityVisible", "EditorIcons"));
|
||||
item->set_button(0, idx, get_theme_icon(SNAME("GuiVisibilityVisible"), SNAME("EditorIcons")));
|
||||
} else {
|
||||
item->set_button(0, idx, get_theme_icon("GuiVisibilityHidden", "EditorIcons"));
|
||||
item->set_button(0, idx, get_theme_icon(SNAME("GuiVisibilityHidden"), SNAME("EditorIcons")));
|
||||
}
|
||||
|
||||
_update_visibility_color(p_node, item);
|
||||
@@ -530,7 +530,7 @@ void SceneTreeEditor::_node_renamed(Node *p_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
emit_signal("node_renamed");
|
||||
emit_signal(SNAME("node_renamed"));
|
||||
|
||||
if (!tree_dirty) {
|
||||
MessageQueue::get_singleton()->push_call(this, "_update_tree");
|
||||
@@ -619,13 +619,13 @@ void SceneTreeEditor::_deselect_items() {
|
||||
// Clear currently selected items in scene tree dock.
|
||||
if (editor_selection) {
|
||||
editor_selection->clear();
|
||||
emit_signal("node_changed");
|
||||
emit_signal(SNAME("node_changed"));
|
||||
}
|
||||
}
|
||||
|
||||
void SceneTreeEditor::_emit_node_selected() {
|
||||
blocked++;
|
||||
emit_signal("node_selected");
|
||||
emit_signal(SNAME("node_selected"));
|
||||
blocked--;
|
||||
}
|
||||
|
||||
@@ -657,7 +657,7 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_
|
||||
selected = editor_selection->get_selected_node_list()[0];
|
||||
_emit_node_selected();
|
||||
} else {
|
||||
emit_signal("node_changed");
|
||||
emit_signal(SNAME("node_changed"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -804,10 +804,10 @@ void SceneTreeEditor::_renamed() {
|
||||
if (!undo_redo) {
|
||||
n->set_name(new_name);
|
||||
which->set_metadata(0, n->get_path());
|
||||
emit_signal("node_renamed");
|
||||
emit_signal(SNAME("node_renamed"));
|
||||
} else {
|
||||
undo_redo->create_action(TTR("Rename Node"));
|
||||
emit_signal("node_prerename", n, new_name);
|
||||
emit_signal(SNAME("node_prerename"), n, new_name);
|
||||
undo_redo->add_do_method(this, "_rename_node", n->get_instance_id(), new_name);
|
||||
undo_redo->add_undo_method(this, "_rename_node", n->get_instance_id(), n->get_name());
|
||||
undo_redo->commit_action();
|
||||
@@ -984,7 +984,7 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
|
||||
drag_data["nodes"] = objs;
|
||||
|
||||
tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM);
|
||||
emit_signal("nodes_dragged");
|
||||
emit_signal(SNAME("nodes_dragged"));
|
||||
|
||||
return drag_data;
|
||||
}
|
||||
@@ -1076,7 +1076,7 @@ void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data,
|
||||
|
||||
if (String(d["type"]) == "nodes") {
|
||||
Array nodes = d["nodes"];
|
||||
emit_signal("nodes_rearranged", nodes, np, section);
|
||||
emit_signal(SNAME("nodes_rearranged"), nodes, np, section);
|
||||
}
|
||||
|
||||
if (String(d["type"]) == "files") {
|
||||
@@ -1084,9 +1084,9 @@ void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data,
|
||||
|
||||
String ftype = EditorFileSystem::get_singleton()->get_file_type(files[0]);
|
||||
if (_is_script_type(ftype)) {
|
||||
emit_signal("script_dropped", files[0], np);
|
||||
emit_signal(SNAME("script_dropped"), files[0], np);
|
||||
} else {
|
||||
emit_signal("files_dropped", files, np, section);
|
||||
emit_signal(SNAME("files_dropped"), files, np, section);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1095,14 +1095,14 @@ void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data,
|
||||
if (se) {
|
||||
String sp = se->get_edited_resource()->get_path();
|
||||
if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(sp))) {
|
||||
emit_signal("script_dropped", sp, np);
|
||||
emit_signal(SNAME("script_dropped"), sp, np);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) {
|
||||
emit_signal("rmb_pressed", tree->get_screen_transform().xform(p_pos));
|
||||
emit_signal(SNAME("rmb_pressed"), tree->get_screen_transform().xform(p_pos));
|
||||
}
|
||||
|
||||
void SceneTreeEditor::update_warning() {
|
||||
@@ -1237,7 +1237,7 @@ void SceneTreeDialog::_notification(int p_what) {
|
||||
} break;
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
connect("confirmed", callable_mp(this, &SceneTreeDialog::_select));
|
||||
filter->set_right_icon(tree->get_theme_icon("Search", "EditorIcons"));
|
||||
filter->set_right_icon(tree->get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
|
||||
filter->set_clear_button_enabled(true);
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
@@ -1252,7 +1252,7 @@ void SceneTreeDialog::_cancel() {
|
||||
|
||||
void SceneTreeDialog::_select() {
|
||||
if (tree->get_selected()) {
|
||||
emit_signal("selected", tree->get_selected()->get_path());
|
||||
emit_signal(SNAME("selected"), tree->get_selected()->get_path());
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user