Skip to content

Commit

Permalink
trying fix offset
Browse files Browse the repository at this point in the history
  • Loading branch information
ceceppa committed Oct 12, 2023
1 parent 95aae91 commit 698487b
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 61 deletions.
22 changes: 11 additions & 11 deletions addons/anima/animations/bouncing_exits/bounce_out.gd
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var KEYFRAMES := {
20: {
scale = Vector3(0.9, 0.9, 0.9)
},
[50, 55]: {
opacity = 1,
scale = Vector3(1.1, 1.1, 1.1)
},
100: {
opacity = 0,
scale = Vector3(0.3, 0.3, 0.3)
}
20: {
scale = Vector3(0.9, 0.9, 0.9)
},
[50, 55]: {
opacity = 1,
scale = Vector3(1.1, 1.1, 1.1)
},
100: {
opacity = 0,
scale = Vector3(0.3, 0.3, 0.3)
},
}
28 changes: 15 additions & 13 deletions addons/anima/core/anima_node.gd
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,25 @@ func reset():
nodes_to_reset.push_front(node)

for node in nodes_to_reset:
if not node.has_meta(ANIMA._INITIAL_STATE_META_KEY):
continue
if node.has_meta(ANIMA._INITIAL_STATE_META_KEY):
var meta_value: Dictionary = node.get_meta(ANIMA._INITIAL_STATE_META_KEY)

var meta_value: Dictionary = node.get_meta(ANIMA._INITIAL_STATE_META_KEY)
for key in meta_value:
var value = meta_value[key]
var initial_value = value._initial_value

for key in meta_value:
var value = meta_value[key]
var initial_value = value._initial_value
if value.has("subkey"):
node[value.property][value.key][value.subkey] = initial_value
elif value.has("key"):
node[value.property][value.key] = initial_value
elif value.has("property"):
node[value.property] = initial_value

if value.has("key"):
node[value.property][value.key] = initial_value
elif value.has("subkey"):
node[value.property][value.key][value.subkey] = initial_value
elif value.has("property"):
node[value.property] = initial_value
node.remove_meta(ANIMA._INITIAL_STATE_META_KEY)

node.remove_meta(ANIMA._INITIAL_STATE_META_KEY)
for meta_key in node.get_meta_list():
if meta_key.begins_with("__anima_"):
node.remove_meta(meta_key)

func reset_and_clear() -> void:
reset()
Expand Down
2 changes: 1 addition & 1 deletion addons/anima/core/tween.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extends Node

signal animation_completed

const VISIBILITY_STRATEGY_META_KEY = "__visibility_strategy"
const VISIBILITY_STRATEGY_META_KEY = "__anima_visibility_strategy"

var PROPERTIES_TO_ATTENUATE = ["rotate", "rotation", "rotation:y", "rotate:y", "y", "position:y", "x"]

