package com.backfire.widget;

import net.yeeyo.doudizhu.feiyu.R;
import android.graphics.Bitmap;
import android.graphics.Point;

import com.backfire.doudizhu.common.DdzApplication;
import com.backfire.graphics.PCanvas;
import com.backfire.room.data.ConfigCenter;
import com.backfire.room.data.ResCenter;

public class CardButton {
	private int icon = 0;
	private int x = 0;
	private int y = 0;
	private int width = 0;
	private int height = 0;
	private boolean isTouch = false;
	private boolean isUp = false;
	public boolean isLaizi = false;
	public boolean isSamllLaizi=false;
	
	private int drawicon = 0;
	private int drawx = 0;
	private int drawy = 0;
	private int drawwidth = 0;
	private int drawheight = 0;
	private boolean drawisTouch = false;
	private boolean drawisUp = false;
	public boolean drawisLaizi = false;
	private boolean drawIsSmallLaizi=false;
	private boolean drawInitFinish=false;
	
	public CardButton(int icon,int x,int y,int width,int height,boolean isLaizi, boolean isSmallLaizi){
		this.icon = icon;
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.isLaizi = isLaizi;
		this.isSamllLaizi=isSmallLaizi;
	}
	public void clear(){
		 icon = 0;
		 x = 0;
		 y = 0;
		 width = 0;
		 height = 0;
		 isTouch = false;
		 isUp = false;
		 isLaizi = false;
		 
		 drawicon = 0;
		 drawx = 0;
		 drawy = 0;
		 drawwidth = 0;
		 drawheight = 0;
		 drawisTouch = false;
		 drawisUp = false;
		 drawisLaizi = false;
		 drawInitFinish=false;
	}
	public void draw(PCanvas canvas){
		if(drawicon<=0) return;
		Bitmap bitmap = DdzApplication.getApplication().getBmpPool().getBitmap(drawicon, drawwidth, drawheight);
		if(bitmap==null) return ;
		if(!drawisUp){
			canvas.drawBitmap(bitmap, drawx, drawy, null);
			if(drawisTouch){
				canvas.drawBitmap(bitmap, drawx, drawy, null);
				Bitmap card_shade=DdzApplication.getApplication().getBmpPool().getBitmap(R.drawable.card_shade, ConfigCenter.self_hand_card_W,ConfigCenter.self_hand_card_H);
				canvas.drawBitmap(card_shade, drawx, drawy, null);
			}
			if(drawIsSmallLaizi){	//绘制小癞子
				Bitmap flower=ResCenter.getFlower();
				if(flower!=null){
					canvas.drawBitmap(flower, drawx, drawy, null);
				}
			}
		}else{
			//TODO 当需要将牌的位置稍微上提一点时，只需要将Y轴坐标减去一个固定的数值，该值需要补充
			canvas.drawBitmap(bitmap, drawx, drawy-ConfigCenter.self_hand_card_Off_H, null);
			if(drawisTouch){
				canvas.drawBitmap(bitmap, drawx, drawy-ConfigCenter.self_hand_card_Off_H, null);
				Bitmap card_shade=DdzApplication.getApplication().getBmpPool().getBitmap(R.drawable.card_shade, ConfigCenter.self_hand_card_W,ConfigCenter.self_hand_card_H);
				canvas.drawBitmap(card_shade, drawx, drawy-ConfigCenter.self_hand_card_Off_H, null);
			}
			if(drawIsSmallLaizi){	//绘制小癞子
				Bitmap flower=ResCenter.getFlower();
				if(flower!=null){
					canvas.drawBitmap(flower, drawx, drawy-ConfigCenter.self_hand_card_Off_H, null);
				}
			}
		}
	}
	public void initDraw(){
		drawicon = icon;
		drawx = x;
		drawy = y;
		drawwidth = width;
		drawheight = height;
		drawisTouch = isTouch;
		drawisUp = isUp;
		drawisLaizi = isLaizi;
		drawIsSmallLaizi=isSamllLaizi;
		drawInitFinish=true;
	}
	public void setPosition(int positionX,int positionY){
		 x = positionX;
		 y = positionY;
	}
	
	public int getPositionX(){
		return x;
	}
	
	public int getPositionY(){
		return y;
	}
	
	public void setIsTouch(boolean flag){
		isTouch = flag;
	}
	public void setIsUp(boolean flag){
		isUp = flag;
	}
	
	public boolean isDrawInitFinish() {
		return drawInitFinish;
	}
	public void setDrawInitFinish(boolean drawInitFinish) {
		this.drawInitFinish = drawInitFinish;
	}

}

