package com.backfire.room.data;

import java.util.ArrayList;

import android.graphics.Paint;
import android.graphics.Paint.FontMetrics;

import com.backfire.doudizhu.common.DdzApplication;
import com.backfire.doudizhu.common.PNumber;
import com.backfire.room.data.State.UserState;

/**
 * @author wf Coordinates of the UI elements in Room Surface
 */
public class ConfigCenter {

	public static final int DEVELOP_WIDTH = 480;
	public static final int DEVELOP_HEIGHT = 320;

	public static final int loadingTextFrontSize = adaptW(50);

	public static final int SeatPos1 = 0;
	public static final int SeatPos2 = 1;
	public static final int SeatPos3 = 2;

	// Initialize flag
	private static boolean mIsInited = false;
	private static final String moneyRegex = "(\\d)(?=(\\d{3})+$)";

	public static int seaW = adaptW(216);
	public static int seaH = adaptH(88);
	// public static int seaX=screenAdaptX(17);
	public static int seaY = adaptY(10);
	public static int sea_card_W = adaptW(52);
	public static int sea_card_H = adaptH(62);
	public static int sea_card_Y = adaptY(22);
	public static int sea_card_noLaizi_gap_border_Off_W = adaptW(24);
	public static int sea_card_laizi_gap_border_Off_W = adaptW(15);
	public static int sea_card_hapyy_Off_W = 0;// adaptW(3);
	public static int sea_card_laizi_Off_W = 0;// adaptW(23);

	public static int game_type_text_W = adaptW(288);
	public static int game_type_text_H = adaptH(204);

	public static int toolbarW = adaptW(721);
	public static int toolbarH = adaptH(114);
	// public static int toolbarX=adaptX(278);
	public static int toolbarY = adaptY(0);

	public static int toolItemW = adaptW(98);
	public static int toolItemH = adaptH(83);
	public static int toolItemY = adaptY(8);

	public static int toolDepositeItemX = adaptX(204);
	public static int toolToolsItemX = adaptX(317);
	public static int toolChatItemX = adaptX(661);
	public static int toolSetItemX = adaptX(775);

	public static int add_VcoinItemW = adaptW(162);
	public static int add_VcoinItemH = adaptH(58);
	public static int add_VcoinItemX = 0;
	public static int add_VcoinItemY = adaptY(380);

	public static int vCoinFontSize = adaptW(30);
	public static int vCoinX = screenAdaptX(1080 - 120);
	public static int vCoinY = adaptY(98);

	public static int rechargeItemW = adaptW(91);
	public static int rechargeItemH = adaptH(36);
	public static int rechargeItemX = adaptX(967);
	public static int rechargeItemY = adaptY(679);

	/*
	 * public static int timeBorderW=adaptW(124); public static int
	 * timeBorderH=adaptH(44); public static int
	 * timeBorderX=screenAdaptX(1080-113); public static int
	 * timeBorderY=adaptY(30);
	 */

	public static int timePosX = adaptX(792);
	public static int timePosY = adaptY(142);
	public static int timeNumW = adaptW(14);
	public static int timeNumH = adaptH(20);
	public static int timeNum_Offset_W = adaptW(2);
	// public static int time_Font_size = adaptW(30);

	public static int roomNameFont_size=adaptW(68);
	
	public static int basePointTagW = adaptW(61);
	public static int basePointTagH = adaptH(27);
	public static int basePointTagX = adaptX(352);
	public static int basePointTagY = adaptY(137);
	public static int basePointX = adaptX(434);
	public static int basePointY = adaptY(142);

	public static int ratioTagW = adaptW(61);
	public static int ratioTagH = adaptH(27);
	public static int ratioTagX = adaptX(602);
	public static int ratioTagY = adaptY(137);
	public static int ratioX = adaptX(684);
	public static int ratioY = adaptY(142);

	public static int yNumberW = adaptW(21);
	public static int yNumberH = adaptH(19);

	// 自己手牌位置
	public static int self_hand_card_W = adaptW(140); // 用户手里牌宽度
	public static int self_hand_card_H = adaptH(182); // 用户手里牌高度
	public static int self_hand_card_PosY = adaptY(527); // 用户手里牌的Y坐标
	public static int self_hand_card_Off_W = adaptW(50); // 用户手里牌的每张牌之间的间距
	public static int self_hand_card_max_Off_W = adaptW(110 * 2 / 3);
	public static int self_hand_card_Off_H = adaptH(20); // 当牌被选择后，牌被提高的高度

	public static int out_card_W = adaptW(66);
	public static int out_card_H = adaptH(93);
	// 20张牌的总长度
	public static int out_card_all_W = adaptW(494);
	public static int out_card_Off_W = adaptW(23);
	public static int[] out_card_PosY;
	public static int[] out_card_Start_X;

