extends Control

class_name DescriptionPane

onready var NameLabel : Label = $NameLabel
onready var TitleLabel : Label = $TitleLabel
onready var DescriptionsLabel : Label = $Descriptions
onready var Portrait : TextureRect = $Portrait

#func _ready():
#	test()
#
#func test():
#	while true:
#		yield(get_tree().create_timer(2), "timeout")
#		show()
#		yield(get_tree().create_timer(2), "timeout")
#		hide()

func easeInOutQuart(x: float):
	return 8 * x * x * x * x if x < 0.5 else 1 - pow(-2 * x + 2, 4) / 2

func fill(name: String, title: String, description: String, portrait : Resource = null):
	NameLabel.text = name
	TitleLabel.text = title
	DescriptionsLabel.text = description

func show():
	easeInEaseOut(Vector2.ZERO)
	
func hide():
	easeInEaseOut(Vector2(-self.margin_right, 0))

func easeInEaseOut(final_pos: Vector2):
	var start_pos = Vector2(self.margin_left, self.margin_top)
	var delta = 0
	while delta <= 1:
		yield(get_tree(), "idle_frame")
		delta += get_process_delta_time()
		self.margin_left = lerp(start_pos.x, final_pos.x, easeInOutQuart(delta))
