54 lines
1.5 KiB
GDScript
54 lines
1.5 KiB
GDScript
extends Panel
|
|
|
|
const DIP_DURATION := 0.36
|
|
|
|
@onready var _tickets: Array = get_children().filter(func(c): return c is TextureRect)
|
|
|
|
var _current_index := 0
|
|
var _tween: Tween
|
|
|
|
|
|
func _ready() -> void:
|
|
for i in _tickets.size():
|
|
_tickets[i].visible = (i == 0)
|
|
_tickets[i].modulate.a = 1.0
|
|
|
|
|
|
func show_index(index: int, animate: bool = true) -> void:
|
|
if index < 0 or index >= _tickets.size() or index == _current_index:
|
|
return
|
|
|
|
var from_ticket: TextureRect = _tickets[_current_index]
|
|
var to_ticket: TextureRect = _tickets[index]
|
|
|
|
if not animate:
|
|
from_ticket.visible = false
|
|
to_ticket.visible = true
|
|
to_ticket.modulate.a = 1.0
|
|
_current_index = index
|
|
return
|
|
|
|
if _tween:
|
|
_tween.kill()
|
|
|
|
var from_mat: ShaderMaterial = from_ticket.material
|
|
var to_mat: ShaderMaterial = to_ticket.material
|
|
|
|
_tween = create_tween()
|
|
_tween.set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)
|
|
if from_mat:
|
|
_tween.tween_method(func(v): from_mat.set_shader_parameter("blur_amount", v), 0.0, 1.0, DIP_DURATION * 0.5)
|
|
_tween.parallel().tween_property(from_ticket, "modulate:a", 0.0, DIP_DURATION * 0.5)
|
|
|
|
_tween.tween_callback(func():
|
|
from_ticket.visible = false
|
|
to_ticket.modulate.a = 0.0
|
|
to_ticket.visible = true
|
|
_current_index = index
|
|
)
|
|
|
|
_tween.set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
|
|
if to_mat:
|
|
_tween.tween_method(func(v): to_mat.set_shader_parameter("blur_amount", v), 1.0, 0.0, DIP_DURATION * 0.5)
|
|
_tween.parallel().tween_property(to_ticket, "modulate:a", 1.0, DIP_DURATION * 0.5)
|