package com.backfire.room.data;

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

import com.backfire.arithmetic.Card;
import com.backfire.doudizhu.common.BitmapManager;
import com.backfire.doudizhu.common.DdzApplication;
import com.backfire.room.data.State.Identity;
import com.backfire.room.data.State.Sex;
import com.backfire.room.data.State.UserState;

/**   
 * @Title: ResCenter.java
 * @Description: TODO(用一句话描述该文件做什么)
 * @author Potter
 * @date 2013年10月29日 下午5:42:01
 * @version V2.0   
 */
public class ResCenter {
	
	public static int getUserIcon(String iconstr){
		int resID = R.drawable.user_icon_1;
		int icon = 0;
		boolean isPureNum=iconstr.matches("[0-9]+");
		if(isPureNum){
			icon = Integer.parseInt(iconstr);
		}
		switch(icon){
			case 1: resID = R.drawable.user_icon_1;break;
			case 2: resID = R.drawable.user_icon_2;break;
			case 3: resID = R.drawable.user_icon_3;break;
			case 4: resID = R.drawable.user_icon_4;break;
			case 5: resID = R.drawable.user_icon_5;break;
			case 6: resID = R.drawable.user_icon_6;break;
			case 7: resID = R.drawable.user_icon_7;break;
			case 8: resID = R.drawable.user_icon_8;break;
			case 9: resID = R.drawable.user_icon_9;break;
			case 10: resID = R.drawable.user_icon_10;break;
			case 11: resID = R.drawable.user_icon_11;break;
			case 12: resID = R.drawable.user_icon_12;break;
			case 13: resID = R.drawable.user_icon_13;break;
			case 14: resID = R.drawable.user_icon_14;break;
			case 15: resID = R.drawable.user_icon_15;break;
			case 16: resID = R.drawable.user_icon_16;break;
			case 17: resID = R.drawable.user_icon_17;break;
			case 18: resID = R.drawable.user_icon_18;break;
			case 19: resID = R.drawable.user_icon_19;break;
			case 20: resID = R.drawable.user_icon_20;break;
			case 21: resID = R.drawable.user_icon_21;break;
		}
		return resID;
	}
	
	public static int getIcon(int icon,int identity,int sex){
		return getIcon(icon,identity, sex, true);
	}
	
	public static int getIcon(int icon,int identity,int sex,boolean isWin){
		int resID=0;
		if(Identity.LANDLORD==identity){
			if(Sex.MALE==sex){
				resID=isWin?R.drawable.m_landlord_h_icon:R.drawable.m_landlord_c_icon;
			}else if(Sex.FEMALE==sex){
				resID=isWin?R.drawable.w_landlord_h_icon:R.drawable.w_landlord_c_icon;
			}
		}else if(Identity.COMMONER==identity){
			if(Sex.MALE==sex){
				resID=isWin?R.drawable.m_peasant_h_icon:R.drawable.m_peasant_c_icon;
			}else if(Sex.FEMALE==sex){
				resID=isWin?R.drawable.w_peasant_h_icon:R.drawable.w_peasant_c_icon;
			}
		}
		if(resID<=0){
			resID=icon;
		}
		return resID;
	}
	
	public static int getOperate(int state) {
		int icon=0;
		switch (state) {
		case UserState.USER_READY:
			icon=R.drawable.ready_text;
			break;
		case UserState.USER_CALL_ONE:
			icon=R.drawable.one_r_text;
			break;
		case UserState.USER_CALL_TWO:
			icon=R.drawable.two_r_text;
			break;
		case UserState.USER_CALL_THREE:
			icon=R.drawable.three_r_text;
			break;
		case UserState.USER_GRAB_GIVEUP:
			icon=R.drawable.no_grab_text;
			break;
		case UserState.USER_GRAB:
			icon=R.drawable.grab_text;
			break;
		case UserState.USER_PLAY_GIVEUP:
			icon=R.drawable.buchu_text;
			break;
		}
		return icon;
	}
	
	public static Bitmap getClockNumber(int i,int scaleToWidth, int scaleToHeight){
		return getClockImage("", i,"",scaleToWidth,scaleToHeight);
	}
	
