summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-02-11 14:38:18 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-02-11 14:38:18 +0100
commit0e81e2a30f9fd0cbe83d101cf324fc76801c1fc6 (patch)
tree61f6b2d4cc579ace9b7e4d32eb329c472a9f46d1
parentab2952580ce4f70bc2f95ad6eb3f749c00c3e7a4 (diff)
parent4c5bd4cb0acf25c082f0bdcd8f37e1903adab5cf (diff)
Merge pull request #73091 from TokageItLab/fix-bezier-edit-button-update
Fix weird bezier edit button update timing in AnimationTrackEditor
-rw-r--r--doc/classes/RigidBody2D.xml22
-rw-r--r--doc/classes/RigidBody3D.xml22
-rw-r--r--editor/animation_track_editor.cpp34
-rw-r--r--editor/animation_track_editor.h1
4 files changed, 66 insertions, 13 deletions
diff --git a/doc/classes/RigidBody2D.xml b/doc/classes/RigidBody2D.xml
index 6e3535f14a..937d0910ec 100644
--- a/doc/classes/RigidBody2D.xml
+++ b/doc/classes/RigidBody2D.xml
@@ -176,6 +176,28 @@
<member name="inertia" type="float" setter="set_inertia" getter="get_inertia" default="0.0">
The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value.
If set to [code]0[/code], inertia is automatically computed (default value).
+ [b]Note:[/b] This value does not change when inertia is automatically computed. Use [PhysicsServer2D] to get the computed inertia.
+ [codeblocks]
+ [gdscript]
+ @onready var ball = $Ball
+
+ func get_ball_inertia():
+ return 1.0 / PhysicsServer2D.body_get_direct_state(ball.get_rid()).inverse_inertia
+ [/gdscript]
+ [csharp]
+ private RigidBody2D _ball;
+
+ public override void _Ready()
+ {
+ _ball = GetNode&lt;RigidBody2D&gt;("Ball");
+ }
+
+ private float GetBallInertia()
+ {
+ return 1.0f / PhysicsServer2D.BodyGetDirectState(_ball.GetRid()).InverseInertia;
+ }
+ [/csharp]
+ [/codeblocks]
</member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="0.0">
Damps the body's movement. By default, the body will use the [b]Default Linear Damp[/b] in [b]Project &gt; Project Settings &gt; Physics &gt; 2d[/b] or any value override set by an [Area2D] the body is in. Depending on [member linear_damp_mode], you can set [member linear_damp] to be added to or to replace the body's damping value.
diff --git a/doc/classes/RigidBody3D.xml b/doc/classes/RigidBody3D.xml
index 148cdf96ee..a066254b4f 100644
--- a/doc/classes/RigidBody3D.xml
+++ b/doc/classes/RigidBody3D.xml
@@ -183,6 +183,28 @@
<member name="inertia" type="Vector3" setter="set_inertia" getter="get_inertia" default="Vector3(0, 0, 0)">
The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body on each axis. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value.
If set to [code]Vector3.ZERO[/code], inertia is automatically computed (default value).
+ [b]Note:[/b] This value does not change when inertia is automatically computed. Use [PhysicsServer3D] to get the computed inertia.
+ [codeblocks]
+ [gdscript]
+ @onready var ball = $Ball
+
+ func get_ball_inertia():
+ return PhysicsServer3D.body_get_direct_state(ball.get_rid()).inverse_inertia.inverse()
+ [/gdscript]
+ [csharp]
+ private RigidBody3D _ball;
+
+ public override void _Ready()
+ {
+ _ball = GetNode&lt;RigidBody3D&gt;("Ball");
+ }
+
+ private Vector3 GetBallInertia()
+ {
+ return PhysicsServer3D.BodyGetDirectState(_ball.GetRid()).InverseInertia.Inverse();
+ }
+ [/csharp]
+ [/codeblocks]
</member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="0.0">
Damps the body's movement. By default, the body will use the [b]Default Linear Damp[/b] in [b]Project &gt; Project Settings &gt; Physics &gt; 3d[/b] or any value override set by an [Area3D] the body is in. Depending on [member linear_damp_mode], you can set [member linear_damp] to be added to or to replace the body's damping value.
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index 3233bd79d5..f33fd1d4dd 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -2003,7 +2003,6 @@ void AnimationTrackEdit::_notification(int p_what) {
draw_texture(down_icon, Vector2(ofs, int(get_size().height - down_icon->get_height()) / 2));
update_mode_rect.size.x += down_icon->get_width();
} else if (animation->track_get_type(track) == Animation::TYPE_BEZIER) {
- Ref<Texture2D> bezier_icon = get_theme_icon(SNAME("EditBezier"), SNAME("EditorIcons"));
update_mode_rect.size.x += down_icon->get_width();
update_mode_rect = Rect2();
} else {
@@ -3311,25 +3310,15 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim, bool p_re
snap->set_disabled(false);
snap_mode->set_disabled(false);
- bezier_edit_icon->set_disabled(true);
-
imported_anim_warning->hide();
- bool import_warning_done = false;
- bool bezier_done = false;
for (int i = 0; i < animation->get_track_count(); i++) {
if (animation->track_is_imported(i)) {
imported_anim_warning->show();
- import_warning_done = true;
- }
- if (animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) {
- bezier_edit_icon->set_disabled(false);
- bezier_done = true;
- }
- if (import_warning_done && bezier_done) {
break;
}
}
+ _check_bezier_exist();
} else {
hscroll->hide();
edit->set_disabled(true);
@@ -3343,6 +3332,24 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim, bool p_re
}
}
+void AnimationTrackEditor::_check_bezier_exist() {
+ bool is_exist = false;
+ for (int i = 0; i < animation->get_track_count(); i++) {
+ if (animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) {
+ is_exist = true;
+ break;
+ }
+ }
+ if (is_exist) {
+ bezier_edit_icon->set_disabled(false);
+ } else {
+ if (bezier_edit->is_visible()) {
+ _cancel_bezier_edit();
+ }
+ bezier_edit_icon->set_disabled(true);
+ }
+}
+
Ref<Animation> AnimationTrackEditor::get_current_animation() const {
return animation;
}
@@ -4490,6 +4497,8 @@ void AnimationTrackEditor::_animation_changed() {
return; // All will be updated, don't bother with anything.
}
+ _check_bezier_exist();
+
if (key_edit) {
if (key_edit->setting) {
// If editing a key, just redraw the edited track, makes refresh less costly.
@@ -4710,7 +4719,6 @@ void AnimationTrackEditor::_new_track_node_selected(NodePath p_path) {
adding_track_path = path_to;
prop_selector->set_type_filter(filter);
prop_selector->select_property_from_instance(node);
- bezier_edit_icon->set_disabled(false);
} break;
case Animation::TYPE_AUDIO: {
if (!node->is_class("AudioStreamPlayer") && !node->is_class("AudioStreamPlayer2D") && !node->is_class("AudioStreamPlayer3D")) {
diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h
index 2a59bda2a4..c733f397e3 100644
--- a/editor/animation_track_editor.h
+++ b/editor/animation_track_editor.h
@@ -399,6 +399,7 @@ class AnimationTrackEditor : public VBoxContainer {
void _update_tracks();
void _redraw_tracks();
void _redraw_groups();
+ void _check_bezier_exist();
void _name_limit_changed();
void _timeline_changed(float p_new_pos, bool p_drag, bool p_timeline_only);