Make several actions in the Inspector dock more obvious

This commit is contained in:
Yuri Sizov 2021-07-16 23:27:00 +03:00
parent 4d3c11e85e
commit 47592f96bc
4 changed files with 163 additions and 58 deletions

View file

@ -59,15 +59,39 @@ void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) {
Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj); Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj);
int index = get_popup()->get_item_count(); String proper_name = "";
get_popup()->add_icon_item(icon, E->get().name.capitalize(), objects.size()); Vector<String> name_parts = E->get().name.split("/");
get_popup()->set_item_h_offset(index, p_depth * 10 * EDSCALE);
for (int i = 0; i < name_parts.size(); i++) {
if (i > 0) {
proper_name += " > ";
}
proper_name += name_parts[i].capitalize();
}
int index = sub_objects_menu->get_item_count();
sub_objects_menu->add_icon_item(icon, proper_name, objects.size());
sub_objects_menu->set_item_h_offset(index, p_depth * 10 * EDSCALE);
objects.push_back(obj->get_instance_id()); objects.push_back(obj->get_instance_id());
_add_children_to_popup(obj, p_depth + 1); _add_children_to_popup(obj, p_depth + 1);
} }
} }
void EditorPath::_show_popup() {
sub_objects_menu->clear();
Size2 size = get_size();
Point2 gp = get_global_position();
gp.y += size.y;
sub_objects_menu->set_position(gp);
sub_objects_menu->set_size(Size2(size.width, 1));
sub_objects_menu->set_parent_rect(Rect2(Point2(gp - sub_objects_menu->get_position()), size));
sub_objects_menu->popup();
}
void EditorPath::_about_to_show() { void EditorPath::_about_to_show() {
Object *obj = ObjectDB::get_instance(history->get_path_object(history->get_path_size() - 1)); Object *obj = ObjectDB::get_instance(history->get_path_object(history->get_path_size() - 1));
if (!obj) { if (!obj) {
@ -75,13 +99,11 @@ void EditorPath::_about_to_show() {
} }
objects.clear(); objects.clear();
get_popup()->clear();
get_popup()->set_size(Size2(get_size().width, 1));
_add_children_to_popup(obj); _add_children_to_popup(obj);
if (get_popup()->get_item_count() == 0) { if (sub_objects_menu->get_item_count() == 0) {
get_popup()->add_item(TTR("No sub-resources found.")); sub_objects_menu->add_item(TTR("No sub-resources found."));
get_popup()->set_item_disabled(0, true); sub_objects_menu->set_item_disabled(0, true);
} }
} }
@ -94,7 +116,7 @@ void EditorPath::update_path() {
Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj); Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj);
if (icon.is_valid()) { if (icon.is_valid()) {
set_icon(icon); current_object_icon->set_texture(icon);
} }
if (i == history->get_path_size() - 1) { if (i == history->get_path_size() - 1) {
@ -120,12 +142,26 @@ void EditorPath::update_path() {
name = obj->get_class(); name = obj->get_class();
} }
set_text(" " + name); // An extra space so the text is not too close of the icon. current_object_label->set_text(" " + name); // An extra space so the text is not too close of the icon.
set_tooltip(obj->get_class()); set_tooltip(obj->get_class());
} }
} }
} }
void EditorPath::clear_path() {
set_disabled(true);
set_tooltip("");
current_object_label->set_text("");
current_object_icon->set_texture(nullptr);
sub_objects_icon->set_visible(false);
}
void EditorPath::enable_path() {
set_disabled(false);
sub_objects_icon->set_visible(true);
}
void EditorPath::_id_pressed(int p_idx) { void EditorPath::_id_pressed(int p_idx) {
ERR_FAIL_INDEX(p_idx, objects.size()); ERR_FAIL_INDEX(p_idx, objects.size());
@ -139,21 +175,59 @@ void EditorPath::_id_pressed(int p_idx) {
void EditorPath::_notification(int p_what) { void EditorPath::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
update_path(); update_path();
// Button overrides Control's method, so we have to improvise.
sub_objects_icon->set_texture(sub_objects_icon->get_icon("select_arrow", "Tree"));
current_object_label->add_font_override("font", get_font("main", "EditorFonts"));
} break;
case NOTIFICATION_READY: {
connect("pressed", this, "_show_popup");
} break; } break;
} }
} }
void EditorPath::_bind_methods() { void EditorPath::_bind_methods() {
ClassDB::bind_method("_show_popup", &EditorPath::_show_popup);
ClassDB::bind_method("_about_to_show", &EditorPath::_about_to_show); ClassDB::bind_method("_about_to_show", &EditorPath::_about_to_show);
ClassDB::bind_method("_id_pressed", &EditorPath::_id_pressed); ClassDB::bind_method("_id_pressed", &EditorPath::_id_pressed);
} }
EditorPath::EditorPath(EditorHistory *p_history) { EditorPath::EditorPath(EditorHistory *p_history) {
history = p_history; history = p_history;
set_clip_text(true);
set_text_align(ALIGN_LEFT); MarginContainer *main_mc = memnew(MarginContainer);
get_popup()->connect("about_to_show", this, "_about_to_show"); main_mc->set_anchors_and_margins_preset(PRESET_WIDE);
get_popup()->connect("id_pressed", this, "_id_pressed"); main_mc->add_constant_override("margin_left", 4 * EDSCALE);
main_mc->add_constant_override("margin_right", 6 * EDSCALE);
main_mc->set_mouse_filter(MOUSE_FILTER_PASS);
add_child(main_mc);
HBoxContainer *main_hb = memnew(HBoxContainer);
main_mc->add_child(main_hb);
current_object_icon = memnew(TextureRect);
current_object_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
main_hb->add_child(current_object_icon);
current_object_label = memnew(Label);
current_object_label->set_clip_text(true);
current_object_label->set_align(Label::ALIGN_LEFT);
current_object_label->set_h_size_flags(SIZE_EXPAND_FILL);
main_hb->add_child(current_object_label);
sub_objects_icon = memnew(TextureRect);
sub_objects_icon->set_visible(false);
sub_objects_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
main_hb->add_child(sub_objects_icon);
sub_objects_menu = memnew(PopupMenu);
add_child(sub_objects_menu);
sub_objects_menu->connect("about_to_show", this, "_about_to_show");
sub_objects_menu->connect("id_pressed", this, "_id_pressed");
set_tooltip(TTR("Open a list of sub-resources."));
} }

