public class CreateCharScr : CScreen, IActionListener
{
	private int xBox;

	private int yBox;

	private int wBox;

	private int hBox;

	private TField tfChar;

	private Command cmdCreate;

	private int selected;

	private int curItemLevel;

	private int[] itemIndex = new int[3];

	private int[][] itemArray = new int[6][]
	{
		new int[5] { 0, 6, 11, 16, 21 },
		new int[5] { 8, 2, 17, 22, 12 },
		new int[3] { 57, 27, 54 },
		new int[5] { 10, 4, 20, 25, 15 },
		new int[5] { 7, 1, 18, 23, 13 },
		new int[5] { 9, 3, 19, 24, 14 }
	};

	private int[] idTemplateLeg = new int[5] { 10, 15, 20, 25, 30 };

	private int[] idTemPlateBody = new int[5] { 35, 40, 45, 50, 55 };

	private int[] idTemplateBalo = new int[5] { 85, 90, 95, 100, 105 };

	private int[] idTemplateSung = new int[8] { 110, 120, 130, 140, 150, 160, 190, 200 };

	private int[] gunDame = new int[3] { 280, 125, 70 };

	private int[] gunSpeed = new int[3] { 280, 250, 350 };

	private int[] gunNum = new int[3] { 1, 2, 3 };

	public static int nItem = 3;

	public static string[][] strItem = new string[3][]
	{
		new string[5] { "Tóc xanh", "Tóc đen", "Tóc cam", "Tóc lá cây", "Tóc xanh dạ" },
		new string[5] { "SWAT", "SAS", "SEAL", "DELTA", "CYBER" },
		new string[3] { "AT", "K98", "MG42" }
	};

	private int[][] point = new int[5][]
	{
		new int[6] { 400, 0, 0, 0, 0, 0 },
		new int[6] { 0, 20, 0, 0, 0, 0 },
		new int[6] { 0, 0, 20, 0, 0, 0 },
		new int[6] { 0, 0, 0, 40, 0, 0 },
		new int[6] { 0, 0, 0, 0, 40, 0 }
	};

	private int[] point2 = new int[6];

	public CreateCharScr()
	{
		wBox = 176;
		hBox = 176;
		xBox = CScreen.w - wBox >> 1;
		yBox = CScreen.h - hBox >> 1;
		yBox -= 6;
		CPlayer.myPlayer = new CPlayer();
		CPlayer.myPlayer.look = 0;
		randomItem();
		CPlayer.myPlayer.x = xBox + 43;
		CPlayer.myPlayer.y = yBox + 110;
		tfChar = new TField();
		tfChar.x = xBox + 16;
		tfChar.y = yBox + 10;
		tfChar.width = 138;
		tfChar.height = CScreen.ITEM_HEIGHT + 2;
		tfChar.setIputType(TField.INPUT_TYPE_ANY);
		tfChar.name = "Tên nhân vật";
		tfChar.strInfo = "Tên nhân vật";
		tfChar.isFocus = true;
		selected = -1;
		left = (cmdCreate = new Command("Bắt đầu", this, 1000, null));
		cmdCreate.x = CCanvas.w / 2 - 38;
		if (yBox + hBox + 3 + 24 <= CScreen.h)
		{
			cmdCreate.y = yBox + hBox + 3;
		}
		else
		{
			cmdCreate.y = CScreen.h - 24;
		}
		left = cmdCreate;
		if (!CCanvas.isTouch)
		{
			center = new Command(string.Empty, this, 1001, null);
		}
		point = new int[5][]
		{
			new int[6] { 400, 0, 0, 0, 0, 0 },
			new int[6] { 0, 20, 0, 0, 0, 0 },
			new int[6] { 0, 0, 20, 0, 0, 0 },
			new int[6] { 0, 0, 0, 40, 0, 0 },
			new int[6] { 0, 0, 0, 0, 40, 0 }
		};
		point[itemIndex[1]][2] += gunDame[itemIndex[2]];
		point[itemIndex[1]][5] += gunSpeed[itemIndex[2]];
	}

	public void setClothesForCharacter(short idItem, int type)
	{
		CRes.outz("set clothes " + idItem);
		if (type == 0)
		{
			CPlayer.myPlayer.head = idItem;
		}
		if (type == 1)
		{
			CPlayer.myPlayer.body = idItem;
		}
		if (type == 2)
		{
			CPlayer.myPlayer.wp = idItem;
		}
	}

	public override void show()
	{
		Panel.load();
		if (CCanvas.isTouch)
		{
			right = new Command(L.back(), this, 2000, null);
			right.img = Command.back;
			right.x = 5;
			right.y = 5;
		}
		else
		{
			right = tfChar.cmdClear;
		}
		base.show();
	}

