-
-
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 @tool_button
annotation for easily creating inspector buttons.
#59289
Conversation
ce9ab70
to
0784e9b
Compare
This looks great, amazing work! What do you think about adding an optional parameter to The editor icon names would refer to one of the icons located in https://github.com/godotengine/godot/tree/master/editor/icons, and they wouldn't have any |
Sure, I can work on that. |
5caa0a3
to
e2fc2e1
Compare
Added! 👍 @export_action('Add') var add:Callable = add_nums;
@export_action('Camera2D') var recenter_camera = func():
pass
@export_action var no_icon = func():
pass |
3561d88
to
89cb9d3
Compare
All checks should be passing now. |
5f8e443
to
ccc6606
Compare
ccc6606
to
6e4a58c
Compare
Tested the new implementation and it works correctly. EDIT: |
This comment was marked as resolved.
This comment was marked as resolved.
15a3bbb
to
466d2d4
Compare
@@ -106,6 +106,7 @@ GDScriptParser::GDScriptParser() { | |||
register_annotation(MethodInfo("@export_category", PropertyInfo(Variant::STRING, "name")), AnnotationInfo::STANDALONE, &GDScriptParser::export_group_annotations<PROPERTY_USAGE_CATEGORY>); | |||
register_annotation(MethodInfo("@export_group", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::STRING, "prefix")), AnnotationInfo::STANDALONE, &GDScriptParser::export_group_annotations<PROPERTY_USAGE_GROUP>, varray("")); | |||
register_annotation(MethodInfo("@export_subgroup", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::STRING, "prefix")), AnnotationInfo::STANDALONE, &GDScriptParser::export_group_annotations<PROPERTY_USAGE_SUBGROUP>, varray("")); | |||
register_annotation(MethodInfo("@tool_button", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::STRING, "icon")), AnnotationInfo::FUNCTION, &GDScriptParser::tool_button_annotation, varray("", ""), true); |
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 is still specifying default arguments.
If you don't want any, use varray()
.
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.
Without the default arguments, I've noticed that it's erroring that I only have 1 argument instead of the 2 required. Is there any way to fix that?
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.
Ah right, it should be varray("")
, to make the icon optional.
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.
Gotcha, I'll get on that and finishing up the rest of the problems listed in a bit. I do want to note that to fix the EditorUndoRedoManager issue, I've changed the tool buttons to instead pass the relevant UndoRedo for that object. If there's a better solution, I'd gladly implement it.
466d2d4
to
3f5c416
Compare
3f5c416
to
ed533bb
Compare
@tool_button
annotation for easily creating inspector buttons.
I see you replaced UndoRedo with EditorUndoRedoManager in response to my comment. Unfortunately it won't work, because all actions should go through EditorUndoRedoManager. |
Gotcha, I'll see what I can do. |
I would like this, will see how I can get this ready for 4.2 |
Superseded by #78355. Thanks for the contribution! |
Closes godotengine/godot-proposals#2149
Adds an function annotation that allows you to add clickable actions to the inspector view of a script.
The script must be a
tool
script and the function must accept the EditorUndoRedoManager as a parameter.Usage:
Another example, where you press a button to add a new enemy to your scene at a random position:
Screen.Recording.2023-04-27.at.6.05.01.AM.mov