Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show valid types in SceneTreeDialog #79593

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,7 @@ void EditorPropertyNodePath::_node_assign() {
if (!scene_tree) {
scene_tree = memnew(SceneTreeDialog);
scene_tree->get_scene_tree()->set_show_enabled_subscene(true);
scene_tree->get_scene_tree()->set_valid_types(valid_types);
scene_tree->set_valid_types(valid_types);
add_child(scene_tree);
scene_tree->connect("selected", callable_mp(this, &EditorPropertyNodePath::_node_selected));
}
Expand Down Expand Up @@ -3145,7 +3145,7 @@ void EditorPropertyResource::_resource_changed(const Ref<Resource> &p_resource)

Vector<StringName> valid_types;
valid_types.push_back("Viewport");
scene_tree->get_scene_tree()->set_valid_types(valid_types);
scene_tree->set_valid_types(valid_types);
scene_tree->get_scene_tree()->set_show_enabled_subscene(true);

add_child(scene_tree);
Expand Down
52 changes: 48 additions & 4 deletions editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "editor/plugins/animation_player_editor_plugin.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#include "editor/plugins/script_editor_plugin.h"
#include "scene/gui/flow_container.h"
#include "scene/gui/label.h"
#include "scene/gui/tab_container.h"
#include "scene/gui/texture_rect.h"
Expand Down Expand Up @@ -1493,8 +1494,51 @@ void SceneTreeDialog::popup_scenetree_dialog() {
popup_centered_clamped(Size2(350, 700) * EDSCALE);
}

void SceneTreeDialog::set_valid_types(const Vector<StringName> &p_valid) {
if (p_valid.is_empty()) {
return;
}

tree->set_valid_types(p_valid);

HBoxContainer *hbox = memnew(HBoxContainer);
content->add_child(hbox);
content->move_child(hbox, 0);

{
Label *label = memnew(Label);
hbox->add_child(label);
label->set_text(TTR("Allowed:"));
}

HFlowContainer *hflow = memnew(HFlowContainer);
hbox->add_child(hflow);
hflow->set_h_size_flags(Control::SIZE_EXPAND_FILL);

for (const StringName &type : p_valid) {
HBoxContainer *hb = memnew(HBoxContainer);
hflow->add_child(hb);

TextureRect *trect = memnew(TextureRect);
hb->add_child(trect);
trect->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE);
trect->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
trect->set_meta("type", type);
valid_type_icons.push_back(trect);

Label *label = memnew(Label);
hb->add_child(label);
label->set_text(type);
label->set_auto_translate(false);
}
}

void SceneTreeDialog::_update_theme() {
filter->set_right_icon(tree->get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
for (TextureRect *trect : valid_type_icons) {
trect->set_custom_minimum_size(Vector2(get_theme_constant(SNAME("class_icon_size"), SNAME("Editor")), 0));
trect->set_texture(EditorNode::get_singleton()->get_class_icon(trect->get_meta("type")));
}
}

void SceneTreeDialog::_notification(int p_what) {
Expand Down Expand Up @@ -1551,21 +1595,21 @@ void SceneTreeDialog::_bind_methods() {

SceneTreeDialog::SceneTreeDialog() {
set_title(TTR("Select a Node"));
VBoxContainer *vbc = memnew(VBoxContainer);
add_child(vbc);
content = memnew(VBoxContainer);
add_child(content);

filter = memnew(LineEdit);
filter->set_h_size_flags(Control::SIZE_EXPAND_FILL);
filter->set_placeholder(TTR("Filter Nodes"));
filter->set_clear_button_enabled(true);
filter->add_theme_constant_override("minimum_character_width", 0);
filter->connect("text_changed", callable_mp(this, &SceneTreeDialog::_filter_changed));
vbc->add_child(filter);
content->add_child(filter);

tree = memnew(SceneTreeEditor(false, false, true));
tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
tree->get_scene_tree()->connect("item_activated", callable_mp(this, &SceneTreeDialog::_select));
vbc->add_child(tree);
content->add_child(tree);

// Disable the OK button when no node is selected.
get_ok_button()->set_disabled(!tree->get_selected());
Expand Down
8 changes: 6 additions & 2 deletions editor/gui/scene_tree_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "scene/gui/tree.h"

class EditorSelection;
class TextureRect;

class SceneTreeEditor : public Control {
GDCLASS(SceneTreeEditor, Control);
Expand Down Expand Up @@ -172,10 +173,10 @@ class SceneTreeEditor : public Control {
class SceneTreeDialog : public ConfirmationDialog {
GDCLASS(SceneTreeDialog, ConfirmationDialog);

VBoxContainer *content = nullptr;
SceneTreeEditor *tree = nullptr;
//Button *select;
//Button *cancel;
LineEdit *filter = nullptr;
LocalVector<TextureRect *> valid_type_icons;

void _select();
void _cancel();
Expand All @@ -189,8 +190,11 @@ class SceneTreeDialog : public ConfirmationDialog {

public:
void popup_scenetree_dialog();
void set_valid_types(const Vector<StringName> &p_valid);

SceneTreeEditor *get_scene_tree() { return tree; }
LineEdit *get_filter_line_edit() { return filter; }

SceneTreeDialog();
~SceneTreeDialog();
};
Expand Down