From a550eef9f38b87cae03acec8754d004703d43e35 Mon Sep 17 00:00:00 2001
From: Lazy-Rabbit-2001 <2733679597@qq.com>
Date: Mon, 30 Dec 2024 23:18:17 +0800
Subject: [PATCH] Improve script class display in Create dialog
---
doc/classes/EditorInterface.xml | 12 ---------
editor/create_dialog.cpp | 44 +++++++++++++++++++++++----------
editor/create_dialog.h | 4 +--
editor/editor_interface.cpp | 16 ++----------
editor/editor_interface.h | 2 +-
5 files changed, 35 insertions(+), 43 deletions(-)
diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml
index b8b69586fe9..d4acb820232 100644
--- a/doc/classes/EditorInterface.xml
+++ b/doc/classes/EditorInterface.xml
@@ -278,7 +278,6 @@
-
Pops up an editor dialog for creating an object.
The [param callback] must take a single argument of type [StringName] which will contain the type name of the selected object or be empty if no item is selected.
@@ -286,17 +285,6 @@
The [param current_type] will be passed in the search box of the create dialog, and the specified type can be immediately selected when the dialog pops up. If the [param current_type] is not derived from [param base_type], there will be no result of the type in the dialog.
The [param dialog_title] allows you to define a custom title for the dialog. This is useful if you want to accurately hint the usage of the dialog. If the [param dialog_title] is an empty string, the dialog will use "Create New 'Base Type'" as the default title.
The [param type_blocklist] contains a list of type names, and the types in the blocklist will be hidden from the create dialog.
- The [param type_suffixes] is a dictionary, with keys being [StringName]s and values being [String]s. Custom suffixes override the default suffixes which are file names of their scripts. For example, if you set a custom suffix as "Custom Suffix" for a global script type,
- [codeblock lang=text]
- Node
- |- MyCustomNode (my_custom_node.gd)
- [/codeblock]
- will be
- [codeblock lang=text]
- Node
- |- MyCustomNode (Custom Suffix)
- [/codeblock]
- Bear in mind that when a built-in type does not have any custom suffix, its suffix will be removed. The suffix of a type created from a script will fall back to its script file name. For global types by scripts, if you customize their suffixes to an empty string, their suffixes will be removed.
[b]Note:[/b] Trying to list the base type in the [param type_blocklist] will hide all types derived from the base type from the create dialog.
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp
index cd3f9b6c0a0..7f1670bcb64 100644
--- a/editor/create_dialog.cpp
+++ b/editor/create_dialog.cpp
@@ -111,6 +111,24 @@ bool CreateDialog::_is_type_preferred(const String &p_type) const {
return EditorNode::get_editor_data().script_class_is_parent(p_type, preferred_search_result_type);
}
+void CreateDialog::_script_button_clicked(TreeItem *p_item, int p_column, int p_button_id, MouseButton p_mouse_button_index) {
+ if (p_mouse_button_index != MouseButton::LEFT) {
+ return;
+ }
+ // The id of opening-script button is 1.
+ if (p_button_id != 1) {
+ return;
+ }
+
+ String scr_path = ScriptServer::get_global_class_path(p_item->get_text(0));
+ Ref