Skip to content

Commit

Permalink
visual editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ceceppa committed Jul 18, 2022
1 parent 335a54b commit 1d7c450
Show file tree
Hide file tree
Showing 14 changed files with 629 additions and 73 deletions.
3 changes: 3 additions & 0 deletions addons/anima/components/AnimaButton.gd
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,6 @@ func _on_mouse_entered() -> void:

func _on_mouse_exited() -> void:
emit_signal("mouse_exited")

func pressed() -> bool:
return _button.pressed
3 changes: 3 additions & 0 deletions addons/anima/core/anima.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ static func begin_single_shot(node: Node, name: String = "anima") -> AnimaNode:
static func Node(node: Node) -> AnimaDeclarationNode:
return AnimaDeclarationNode.new(node)

static func Nodes(nodes: Array) -> AnimaDeclarationNodes:
return AnimaDeclarationNodes.new(nodes)

static func Group(group: Node, items_delay: float, animation_type: int = ANIMA.GROUP.FROM_TOP, point := 0) -> AnimaDeclarationGroup:
var c := AnimaDeclarationGroup.new()

Expand Down
39 changes: 22 additions & 17 deletions addons/anima/core/anima_node.gd
Original file line number Diff line number Diff line change
Expand Up @@ -382,34 +382,39 @@ func _setup_animation(data: Dictionary) -> float:
return _setup_node_animation(data)

func _setup_node_animation(data: Dictionary) -> float:
var node = data.node
var n = data.node
var nodes: Array = data.nodes if data.has("nodes") else []
var delay = data.delay if data.has('delay') else 0.0
var duration = data.duration

data._wait_time = max(0.0, data._wait_time + delay)

if data.has("property") and not data.has("animation"):
data._is_first_frame = true
data._is_last_frame = true
if n:
nodes.push_back(n)

if data.has("animation"):
var keyframes = data.animation
for node in nodes:
if data.has("property") and not data.has("animation"):
data._is_first_frame = true
data._is_last_frame = true

if keyframes is String:
keyframes = AnimaAnimationsUtils.get_animation_keyframes(data.animation)
if data.has("animation"):
var keyframes = data.animation

if keyframes.size() == 0:
printerr('animation not found: %s' % data.animation)
if keyframes is String:
keyframes = AnimaAnimationsUtils.get_animation_keyframes(data.animation)

return duration
if keyframes.size() == 0:
printerr('animation not found: %s' % data.animation)

var real_duration = _anima_tween.add_frames(data, keyframes)
return duration

if real_duration > 0:
duration = real_duration
else:
if is_instance_valid(_anima_tween):
_anima_tween.add_animation_data(data)
var real_duration = _anima_tween.add_frames(data, keyframes)

if real_duration > 0:
duration = real_duration
else:
if is_instance_valid(_anima_tween):
_anima_tween.add_animation_data(data)

return duration

Expand Down
123 changes: 123 additions & 0 deletions addons/anima/core/declaration/anima_declaration_nodes.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
class_name AnimaDeclarationNodes

var _data: Dictionary

func _init(nodes: Array = []):
_data.nodes = nodes

func _set_data(data: Dictionary) -> void:
_data = data

func _create_declaration_for_animation(data: Dictionary) -> AnimaDeclarationForAnimation:
var c:= AnimaDeclarationForAnimation.new()

for key in data:
_data[key] = data[key]

return c._init_me(_data)

func _create_declaration_with_easing(data: Dictionary) -> AnimaDeclarationForProperty:
var c:= AnimaDeclarationForProperty.new()

for key in data:
_data[key] = data[key]

return c._init_me(_data)

func _create_relative_declaration_with_easing(data: Dictionary) -> AnimaDeclarationForRelativeProperty:
var c:= AnimaDeclarationForRelativeProperty.new()

for key in data:
_data[key] = data[key]

return c._init_me(_data)