	// 3个座位图像的坐标和座位图像的长宽
	public static int room_seat_W = adaptW(162);
	public static int room_seat_H = adaptH(196);
	public static int[] room_seat_X;
	public static int[] room_seat_Y;

	public static int room_chatW = adaptW(353);
	public static int room_chatH = adaptH(44);
	public static int room_chatFontSize = adaptW(32);
	// 偏移对应的座位头像偏移值
	public static int room_chat_offset_W = adaptW(12);
	public static int room_chat_offset_H = adaptH(145);

	// 3个座位图像的坐标和座位图像的长宽
	public static int room_seat_image_W = adaptW(118);
	public static int room_seat_image_H = adaptH(112);
	public static int[] room_seat_image_X;
	public static int[] room_seat_image_Y;
	// 相对room_seat_image左上角位置
	public static int room_seat_card_icon_W = adaptW(20);
	public static int room_seat_card_icon_H = adaptH(25);
	public static int[] room_seat_card_icon_X;
	public static int[] room_seat_card_icon_Y;
	// 相对room_seat_image左上角位置
	public static int[] room_seat_card_num_X;
	public static int[] room_seat_card_num_Y;
	public static int seat_card_num_Font_size = adaptW(30);
	// 身份
	public static int side_tag_W = adaptW(51);
	public static int side_tag_H = adaptH(91);
	// 相对座位右边偏移值
	public static int side_tag_offset_W = -adaptW(43);
	public static int side_tag_offset_H = -adaptH(18);
	// 昵称
	public static int side_nick_W = adaptW(90);
	public static int side_nick_H = adaptH(28);
	public static int side_nick_font_size = adaptW(24);
	// 相对座位左上角偏移值
	public static int side_nick_offset_W = adaptW(30);
	public static int side_nick_offset_H = adaptH(2);
	// 金币
	public static int side_money_W = adaptW(150);
	public static int side_money_H = adaptH(22);
	public static int side_money_font_size = adaptW(28);
	// 相对座位右下角偏移值
	public static int side_money_offset_W = adaptW(45);
	public static int side_money_offset_H = adaptH(40);

	// 操作tag
	public static int operate_tag_offset_W = adaptW(9);
	public static int operate_tag_offset_H = adaptH(24);
	public static int operate_tag_H = adaptH(35);
	public static int operate_two_W = adaptW(64);
	public static int operate_three_W = adaptW(95);
	// 托管tag
	public static int desposit_tag_W = adaptW(60);
	public static int desposit_tag_H = adaptH(46);
	// 托管机器人
	public static int desposit_tag_bt_W = adaptW(247);
	public static int desposit_tag_bt_H = adaptH(215);

	public static int room_bt_W = adaptW(187);
	public static int room_bt_H = adaptH(83);
	public static int room_bt_Y = adaptY(431);

	public static int read_bt_X = adaptX(356);
	public static int leave_bt_X = adaptX(629);
	public static int one_bt_X = adaptX(295);
	public static int two_bt_X = adaptX(493);
	public static int three_bt_X = adaptX(690);

	public static int pass_bt_X = adaptX(186);
	public static int reselect_bt_X = adaptX(376);
	public static int prompt_bt_X = adaptX(567);
	public static int play_bt_X = adaptX(757);

	public static int grab_bt_X = adaptX(365);
	public static int nograb_bt_X = adaptX(629);

	public static int clock_bg_W = adaptW(79);
	public static int clock_bg_H = adaptH(80);
	public static int clock_num_W = adaptW(29);
	public static int clock_num_H = adaptH(40);
	public static int[] clock_X;
	public static int[] clock_Y;
	public static int click_center_Y = adaptY(311);
	// 炸弹
	public static int bomb_anim_W = adaptW(241);
	public static int bomb_anim_H = adaptH(231);
	// 火箭
	public static int rocket_anim_W = adaptW(328);
	public static int rocket_anim_H = adaptH(425);
	// 顺子
	public static int chain_anim_W = adaptW(266);
	public static int chain_anim_H = adaptW(239);
	// 连对
	public static int chain_anim_pair_W = adaptW(178);
	public static int chain_anim_pair_H = adaptW(106);
	// 飞机
	public static int plane_anim_body_W = adaptW(122);
	public static int plane_anim_body_H = adaptW(71);
	public static int plane_anim_smoke_W = adaptW(105);
	public static int plane_anim_smoke_H = adaptW(46);
	// 飞机上下浮动高度
	public static int plane_anim_relacate_Y_H = adaptH(4);
	// 飞机路径长度
	public static int plane_anim_x_path_length = adaptW(670);
	public static int plane_anim_x_step_lenght = adaptW(20);
	// 抽选癞子
	public static int select_laizi_anim_W = adaptW(245);
	public static int select_laizi_anim_H = adaptW(252);
	public static int select_laizi_anim_time = 1400;
	// 垂直上升高度
	public static int select_laizi_rise_H = adaptH(200);
	public static int select_laizi_offset_H = adaptH(32);
	public static int select_laizi_rise_V = adaptH(10);
	public static int select_laizi_move_V = adaptW(10);
	public static int select_laizi_scale_V = adaptW(4);
	// 爆出癞子动画高度
	public static int burst_Laizi_anim_H = adaptH(368);
	// public static int burst_laizi_anim_des_X=seaX+seaW/2;
	public static int burst_laizi_anim_des_Y = sea_card_Y;
	public static int burst_laizi_anim_time = 200;
	public static int burst_laizi_anim_turnV = adaptW(90);// 40旋转速度比较合适
	public static int burst_laizi_anim_moveV = adaptW(1);// 提升正常移动速度的多少倍

