-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add support for exporting script classes without a name #82528
Conversation
It should show the script's icon (its own icon if set or base node type). Also instead of full path, which can be very long, I think it should be filename only. |
Okay, I'll see if I can edit this to make the result a bit more presentable |
8927682
to
edd8668
Compare
edd8668
to
6dbb65a
Compare
You could've used EditorData's |
Okay, I'll update it again to use this function |
Hmm, that function appears to be bugged, doesn't return an icon from scripts that don't have any custom defined icon. I guess I'll open up another PR for that once I've tested things. |
We could either: |
Maybe try |
6dbb65a
to
207225b
Compare
@KoBeWi Okay, I've gone back to have a look at this. The solution I've landed on is basically deriving the icon during the set_valid_types method and storing it in the metadata.
This is a bit more simplified and also solves an issue with the earlier implementation that it wouldn't use custom icons unless we defined a global class. This time, it simply attempts to get a class icon, and if it fails, it will check if a script exists for that path. If it does, it will change the type name to just the name of the script and will use the get_script_icon method. Since this doesn't work for scripts which don't have explicitly defined custom icons, I decided instead of trying to determine the base type, to just fall back on the script's class's own icon if a custom icon cannot be found. This is consistent with how script icons are displayed in the inspector and seems pretty consistent. Basically, you now get a script icon (a cog for GDScript specifically), or you get whatever you define with icon() now displaying correctly without the need give your script an explicit class_name. |
editor/gui/scene_tree_editor.cpp
Outdated
// If we can't find a global class icon, try to find one for the script. | ||
if (type_icon.is_null()) { | ||
if (ResourceLoader::exists(type, "Script")) { | ||
Ref<Script> node_script = ResourceLoader::load(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there might be a better way, but at least it works.
Ref<Script> node_script = p_node->get_script(); | ||
while (node_script.is_valid()) { | ||
if (node_script->get_path() == E) { | ||
valid = true; | ||
break; | ||
} | ||
node_script = node_script->get_base_script(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be changed to method probably, but I wonder how it could be reused in editor properties too (since it's the same).
207225b
to
bd4d74a
Compare
Updated some of the things pointed out. |
Allow script path type hints to be used in drag and drop and scene tree popup.
bd4d74a
to
7559eb1
Compare
Updated now. |
Thanks! |
In the current editor implementation, you can export classes with custom script types and have the correct type validation be performed for both the inspector drag and drop behaviour and the scene tree selection popup. However, you can also export classes which are not defined by custom classes, but by script path constants, but these will not be validated by either of these editor options. This PR will check the script path of nodes to determine if they match. It also checks the inheritence of scripts.
It's debatable whether this is technically a bug or not, but it deviates from standard expecting operating behaviour given what is permissible in scripting, and is generally quite annoying if you don't like defining custom class names for every minor script.