	public override void keyPressed(int keyCode)
	{
		if (selected == -1)
		{
			tfChar.keyPressed(keyCode);
			if (!CCanvas.isTouch)
			{
				right = tfChar.cmdClear;
			}
			else
			{
				right = null;
			}
		}
		base.keyPressed(keyCode);
	}

	public override void update()
	{
		CPlayer.myPlayer.action();
		tfChar.update();
		if (CCanvas.isTouch)
		{
			if (CCanvas.isPointer(tfChar.x, tfChar.y, tfChar.width, tfChar.height) && CCanvas.isPointerClick)
			{
				if (mSystem.isSmartPhone)
				{
					tfChar.isFocus = true;
				}
				else
				{
					tfChar.doChangeToTextBox(false);
				}
				CCanvas.isPointerClick = false;
			}
			if (CCanvas.isPointerJustRelease)
			{
				selected = -1;
				int num = yBox + 40;
				for (int i = 0; i < nItem; i++)
				{
					if (CCanvas.isPointer(xBox + wBox - 92, num, 76, 24))
					{
						CCanvas.clearAllPointerEvent();
						itemIndex[i]++;
						if (itemIndex[i] > itemArray[i].Length - 1)
						{
							itemIndex[i] = 0;
						}
						int num2 = itemIndex[i];
						int num3 = itemArray[i][num2];
						CRes.outz("index= " + num2);
						setClothesForCharacter((short)num3, i);
						if (i == 1)
						{
							int num4 = itemArray[4][num2];
							CPlayer.myPlayer.leg = (short)num4;
							num4 = itemArray[3][num2];
							CPlayer.myPlayer.wing = (short)num4;
							num4 = itemArray[5][num2];
							CPlayer.myPlayer.hat = (short)num4;
						}
						point = new int[5][]
						{
							new int[6] { 400, 0, 0, 0, 0, 0 },
							new int[6] { 0, 20, 0, 0, 0, 0 },
							new int[6] { 0, 0, 20, 0, 0, 0 },
							new int[6] { 0, 0, 0, 40, 0, 0 },
							new int[6] { 0, 0, 0, 0, 40, 0 }
						};
						point[itemIndex[1]][2] += gunDame[itemIndex[2]];
						point[itemIndex[1]][5] += gunSpeed[itemIndex[2]];
						return;
					}
					num += 28;
				}
			}
			else if (CCanvas.isPointerDown)
			{
				int num5 = yBox + 40;
				for (int j = 0; j < nItem; j++)
				{
					if (CCanvas.isPointer(xBox + wBox - 92, num5, 76, 24))
					{
						selected = j;
						return;
					}
					num5 += 28;
				}
				selected = -1;
			}
		}
		else
		{
			if (CCanvas.keyPressed[2])
			{
				CCanvas.clearKeyPressed();
				selected--;
				if (selected < -1)
				{
					selected = nItem - 1;
				}
				if (selected == -1)
				{
					tfChar.isFocus = true;
					right = tfChar.cmdClear;
				}
				else
				{
					right = new Command(L.back(), this, 2000, null);
					tfChar.isFocus = false;
				}
			}
			if (CCanvas.keyPressed[8])
			{
				CCanvas.clearKeyPressed();
				selected++;
				if (selected > nItem - 1)
				{
					selected = -1;
				}
				if (selected == -1)
				{
					tfChar.isFocus = true;
					right = tfChar.cmdClear;
				}
				else
				{
					right = new Command(L.back(), this, 2000, null);
					tfChar.isFocus = false;
				}
			}
		}
		base.update();
	}

	private void randomItem()
	{
		itemIndex[0] = CRes.random(0, strItem[0].Length);
		itemIndex[1] = CRes.random(0, strItem[1].Length);
		itemIndex[2] = CRes.random(0, strItem[2].Length);
		for (int i = 0; i < 3; i++)
		{
			int num = itemIndex[i];
			int num2 = itemArray[i][num];
			setClothesForCharacter((short)num2, i);
			if (i == 1)
			{
				int num3 = itemArray[4][num];
				CPlayer.myPlayer.leg = (short)num3;
				num3 = itemArray[3][num];
				CPlayer.myPlayer.wing = (short)num3;
				num3 = itemArray[5][num];
				CPlayer.myPlayer.hat = (short)num3;
			}
		}
		point = new int[5][]
		{
			new int[6] { 400, 0, 0, 0, 0, 0 },
			new int[6] { 0, 20, 0, 0, 0, 0 },
			new int[6] { 0, 0, 20, 0, 0, 0 },
			new int[6] { 0, 0, 0, 40, 0, 0 },
			new int[6] { 0, 0, 0, 0, 40, 0 }
		};
		point[itemIndex[1]][2] += gunDame[itemIndex[2]];
		point[itemIndex[1]][5] += gunSpeed[itemIndex[2]];
	}

