improve ui and bug fix
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
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 move_tween: Tween
|
||||
var is_photo_mode_enable = false
|
||||
var current_execution: int = 0
|
||||
|
||||
func _ready() -> void:
|
||||
GameState.on_photo_taken_prepare.connect(_hide_photo_taken)
|
||||
GameState.on_photo_taken_finished.connect(_show_photo_taken)
|
||||
CollectionManager.on_photo_saved.connect(_set_photo_taken)
|
||||
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()
|
||||
@@ -17,10 +26,77 @@ func _set_photo_taken(file_path) -> void:
|
||||
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 tween = TweenFX.explode(self, 5, 3)
|
||||
await tween.finished
|
||||
|
||||
var explode_tween_duration = 5.5
|
||||
var move_tween_duration = 1.0
|
||||
|
||||
var explode_tween = TweenFX.explode(self, explode_tween_duration, 3)
|
||||
|
||||
await get_tree().create_timer(explode_tween_duration / 2).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)
|
||||
|
||||
await explode_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 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()
|
||||
|
||||
Reference in New Issue
Block a user