using System;
using System.Threading.Tasks;
using Godot;

public partial class UIHandler : Control
{
	public override void _Ready()
	{
		GetNode<ColorPickerButton>("./MainUI/HeaderContainer/Header/LightColor").Color = GameData.lightColor;
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{

	}

	public void ChangeColor(Color color)
	{
		GameData.lightColor = color;
		LightHandler.RedrawLights(color);
	}

	public void ShowNamingPopup(Robot robot)
	{
		VBoxContainer namingContainer = GetNode<VBoxContainer>("./Popup/RobotNaming");
		namingContainer.Visible = true;
		GameData.canMove = false;
		LineEdit name = namingContainer.GetNode<LineEdit>("./LineEdit");
		Button button = namingContainer.GetNode<Button>("./Button");

		Action handler = null;
		handler = () =>
		{
			robot.Name = name.Text;
			name.Text = "";
			namingContainer.Visible = false;
			GameData.canMove = true;
			button.ButtonUp -= handler;
		};

		button.ButtonUp += handler;
	}

}
