tab animations
This commit is contained in:
@@ -4,10 +4,11 @@ extends Control
|
||||
signal tab_pressed
|
||||
signal tab_closed
|
||||
|
||||
@onready var gradient_texture: TextureRect = $GradientTexture
|
||||
@onready var button: Button = $Button
|
||||
@onready var close_button: Button = $CloseButton
|
||||
@onready var icon: TextureRect = $Icon
|
||||
@onready var gradient_texture: TextureRect = %GradientTexture
|
||||
@onready var button: Button = %Button
|
||||
@onready var close_button: Button = %CloseButton
|
||||
@onready var icon: TextureRect = %Icon
|
||||
@onready var animation: AnimationPlayer = $AnimationPlayer
|
||||
|
||||
const TAB_GRADIENT: GradientTexture2D = preload("res://Scenes/Styles/TabGradient.tres")
|
||||
const TAB_GRADIENT_DEFAULT: GradientTexture2D = preload("res://Scenes/Styles/TabGradientDefault.tres")
|
||||
@@ -20,6 +21,7 @@ const CLOSE_BUTTON_NORMAL: StyleBoxFlat = preload("res://Scenes/Styles/CloseButt
|
||||
|
||||
var is_active := false
|
||||
var mouse_over_tab := false
|
||||
var loading_tween: Tween
|
||||
|
||||
func _ready():
|
||||
add_to_group("tabs")
|
||||
@@ -44,6 +46,32 @@ func set_icon(new_icon: Texture) -> void:
|
||||
icon.texture = new_icon
|
||||
icon.rotation = 0
|
||||
|
||||
func update_icon_from_url(icon_url: String) -> void:
|
||||
const LOADER_CIRCLE = preload("res://Assets/Icons/loader-circle.svg")
|
||||
|
||||
loading_tween = create_tween()
|
||||
|
||||
set_icon(LOADER_CIRCLE)
|
||||
|
||||
loading_tween.set_loops()
|
||||
|
||||
icon.pivot_offset = Vector2(11.5, 11.5)
|
||||
loading_tween.tween_method(func(angle):
|
||||
if !is_instance_valid(icon):
|
||||
if loading_tween: loading_tween.kill()
|
||||
return
|
||||
icon.rotation = angle
|
||||
, 0.0, TAU, 1.0)
|
||||
|
||||
var icon_resource = await Network.fetch_image(icon_url)
|
||||
|
||||
# Only update if tab still exists
|
||||
if is_instance_valid(self):
|
||||
set_icon(icon_resource)
|
||||
if loading_tween:
|
||||
loading_tween.kill()
|
||||
loading_tween = null
|
||||
|
||||
func _on_button_mouse_entered() -> void:
|
||||
mouse_over_tab = true
|
||||
if is_active: return
|
||||
@@ -55,6 +83,9 @@ func _on_button_mouse_exited() -> void:
|
||||
gradient_texture.texture = TAB_GRADIENT_DEFAULT
|
||||
|
||||
func _exit_tree():
|
||||
if loading_tween:
|
||||
loading_tween.kill()
|
||||
loading_tween = null
|
||||
remove_from_group("tabs")
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
@@ -70,4 +101,6 @@ func _on_button_pressed() -> void:
|
||||
|
||||
func _on_close_button_pressed() -> void:
|
||||
tab_closed.emit()
|
||||
animation.play("appear", -1, -1.0, true)
|
||||
await animation.animation_finished
|
||||
queue_free()
|
||||
|
||||
Reference in New Issue
Block a user