From 64dccf65998ab8dbafedd5c11ca51798650575b0 Mon Sep 17 00:00:00 2001 From: Alessandro Senese Date: Mon, 2 Sep 2024 12:41:52 +0100 Subject: [PATCH] fix issue with chaining animations --- addons/anima/core/anima_tween.gd | 27 ++++++++++++ .../declaration/anima_declaration_for_base.gd | 8 ++-- .../declaration/anima_declaration_node.gd | 42 +++++++++++++------ .../ui/AnimationPicker/AnimationPicker.tscn | 39 ++++++++--------- addons/anima/ui/EventItem.tscn | 2 - project.godot | 2 +- 6 files changed, 81 insertions(+), 39 deletions(-) diff --git a/addons/anima/core/anima_tween.gd b/addons/anima/core/anima_tween.gd index 55fcbcc..bf465a2 100644 --- a/addons/anima/core/anima_tween.gd +++ b/addons/anima/core/anima_tween.gd @@ -417,6 +417,7 @@ class AnimatedItem extends Node: var _property_data: Dictionary var _easing_curve: Curve var _visibility_applied := false + var _animate_callback: Callable func set_animation_data(data: Dictionary, property_data: Dictionary) -> void: _animation_data = data @@ -439,6 +440,11 @@ class AnimatedItem extends Node: _node = data.node _node.remove_meta("_visibility_strategy_reverted") + _animate_callback = _animate_normal + + if _animation_data.has("_decimals"): + _animate_callback = _animate_with_fixed_decimals + if _animation_data.has("__debug"): print("Using:") printt("", property_data) @@ -487,6 +493,9 @@ class AnimatedItem extends Node: _node.show() func animate(elapsed: float) -> void: + _animate_callback.call(elapsed) + + func _animate_normal(elapsed: float) -> void: if not _visibility_applied: set_visibility_strategy() @@ -504,6 +513,24 @@ class AnimatedItem extends Node: apply_value(value) + func _animate_with_fixed_decimals(elapsed: float) -> void: + if not _visibility_applied: + set_visibility_strategy() + + if _property_data.size() == 0: + _property_data = AnimaTweenUtils.calculate_from_and_to(_animation_data) + + if _animation_data.has("__debug"): + printt("_property_data", _property_data) + print("") + + var from = _property_data.from + var diff = _property_data.diff + + var value = snapped(from + (diff * elapsed), _animation_data._decimals) + + apply_value(value) + func apply_value(value) -> void: printerr("Please use LinearAnimatedItem or EasingAnimatedItem class intead!!!") diff --git a/addons/anima/core/declaration/anima_declaration_for_base.gd b/addons/anima/core/declaration/anima_declaration_for_base.gd index aff3c5e..1b4bf57 100644 --- a/addons/anima/core/declaration/anima_declaration_for_base.gd +++ b/addons/anima/core/declaration/anima_declaration_for_base.gd @@ -83,11 +83,11 @@ func anima_on_completed(target: Callable, on_completed_value = null, on_backward return self -func with() -> AnimaDeclarationNode: - return _parent_class._with() +func anima_with(new_class = null) -> AnimaDeclarationNode: + return _parent_class._with(new_class) -func then() -> AnimaDeclarationNode: - return _parent_class._then() +func anima_then(new_class = null) -> AnimaDeclarationNode: + return _parent_class._then(new_class) func play() -> AnimaNode: return _parent_class.play() diff --git a/addons/anima/core/declaration/anima_declaration_node.gd b/addons/anima/core/declaration/anima_declaration_node.gd index 8140cf3..b109dff 100644 --- a/addons/anima/core/declaration/anima_declaration_node.gd +++ b/addons/anima/core/declaration/anima_declaration_node.gd @@ -36,13 +36,18 @@ func _init(node: Node = null): _data.clear() _target_data = _data - _target_data.node = node + if node: + _target_data.node = node func _set_data(data: Dictionary): - _target_data = data + for key in data: + _target_data[key] = data[key] return self +func get_data(): + return _target_data + func _create_declaration_for_animation(data: Dictionary) -> AnimaDeclarationForAnimation: var c:= AnimaDeclarationForAnimation.new(self) @@ -85,6 +90,11 @@ func anima_property(property: String, final_value = null, duration = null) -> An return _anima_declaration +func anima_property_with_decimals(property: String, final_value = null, decimals: int = 2, duration = null) -> AnimaDeclarationForProperty: + _anima_declaration = _create_declaration_with_easing({ property = property, to = final_value, duration = duration, _decimals = decimals }) + + return _anima_declaration + func anima_fade_in(duration = null) -> AnimaDeclarationForProperty: _anima_declaration = _create_declaration_with_easing({ property = "opacity", from = 0.0, to = 1.0, duration = duration }) @@ -233,22 +243,28 @@ func clear(): return self -func _then(): - return _nested_animation("_then") +func _then(new_class): + return _nested_animation("_then", new_class) -func _with(): - return _nested_animation("_with") +func _with(new_class): + return _nested_animation("_with", new_class) -func _nested_animation(key): +func _nested_animation(key, new_class): if not _target_data.has(key): _target_data[key] = {} - if _target_data.has("node"): - _target_data[key].node = _target_data.node - elif _target_data.has("grid"): - _target_data[key].grid = _target_data.grid - elif _target_data.has("group"): - _target_data[key].group = _target_data.group + if new_class: + var data = new_class.get_data() + + for k in data: + _target_data[key][k] = data[k] + else: + if _target_data.has("node"): + _target_data[key].node = _target_data.node + elif _target_data.has("grid"): + _target_data[key].grid = _target_data.grid + elif _target_data.has("group"): + _target_data[key].group = _target_data.group var has_duration = _target_data.has("duration") var duration = _target_data.duration if has_duration else null diff --git a/addons/anima/ui/AnimationPicker/AnimationPicker.tscn b/addons/anima/ui/AnimationPicker/AnimationPicker.tscn index 4b66094..9893833 100644 --- a/addons/anima/ui/AnimationPicker/AnimationPicker.tscn +++ b/addons/anima/ui/AnimationPicker/AnimationPicker.tscn @@ -5,6 +5,9 @@ [ext_resource type="Texture2D" uid="uid://ca72ljjcye5v1" path="res://addons/anima/resources/anima-preview.png" id="2_pk6n6"] [ext_resource type="PackedScene" uid="uid://0luo7c2dwb4l" path="res://addons/anima/ui/AnimationPicker/CTASecondaryButton.tscn" id="3_qvnfb"] +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0ikkc"] +bg_color = Color(1, 1, 1, 1) + [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_4yg3m"] content_margin_left = 12.0 content_margin_right = 12.0 @@ -20,9 +23,6 @@ content_margin_left = 12.0 content_margin_right = 12.0 bg_color = Color(0.14902, 0.27451, 0.32549, 1) -[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0ikkc"] -bg_color = Color(1, 1, 1, 1) - [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0op83"] bg_color = Color(0.215686, 0.215686, 0.215686, 1) corner_radius_bottom_right = 8 @@ -55,10 +55,11 @@ layout_mode = 2 size_flags_vertical = 3 theme_override_colors/font_hovered_color = Color(0, 0, 0, 1) theme_override_font_sizes/font_size = 18 +theme_override_styles/panel = SubResource("StyleBoxFlat_0ikkc") theme_override_styles/tab_selected = SubResource("StyleBoxFlat_4yg3m") theme_override_styles/tab_hovered = SubResource("StyleBoxFlat_0tlf5") theme_override_styles/tab_unselected = SubResource("StyleBoxFlat_5ixaa") -theme_override_styles/panel = SubResource("StyleBoxFlat_0ikkc") +current_tab = 0 [node name="Animations" type="HBoxContainer" parent="TabContainer"] layout_mode = 2 @@ -218,20 +219,20 @@ auto_brace_completion_highlight_matching = true [connection signal="item_rect_changed" from="." to="." method="_on_item_rect_changed"] [connection signal="text_submitted" from="TabContainer/Animations/Control/Panel/MarginContainer/HBoxContainer/AnimationSpeed" to="." method="_on_animation_speed_text_submitted"] [connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/HeaderButton" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/HeaderButton" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18802" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18802" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18812" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18812" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18822" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18822" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18834" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18834" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18846" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18846" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18876" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18876" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18904" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18904" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18914" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18914" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18926" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18926" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18938" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18938" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18948" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18948" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18958" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18958" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18968" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18968" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18972" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18972" method="_on_toggled"] -[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18992" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@18992" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22453" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22453" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22463" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22463" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22473" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22473" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22485" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22485" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22497" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22497" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22527" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22527" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22555" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22555" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22565" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22565" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22577" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22577" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22589" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22589" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22599" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22599" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22609" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22609" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22619" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22619" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22623" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22623" method="_on_toggled"] +[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22643" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22643" method="_on_toggled"] [connection signal="pressed" from="TabContainer/Animations/VBoxContainer/MarginContainer/HBoxContainer/UseAnimation" to="." method="_on_use_animation_pressed"] [connection signal="pressed" from="TabContainer/Animations/VBoxContainer/MarginContainer/HBoxContainer/CloseButton" to="." method="_on_close_button_pressed"] diff --git a/addons/anima/ui/EventItem.tscn b/addons/anima/ui/EventItem.tscn index 2fc93f3..4b20876 100644 --- a/addons/anima/ui/EventItem.tscn +++ b/addons/anima/ui/EventItem.tscn @@ -104,7 +104,6 @@ layout_mode = 2 size_flags_horizontal = 3 item_count = 3 popup/item_0/text = "Forward" -popup/item_0/id = 0 popup/item_1/text = "Backwards" popup/item_1/id = 1 popup/item_2/text = "Loop" @@ -132,7 +131,6 @@ layout_mode = 2 size_flags_horizontal = 3 item_count = 3 popup/item_0/text = "Forward" -popup/item_0/id = 0 popup/item_1/text = "Backward" popup/item_1/id = 1 popup/item_2/text = "In circle" diff --git a/project.godot b/project.godot index 3973854..69f423f 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="Anima" run/main_scene="res://demos/DemosSelector.tscn" -config/features=PackedStringArray("4.2") +config/features=PackedStringArray("4.3") [autoload]