	public override void paint(mGraphics g)
	{
		BackgroundNew.paintBGGameScr(g);
		g.translate(-g.getTranslateX(), -g.getTranslateY());
		CScreen.paintBorderRect(g, xBox, yBox, wBox, hBox);
		g.drawImage(CPlayer.bong, CPlayer.myPlayer.x, CPlayer.myPlayer.y, 3, false);
		CPlayer.myPlayer.paintPlayer3(g, CPlayer.myPlayer.x, CPlayer.myPlayer.y);
		mFont.tahoma_7b_dark.drawString(g, "Số đạn: " + gunNum[itemIndex[2]], CPlayer.myPlayer.x, CPlayer.myPlayer.y - 60, 2);
		if (curItemLevel != 0)
		{
			mFont.tahoma_7b_dark.drawString(g, "Cấp " + (curItemLevel + 1), CPlayer.myPlayer.x, CPlayer.myPlayer.y - 60, 2);
		}
		int num = yBox + 40;
		for (int i = 0; i < nItem; i++)
		{
			if (selected == i)
			{
				Command.paintOngMau(CScreen.btn1left, CScreen.btn1mid, CScreen.btn1right, xBox + wBox - 92, num, 76, g);
			}
			else
			{
				Command.paintOngMau(CScreen.btn0left, CScreen.btn0mid, CScreen.btn0right, xBox + wBox - 92, num, 76, g);
			}
			int num2 = itemIndex[i];
			mFont.tahoma_7b_dark.drawString(g, strItem[i][num2], xBox + wBox - 54, num + 6, 2);
			num += 28;
		}
		int num3 = xBox + 15;
		for (int j = 0; j < Panel.imgUpgrade.Length; j++)
		{
			g.drawImage(Panel.imgUpgrade[j], num3, num, 0, false);
			int num4 = itemIndex[1];
			mFont.tahoma_7b_dark.drawString(g, point[num4][j] + string.Empty, num3 + 25, num + 6, 0);
			if (j == 2)
			{
				num3 = xBox + 15;
				num += 24;
			}
			else
			{
				num3 += 53;
			}
		}
		tfChar.paint(g);
		base.paint(g);
	}

	public void perform(int idAction, object p1)
	{
		CRes.outz("action = " + idAction);
		if (idAction == 10020)
		{
			CCanvas.endDlg();
		}
		if (idAction == 10019)
		{
			Session_ME.gI().close();
			CCanvas.endDlg();
			LoginScr.gI().show();
		}
		if (idAction == 2000)
		{
			if (LoginScr.gI().isLogin2)
			{
				if (mSystem.isIphone)
				{
					perform(10019, null);
				}
				else
				{
					CCanvas.startYesNoDlg(L.note(), new Command(L.yes(), this, 10019, null), new Command(L.no(), this, 10020, null));
				}
				return;
			}
			Session_ME.gI().close();
			LoginScr.gI().show();
		}
		if (idAction == 1000)
		{
			CCanvas.startWaitDlgWithoutCancel(L.pleaseWait());
			string name = tfChar.getText().Trim();
			GameService.gI().createChar(name, CPlayer.myPlayer.head, CPlayer.myPlayer.leg, CPlayer.myPlayer.body, CPlayer.myPlayer.wing, CPlayer.myPlayer.wp, CPlayer.myPlayer.hat);
		}
		if (idAction == 1001 && selected != -1)
		{
			CRes.outz("select=" + selected);
			itemIndex[selected]++;
			if (itemIndex[selected] > itemArray[selected].Length - 1)
			{
				itemIndex[selected] = 0;
			}
			int num = itemIndex[selected];
			int num2 = itemArray[selected][num];
			setClothesForCharacter((short)num2, selected);
			if (selected == 1)
			{
				int num3 = itemArray[4][num];
				CPlayer.myPlayer.leg = (short)num3;
				num3 = itemArray[3][num];
				CPlayer.myPlayer.wing = (short)num3;
				num3 = itemArray[5][num];
				CPlayer.myPlayer.hat = (short)num3;
			}
			point = new int[5][]
			{
				new int[6] { 400, 0, 0, 0, 0, 0 },
				new int[6] { 0, 20, 0, 0, 0, 0 },
				new int[6] { 0, 0, 20, 0, 0, 0 },
				new int[6] { 0, 0, 0, 40, 0, 0 },
				new int[6] { 0, 0, 0, 0, 40, 0 }
			};
			point[itemIndex[1]][2] += gunDame[itemIndex[2]];
			point[itemIndex[1]][5] += gunSpeed[itemIndex[2]];
		}
	}
}
