summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/doc_classes/@GDScript.xml
diff options
context:
space:
mode:
authorDanil Alexeev <danil@alexeev.xyz>2024-09-26 20:34:29 +0300
committerMack <86566939+Macksaur@users.noreply.github.com>2024-09-27 22:24:15 +0100
commit85dfd896536ff04dba4afd7d461a28e0ac4b9aee (patch)
tree26583e929ae35235c783fcd9b6de43805ce5434d /modules/gdscript/doc_classes/@GDScript.xml
parent76a135926aef1f02f27e4e09093787f2c670956d (diff)
downloadredot-engine-85dfd896536ff04dba4afd7d461a28e0ac4b9aee.tar.gz
Add `@export_tool_button` annotation for easily creating inspector buttons
Co-authored-by: jordi <creptthrust@gmail.com> Co-authored-by: K. S. Ernest (iFire) Lee <ernest.lee@chibifire.com> Co-authored-by: Mack <86566939+Macksaur@users.noreply.github.com>
Diffstat (limited to 'modules/gdscript/doc_classes/@GDScript.xml')
-rw-r--r--modules/gdscript/doc_classes/@GDScript.xml35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml
index f539f27848..5fe47d69df 100644
--- a/modules/gdscript/doc_classes/@GDScript.xml
+++ b/modules/gdscript/doc_classes/@GDScript.xml
@@ -669,6 +669,41 @@
[b]Note:[/b] Subgroups cannot be nested, they only provide one extra level of depth. Just like the next group ends the previous group, so do the subsequent subgroups.
</description>
</annotation>
+ <annotation name="@export_tool_button">
+ <return type="void" />
+ <param index="0" name="text" type="String" />
+ <param index="1" name="icon" type="String" default="&quot;&quot;" />
+ <description>
+ Export a [Callable] property as a clickable button with the label [param text]. When the button is pressed, the callable is called.
+ If [param icon] is specified, it is used to fetch an icon for the button via [method Control.get_theme_icon], from the [code]"EditorIcons"[/code] theme type. If [param icon] is omitted, the default [code]"Callable"[/code] icon is used instead.
+ Consider using the [EditorUndoRedoManager] to allow the action to be reverted safely.
+ See also [constant PROPERTY_HINT_TOOL_BUTTON].
+ [codeblock]
+ @tool
+ extends Sprite2D
+
+ @export_tool_button("Hello") var hello_action = hello
+ @export_tool_button("Randomize the color!", "ColorRect")
+ var randomize_color_action = randomize_color
+
+ func hello():
+ print("Hello world!")
+
+ func randomize_color():
+ var undo_redo = EditorInterface.get_editor_undo_redo()
+ undo_redo.create_action("Randomized Sprite2D Color")
+ undo_redo.add_do_property(self, &amp;"self_modulate", Color(randf(), randf(), randf()))
+ undo_redo.add_undo_property(self, &amp;"self_modulate", self_modulate)
+ undo_redo.commit_action()
+ [/codeblock]
+ [b]Note:[/b] The property is exported without the [constant PROPERTY_USAGE_STORAGE] flag because a [Callable] cannot be properly serialized and stored in a file.
+ [b]Note:[/b] In an exported project neither [EditorInterface] nor [EditorUndoRedoManager] exist, which may cause some scripts to break. To prevent this, you can use [method Engine.get_singleton] and omit the static type from the variable declaration:
+ [codeblock]
+ var undo_redo = Engine.get_singleton(&amp;"EditorInterface").get_editor_undo_redo()
+ [/codeblock]
+ [b]Note:[/b] Avoid storing lambda callables in member variables of [RefCounted]-based classes (e.g. resources), as this can lead to memory leaks. Use only method callables and optionally [method Callable.bind] or [method Callable.unbind].
+ </description>
+ </annotation>
<annotation name="@icon">
<return type="void" />
<param index="0" name="icon_path" type="String" />