func anima_animation(animation: String, duration = null, ignore_initial_values := false) -> AnimaDeclarationForAnimation:
return _create_declaration_for_animation({ animation = animation, duration = duration, _ignore_initial_values = ignore_initial_values })

func anima_animation_frames(frames: Dictionary, duration = null, ignore_initial_values := false) -> AnimaDeclarationForAnimation:
return _create_declaration_for_animation({ animation = frames, duration = duration, _ignore_initial_values = ignore_initial_values })

func anima_property(property: String, final_value = null, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = property, to = final_value, duration = duration })

func anima_fade_in(duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "opacity", from = 0.0, to = 1.0, duration = duration })

func anima_fade_out(duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "opacity", from = 1.0, to = 0.0, duration = duration })

func anima_position(position: Vector2, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "position", to = position, duration = duration })

func anima_position3D(position: Vector3, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "position", to = position, duration = duration })

func anima_position_x(x: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "x", to = x, duration = duration })

func anima_position_y(y: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "y", to = y, duration = duration })

func anima_position_z(z: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "z", to = z, duration = duration })

func anima_relative_position(position: Vector2, duration = null) -> AnimaDeclarationForRelativeProperty:
return _create_relative_declaration_with_easing({ property = "position", to = position, duration = duration, relative = true })

func anima_relative_position3D(position: Vector3, duration = null) -> AnimaDeclarationForRelativeProperty:
return _create_relative_declaration_with_easing({ property = "position", to = position, duration = duration, relative = true })

func anima_relative_position_x(x: float, duration = null) -> AnimaDeclarationForRelativeProperty:
return _create_relative_declaration_with_easing({ property = "x", to = x, duration = duration, relative = true })

func anima_relative_position_y(y: float, duration = null) -> AnimaDeclarationForRelativeProperty:
return _create_relative_declaration_with_easing({ property = "y", to = y, duration = duration, relative = true })

func anima_relative_position_z(z: float, duration = null) -> AnimaDeclarationForRelativeProperty:
return _create_relative_declaration_with_easing({ property = "z", to = z, duration = duration, relative = true })

func anima_scale(scale: Vector2, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "scale", to = scale, duration = duration })

func anima_scale3D(scale: Vector3, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "scale", to = scale, duration = duration })

func anima_scale_x(x: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "scale:x", to = x, duration = duration })

func anima_scale_y(y: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "scale:y", to = y, duration = duration })

func anima_scale_z(z: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "scale:z", to = z, duration = duration })

func anima_size(size: Vector2, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "size", to = size, duration = duration })

func anima_size3D(size: Vector3, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "size", to = size, duration = duration })

func anima_size_x(size: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "size:x", to = size, duration = duration })

func anima_size_y(size: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "size:y", to = size, duration = duration })

func anima_size_z(size: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "size:z", to = size, duration = duration })

func anima_rotate(rotate: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "rotate", to = rotate, duration = duration })

func anima_rotate3D(rotate: Vector3, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "rotation", to = rotate, duration = duration })

func anima_rotate_x(x: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "rotation:x", to = x, duration = duration })

func anima_rotate_y(y: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "rotation:y", to = y, duration = duration })

func anima_rotate_z(z: float, duration = null) -> AnimaDeclarationForProperty:
return _create_declaration_with_easing({ property = "rotation:z", to = z, duration = duration })
15 changes: 12 additions & 3 deletions addons/anima/core/tween.gd
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func _apply_initial_values(animation_data: Dictionary) -> void:
var is_rect2 = property_data.has("is_rect2") and property_data.is_rect2
var is_object = typeof(property_data.property) == TYPE_OBJECT

if value is String:
value = AnimaTweenUtils.maybe_calculate_value(value, animation_data)

