Skip to content

Commit

Permalink
test animatable vbox
Browse files Browse the repository at this point in the history
  • Loading branch information
ceceppa committed Sep 6, 2024
1 parent 3cb11e8 commit 42cc0d0
Show file tree
Hide file tree
Showing 34 changed files with 883 additions and 108 deletions.
1 change: 0 additions & 1 deletion TestScene/Test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,3 @@ func _on_Button_pressed():
Anima.begin(self).then(
Anima.Node($Button).anima_position_x(half_screen_x, 1).anima_from(-178)
).play_with_delay(1)

5 changes: 1 addition & 4 deletions addons/anima/anima_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ func _enter_tree():

add_inspector_plugin(_anima_inspector_plugin)

func _ready():
_anima_inspector_plugin.set_godot_theme(get_editor_interface().get_base_control().theme)

func _exit_tree():
remove_autoload_singleton('ANIMA')

Expand All @@ -31,6 +28,6 @@ func _update_animated_events(node: Node, current_data: Array[Dictionary], events
undo_redo.commit_action()

func _undo_update_animated_events(node: Node, previous_data):
node.set_animated_events(previous_data)
node._animatable.set_animated_events(previous_data)

_anima_inspector_plugin.refresh_event_items()
229 changes: 229 additions & 0 deletions addons/anima/components/AnimatedHBoxContainer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
@tool
extends HBoxContainer
class_name AnimaAnimatedHBoxContainer

@export var _events: Array[Dictionary] = []

var _animatable = AnimaAnimatable.new(self, _events)

func _notification(what):
_animatable.on_notification(what)

#
#signal animation_completed
#signal animation_event_completed(name: String)
#
#var _can_exit := true
#var _has_delete_been_called := false
#var _exit_event_data: Dictionary
#
#var _should_handle_visibility_change := false
#var _on_visible_event_data
#var _on_hidden_event_data
#
#var _ignore_animations := false
#var _ignore_visibility_event := false
#
#var _old_visibility := visible
#
#func _ready():
#if get_parent() is Window:
#get_tree().set_auto_accept_quit(_can_exit)
#
#func _enter_tree():
#_handle_events()
#
#func _handle_events():
#for event in _events:
#if not event.has("event_data") or \
#(event.event_data.has("skip") and event.event_data.skip):
#continue
#
#match event.event_name:
#"tree_exiting":
#_can_exit = false
#_exit_event_data = event
#"on_visible":
#_should_handle_visibility_change = true
#_on_visible_event_data = event
#"on_hidden":
#_should_handle_visibility_change = true
#_on_hidden_event_data = event
#_:
#connect(event.event_name, _animate_event.bind(event))
#
#func _update_events():
#for s in get_signal_list():
#if is_connected(s.name, _animate_event):
#disconnect(s.name, _animate_event)
#
#_can_exit = true
#_should_handle_visibility_change = false
#_on_visible_event_data = null
#_on_hidden_event_data = null
#
#_handle_events()
#
#func _animate_event(event: Dictionary):
#var data = event.event_data
#
#var anima = (
#Anima.Grid(self)
#.anima_animation(data.animation, data.duration)
#.anima_delay(data.delay)
#)
#
#var on_started = _get_animation_event("on_started", event)
#var on_completed = _get_animation_event("on_completed", event)
#
#if on_started:
#anima.anima_on_started(on_started)
#
#if on_completed:
#anima.anima_on_completed(on_completed)
#
#return
#if data.play_mode == 0:
#anima.play()
#elif data.play_mode == 1:
#anima.play_backwards()
#else:
#prints(data.loop_mode, data.loop_times)
#if data.loop_mode == 0:
#anima.loop(data.loop_times)
#elif data.loop_mode == 1:
#anima.loop_backwards(data.loop_times)
#else:
#anima.loop_in_circle(data.loop_times)
#
#await anima.animation_completed
#
#animation_completed.emit()
#animation_event_completed.emit(event.event_name)
#
#func _get_animation_event(event_name: String, data: Dictionary):
#if not data.has("events") or not data.events.has(event_name):
#return null
#
#var event = data.events[event_name]
#var node: Node = get_node(event.path)
#
#if not node:
#return null
#
#return func():
#if event.type == 0:
#if event.args.size() == 0:
#node.call(event.name)
#else:
#node.callv(event.name, event.args)
#
#func set_animated_events(events: Array[Dictionary]) -> void:
#_events = events
#
#_update_events()
#
#func get_animated_events() -> Array[Dictionary]:
#return _events
#
#func get_animated_event_at(index: int) -> Dictionary:
#return _events[index] if index <= _events.size() else {}
#
#func set_animated_event_name_at(index: int, event_name: String) -> Array[Dictionary]:
#_events[index].event_name = event_name
#
#_update_events()
#
#return _events
#
#func set_animated_event_data_at(index: int, data: Dictionary) -> Array[Dictionary]:
#_events[index].event_data = data
#
#_update_events()
#
#return _events
#
#func set_animated_event(index: int, event_name: String, data: Dictionary):
#_events[index] = { event_name = event_name, event_data = data }
#
#_update_events()
#
#func add_new_event() -> Array[Dictionary]:
#_events.push_back({})
#
#return _events
#
#func remove_event_at(index: int) -> Array[Dictionary]:
#_events.remove_at(index)
#
#return _events
#
#func _notification(what):
#match what:
#NOTIFICATION_VISIBILITY_CHANGED:
#if not _should_handle_visibility_change or _old_visibility == visible:
#return
#
#if _ignore_visibility_event:
#_ignore_visibility_event = false
#
#return
#
#_old_visibility = visible
#
#if visible and _on_visible_event_data:
#_trigger_animate_event(_on_visible_event_data)
#elif not visible and _on_hidden_event_data:
#_ignore_visibility_event = true
#
#await get_tree().process_frame
#
#show()
#
#await _trigger_animate_event(_on_hidden_event_data)
#
#hide()
#
#NOTIFICATION_WM_CLOSE_REQUEST:
#if !_can_exit:
#_ignore_animations = true
#
#await _trigger_animate_event(_exit_event_data)
#NOTIFICATION_PREDELETE:
#if not _can_exit and not _has_delete_been_called:
#printerr("Due Godot limitations, please call delete instead of `*_free()` to play the exiting animation")
#
#func set_on_event_data(index: int, anima_event_name: String, data) -> Array[Dictionary]:
#if not _events[index].has("events"):
#_events[index].events = {}
#
#if data == null:
#_events[index].events.erase(anima_event_name)
#else:
#_events[index].events[anima_event_name] = data
#
#return _events
#
#func _trigger_animate_event(event_data):
#_animate_event(event_data)
#
##await anima.animation_completed
#
#func preview_animated_event_at(index: int) -> void:
#_animate_event(_events[index])
##
##await anima.animation_completed
##
##anima.reset_and_clear()
#
#func delete():
#if _can_exit:
#queue_free()
#
#return
#
#_has_delete_been_called = true
#
#await _trigger_animate_event(_exit_event_data)
#
#queue_free()
Loading

0 comments on commit 42cc0d0

Please sign in to comment.