Expand Down
22 changes: 19 additions & 3 deletions addons/anima/ui/AnimationPicker/AnimationPicker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ const HEADER_BUTTON = preload("res://addons/anima/ui/AnimationPicker/HeaderButto
const ANIMATION_BUTTON = preload("res://addons/anima/ui/AnimationPicker/AnimationButton.tscn")

@onready var List: VBoxContainer = find_child("ListContainer")
@onready var DemoControl: Control = find_child("DemoControl")
@onready var LabelDemo: Control = find_child("LabelDemo")
@onready var SpriteDemo: Sprite2D = find_child("SpriteDemo")
@onready var AnimationSpeed: LineEdit = find_child("AnimationSpeed")

var ActiveDemoNode: Node

signal animation_selected(name: String)
signal close_pressed

Expand Down Expand Up @@ -42,7 +45,12 @@ func _ready():

is_first_header = false

_anima = Anima.begin(DemoControl)
_anima = Anima.begin(self)
_on_item_rect_changed()

ActiveDemoNode = SpriteDemo
ActiveDemoNode.show()
# LabelDemo.modulate.a = 0

func _create_new_header(animation: String) -> Button:
var button: Button = HEADER_BUTTON.instantiate()
Expand Down Expand Up @@ -80,7 +88,7 @@ func _on_animation_button_pressed(animation_name: String):
_anima.reset_and_clear()

var anima := _anima.then(
Anima.Node(DemoControl).anima_animation(animation_name, AnimationSpeed.get_text().to_float())
Anima.Node(ActiveDemoNode).anima_animation(animation_name, AnimationSpeed.get_text().to_float())
).play()

await anima.animation_completed
Expand All @@ -90,3 +98,11 @@ func _on_use_animation_pressed():

func _on_close_button_pressed():
close_pressed.emit()

func _on_animation_speed_text_submitted(new_text):
_on_animation_button_pressed(_animation_name)

func _on_item_rect_changed():
if SpriteDemo:
SpriteDemo.position = LabelDemo.position
SpriteDemo.offset = (SpriteDemo.get_rect().size / 2) - (SpriteDemo.get_rect().size - LabelDemo.get_rect().size) / 2
109 changes: 88 additions & 21 deletions addons/anima/ui/AnimationPicker/AnimationPicker.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
[gd_scene load_steps=9 format=3 uid="uid://brxnmcufd6edq"]
[gd_scene load_steps=13 format=3 uid="uid://brxnmcufd6edq"]

[ext_resource type="Script" path="res://addons/anima/ui/AnimationPicker/AnimationPicker.gd" id="1_cyqje"]
[ext_resource type="PackedScene" uid="uid://hrxmgulob80r" path="res://addons/anima/ui/AnimationPicker/CTAPrimaryButton.tscn" id="2_6r4ts"]
[ext_resource type="Texture2D" uid="uid://bxufb8w78e7ja" 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_4yg3m"]
content_margin_left = 12.0
content_margin_right = 12.0
bg_color = Color(0.164706, 0.615686, 0.560784, 1)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0tlf5"]
content_margin_left = 12.0
content_margin_right = 12.0
bg_color = Color(0.913725, 0.768627, 0.415686, 1)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_5ixaa"]
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)

Expand All @@ -14,6 +29,14 @@ corner_radius_bottom_right = 8
corner_radius_bottom_left = 8
shadow_size = 2

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_uodjx"]
bg_color = Color(0.913725, 0.768627, 0.415686, 1)
corner_radius_top_left = 8
corner_radius_top_right = 8
corner_radius_bottom_right = 8
corner_radius_bottom_left = 8
shadow_size = 2

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kcx2w"]
bg_color = Color(0.8, 0.8, 0.811765, 1)

Expand All @@ -30,6 +53,11 @@ script = ExtResource("1_cyqje")
[node name="TabContainer" type="TabContainer" parent="."]
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/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")

[node name="Animations" type="HBoxContainer" parent="TabContainer"]
Expand Down Expand Up @@ -57,14 +85,13 @@ grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="DemoControl" type="Label" parent="TabContainer/Animations/Control/ControlContainer"]
[node name="LabelDemo" type="Label" parent="TabContainer/Animations/Control/ControlContainer"]
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
theme_override_font_sizes/font_size = 92
text = "Anima"

[node name="SpriteDemo" type="Sprite2D" parent="TabContainer/Animations/Control/ControlContainer"]
visible = false
modulate = Color(0, 0, 0, 1)
position = Vector2(152.5, 66)
texture = ExtResource("2_pk6n6")
Expand All @@ -90,13 +117,47 @@ layout_mode = 2

[node name="Label" type="Label" parent="TabContainer/Animations/Control/Panel/MarginContainer/HBoxContainer"]
layout_mode = 2
text = "Animation speed (s):"
text = "Animation duration (s):"

[node name="AnimationSpeed" type="LineEdit" parent="TabContainer/Animations/Control/Panel/MarginContainer/HBoxContainer"]
layout_mode = 2
text = "0.3"
text = "0.7"
alignment = 2

[node name="ControlWarning" type="MarginContainer" parent="TabContainer/Animations/Control"]
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -101.5
offset_top = -42.0
offset_right = 101.5
grow_horizontal = 2
grow_vertical = 0
theme_override_constants/margin_bottom = 12