	public static boolean volume_off = false;
	static {
		int screenW = DdzApplication.getApplication().screenWidth;
		int startX = screenW - room_seat_W;
		int rightStartX = startX - screenAdaptX(8);
		room_seat_X = new int[] { rightStartX, screenAdaptX(8), screenAdaptX(8) };
		room_seat_Y = new int[] { adaptY(24), adaptY(24), adaptY(301) };

		int offsetX = 24;
		int offsetY = 33;
		rightStartX = startX - screenAdaptX(8 - offsetX);
		room_seat_image_X = new int[] { rightStartX, screenAdaptX(8 + offsetX),
				screenAdaptX(8 + offsetX) };
		room_seat_image_Y = new int[] { adaptY(24 + offsetY),
				adaptY(24 + offsetY), adaptY(301 + offsetY) };

		offsetX = 50;
		offsetY = 200;
		rightStartX = startX - screenAdaptX(8 - offsetX);
		room_seat_card_icon_X = new int[] { rightStartX,
				screenAdaptX(8 + offsetX), screenAdaptX(8 + offsetX) };
		room_seat_card_icon_Y = new int[] { adaptY(24 + offsetY),
				adaptY(24 + offsetY), adaptY(301 + offsetY) };

		offsetX = 84;
		offsetY = 208;
		rightStartX = startX - screenAdaptX(8 - offsetX);
		room_seat_card_num_X = new int[] { rightStartX,
				screenAdaptX(8 + offsetX), screenAdaptX(8 + offsetX) };
		room_seat_card_num_Y = new int[] { adaptY(24 + offsetY),
				adaptY(24 + offsetY), adaptY(301 + offsetY) };

		rightStartX = screenW - screenAdaptX(191);
		out_card_Start_X = new int[] { rightStartX, screenAdaptX(191),
				screenAdaptX(291) };
		out_card_PosY = new int[] { adaptY(189), adaptY(189), adaptY(412) };

		rightStartX = screenW - screenAdaptX(277);
		clock_X = new int[] { rightStartX, screenAdaptX(215), screenAdaptX(215) };
		clock_Y = new int[] { adaptY(170), adaptY(170), adaptY(331) };

		sea_card_hapyy_Off_W = (seaW - (3 * sea_card_W + 2 * sea_card_noLaizi_gap_border_Off_W)) / 2;
		sea_card_laizi_Off_W = (seaW - 3 * sea_card_laizi_gap_border_Off_W - 2 * sea_card_W) / 4;

		add_VcoinItemX = screenW - add_VcoinItemW - screenAdaptX(45);
	}

	public static int getFontAddHeight(Paint paint) {
		FontMetrics fm = paint.getFontMetrics();
		return (int) Math.ceil(fm.bottom - fm.descent);
	}

	public static String getRoomMoney(long money) {
		float f = 0f;
		if (money < 10000l) {
			return getLobbyMoney(money);
		} else if (money < 1000000f) {
			return PNumber.changeFloatAccuracy(money / 10000f, 1) + "W";
		} else {
			return PNumber.changeFloatAccuracy(money / 1000000f, 2) + "M";
		}
	}

