extends Panel

signal pressed(layer: int)

@onready var buttons: Control = $Buttons
@onready var value_label_pos: PanelContainer = $ValueLabelPos
@onready var value_rich_text_label: RichTextLabel = $ValueLabelPos/VBoxContainer/ValueRichTextLabel

var min_layer = -8
var button_size = Vector2(64.0, 31.0)
var button_pos_origin = Vector2(130.0, 45.0)
var button_pos_step = Vector2(35.0, 33.0)

func _ready() -> void:
	var layer = min_layer
	var i = 0
	for btn in buttons.get_children():
		if btn is Button:
			btn.position.x = button_pos_origin.x + button_pos_step.x * i
			btn.position.y = button_pos_origin.y + button_pos_step.y * btn.z_index
			btn.size = button_size
			
			btn.pressed.connect(_on_button_pressed.bind(layer))
			btn.mouse_entered.connect(_on_button_mouse_entered.bind(layer))
			btn.mouse_exited.connect(_on_button_mouse_exited)
			
			layer += 1
			i += 1


func _process(_delta: float) -> void:
	pass

func _on_button_pressed(index):
	pressed.emit(index)

func _on_button_mouse_entered(index):
	value_label_pos.position.x = button_pos_origin.x + button_pos_step.x * (index - min_layer)
	value_rich_text_label.text = "[font_size=15][b]%d[/b][/font_size]" % index

func _on_button_mouse_exited():
	value_label_pos.position.x = -9999