View file

@ -32,16 +32,24 @@
#define EDITOR_PATH_H #define EDITOR_PATH_H
#include "editor_data.h" #include "editor_data.h"
#include "scene/gui/menu_button.h" #include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/popup_menu.h"
class EditorPath : public MenuButton { class EditorPath : public Button {
GDCLASS(EditorPath, MenuButton); GDCLASS(EditorPath, Button);
EditorHistory *history; EditorHistory *history;
TextureRect *current_object_icon;
Label *current_object_label;
TextureRect *sub_objects_icon;
PopupMenu *sub_objects_menu;
Vector<ObjectID> objects; Vector<ObjectID> objects;
EditorPath(); EditorPath();
void _show_popup();
void _id_pressed(int p_idx); void _id_pressed(int p_idx);
void _about_to_show(); void _about_to_show();
void _add_children_to_popup(Object *p_obj, int p_depth = 0); void _add_children_to_popup(Object *p_obj, int p_depth = 0);
@ -52,6 +60,8 @@ protected:
public: public:
void update_path(); void update_path();
void clear_path();
void enable_path();
EditorPath(EditorHistory *p_history); EditorPath(EditorHistory *p_history);
}; };

View file

@ -42,6 +42,14 @@ void InspectorDock::_menu_option(int p_option) {
case COLLAPSE_ALL: { case COLLAPSE_ALL: {
_menu_collapseall(); _menu_collapseall();
} break; } break;
case RESOURCE_SAVE: {
_save_resource(false);
} break;
case RESOURCE_SAVE_AS: {
_save_resource(true);
} break;
case RESOURCE_MAKE_BUILT_IN: { case RESOURCE_MAKE_BUILT_IN: {
_unref_resource(); _unref_resource();
} break; } break;
@ -52,13 +60,6 @@ void InspectorDock::_menu_option(int p_option) {
_paste_resource(); _paste_resource();
} break; } break;
case RESOURCE_SAVE: {
_save_resource(false);
} break;
case RESOURCE_SAVE_AS: {
_save_resource(true);
} break;
case OBJECT_REQUEST_HELP: { case OBJECT_REQUEST_HELP: {
if (current) { if (current) {
editor->set_visible_editor(EditorNode::EDITOR_SCRIPT); editor->set_visible_editor(EditorNode::EDITOR_SCRIPT);
@ -332,11 +333,19 @@ void InspectorDock::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
set_theme(editor->get_gui_base()->get_theme()); set_theme(editor->get_gui_base()->get_theme());
resource_new_button->set_icon(get_icon("New", "EditorIcons")); resource_new_button->set_icon(get_icon("New", "EditorIcons"));
resource_load_button->set_icon(get_icon("Load", "EditorIcons")); resource_load_button->set_icon(get_icon("Load", "EditorIcons"));
resource_save_button->set_icon(get_icon("Save", "EditorIcons")); resource_save_button->set_icon(get_icon("Save", "EditorIcons"));
resource_extra_button->set_icon(get_icon("GuiTabMenu", "EditorIcons"));
PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), get_icon("ActionPaste", "EditorIcons"));
resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_COPY), get_icon("ActionCopy", "EditorIcons"));
backward_button->set_icon(get_icon("Back", "EditorIcons")); backward_button->set_icon(get_icon("Back", "EditorIcons"));
forward_button->set_icon(get_icon("Forward", "EditorIcons")); forward_button->set_icon(get_icon("Forward", "EditorIcons"));
history_menu->set_icon(get_icon("History", "EditorIcons")); history_menu->set_icon(get_icon("History", "EditorIcons"));
object_menu->set_icon(get_icon("Tools", "EditorIcons")); object_menu->set_icon(get_icon("Tools", "EditorIcons"));
warning->set_icon(get_icon("NodeWarning", "EditorIcons")); warning->set_icon(get_icon("NodeWarning", "EditorIcons"));
@ -408,12 +417,7 @@ void InspectorDock::update(Object *p_object) {
object_menu->set_disabled(true); object_menu->set_disabled(true);
warning->hide(); warning->hide();
search->set_editable(false); search->set_editable(false);
editor_path->clear_path();
editor_path->set_disabled(true);
editor_path->set_text("");
editor_path->set_tooltip("");
editor_path->set_icon(nullptr);
return; return;
} }
@ -422,35 +426,28 @@ void InspectorDock::update(Object *p_object) {
object_menu->set_disabled(false); object_menu->set_disabled(false);
search->set_editable(true); search->set_editable(true);
editor_path->set_disabled(false); editor_path->enable_path();
resource_save_button->set_disabled(!is_resource); resource_save_button->set_disabled(!is_resource);
open_docs_button->set_visible(is_resource || is_node);
PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource);
resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_MAKE_BUILT_IN), !is_resource);
PopupMenu *p = object_menu->get_popup(); PopupMenu *p = object_menu->get_popup();
p->clear(); p->clear();
p->add_shortcut(ED_SHORTCUT("property_editor/expand_all", TTR("Expand All Properties")), EXPAND_ALL); p->add_icon_shortcut(get_icon("GuiTreeArrowDown", "EditorIcons"), ED_SHORTCUT("property_editor/expand_all", TTR("Expand All")), EXPAND_ALL);
p->add_shortcut(ED_SHORTCUT("property_editor/collapse_all", TTR("Collapse All Properties")), COLLAPSE_ALL); p->add_icon_shortcut(get_icon("GuiTreeArrowRight", "EditorIcons"), ED_SHORTCUT("property_editor/collapse_all", TTR("Collapse All")), COLLAPSE_ALL);
p->add_separator();
if (is_resource) {
p->add_item(TTR("Save"), RESOURCE_SAVE);
p->add_item(TTR("Save As..."), RESOURCE_SAVE_AS);
p->add_separator();
}
p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTR("Copy Params")), OBJECT_COPY_PARAMS);
p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTR("Paste Params")), OBJECT_PASTE_PARAMS);
p->add_separator(); p->add_separator();
p->add_shortcut(ED_SHORTCUT("property_editor/paste_resource", TTR("Edit Resource Clipboard")), RESOURCE_EDIT_CLIPBOARD); p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTR("Copy Properties")), OBJECT_COPY_PARAMS);
if (is_resource) { p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTR("Paste Properties")), OBJECT_PASTE_PARAMS);
p->add_shortcut(ED_SHORTCUT("property_editor/copy_resource", TTR("Copy Resource")), RESOURCE_COPY);
p->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTR("Make Built-In")), RESOURCE_MAKE_BUILT_IN);
}
if (is_resource || is_node) { if (is_resource || is_node) {
p->add_separator(); p->add_separator();
p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique", TTR("Make Sub-Resources Unique")), OBJECT_UNIQUE_RESOURCES); p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique", TTR("Make Sub-Resources Unique")), OBJECT_UNIQUE_RESOURCES);
p->add_separator();
p->add_icon_shortcut(get_icon("HelpSearch", "EditorIcons"), ED_SHORTCUT("property_editor/open_help", TTR("Open in Help")), OBJECT_REQUEST_HELP);
} }
List<MethodInfo> methods; List<MethodInfo> methods;
@ -528,6 +525,17 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
resource_save_button->set_focus_mode(Control::FOCUS_NONE); resource_save_button->set_focus_mode(Control::FOCUS_NONE);
resource_save_button->set_disabled(true); resource_save_button->set_disabled(true);
resource_extra_button = memnew(MenuButton);
resource_extra_button->set_icon(get_icon("GuiTabMenu", "EditorIcons"));
general_options_hb->add_child(resource_extra_button);
resource_extra_button->get_popup()->add_icon_shortcut(get_icon("ActionPaste", "EditorIcons"), ED_SHORTCUT("property_editor/paste_resource", TTR("Edit Resource from Clipboard")), RESOURCE_EDIT_CLIPBOARD);
resource_extra_button->get_popup()->add_icon_shortcut(get_icon("ActionCopy", "EditorIcons"), ED_SHORTCUT("property_editor/copy_resource", TTR("Copy Resource")), RESOURCE_COPY);
resource_extra_button->get_popup()->set_item_disabled(1, true);
resource_extra_button->get_popup()->add_separator();
resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTR("Make Resource Built-In")), RESOURCE_MAKE_BUILT_IN);
resource_extra_button->get_popup()->set_item_disabled(3, true);
resource_extra_button->get_popup()->connect("id_pressed", this, "_menu_option");
general_options_hb->add_spacer(); general_options_hb->add_spacer();
backward_button = memnew(ToolButton); backward_button = memnew(ToolButton);
@ -553,30 +561,41 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) {
history_menu->connect("about_to_show", this, "_prepare_history"); history_menu->connect("about_to_show", this, "_prepare_history");
history_menu->get_popup()->connect("id_pressed", this, "_select_history"); history_menu->get_popup()->connect("id_pressed", this, "_select_history");
HBoxContainer *node_info_hb = memnew(HBoxContainer); HBoxContainer *subresource_hb = memnew(HBoxContainer);
add_child(node_info_hb); add_child(subresource_hb);
editor_path = memnew(EditorPath(editor->get_editor_history())); editor_path = memnew(EditorPath(editor->get_editor_history()));
editor_path->set_h_size_flags(Control::SIZE_EXPAND_FILL); editor_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
node_info_hb->add_child(editor_path); subresource_hb->add_child(editor_path);
object_menu = memnew(MenuButton); open_docs_button = memnew(Button);
object_menu->set_icon(get_icon("Tools", "EditorIcons")); open_docs_button->set_flat(true);
node_info_hb->add_child(object_menu); open_docs_button->set_visible(false);
object_menu->set_tooltip(TTR("Object properties.")); open_docs_button->set_tooltip(TTR("Open documentation for this object."));
object_menu->get_popup()->connect("id_pressed", this, "_menu_option"); open_docs_button->set_icon(get_icon("HelpSearch", "EditorIcons"));
open_docs_button->set_shortcut(ED_SHORTCUT("property_editor/open_help", TTR("Open Documentation")));
subresource_hb->add_child(open_docs_button);
open_docs_button->connect("pressed", this, "_menu_option", varray(OBJECT_REQUEST_HELP));
new_resource_dialog = memnew(CreateDialog); new_resource_dialog = memnew(CreateDialog);
editor->get_gui_base()->add_child(new_resource_dialog); editor->get_gui_base()->add_child(new_resource_dialog);
new_resource_dialog->set_base_type("Resource"); new_resource_dialog->set_base_type("Resource");
new_resource_dialog->connect("create", this, "_resource_created"); new_resource_dialog->connect("create", this, "_resource_created");
HBoxContainer *property_tools_hb = memnew(HBoxContainer);
add_child(property_tools_hb);
search = memnew(LineEdit); search = memnew(LineEdit);
search->set_h_size_flags(Control::SIZE_EXPAND_FILL); search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
search->set_placeholder(TTR("Filter properties")); search->set_placeholder(TTR("Filter properties"));
search->set_right_icon(get_icon("Search", "EditorIcons")); search->set_right_icon(get_icon("Search", "EditorIcons"));
search->set_clear_button_enabled(true); search->set_clear_button_enabled(true);
add_child(search); property_tools_hb->add_child(search);
object_menu = memnew(MenuButton);
object_menu->set_icon(get_icon("Tools", "EditorIcons"));
property_tools_hb->add_child(object_menu);
object_menu->set_tooltip(TTR("Manage object properties."));
object_menu->get_popup()->connect("id_pressed", this, "_menu_option");
warning = memnew(Button); warning = memnew(Button);
add_child(warning); add_child(warning);

View file

@ -82,9 +82,11 @@ class InspectorDock : public VBoxContainer {
ToolButton *resource_new_button; ToolButton *resource_new_button;
ToolButton *resource_load_button; ToolButton *resource_load_button;
MenuButton *resource_save_button; MenuButton *resource_save_button;
MenuButton *resource_extra_button;
MenuButton *history_menu; MenuButton *history_menu;
LineEdit *search; LineEdit *search;
Button *open_docs_button;
MenuButton *object_menu; MenuButton *object_menu;
EditorPath *editor_path; EditorPath *editor_path;