package sample.game.model.titleAi;

import library.core.listener.OnCoreTouchDownListener;
import library.core.mainAI.RiverCrossingAI;
import library.core.model.CoreModel;
import library.core.system.CoreImageData;
import sample.game.controller.TitleAiController;

public class NumberButton extends CoreModel implements OnCoreTouchDownListener{

	public enum TitleAiButtonType{
		boat,
		minister,
		wolf,
		cabbage,
		cattle,
	};

	private TitleAiButtonType type=TitleAiButtonType.boat;
	private int num=0;

	private CoreImageData onImage;
	private CoreImageData offImage;

	private TitleAiController controller;
	private boolean canUse;


	public NumberButton(boolean isOn,TitleAiController controller,TitleAiButtonType type,int menberNum,
			CoreImageData onImage,CoreImageData offImage, float centerX, float centerY,
			float width, float height) {
		super(offImage, centerX, centerY, width, height);

		this.type=type;
		this.num=menberNum;
		this.controller=controller;

		this.onImage=onImage;
		this.offImage=offImage;

		this.canUse=true;

		if(isOn){
			this.setNum();
			this.setImageData(onImage);
		}
	}


/*	*//**
	 * 個数の変更
	 *//*
	@Override
	public void onTouchUp() {
		if(!canUse) return;

		//controller.iconMove(type);

		switch (type) {
		case boat:
			this.controller.setBoatSize(num);
			break;
		case minister:
			this.controller.setMinisterNum(num);
			break;
		case wolf:
			this.controller.setWolfNum(num);
			break;
		case cabbage:
			this.controller.setCabbageNum(num);
			break;
		case cattle:
			this.controller.setCattleNum(num);
			break;
		}

		this.setImageData(onImage);

		//自身と同じ属性のボタンをオフにする
		controller.elseButtonOff(this);
	}*/

	/**
	 * ボタンをオフにする (タイプを与えてそのタイプならボタンを消す)
	 */
	public void setOffImage(TitleAiButtonType type){
		if(type==this.type){
			this.setImageData(offImage);
		}
	}


	public TitleAiButtonType getType() {
		return type;
	}


/**
 * ボタンの有効設定
 * @param canUse
 */
	public void setCanUse(boolean canUse) {
		this.canUse = canUse;
	}


	@Override
	public void onTouchDown() {
		if(!canUse) return;

		RiverCrossingAI.getSePlayer().play(2);

		this.setNum();

		this.setImageData(onImage);

		//自身と同じ属性のボタンをオフにする
		controller.elseButtonOff(this);

	}


	private void setNum(){
		switch (type) {
		case boat:
			this.controller.setBoatSize(num);
			break;
		case minister:
			this.controller.setMinisterNum(num);
			break;
		case wolf:
			this.controller.setWolfNum(num);
			break;
		case cabbage:
			this.controller.setCabbageNum(num);
			break;
		case cattle:
			this.controller.setCattleNum(num);
			break;
		}
	}



}