[node name="Panel" type="PanelContainer" parent="TabContainer/Animations/Control/ControlWarning"]
layout_mode = 2
size_flags_vertical = 8
theme_override_styles/panel = SubResource("StyleBoxFlat_uodjx")

[node name="MarginContainer" type="MarginContainer" parent="TabContainer/Animations/Control/ControlWarning/Panel"]
layout_mode = 2
theme_override_constants/margin_left = 12
theme_override_constants/margin_top = 8
theme_override_constants/margin_right = 12
theme_override_constants/margin_bottom = 8

[node name="HBoxContainer" type="HBoxContainer" parent="TabContainer/Animations/Control/ControlWarning/Panel/MarginContainer"]
layout_mode = 2

[node name="Label" type="Label" parent="TabContainer/Animations/Control/ControlWarning/Panel/MarginContainer/HBoxContainer"]
layout_mode = 2
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "Skew animations do not work with a \"Control\" node"

[node name="PanelContainer" type="PanelContainer" parent="TabContainer/Animations"]
custom_minimum_size = Vector2(1, 0)
layout_mode = 2
Expand All @@ -105,6 +166,7 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_kcx2w")
[node name="VBoxContainer" type="VBoxContainer" parent="TabContainer/Animations"]
custom_minimum_size = Vector2(320, 0)
layout_mode = 2
theme_override_constants/separation = 0

[node name="ScrollContainer" type="ScrollContainer" parent="TabContainer/Animations/VBoxContainer"]
layout_mode = 2
Expand All @@ -114,7 +176,6 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_6myxi")
[node name="ListContainer" type="VBoxContainer" parent="TabContainer/Animations/VBoxContainer/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 0

[node name="MarginContainer" type="MarginContainer" parent="TabContainer/Animations/VBoxContainer"]
Expand Down Expand Up @@ -150,21 +211,27 @@ layout_mode = 2
size_flags_horizontal = 3
text = "Close"

[node name="Key Frames" type="HBoxContainer" parent="TabContainer"]
visible = false
layout_mode = 2

[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" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33286" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33286" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33291" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33291" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33296" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33296" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33302" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33302" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33308" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33308" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33323" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33323" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33337" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33337" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33342" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33342" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33348" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33348" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33354" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33354" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33359" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33359" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33364" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33364" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33369" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33369" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33371" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33371" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33381" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@33381" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22194" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22194" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22199" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22199" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22204" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22204" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22210" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22210" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22216" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22216" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22231" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22231" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22245" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22245" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22250" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22250" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22256" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22256" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22262" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22262" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22267" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22267" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22272" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22272" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22277" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22277" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22279" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22279" method="_on_toggled" flags=18]
[connection signal="toggled" from="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22289" to="TabContainer/Animations/VBoxContainer/ScrollContainer/ListContainer/@Button@22289" method="_on_toggled" flags=18]
[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"]
13 changes: 11 additions & 2 deletions addons/anima/utils/node_properties.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#
class_name AnimaNodesProperties

const ANIMA_PIVOT_APPLIED_META = "__anima_pivot_applied"

static func get_position(node: Node):
if node is Control or node is Window:
return node.position
Expand Down Expand Up @@ -41,8 +43,10 @@ static func get_rotation(node: Node):
static func set_2D_pivot(node: Node, pivot: int) -> void:
var size: Vector2 = get_size(node)

if node is Window:
pass
if node is Window or node.has_meta(ANIMA_PIVOT_APPLIED_META):
return

node.set_meta(ANIMA_PIVOT_APPLIED_META, true)

match pivot:
ANIMA.PIVOT.TOP_CENTER:
Expand All @@ -64,6 +68,11 @@ static func set_2D_pivot(node: Node, pivot: int) -> void:
ANIMA.PIVOT.CENTER:
if node is Control:
node.set_pivot_offset(size / 2)
else:
var position = node.position

node.offset = Vector2(size.x / 2, size.y / 2)
node.position = position - node.offset
ANIMA.PIVOT.BOTTOM_CENTER:
if node is Control:
node.set_pivot_offset(Vector2(size.x / 2, size.y / 2))
Expand Down
Loading

0 comments on commit 698487b

Please sign in to comment.