	public static ArrayList<Integer> getMoneyList(long money) {
		ArrayList<Integer> list = new ArrayList<Integer>();
		int temp = 0;
		if (money >= 1000000l) {
			temp = (int) (money / 1000000);
			list.add(temp);
			money = money % 1000000;
		}
		if (money >= 100000l) {
			temp = (int) (money / 100000);
			list.add(temp);
			money = money % 100000;
		} else {
			if (list.size() > 0) {
				list.add(0);
			}
		}
		if (money >= 10000l) {
			temp = (int) (money / 10000);
			list.add(temp);
			money = money % 10000;
		} else {
			if (list.size() > 0) {
				list.add(0);
			}
		}
		if (money >= 1000l) {
			temp = (int) (money / 1000);
			list.add(temp);
			money = money % 1000;
		} else {
			if (list.size() > 0) {
				list.add(0);
			}
		}
		if (money >= 100l) {
			temp = (int) (money / 100);
			list.add(temp);
			money = money % 100;
		} else {
			if (list.size() > 0) {
				list.add(0);
			}
		}
		if (money >= 10l) {
			temp = (int) (money / 10);
			list.add(temp);
			money = money % 10;
		} else {
			if (list.size() > 0) {
				list.add(0);
			}
		}
		list.add((int) money);
		return list;
	}

	public static String getMoney(long money) {
		String moneyStr;
		long kk = 0;
		if (money >= 100000) {
			kk = money / 1000;
		}
		if (kk > 0) {
			String temp = ("" + kk).trim();
			moneyStr = temp.replaceAll(moneyRegex, "$1,") + "k"; //
			// 转换后的结果如下：1234000-->1，234K
		} else {
			String temp = ("" + money).trim();
			moneyStr = temp.replaceAll(moneyRegex, "$1,"); //
			// 转换后的结果如下：1234-->1，234
		}
		return moneyStr;
	}

	public static String getLobbyMoney(long money) {
		String moneyStr = ("" + money).trim().replaceAll(moneyRegex, "$1,");
		return moneyStr;
	}

	public static int adaptX(int rawX) {
		rawX = v4(rawX);
		float rate = adaptRate();
		int result = 0;
		if (rate > 0) {
			result = (int) (rawX * rate);
		} else {
			rate = -rate;
			result = (int) ((DdzApplication.getApplication().screenWidth - DEVELOP_WIDTH
					* rate) / 2 + rawX * rate);
		}
		if (result <= 0) {
			result = 1;
		}
		return result;
	}

	/**
	 * 左右两边按实际屏幕适配
	 * 
	 * @param rawX
	 * @return
	 */
	public static int screenAdaptX(int rawX) {
		rawX = v4(rawX);
		float rate = adaptRate();
		int result = 0;
		if (rate > 0) {// 返回小比列x
			result = (int) (rawX * rate);
		} else {// 返回小比列y
			rate = -rate;
			result = (int) (rawX * rate);
		}
		return result;
	}

	/**
	 * 左右两边按实际屏幕适配
	 * 
	 * @param rawX
	 * @return
	 */
	/*
	 * public static int screenAdaptX(int rawX){ rawX = v4(rawX); float rate =
	 * ((
	 * float)DdzApplication.getApplication().screenWidth)/(float)DEVELOP_WIDTH;
	 * int result = (int) (rawX*rate); return result; }
	 */

	public static int adaptY(int rawY) {
		rawY = v4(rawY);
		float rate = adaptRate();
		int result = 0;
		if (rate > 0) {
			result = (int) ((DdzApplication.getApplication().screenHeight - DEVELOP_HEIGHT
					* rate) / 2 + rawY * rate);
		} else {
			rate = -rate;
			result = (int) (rawY * rate);
		}
		if (result <= 0) {
			result = 1;
		}
		return result;
	}

	public static int adaptW(int x) {
		int result = (int) (v4(x) * Math.abs(adaptRate()));
		if (result <= 0) {
			result = 1;
		}
		return result;
	}

	public static int adaptH(int y) {
		int result = (int) (v4(y) * Math.abs(adaptRate()));
		if (result <= 0) {
			result = 1;
		}
		return result;
	}

	public static float adaptRate() {
		try {
			int screenWidth = DdzApplication.getApplication().screenWidth;
			int screenHeight = DdzApplication.getApplication().screenHeight;
			float rateX = ((float) screenWidth) / (float) DEVELOP_WIDTH;
			float ratey = ((float) screenHeight) / (float) DEVELOP_HEIGHT;
			if (rateX > ratey) {
				return -ratey;
			} else
				return rateX;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 1;
	}

	public static int v4(int i) {
		return i * 4 / 9;
	}

	public static int getOperateTextW(int state) {
		int width = 0;
		switch (state) {
		case UserState.USER_READY:
		case UserState.USER_CALL_ONE:
		case UserState.USER_CALL_TWO:
		case UserState.USER_CALL_THREE:
		case UserState.USER_GRAB_GIVEUP:
		case UserState.USER_PLAY_GIVEUP:
			width = operate_two_W;
			break;
		case UserState.USER_GRAB:
			width = operate_three_W;
			break;
		}
		return width;
	}
}
