extends Control

@onready
var player_name := $HBoxContainer/Name

@onready
var points := $HBoxContainer/Points

@onready
var add := $HBoxContainer/AddPoint

@onready
var minus := $HBoxContainer/RemovePoint

@onready
var character := $HBoxContainer/Character

signal change_character_clicked


# Called when the node enters the scene tree for the first time.
func _ready():
	print("_ready")
	add.pressed.connect(add_point)
	minus.pressed.connect(minus_point)
	character.pressed.connect(change_character)
	player_name.mouse_filter = Control.MOUSE_FILTER_PASS
	player_name.gui_input.connect(name_clicked)

func name_clicked(event):
	if (event is InputEventMouseButton && event.pressed && event.button_index == MOUSE_BUTTON_LEFT):
		print("Clicked: " + player_name.text)

func add_point():
	var value := int(points.text)
	points.text = str(value + 1)
	
func minus_point():
	var value := int(points.text)
	points.text = str(value - 1)
	
func change_character():
	print("change_character")
	change_character_clicked.emit()

func _on_control_character_selected_clicked(file_name: String):
	print("Back in player list with: " + file_name)
	
	var texture = load("res://characters/" + file_name)
	character.custom_minimum_size = Vector2(80, 40)
	character.ignore_texture_size = true
	character.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT
	character.texture_normal = texture