if is_rect2:
push_warning("not yet implemented")
pass
Expand Down Expand Up @@ -348,18 +351,24 @@ func _calculate_frame_data(wait_time: float, animation_data: Dictionary, relativ

for property_to_animate in keys:
var data = animation_data.duplicate()
var start_percentage = previous_key_value[property_to_animate].percentage
var start_percentage = previous_key_value[property_to_animate].percentage if previous_key_value.has(property_to_animate) else 0
var percentage = (current_frame_key - start_percentage) / 100.0
var frame_duration = max(ANIMA.MINIMUM_DURATION, duration * percentage)
var percentage_delay := 0.0
var relative = relative_properties.find(property_to_animate) >= 0
var initial_key = "__initial_" + property_to_animate
var initial_value = node.get_meta(initial_key)
var initial_value = node.get_meta(initial_key) if node.has_meta(initial_key) else null

if start_percentage > 0:
percentage_delay += (start_percentage/ 100.0) * duration

var from_value = previous_key_value[property_to_animate].value
var from_value

if previous_key_value.has(property_to_animate):
from_value = previous_key_value[property_to_animate].value
else:
from_value = AnimaNodesProperties.get_property_value(node, animation_data, property_to_animate)

var to_value = frame_data[property_to_animate]

#
Expand Down
1 change: 1 addition & 0 deletions addons/anima/icons/collapse-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions addons/anima/ui/AnimaEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func _restore_data(data: Dictionary) -> void:
else:
pass

_frames_editor.select_frame(frame_key)
var the_frame = _frames_editor.select_frame(frame_key)

var frame_name: String = frame_data.name if frame_data.has("name") and frame_data.name else "Frame " + str(index)

Expand All @@ -158,6 +158,11 @@ func _restore_data(data: Dictionary) -> void:

item.restore_data(value)

# TODO: Restore collapse
if frame_data.has("collapsed") and frame_data.collapsed:
# the_frame.collapse()
pass

_frames_editor.set_is_restoring_data(false)


Expand Down Expand Up @@ -287,4 +292,4 @@ func _on_select_easing(source: Node) -> void:
$AnimaEasingsWindow.popup_centered()

func _on_AnimaEasingsWindow_easing_selected(easing_name: String, easing_value: int):
prints(easing_name, easing_value)
_animation_source_node.set_easing(easing_name, easing_value)
13 changes: 12 additions & 1 deletion addons/anima/ui/editor/AnimaAnimationData.gd
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func get_data() -> Dictionary:
initialValue = _property_values.find_node("InitialValue").get_value(),
relative = _property_values.find_node("RelativeCheck").pressed,
pivot = _property_values.find_node("PivotButton").get_value(),
easing = [easing_button.name, easing_value]
easing = [easing_button.text, easing_value]
}

return data
Expand Down Expand Up @@ -122,6 +122,9 @@ func restore_data(data: Dictionary) -> void:
if data.has("pivot"):
_property_values.find_node("PivotButton").set_value(data.pivot)

if data.has("easing"):
set_easing(data.easing[0], data.easing[1])

func set_relative_property(node_path: String, property: String) -> void:
var value = _relative_source.get_value()

Expand Down Expand Up @@ -158,6 +161,14 @@ func selected_animation(label, name) -> void:

emit_signal("updated")

func set_easing(name: String, value: int) -> void:
var button: Button = find_node("EasingButton")

button.text = name
button.set_meta("easing_value", value)

emit_signal("updated")

func _on_AnimateProperty_pressed():
emit_signal("updated")

Expand Down
1 change: 0 additions & 1 deletion addons/anima/ui/editor/AnimaAnimationData.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,6 @@ margin_left = 172.0
margin_top = 243.0
margin_right = 996.0
margin_bottom = 288.0
rect_min_size = Vector2( 0, 32 )

[node name="Easing" type="Label" parent="Content/MarginContainer/AnimaData/AnimateWith/Wrapper/Container/PropertyValues/AnimateGrid"]
margin_top = 306.0
Expand Down
Loading

0 comments on commit 1d7c450

Please sign in to comment.