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

Add custom icons to script classes. #20560

Merged
merged 1 commit into from
Aug 15, 2018

Conversation

willnationsdev
Copy link
Contributor

@willnationsdev willnationsdev commented Jul 29, 2018

This builds on #20233 by adding custom icon support. It lets you supply a string constant following the class name in order to define a custom icon. It does not support other data types (e.g. singleton.ICON or something). However, I've tested it for running, closing, and re-opening the editor, showing in the CreateDialog, showing in the SceneTreeDock, clearing the script (to revert back to base class icon), and then loading the script from the ScriptCreateDIalog (to bring the custom icon back). All of that is working, so I think it should be good to go. I also added a few custom error reports to the parser.

Edit: Also, the "correct usage" works with both absolute and relative file paths.

Correct Usage:
correct_usage

Bad Filepath:
bad_file

Bad data type:
bad_type

CreateDialog Display:
demo_create_dialog

SceneTreeDock Display, after creating the node:
demo_scene_tree_dock_created

SceneTreeDock Display, after clearing the script:
demo_scene_tree_dock_cleared

SceneTreeDock Display, after re-adding the script:
demo_scene_tree_dock_added

@mysticfall
Copy link
Contributor

mysticfall commented Jul 29, 2018

Hopefully, we might get an equivalent feature in future, using a class level attribute?

Anyway, looks really cool. Great work!

@willnationsdev
Copy link
Contributor Author

willnationsdev commented Jul 29, 2018

@mysticfall

using a class level attribute?

If you mean with C#, then yes, that should be very doable I would think. The only thing one has to do to make this stuff work is implement a pair of ScriptLanguage methods. Something like...

bool CSharpScriptLanguage::handles_global_class_type(const String &p_type) const {
    return p_type == "CSharpScript";
}
String CSharpScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) {
    //do stuff here to parse and/or analyze the script at p_path.
    //At the end of the process, be sure to return the name of your script class's type.
    //Also set *r_base_type to the in-engine C++ class that's the base type (you do this even for derived scripts)
    //Also set *r_icon_path to whatever path has optionally been given for the type.
    //Example, detect that the class has the attribute [Icon="res://icon.svg"]
}

:-)

@mysticfall
Copy link
Contributor

Thats a great news! Usually, more than half of my scenes are generic Nodes so I really needed this. I'll probably open a feature request about C# support then. Thanks!

@akien-mga
Copy link
Member

Needs a rebase, otherwise should be good to merge as per today's PR meeting.

@Flavelius
Copy link
Contributor

It would be helpful if this was available for c# too.

@willnationsdev
Copy link
Contributor Author

@Flavelius when script class support comes for C#, the icons will too. Draft PR is in the works, but I haven't had time to work on it lately.

@TandersT
Copy link

Is there any news of this for C#?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants