package com.pesets.idle.scenes.ui;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.pesets.game.Player;
import com.pesets.game.items.EquipItem;

public class SkillPriority extends Window implements ClickListener {

	Player player;
	TextButton firstButton, secondButton;

	public SkillPriority(Skin skin, Player player) {
		super("State priorities", skin);
		this.player = player;
		
		firstButton = new TextButton(skin);
		firstButton.setClickListener(this);
		secondButton = new TextButton(skin);
		secondButton.setClickListener(this);
		

		width = 200;
		width(200);
		
		add(firstButton).expand();
		row();
		add(secondButton).expand();
		
		setNames();
	}
	
	private void setNames()
	{
		firstButton.setText("First: " + EquipItem.stateNames[player.getFirstStatePiority()]);
		secondButton.setText("Second: " + EquipItem.stateNames[player.getSecondStatePriority()]);
	}

	@Override
	public void click(Actor actor, float x, float y) {
		if (actor == firstButton)
		{
			int state = player.getFirstStatePiority();
			state = (state + 1) % 4;
			if (state == player.getSecondStatePriority())
				state = (state + 1) % 4;
			player.setFirstStatePiority(state);
		}
		else if (actor == secondButton)
		{
			int state = player.getSecondStatePriority();
			state = (state + 1) % 4;
			if (state == player.getFirstStatePiority())
				state = (state + 1) % 4;
			player.setSecondStatePriority(state);
		}
		
		setNames();
	}
}