	public static Bitmap getClockImage(String pre,int i,String suff,int scaleToWidth, int scaleToHeight){
		BitmapManager bitmapManager = DdzApplication.getApplication().getBmpPool();
		Bitmap bitmap=null;
		int value=i%10;
		switch (value) {
		case 0:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_0,scaleToWidth,scaleToHeight);
			break;
		case 1:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_1,scaleToWidth,scaleToHeight);
			break;
		case 2:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_2,scaleToWidth,scaleToHeight);
			break;
		case 3:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_3,scaleToWidth,scaleToHeight);
			break;
		case 4:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_4,scaleToWidth,scaleToHeight);
			break;
		case 5:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_5,scaleToWidth,scaleToHeight);
			break;
		case 6:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_6,scaleToWidth,scaleToHeight);
			break;
		case 7:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_7,scaleToWidth,scaleToHeight);
			break;
		case 8:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_8,scaleToWidth,scaleToHeight);
			break;	
		case 9:
			bitmap=bitmapManager.getBitmap(R.drawable.clock_9,scaleToWidth,scaleToHeight);
			break;
		}
		return bitmap;
	}
	
	public static Bitmap getNumber(int i,int scaleToWidth, int scaleToHeight){
		return getNumber("", i,"",scaleToWidth,scaleToHeight);
	}
	
	public static Bitmap getNumber(String pre,int i,String suff,int scaleToWidth, int scaleToHeight){
		BitmapManager bitmapManager = DdzApplication.getApplication().getBmpPool();
		Bitmap bitmap=null;
		int value=i%10;
		switch (value) {
		case 0:
			bitmap=bitmapManager.getBitmap(R.drawable.y_0,scaleToWidth,scaleToHeight);
			break;
		case 1:
			bitmap=bitmapManager.getBitmap(R.drawable.y_1,scaleToWidth,scaleToHeight);
			break;
		case 2:
			bitmap=bitmapManager.getBitmap(R.drawable.y_2,scaleToWidth,scaleToHeight);
			break;
		case 3:
			bitmap=bitmapManager.getBitmap(R.drawable.y_3,scaleToWidth,scaleToHeight);
			break;
		case 4:
			bitmap=bitmapManager.getBitmap(R.drawable.y_4,scaleToWidth,scaleToHeight);
			break;
		case 5:
			bitmap=bitmapManager.getBitmap(R.drawable.y_5,scaleToWidth,scaleToHeight);
			break;
		case 6:
			bitmap=bitmapManager.getBitmap(R.drawable.y_6,scaleToWidth,scaleToHeight);
			break;
		case 7:
			bitmap=bitmapManager.getBitmap(R.drawable.y_7,scaleToWidth,scaleToHeight);
			break;
		case 8:
			bitmap=bitmapManager.getBitmap(R.drawable.y_8,scaleToWidth,scaleToHeight);
			break;	
		case 9:
			bitmap=bitmapManager.getBitmap(R.drawable.y_9,scaleToWidth,scaleToHeight);
			break;
		}
		return bitmap;
	}
	
	public static Bitmap getTimeNumber(char i,int scaleToWidth, int scaleToHeight){
		return getTimeNumber("", i,"",scaleToWidth,scaleToHeight);
	}
	
	public static Bitmap getTimeNumber(String pre,char i,String suff,int scaleToWidth, int scaleToHeight){
		BitmapManager bitmapManager = DdzApplication.getApplication().getBmpPool();
		Bitmap bitmap=null;
		char value=i;
		switch (value) {
		case '0':
			bitmap=bitmapManager.getBitmap(R.drawable.time_0,scaleToWidth,scaleToHeight);
			break;
		case '1':
			bitmap=bitmapManager.getBitmap(R.drawable.time_1,scaleToWidth,scaleToHeight);
			break;
		case '2':
			bitmap=bitmapManager.getBitmap(R.drawable.time_2,scaleToWidth,scaleToHeight);
			break;
		case '3':
			bitmap=bitmapManager.getBitmap(R.drawable.time_3,scaleToWidth,scaleToHeight);
			break;
		case '4':
			bitmap=bitmapManager.getBitmap(R.drawable.time_4,scaleToWidth,scaleToHeight);
			break;
		case '5':
			bitmap=bitmapManager.getBitmap(R.drawable.time_5,scaleToWidth,scaleToHeight);
			break;
		case '6':
			bitmap=bitmapManager.getBitmap(R.drawable.time_6,scaleToWidth,scaleToHeight);
			break;
		case '7':
			bitmap=bitmapManager.getBitmap(R.drawable.time_7,scaleToWidth,scaleToHeight);
			break;
		case '8':
			bitmap=bitmapManager.getBitmap(R.drawable.time_8,scaleToWidth,scaleToHeight);
			break;	
		case '9':
			bitmap=bitmapManager.getBitmap(R.drawable.time_9,scaleToWidth,scaleToHeight);
			break;
		default:
			bitmap=bitmapManager.getBitmap(R.drawable.time_colon,scaleToWidth,scaleToHeight);
			break;
		}
		return bitmap;
	}
	
	/**获取每张牌对应的id值*/
	public static int getCard(int color,int data,boolean isLaizi,boolean isSmallLaizi,boolean isFLower) {
		if (data <= 0) {
			return R.drawable.card_back;
		}
		if(data == Card.PointSmallJoker){
			return R.drawable.card_joker_s;
		}else if(data == Card.PointBigJoker){
			return R.drawable.card_joker_l;
		}else if(isLaizi){
			if(isSmallLaizi){
				if(isFLower){
					return getFlowerCard(color,data);
				}else{
					return getCard(color,data);
				}
			}else{
				return laizi(data);
			}
		}else{
			return getCard(color,data);
		}
	}
	
	public static Bitmap getCardImg(Card card){
		BitmapManager bitmapManager = DdzApplication.getApplication().getBmpPool();
		Bitmap bitmap=null;
		int resID=getCard(card.getColor(), card.getPoint(), card.isLaiZi(), card.isSmallLaizi(), card.isFlower());
		bitmap=bitmapManager.getBitmap(resID, ConfigCenter.self_hand_card_W, ConfigCenter.self_hand_card_H);
		return bitmap;
	}
	
	public static Bitmap getFlower(){
		BitmapManager bitmapManager = DdzApplication.getApplication().getBmpPool();
		Bitmap bitmap=bitmapManager.getBitmap(R.drawable.card_flower, ConfigCenter.self_hand_card_W,ConfigCenter.self_hand_card_H);
		return bitmap;
	}
	
	private static int getCard(int type,int data){
		switch (type) {
		case Card.Spade:
				return diamonds(data);
	
		case Card.Heart:
				return clubs(data);
	
		case Card.Club:
				return hearts(data);
	
		case Card.Dimond:
				return spades(data);
				
			default:
				return R.drawable.card_back;
		}
	}
	private static int getFlowerCard(int type,int data){
		switch (type) {
		case Card.Spade:
				return dimondFlowerCard(data);
	
		case Card.Heart:
				return clubFlowerCardS(data);
	
		case Card.Club:
				return heartFlowerCardS(data);
	
		case Card.Dimond:
				return spadeFlowerCardS(data);
				
			default:
				return R.drawable.card_back;
		}
	}
	/**黑桃*/
	private static int spades(int value) {
		switch (value) {
		case Card.Point3:
			return R.drawable.card_3_4;
		case Card.Point4:
			return R.drawable.card_4_4;
		case Card.Point5:
			return R.drawable.card_5_4;
		case Card.Point6:
			return R.drawable.card_6_4;
		case Card.Point7:
			return R.drawable.card_7_4;
		case Card.Point8:
			return R.drawable.card_8_4;
		case Card.Point9:
			return R.drawable.card_9_4;
		case Card.Point10:
			return R.drawable.card_10_4;
		case Card.PointJ:
			return R.drawable.card_j_4;
		case Card.PointQ:
			return R.drawable.card_q_4;
		case Card.PointK:
			return R.drawable.card_k_4;
		case Card.PointA:
			return R.drawable.card_a_4;
		case Card.Point2:
			return R.drawable.card_2_4;
		default:
			return R.drawable.card_back;
		}
	}
	/**红桃*/
	private static int hearts(int value) {
		switch (value) {
		case Card.Point3:
			return R.drawable.card_3_3;
		case Card.Point4:
			return R.drawable.card_4_3;
		case Card.Point5:
			return R.drawable.card_5_3;
		case Card.Point6:
			return R.drawable.card_6_3;
		case Card.Point7:
			return R.drawable.card_7_3;
		case Card.Point8:
			return R.drawable.card_8_3;
		case Card.Point9:
			return R.drawable.card_9_3;
		case Card.Point10:
			return R.drawable.card_10_3;
		case Card.PointJ:
			return R.drawable.card_j_3;
		case Card.PointQ:
			return R.drawable.card_q_3;
		case Card.PointK:
			return R.drawable.card_k_3;
		case Card.PointA:
			return R.drawable.card_a_3;
		case Card.Point2:
			return R.drawable.card_2_3;
		default:
			return R.drawable.card_back;
		}
	}
	/**梅花*/
	private static int clubs(int value) {
		switch (value) {
		case Card.Point3:
			return R.drawable.card_3_2;
		case Card.Point4:
			return R.drawable.card_4_2;
		case Card.Point5:
			return R.drawable.card_5_2;
		case Card.Point6:
			return R.drawable.card_6_2;
		case Card.Point7:
			return R.drawable.card_7_2;
		case Card.Point8:
			return R.drawable.card_8_2;
		case Card.Point9:
			return R.drawable.card_9_2;
		case Card.Point10:
			return R.drawable.card_10_2;
		case Card.PointJ:
			return R.drawable.card_j_2;
		case Card.PointQ:
			return R.drawable.card_q_2;
		case Card.PointK:
			return R.drawable.card_k_2;
		case Card.PointA:
			return R.drawable.card_a_2;
		case Card.Point2:
			return R.drawable.card_2_2;
		default:
			return R.drawable.card_back;
		}
	}
	/**方块*/
	private static int diamonds(int value) {
		switch (value) {
		case Card.Point3:
			return R.drawable.card_3_1;
		case Card.Point4:
			return R.drawable.card_4_1;
		case Card.Point5:
			return R.drawable.card_5_1;
		case Card.Point6:
			return R.drawable.card_6_1;
		case Card.Point7:
			return R.drawable.card_7_1;
		case Card.Point8:
			return R.drawable.card_8_1;
		case Card.Point9:
			return R.drawable.card_9_1;
		case Card.Point10:
			return R.drawable.card_10_1;
		case Card.PointJ:
			return R.drawable.card_j_1;
		case Card.PointQ:
			return R.drawable.card_q_1;
		case Card.PointK:
			return R.drawable.card_k_1;
		case Card.PointA:
			return R.drawable.card_a_1;
		case Card.Point2:
			return R.drawable.card_2_1;
		default:
			return R.drawable.card_back;
		}
	}
	/**癞子*/
	public static int laizi(int value) {
		switch (value) {
		case Card.Point3:
			return R.drawable.card_laizi_3;
		case Card.Point4:
			return R.drawable.card_laizi_4;
		case Card.Point5:
			return R.drawable.card_laizi_5;
		case Card.Point6:
			return R.drawable.card_laizi_6;
		case Card.Point7:
			return R.drawable.card_laizi_7;
		case Card.Point8:
			return R.drawable.card_laizi_8;
		case Card.Point9:
			return R.drawable.card_laizi_9;
		case Card.Point10:
			return R.drawable.card_laizi_10;
		case Card.PointJ:
			return R.drawable.card_laizi_j;
		case Card.PointQ:
			return R.drawable.card_laizi_q;
		case Card.PointK:
			return R.drawable.card_laizi_k;
		case Card.PointA:
			return R.drawable.card_laizi_a;
		case Card.Point2:
			return R.drawable.card_laizi_2;
		default:
			return R.drawable.card_back;
		}
	}
	private static int dimondFlowerCard(int point) {
		switch (point) {
		case Card.PointJ:
			return R.drawable.card_n_j_1;
		case Card.PointQ:
			return R.drawable.card_n_q_1;
		case Card.PointK:
			return R.drawable.card_n_k_1;
		}
		return R.drawable.card_back;
	}
	public static int clubFlowerCardS(int point){
		switch (point) {
		case Card.PointJ:
			return R.drawable.card_n_j_2;
		case Card.PointQ:
			return R.drawable.card_n_q_2;
		case Card.PointK:
			return R.drawable.card_n_k_2;
		}
		return R.drawable.card_back;
	}
	public static int heartFlowerCardS(int point){
		switch (point) {
		case Card.PointJ:
			return R.drawable.card_n_j_3;
		case Card.PointQ:
			return R.drawable.card_n_q_3;
		case Card.PointK:
			return R.drawable.card_n_k_3;
		}
		return R.drawable.card_back;
	}
	public static int spadeFlowerCardS(int point){
		switch (point) {
		case Card.PointJ:
			return R.drawable.card_n_j_4;
		case Card.PointQ:
			return R.drawable.card_n_q_4;
		case Card.PointK:
			return R.drawable.card_n_k_4;
		}
		return R.drawable.card_back;
	}

	public static int getFitChatWordBorder(int seatIdx) {
		int resID=0;
		switch (seatIdx) {
		case ConfigCenter.SeatPos1:
			resID=R.drawable.chat_word_rt_border;
			break;
		case ConfigCenter.SeatPos2:
			resID=R.drawable.chat_word_lt_border;
			break;
		case ConfigCenter.SeatPos3:
			resID=R.drawable.chat_word_lb_border;
			break;
		default:
			resID=R.drawable.chat_word_lb_border;
			break;
		}
		return resID;
	}
	public static String getFormSuffix(int formType){
		String formStr="";
		if(formType==1){
			formStr="-癞子场";
		}else if(formType==2){
			formStr="-超级癞子场";
		}else{
			formStr="-经典场";
		}
		return formStr;
	}
}
