extends Control @onready var photo_texture: TextureRect = $%PhotoTexture @onready var collectible_button: Control = get_parent().get_node_or_null("%CollectibleIconButton") var initial_pos_saved := false var initial_pos: Vector2 var appear_tween: Tween var move_tween: Tween var is_photo_mode_enable = false var current_execution: int = 0 func _ready() -> void: CollectionManager.on_photo_preview_ready.connect(_set_photo_preview) GameState.on_enable_photo_mode_request.connect(_on_enable_photo_mode) GameState.on_disable_photo_mode_request.connect(_on_disable_photo_mode) GameState.on_photo_taken_finished.connect(_show_photo_taken) GameState.on_photo_taken_prepare.connect(_hide_photo_taken) func _hide_photo_taken() -> void: hide() func _set_photo_preview(image: Image) -> void: if image: var texture = ImageTexture.create_from_image(image) photo_texture.texture = texture func _show_photo_taken() -> void: current_execution += 1 var my_execution = current_execution reset() if not initial_pos_saved: initial_pos = global_position initial_pos_saved = true global_position = initial_pos scale = Vector2(1,1) modulate.a = 1.0 rotation_degrees = 0.0 show() var appear_duration = 0.8 var float_duration = 1.5 var move_tween_duration = 1.0 var shrink_duration = 1 var scale_amt = 3.0 appear_tween = create_tween() appear_tween.tween_property(self, "scale", Vector2.ONE * scale_amt, appear_duration).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT) appear_tween.parallel().tween_property(self, "rotation_degrees", randf_range(-10, 10), appear_duration * 0.8) await get_tree().create_timer(appear_duration + float_duration).timeout if my_execution != current_execution: return if not is_photo_mode_enable: return collectible_button.scale = Vector2(1,1) collectible_button.show() collectible_button.modulate.a = 1 TweenFX.fold_in(collectible_button, 1) move_tween = create_tween() var target_pos = collectible_button.global_position move_tween.tween_property(self, "global_position:x", target_pos.x, move_tween_duration).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT) move_tween.parallel().tween_property(self, "global_position:y", target_pos.y, move_tween_duration).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN) move_tween.parallel().tween_property(self, "scale", Vector2.ONE * 0.1, shrink_duration).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_IN_OUT) move_tween.parallel().tween_property(self, "modulate:a", 0.0, shrink_duration).set_trans(Tween.TRANS_LINEAR) await move_tween.finished if my_execution != current_execution: return var fold_out_tween = TweenFX.fold_out(collectible_button) if fold_out_tween: await fold_out_tween.finished if my_execution != current_execution: return hide() collectible_button.scale = Vector2(1,1) collectible_button.modulate.a = 1 collectible_button.hide() func _on_enable_photo_mode() -> void: is_photo_mode_enable = true func _on_disable_photo_mode() -> void: is_photo_mode_enable = false reset() func reset() -> void: TweenFX.stop_all(self) if appear_tween: appear_tween.kill() if move_tween: move_tween.kill() hide() if collectible_button: TweenFX.stop_all(collectible_button) collectible_button.scale = Vector2(1,1) if is_photo_mode_enable: collectible_button.modulate.a = 1 collectible_button.hide()