summaryrefslogtreecommitdiffstats
path: root/editor/plugins/collision_shape_2d_editor_plugin.cpp
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2021-08-12 11:26:47 -0700
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2021-08-19 10:31:19 -0700
commit645bc94bfcb0d494e9d53e29aee1419800adcd4e (patch)
tree1ff9fd17f54d9490effc9bb09f0610bad3577b3c /editor/plugins/collision_shape_2d_editor_plugin.cpp
parent93dac1c7db0837eba82831e6391a022d454b67f9 (diff)
downloadredot-engine-645bc94bfcb0d494e9d53e29aee1419800adcd4e.tar.gz
Fix capsule height/radius setters with linked properties
Capsule height and radius setters can modify each other, rather than using clamping, to avoid cases where values are not set correctly when loading a scene (depending on the order of properties). Inspector undo/redo: Added the possibility to link properties together in the editor, so they can be undone together, for cases where a property can modify another one. Gizmo undo/redo: Capsule handles pass both radius and height values so they can be undone together.
Diffstat (limited to 'editor/plugins/collision_shape_2d_editor_plugin.cpp')
-rw-r--r--editor/plugins/collision_shape_2d_editor_plugin.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp
index 486f947e43..c2684305ef 100644
--- a/editor/plugins/collision_shape_2d_editor_plugin.cpp
+++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp
@@ -50,12 +50,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const {
switch (shape_type) {
case CAPSULE_SHAPE: {
Ref<CapsuleShape2D> capsule = node->get_shape();
-
- if (idx == 0) {
- return capsule->get_radius();
- } else if (idx == 1) {
- return capsule->get_height();
- }
+ return Vector2(capsule->get_radius(), capsule->get_height());
} break;
@@ -209,17 +204,17 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) {
case CAPSULE_SHAPE: {
Ref<CapsuleShape2D> capsule = node->get_shape();
+ Vector2 values = p_org;
+
if (idx == 0) {
undo_redo->add_do_method(capsule.ptr(), "set_radius", capsule->get_radius());
- undo_redo->add_do_method(canvas_item_editor, "update_viewport");
- undo_redo->add_undo_method(capsule.ptr(), "set_radius", p_org);
- undo_redo->add_do_method(canvas_item_editor, "update_viewport");
} else if (idx == 1) {
undo_redo->add_do_method(capsule.ptr(), "set_height", capsule->get_height());
- undo_redo->add_do_method(canvas_item_editor, "update_viewport");
- undo_redo->add_undo_method(capsule.ptr(), "set_height", p_org);
- undo_redo->add_undo_method(canvas_item_editor, "update_viewport");
}
+ undo_redo->add_do_method(canvas_item_editor, "update_viewport");
+ undo_redo->add_undo_method(capsule.ptr(), "set_radius", values[0]);
+ undo_redo->add_undo_method(capsule.ptr(), "set_height", values[1]);
+ undo_redo->add_undo_method(canvas_item_editor, "update_viewport");
} break;