Merge pull request #51413 from KoBeWi/🚗

This commit is contained in:
Rémi Verschelde 2021-10-04 20:31:47 +02:00 committed by GitHub
commit 8f227e9da3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 15 deletions

View File

@ -480,6 +480,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
// SceneTree
_initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
_initial_set("docks/scene_tree/auto_expand_to_selected", true);
// FileSystem
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "docks/filesystem/thumbnail_size", 64, "32,128,16")

View File

@ -411,10 +411,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
} break;
case TOOL_EXPAND_COLLAPSE: {
if (!scene_tree->get_selected()) {
break;
}
Tree *tree = scene_tree->get_scene_tree();
TreeItem *selected_item = tree->get_selected();
@ -979,6 +975,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
} break;
case TOOL_AUTO_EXPAND: {
scene_tree->set_auto_expand_selected(!EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), true);
} break;
case TOOL_SCENE_EDITABLE_CHILDREN: {
if (!profile_allow_editing) {
break;
@ -1223,6 +1222,7 @@ void SceneTreeDock::_notification(int p_what) {
button_instance->set_icon(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")));
button_create_script->set_icon(get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons")));
button_detach_script->set_icon(get_theme_icon(SNAME("ScriptRemove"), SNAME("EditorIcons")));
button_tree_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons")));
filter->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
filter->set_clear_button_enabled(true);
@ -1291,12 +1291,14 @@ void SceneTreeDock::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
clear_inherit_confirm->connect("confirmed", callable_mp(this, &SceneTreeDock::_tool_selected), make_binds(TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM, false));
scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false);
} break;
case NOTIFICATION_EXIT_TREE: {
clear_inherit_confirm->disconnect("confirmed", callable_mp(this, &SceneTreeDock::_tool_selected));
} break;
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
scene_tree->set_auto_expand_selected(EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"), false);
button_add->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
button_instance->set_icon(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")));
button_create_script->set_icon(get_theme_icon(SNAME("ScriptCreate"), SNAME("EditorIcons")));
@ -2694,7 +2696,6 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
menu->add_icon_shortcut(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
menu->add_icon_shortcut(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANTIATE);
}
menu->add_icon_shortcut(get_theme_icon(SNAME("Collapse"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/expand_collapse_all"), TOOL_EXPAND_COLLAPSE);
menu->add_separator();
existing_script = selected->get_script();
@ -2832,6 +2833,18 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
menu->popup();
}
void SceneTreeDock::_open_tree_menu() {
menu->clear();
menu->add_icon_shortcut(get_theme_icon(SNAME("Collapse"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/expand_collapse_all"), TOOL_EXPAND_COLLAPSE);
menu->add_check_item(TTR("Auto Expand to Selected"), TOOL_AUTO_EXPAND);
menu->set_item_checked(menu->get_item_idx_from_text(TTR("Auto Expand to Selected")), EditorSettings::get_singleton()->get("docks/scene_tree/auto_expand_to_selected"));
menu->set_size(Size2(1, 1));
menu->set_position(get_screen_position() + get_local_mouse_position());
menu->popup();
}
void SceneTreeDock::_filter_changed(const String &p_filter) {
scene_tree->set_filter(p_filter);
}
@ -3271,6 +3284,11 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
filter_hbc->add_child(button_detach_script);
button_detach_script->hide();
button_tree_menu = memnew(Button);
button_tree_menu->set_flat(true);
button_tree_menu->connect("pressed", callable_mp(this, &SceneTreeDock::_open_tree_menu));
filter_hbc->add_child(button_tree_menu);
button_hb = memnew(HBoxContainer);
vbc->add_child(button_hb);

View File

@ -81,6 +81,7 @@ class SceneTreeDock : public VBoxContainer {
TOOL_COPY_NODE_PATH,
TOOL_BUTTON_MAX,
TOOL_OPEN_DOCUMENTATION,
TOOL_AUTO_EXPAND,
TOOL_SCENE_EDITABLE_CHILDREN,
TOOL_SCENE_USE_PLACEHOLDER,
TOOL_SCENE_MAKE_LOCAL,
@ -115,6 +116,7 @@ class SceneTreeDock : public VBoxContainer {
Button *button_instance;
Button *button_create_script;
Button *button_detach_script;
Button *button_tree_menu;
Button *button_2d;
Button *button_3d;
@ -237,6 +239,7 @@ class SceneTreeDock : public VBoxContainer {
void _quick_open();
void _tree_rmb(const Vector2 &p_menu_pos);
void _open_tree_menu();
void _filter_changed(const String &p_filter);

View File

@ -737,17 +737,18 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : nullptr;
if (item) {
// make visible when it's collapsed
TreeItem *node = item->get_parent();
while (node && node != tree->get_root()) {
node->set_collapsed(false);
node = node->get_parent();
if (auto_expand_selected) {
// Make visible when it's collapsed.
TreeItem *node = item->get_parent();
while (node && node != tree->get_root()) {
node->set_collapsed(false);
node = node->get_parent();
}
item->select(0);
item->set_as_cursor(0);
selected = p_node;
tree->ensure_cursor_is_visible();
}
item->select(0);
item->set_as_cursor(0);
selected = p_node;
tree->ensure_cursor_is_visible();
} else {
if (!p_node) {
selected = nullptr;
@ -1127,11 +1128,19 @@ void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) {
void SceneTreeEditor::update_warning() {
_warning_changed(nullptr);
}
void SceneTreeEditor::_warning_changed(Node *p_for_node) {
//should use a timer
update_timer->start();
}
void SceneTreeEditor::set_auto_expand_selected(bool p_auto, bool p_update_settings) {
if (p_update_settings) {
EditorSettings::get_singleton()->set("docks/scene_tree/auto_expand_to_selected", p_auto);
}
auto_expand_selected = p_auto;
}
void SceneTreeEditor::set_connect_to_script_mode(bool p_enable) {
connect_to_script_mode = p_enable;
update_tree();

View File

@ -64,6 +64,7 @@ class SceneTreeEditor : public Control {
AcceptDialog *error;
AcceptDialog *warning;
bool auto_expand_selected = true;
bool connect_to_script_mode;
bool connecting_signal;
@ -152,6 +153,7 @@ public:
void update_tree() { _update_tree(); }
void set_auto_expand_selected(bool p_auto, bool p_update_settings);
void set_connect_to_script_mode(bool p_enable);
void set_connecting_signal(bool p_enable);