Add example project for how to use CanvasItemGizmoPlugins#1305
Add example project for how to use CanvasItemGizmoPlugins#1305derkork wants to merge 2 commits intogodotengine:masterfrom
Conversation
| func _get_gizmo_name() -> String: | ||
| return "Circle" | ||
|
|
||
| ## This function tells the editor whether this node has a bounding rectangle. |
There was a problem hiding this comment.
| ## This function tells the editor whether this node has a bounding rectangle. | |
| ## This function tells the editor whether this node has a bounding rectangle. |
Everywhere, two empty lines between methods
| ## This is only called if _edit_use_rect returns true. | ||
| func _edit_get_rect(gizmo: EditorCanvasItemGizmo) -> Rect2: | ||
| # First we get the node we're editing | ||
| var circle:Circle = gizmo.get_canvas_item() |
There was a problem hiding this comment.
| var circle:Circle = gizmo.get_canvas_item() | |
| var circle: Circle = gizmo.get_canvas_item() |
Everywhere for var
There was a problem hiding this comment.
Per the GDScript style guide, no space before the standalone colon.
There was a problem hiding this comment.
Okay I thought we did the opposite recently, will correct
| ## This function tells the editor what the bounding rectangle of the node is. | ||
| ## This is only called if _edit_use_rect returns true. | ||
| func _edit_get_rect(gizmo: EditorCanvasItemGizmo) -> Rect2: | ||
| # First we get the node we're editing |
There was a problem hiding this comment.
| # First we get the node we're editing | |
| # First we get the node we're editing. |
For all
| # the base state (transform, etc.) is automatically saved from the | ||
| # underlying node, so we only need to add what is custom to our node. In our case | ||
| # this is just the pivot field. | ||
| return {"pivot" : circle.pivot } |
There was a problem hiding this comment.
| return {"pivot" : circle.pivot } | |
| return { "pivot" : circle.pivot } |
Trailing whitespace needs to be removed everywhere
| var _circle_gizmo_plugin:CircleGizmoPlugin | ||
| var _flower_gizmo_plugin:FlowerGizmoPlugin | ||
|
|
||
| ## Registers the gizmo plugins with the editor. |
There was a problem hiding this comment.
| ## Registers the gizmo plugins with the editor. | |
| ## Registers the gizmo plugins with the editor. |
Same here
| return | ||
|
|
||
| var undo_redo:EditorUndoRedoManager = EditorInterface.get_editor_undo_redo() | ||
| undo_redo.create_action("Set radius ") |
There was a problem hiding this comment.
| undo_redo.create_action("Set radius ") | |
| undo_redo.create_action("Set radius") |
| func _edit_get_rect(gizmo: EditorCanvasItemGizmo) -> Rect2: | ||
| # First we get the node we're editing | ||
| var circle:Circle = gizmo.get_canvas_item() | ||
|
|
There was a problem hiding this comment.
Empty lines should be fully empty with no trailing whitespace, everywhere
|
|
||
| # Otherwise, we need to create an undo/redo action for the change: | ||
| var undo_redo:EditorUndoRedoManager = EditorInterface.get_editor_undo_redo() | ||
| undo_redo.create_action("Set radius ") |
There was a problem hiding this comment.
| undo_redo.create_action("Set radius ") | |
| undo_redo.create_action("Set radius") |
| ## The radius of the flower disk. | ||
| @export var radius:float = 100: | ||
| set(value): | ||
| radius = max(0, value) |
There was a problem hiding this comment.
| radius = max(0, value) | |
| radius = maxf(0, value) |
| @export var radius:float = 100: | ||
| set(value): | ||
| # don't allow negative values | ||
| radius = max(0, value) |
There was a problem hiding this comment.
| radius = max(0, value) | |
| radius = maxf(0, value) |
This PR adds an example project for the new 2D gizmo plugins introduced in: godotengine/godot#112979. I'll keep this a draft until the PR is in a state to be merged.