mirror of
https://github.com/godotengine/godot.git
synced 2025-11-01 14:11:15 +00:00
Merge pull request #106923 from timothyqiu/category-created-equal
Improve `EditorInspectorCategory`
This commit is contained in:
commit
d724ff20d8
3 changed files with 117 additions and 87 deletions
|
|
@ -48,7 +48,6 @@
|
|||
#include "editor/multi_node_edit.h"
|
||||
#include "editor/plugins/script_editor_plugin.h"
|
||||
#include "editor/themes/editor_scale.h"
|
||||
#include "editor/themes/editor_theme_manager.h"
|
||||
#include "scene/gui/margin_container.h"
|
||||
#include "scene/gui/separator.h"
|
||||
#include "scene/gui/spin_box.h"
|
||||
|
|
@ -1554,6 +1553,17 @@ void EditorInspectorPlugin::_bind_methods() {
|
|||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
|
||||
static Ref<Script> _get_category_script(const PropertyInfo &p_info) {
|
||||
if (!p_info.hint_string.is_empty() && !EditorNode::get_editor_data().is_type_recognized(p_info.name) && ResourceLoader::exists(p_info.hint_string, "Script")) {
|
||||
return ResourceLoader::load(p_info.hint_string, "Script");
|
||||
}
|
||||
return Ref<Script>();
|
||||
}
|
||||
|
||||
void EditorInspectorCategory::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("unfavorite_all"));
|
||||
}
|
||||
|
||||
void EditorInspectorCategory::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
|
||||
|
|
@ -1570,14 +1580,17 @@ void EditorInspectorCategory::_notification(int p_what) {
|
|||
} break;
|
||||
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
if (menu) {
|
||||
if (is_favorite) {
|
||||
menu->set_item_icon(menu->get_item_index(EditorInspector::MENU_UNFAVORITE_ALL), get_editor_theme_icon(SNAME("Unfavorite")));
|
||||
} else {
|
||||
menu->set_item_icon(menu->get_item_index(MENU_OPEN_DOCS), get_editor_theme_icon(SNAME("Help")));
|
||||
}
|
||||
}
|
||||
menu_icon_dirty = true;
|
||||
_update_icon();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_TRANSLATION_CHANGED: {
|
||||
if (is_favorite) {
|
||||
label = TTR("Favorites");
|
||||
}
|
||||
queue_accessibility_update();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_DRAW: {
|
||||
Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg"));
|
||||
|
||||
|
|
@ -1623,19 +1636,7 @@ void EditorInspectorCategory::_notification(int p_what) {
|
|||
}
|
||||
|
||||
void EditorInspectorCategory::_accessibility_action_menu(const Variant &p_data) {
|
||||
if (!is_favorite) {
|
||||
if (!menu) {
|
||||
menu = memnew(PopupMenu);
|
||||
menu->add_icon_item(get_editor_theme_icon(SNAME("Help")), TTR("Open Documentation"), MENU_OPEN_DOCS);
|
||||
add_child(menu);
|
||||
menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorInspectorCategory::_handle_menu_option));
|
||||
}
|
||||
menu->set_item_disabled(menu->get_item_index(MENU_OPEN_DOCS), !EditorHelp::get_doc_data()->class_list.has(doc_class_name));
|
||||
}
|
||||
|
||||
menu->set_position(get_screen_position());
|
||||
menu->reset_size();
|
||||
menu->popup();
|
||||
_popup_context_menu(get_screen_position());
|
||||
}
|
||||
|
||||
Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) const {
|
||||
|
|
@ -1647,13 +1648,29 @@ Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) cons
|
|||
return EditorHelpBitTooltip::show_tooltip(const_cast<EditorInspectorCategory *>(this), p_text);
|
||||
}
|
||||
|
||||
void EditorInspectorCategory::set_as_favorite(EditorInspector *p_for_inspector) {
|
||||
void EditorInspectorCategory::set_as_favorite() {
|
||||
is_favorite = true;
|
||||
_update_icon();
|
||||
}
|
||||
|
||||
menu = memnew(PopupMenu);
|
||||
menu->add_item(TTR("Unfavorite All"), EditorInspector::MENU_UNFAVORITE_ALL);
|
||||
add_child(menu);
|
||||
menu->connect(SceneStringName(id_pressed), callable_mp(p_for_inspector, &EditorInspector::_handle_menu_option));
|
||||
void EditorInspectorCategory::set_property_info(const PropertyInfo &p_info) {
|
||||
info = p_info;
|
||||
|
||||
Ref<Script> scr = _get_category_script(info);
|
||||
if (scr.is_valid()) {
|
||||
StringName script_name = EditorNode::get_editor_data().script_class_get_name(scr->get_path());
|
||||
if (script_name != StringName()) {
|
||||
label = script_name;
|
||||
}
|
||||
}
|
||||
if (label.is_empty()) {
|
||||
label = info.name;
|
||||
}
|
||||
_update_icon();
|
||||
}
|
||||
|
||||
void EditorInspectorCategory::set_doc_class_name(const String &p_name) {
|
||||
doc_class_name = p_name;
|
||||
}
|
||||
|
||||
Size2 EditorInspectorCategory::get_minimum_size() const {
|
||||
|
|
@ -1676,36 +1693,77 @@ Size2 EditorInspectorCategory::get_minimum_size() const {
|
|||
|
||||
void EditorInspectorCategory::_handle_menu_option(int p_option) {
|
||||
switch (p_option) {
|
||||
case MENU_OPEN_DOCS:
|
||||
case MENU_OPEN_DOCS: {
|
||||
ScriptEditor::get_singleton()->goto_help("class:" + doc_class_name);
|
||||
EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
|
||||
break;
|
||||
} break;
|
||||
|
||||
case MENU_UNFAVORITE_ALL: {
|
||||
emit_signal(SNAME("unfavorite_all"));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInspectorCategory::gui_input(const Ref<InputEvent> &p_event) {
|
||||
void EditorInspectorCategory::_popup_context_menu(const Point2i &p_position) {
|
||||
if (!is_favorite && doc_class_name.is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Ref<InputEventMouseButton> &mb_event = p_event;
|
||||
if (mb_event.is_null() || !mb_event->is_pressed() || mb_event->get_button_index() != MouseButton::RIGHT) {
|
||||
if (menu == nullptr) {
|
||||
menu = memnew(PopupMenu);
|
||||
|
||||
if (is_favorite) {
|
||||
menu->add_item(TTRC("Unfavorite All"), MENU_UNFAVORITE_ALL);
|
||||
} else {
|
||||
menu->add_item(TTRC("Open Documentation"), MENU_OPEN_DOCS);
|
||||
menu->set_item_disabled(-1, !EditorHelp::get_doc_data()->class_list.has(doc_class_name));
|
||||
}
|
||||
|
||||
menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorInspectorCategory::_handle_menu_option));
|
||||
add_child(menu);
|
||||
}
|
||||
|
||||
if (menu_icon_dirty) {
|
||||
if (is_favorite) {
|
||||
menu->set_item_icon(menu->get_item_index(MENU_UNFAVORITE_ALL), get_editor_theme_icon(SNAME("Unfavorite")));
|
||||
} else {
|
||||
menu->set_item_icon(menu->get_item_index(MENU_OPEN_DOCS), get_editor_theme_icon(SNAME("Help")));
|
||||
}
|
||||
menu_icon_dirty = false;
|
||||
}
|
||||
|
||||
menu->set_position(p_position);
|
||||
menu->reset_size();
|
||||
menu->popup();
|
||||
}
|
||||
|
||||
void EditorInspectorCategory::_update_icon() {
|
||||
if (is_favorite) {
|
||||
icon = get_editor_theme_icon(SNAME("Favorites"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_favorite) {
|
||||
if (!menu) {
|
||||
menu = memnew(PopupMenu);
|
||||
menu->add_icon_item(get_editor_theme_icon(SNAME("Help")), TTR("Open Documentation"), MENU_OPEN_DOCS);
|
||||
add_child(menu);
|
||||
menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorInspectorCategory::_handle_menu_option));
|
||||
icon = Ref<Texture2D>();
|
||||
|
||||
Ref<Script> scr = _get_category_script(info);
|
||||
if (scr.is_valid()) {
|
||||
StringName script_name = EditorNode::get_editor_data().script_class_get_name(scr->get_path());
|
||||
if (script_name == StringName()) {
|
||||
icon = EditorNode::get_singleton()->get_object_icon(scr.ptr(), "Object");
|
||||
} else {
|
||||
icon = EditorNode::get_singleton()->get_class_icon(script_name);
|
||||
}
|
||||
}
|
||||
if (icon.is_null() && !info.name.is_empty()) {
|
||||
icon = EditorNode::get_singleton()->get_class_icon(info.name);
|
||||
}
|
||||
menu->set_item_disabled(menu->get_item_index(MENU_OPEN_DOCS), !EditorHelp::get_doc_data()->class_list.has(doc_class_name));
|
||||
}
|
||||
|
||||
menu->set_position(get_screen_position() + mb_event->get_position());
|
||||
menu->reset_size();
|
||||
menu->popup();
|
||||
void EditorInspectorCategory::gui_input(const Ref<InputEvent> &p_event) {
|
||||
const Ref<InputEventMouseButton> &mb = p_event;
|
||||
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
|
||||
_popup_context_menu(get_screen_position() + mb->get_position());
|
||||
}
|
||||
}
|
||||
|
||||
EditorInspectorCategory::EditorInspectorCategory() {
|
||||
|
|
@ -3614,17 +3672,13 @@ void EditorInspector::update_tree() {
|
|||
continue; // Empty, ignore it.
|
||||
}
|
||||
|
||||
String category_label;
|
||||
String category_tooltip;
|
||||
Ref<Texture> category_icon;
|
||||
|
||||
// Do not add an icon, do not change the current class (`doc_name`) for custom categories.
|
||||
if (is_custom_category) {
|
||||
category_label = p.name;
|
||||
category_tooltip = p.name;
|
||||
} else {
|
||||
doc_name = p.name;
|
||||
category_label = p.name;
|
||||
|
||||
// Use category's owner script to update some of its information.
|
||||
if (!EditorNode::get_editor_data().is_type_recognized(p.name) && ResourceLoader::exists(p.hint_string, "Script")) {
|
||||
|
|
@ -3632,14 +3686,6 @@ void EditorInspector::update_tree() {
|
|||
if (scr.is_valid()) {
|
||||
doc_name = scr->get_doc_class_name();
|
||||
|
||||
StringName script_name = EditorNode::get_editor_data().script_class_get_name(scr->get_path());
|
||||
if (script_name != StringName()) {
|
||||
category_label = script_name;
|
||||
category_icon = EditorNode::get_singleton()->get_class_icon(script_name);
|
||||
} else {
|
||||
category_icon = EditorNode::get_singleton()->get_object_icon(scr.ptr(), "Object");
|
||||
}
|
||||
|
||||
// Property favorites aren't compatible with built-in scripts.
|
||||
if (scr->is_built_in()) {
|
||||
disable_favorite = true;
|
||||
|
|
@ -3647,10 +3693,6 @@ void EditorInspector::update_tree() {
|
|||
}
|
||||
}
|
||||
|
||||
if (category_icon.is_null() && !p.name.is_empty()) {
|
||||
category_icon = EditorNode::get_singleton()->get_class_icon(p.name);
|
||||
}
|
||||
|
||||
if (use_doc_hints) {
|
||||
// `|` separators used in `EditorHelpBit`.
|
||||
category_tooltip = "class|" + doc_name + "|";
|
||||
|
|
@ -3668,15 +3710,14 @@ void EditorInspector::update_tree() {
|
|||
|
||||
// Create an EditorInspectorCategory and add it to the inspector.
|
||||
EditorInspectorCategory *category = memnew(EditorInspectorCategory);
|
||||
category->set_property_info(p);
|
||||
main_vbox->add_child(category);
|
||||
category_vbox = nullptr; // Reset.
|
||||
|
||||
// Set the category info.
|
||||
category->label = category_label;
|
||||
category->set_tooltip_text(category_tooltip);
|
||||
category->icon = category_icon;
|
||||
if (!is_custom_category) {
|
||||
category->doc_class_name = doc_name;
|
||||
category->set_doc_class_name(doc_name);
|
||||
}
|
||||
|
||||
// Add editors at the start of a category.
|
||||
|
|
@ -5239,8 +5280,6 @@ void EditorInspector::_notification(int p_what) {
|
|||
break;
|
||||
}
|
||||
|
||||
favorites_category->icon = get_editor_theme_icon(SNAME("Favorites"));
|
||||
|
||||
int separation = get_theme_constant(SNAME("v_separation"), SNAME("EditorInspector"));
|
||||
base_vbox->add_theme_constant_override("separation", separation);
|
||||
begin_vbox->add_theme_constant_override("separation", separation);
|
||||
|
|
@ -5425,14 +5464,6 @@ void EditorInspector::_add_meta_confirm() {
|
|||
undo_redo->commit_action();
|
||||
}
|
||||
|
||||
void EditorInspector::_handle_menu_option(int p_option) {
|
||||
switch (p_option) {
|
||||
case MENU_UNFAVORITE_ALL:
|
||||
_clear_current_favorites();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInspector::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("edit", "object"), &EditorInspector::edit);
|
||||
ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change);
|
||||
|
|
@ -5467,10 +5498,10 @@ EditorInspector::EditorInspector() {
|
|||
base_vbox->add_child(favorites_section);
|
||||
favorites_section->hide();
|
||||
|
||||
favorites_category = memnew(EditorInspectorCategory);
|
||||
favorites_category->set_as_favorite(this);
|
||||
EditorInspectorCategory *favorites_category = memnew(EditorInspectorCategory);
|
||||
favorites_category->set_as_favorite();
|
||||
favorites_category->connect("unfavorite_all", callable_mp(this, &EditorInspector::_clear_current_favorites));
|
||||
favorites_section->add_child(favorites_category);
|
||||
favorites_category->label = TTR("Favorites");
|
||||
|
||||
favorites_vbox = memnew(VBoxContainer);
|
||||
favorites_section->add_child(favorites_vbox);
|
||||
|
|
|
|||
|
|
@ -303,29 +303,36 @@ public:
|
|||
class EditorInspectorCategory : public Control {
|
||||
GDCLASS(EditorInspectorCategory, Control);
|
||||
|
||||
friend class EditorInspector;
|
||||
|
||||
// Right-click context menu options.
|
||||
enum ClassMenuOption {
|
||||
MENU_OPEN_DOCS,
|
||||
MENU_UNFAVORITE_ALL,
|
||||
};
|
||||
|
||||
PropertyInfo info;
|
||||
Ref<Texture2D> icon;
|
||||
String label;
|
||||
String doc_class_name;
|
||||
PopupMenu *menu = nullptr;
|
||||
bool is_favorite = false;
|
||||
bool menu_icon_dirty = true;
|
||||
|
||||
void _handle_menu_option(int p_option);
|
||||
void _popup_context_menu(const Point2i &p_position);
|
||||
void _update_icon();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
void _notification(int p_what);
|
||||
virtual void gui_input(const Ref<InputEvent> &p_event) override;
|
||||
|
||||
void _accessibility_action_menu(const Variant &p_data);
|
||||
|
||||
public:
|
||||
void set_as_favorite(EditorInspector *p_for_inspector);
|
||||
void set_as_favorite();
|
||||
void set_property_info(const PropertyInfo &p_info);
|
||||
void set_doc_class_name(const String &p_name);
|
||||
|
||||
virtual Size2 get_minimum_size() const override;
|
||||
virtual Control *make_custom_tooltip(const String &p_text) const override;
|
||||
|
|
@ -555,7 +562,6 @@ public:
|
|||
class EditorInspector : public ScrollContainer {
|
||||
GDCLASS(EditorInspector, ScrollContainer);
|
||||
|
||||
friend class EditorInspectorCategory;
|
||||
friend class EditorPropertyResource;
|
||||
|
||||
enum {
|
||||
|
|
@ -564,15 +570,9 @@ class EditorInspector : public ScrollContainer {
|
|||
static Ref<EditorInspectorPlugin> inspector_plugins[MAX_PLUGINS];
|
||||
static int inspector_plugin_count;
|
||||
|
||||
// Right-click context menu options.
|
||||
enum ClassMenuOption {
|
||||
MENU_UNFAVORITE_ALL,
|
||||
};
|
||||
|
||||
bool can_favorite = false;
|
||||
PackedStringArray current_favorites;
|
||||
VBoxContainer *favorites_section = nullptr;
|
||||
EditorInspectorCategory *favorites_category = nullptr;
|
||||
VBoxContainer *favorites_vbox = nullptr;
|
||||
VBoxContainer *favorites_groups_vbox = nullptr;
|
||||
HSeparator *favorites_separator = nullptr;
|
||||
|
|
@ -687,8 +687,6 @@ class EditorInspector : public ScrollContainer {
|
|||
void _add_meta_confirm();
|
||||
void _show_add_meta_dialog();
|
||||
|
||||
void _handle_menu_option(int p_option);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
|
|
|
|||
|
|
@ -938,6 +938,7 @@ void EditorNode::_notification(int p_what) {
|
|||
use_system_accent_color = EDITOR_GET("interface/theme/use_system_accent_color");
|
||||
|
||||
if (EditorThemeManager::is_generated_theme_outdated()) {
|
||||
class_icon_cache.clear();
|
||||
_update_theme();
|
||||
_build_icon_type_cache();
|
||||
recent_scenes->reset_size();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue