Skip to content

Commit

Permalink
fix animations and add reset
Browse files Browse the repository at this point in the history
  • Loading branch information
ceceppa committed Sep 26, 2023
1 parent 0b0d1ef commit 39efa3f
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 42 deletions.
1 change: 1 addition & 0 deletions TestScene/Test.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ anchors_preset = 0
script = ExtResource("1")

[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_left = 624.0
offset_top = 331.0
offset_right = 793.0
Expand Down
8 changes: 4 additions & 4 deletions addons/anima/animations/attention_seeker/swing.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ var KEYFRAMES := {
"rotate:y": 0,
},
20: {
"rotate:y": 15,
"rotate:y": 0.2617,
},
40: {
"rotate:y": -10,
"rotate:y": -0.174533,
},
60: {
"rotate:y": 5,
"rotate:y": 0.0872665,
},
80: {
"rotate:y": -5,
"rotate:y": -0.0872665,
},
100: {
"rotate:y": 0,
Expand Down
6 changes: 3 additions & 3 deletions addons/anima/animations/attention_seeker/tada.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ var KEYFRAMES := {
},
[10, 20]: {
scale = Vector3(0.9, 0.9, 0.9),
"rotate:y" = -3
"rotate:y" = -0.0523599
},
[30, 50, 70, 90]: {
scale = Vector3(1.1, 1.1, 1.1),
"rotate:y" = 3
"rotate:y" = 0.0523599
},
[40, 60, 80]: {
scale = Vector3(1.1, 1.1, 1.1),
"rotate:y" = -3
"rotate:y" = -0.0523599
},
"pivot": ANIMA.PIVOT.CENTER
}
12 changes: 9 additions & 3 deletions addons/anima/components/anima_animated_control_inspector.gd
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
@tool
extends EditorInspectorPlugin

var _animation_picker := preload("res://addons/anima/ui/AnimationPicker.tscn").instantiate()
var _animation_picker := Window.new()
var _animation_picker_content: VBoxContainer = preload("res://addons/anima/ui/AnimationPicker.tscn").instantiate()
var _parent: EditorPlugin

func _init(parent: EditorPlugin):
_parent = parent

_animation_picker.add_child(_animation_picker_content)
_animation_picker.hide()
_parent.add_child(_animation_picker)

_animation_picker.close_requested.connect(_close_animation_picker)

func _can_handle(object):
return object.has_method("is_anima_animated_control")

Expand All @@ -22,5 +26,7 @@ func _parse_begin(object):
add_custom_control(button)

func _on_add_event_pressed():
_animation_picker.show()
prints("ciao", _animation_picker.visible, _animation_picker.position, _animation_picker.size)
_animation_picker.popup_centered(Vector2(1024, 768))

func _close_animation_picker():
_animation_picker.hide()
28 changes: 23 additions & 5 deletions addons/anima/core/anima_node.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ signal animation_completed
signal loop_started
signal loop_completed

const INITIAL_STATE_META_KEY: String = "AnimaInitialStates"

var _anima_tween := AnimaTween.new()

var _timer := Timer.new()
Expand Down Expand Up @@ -207,6 +209,23 @@ func stop() -> AnimaNode:

return self

func stop_and_reset():
stop()
reset()

func reset():
var animation_data = get_animation_data()

for data in animation_data:
var meta_value: Dictionary = data.node.get_meta(INITIAL_STATE_META_KEY) if data.node.has_meta(INITIAL_STATE_META_KEY) else {}

for key in meta_value:
print(key)

func reset_and_clear() -> void:
reset()
clear()

func loop(times: int = -1) -> AnimaNode:
return _do_loop(times, AnimaTween.PLAY_MODE.NORMAL)

Expand Down Expand Up @@ -350,13 +369,12 @@ func _setup_animation(data: Dictionary) -> float:
return 0.0

var node: Node = data.node
var meta_key: String = ""
var meta_value: Dictionary = data.node.get_meta(INITIAL_STATE_META_KEY) if data.node.has_meta(INITIAL_STATE_META_KEY) else {}

if data.has("property"):
meta_key = "AnimaInitial%s%s" % [str(node.name).replace("-", "").replace(" ", ""), str(data.property).replace("_", "")]
if data.has("property") and not meta_value.has(data.property):
meta_value[data.property] = AnimaNodesProperties.get_property_value(node, data, data.property)

if meta_key.length() > 0 and not data.has("from") and data.has("property") and not node.has_meta(meta_key):
data.node.set_meta(meta_key, AnimaNodesProperties.get_property_value(node, data, data.property))
data.node.set_meta(INITIAL_STATE_META_KEY, meta_value)

return _setup_node_animation(data)

Expand Down
17 changes: 12 additions & 5 deletions addons/anima/ui/AnimationPicker.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
@tool
extends Window
extends VBoxContainer

@onready var List: VBoxContainer = find_child("ListContainer")
@onready var DemoLabel: Label = find_child("DemoLabel")

var _anima: AnimaNode

func _ready():
print("here")
var animations = AnimaAnimationsUtils.get_available_animation_by_category()

for group in animations:
Expand All @@ -22,13 +24,14 @@ func _ready():
List.add_child(container)
List.add_spacer(false)

_anima = Anima.begin(DemoLabel)

func _create_new_header(animation: String) -> Button:
var button := Button.new()

button.toggle_mode = true
button.set_text(animation.replace('_', ' ').capitalize())
button.pressed.connect(func():
# var group: VBoxContainer = List.find_child("__" + animation)
var group: VBoxContainer

for child in List.get_children():
Expand All @@ -48,9 +51,13 @@ func _create_animation_button(label: String) -> Button:
button.text = label.replace('_', ' ').capitalize()
button.set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT)
button.set_meta('_animation', label)
button.connect("pressed",Callable(self,'_on_animation_button_pressed').bind(button))

button.pressed.connect(_on_animation_button_pressed.bind(label))
return button

func _on_close_requested():
hide()

func _on_animation_button_pressed(animation_name: String):
_anima.reset_and_clear()

await _anima.then( Anima.Node(DemoLabel).anima_animation(animation_name) ).play()
50 changes: 28 additions & 22 deletions addons/anima/ui/AnimationPicker.tscn
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
[gd_scene load_steps=2 format=3 uid="uid://brxnmcufd6edq"]
[gd_scene load_steps=3 format=3 uid="uid://brxnmcufd6edq"]

[ext_resource type="Script" path="res://addons/anima/ui/AnimationPicker.gd" id="1_3cmj5"]

[node name="AnimationPicker" type="Window"]
size = Vector2i(500, 500)
visible = false
always_on_top = true
min_size = Vector2i(500, 500)
script = ExtResource("1_3cmj5")
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_6myxi"]

[node name="VBoxContainer" type="VBoxContainer" parent="."]
[node name="AnimationPicker" type="VBoxContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_3cmj5")

[node name="TabBar" type="TabBar" parent="VBoxContainer"]
[node name="TabContainer" type="TabContainer" parent="."]
layout_mode = 2
tab_count = 2
tab_0/title = "Animations"
tab_1/title = "Keyframes"
size_flags_vertical = 3

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
[node name="Animations" type="HBoxContainer" parent="TabContainer"]
layout_mode = 2
size_flags_vertical = 3

[node name="Control" type="Control" parent="VBoxContainer/HBoxContainer"]
[node name="Control" type="Control" parent="TabContainer/Animations"]
layout_mode = 2
size_flags_horizontal = 3

[node name="ControlContainer" type="CenterContainer" parent="VBoxContainer/HBoxContainer/Control"]
layout_mode = 0
[node name="ControlContainer" type="CenterContainer" parent="TabContainer/Animations/Control"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -25.0
offset_top = -13.0
offset_right = 25.0
offset_bottom = 13.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="ControlTest" type="Label" parent="VBoxContainer/HBoxContainer/Control/ControlContainer"]
[node name="DemoLabel" type="Label" parent="TabContainer/Animations/Control/ControlContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 92
text = "Anima"

[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer/HBoxContainer"]
custom_minimum_size = Vector2(300, 2.08165e-12)
[node name="ScrollContainer" type="ScrollContainer" parent="TabContainer/Animations"]
custom_minimum_size = Vector2(260, 0)
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_6myxi")

[node name="ListContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/ScrollContainer"]
[node name="ListContainer" type="VBoxContainer" parent="TabContainer/Animations/ScrollContainer"]
layout_mode = 2

[connection signal="close_requested" from="." to="." method="_on_close_requested"]
size_flags_horizontal = 3

0 comments on commit 39efa3f

Please sign in to comment.