namespace Assets.src.player
{
	public class TabClanIcon : IActionListener
	{
		private int x;

		private int y;

		private int w;

		private int h;

		private Command left;

		private Command right;

		private Command center;

		private int WIDTH = 24;

		public static int[] clanColor = new int[25]
		{
			0, 16777215, 16580535, 16187136, 16765814, 16756224, 10447872, 16739693, 16715021, 11666950,
			11141027, 5308227, 1167362, 10335999, 5078015, 70112, 11008767, 2618111, 53212, 14657791,
			12603903, 9769952, 12500670, 6250335, 0
		};

		public static string[] clanName = new string[25]
		{
			string.Empty,
			"Trắng",
			"Vàng nhạt",
			"Vàng đậm",
			"Cam nhạt",
			"Cam",
			"Nâu",
			"Đỏ nhạt",
			"Đỏ",
			"Đỏ đậm",
			"Lá cây nhạt",
			"Lá cây",
			"Lác cây đậm",
			"Dương nhạt",
			"Dương",
			"Dương đậm",
			"Xanh dạ nhạt",
			"Xanh dạ",
			"Xanh dạ đậm",
			"Tím nhạt",
			"Tím",
			"Tím đậm",
			"Xám nhạt",
			"Xám đậm",
			"Đen"
		};

		public static sbyte currPage;

		public static sbyte maxPage;

		public int nItem;

		private int disStart = 20;

		public Scroll scrMain;

		public int cmtoX;

		public int cmx;

		public int cmvx;

		public int cmdx;

		public bool isShow;

		public bool isGetName;

		public string text;

		private bool isRequest;

		private bool isUpdate;

		public MyVector vItems = new MyVector("vItems");

		private int msgID;

		private int select;

		private int lastSelect;

		private ScrollResult sr;

		private sbyte page;

		public TabClanIcon()
		{
			left = new Command(L.select(), this, 1, null);
			right = new Command(L.close(), this, 2, null);
		}

		public void init()
		{
			if (isGetName)
			{
				w = 170;
				h = 118;
				x = CCanvas.w / 2 - w / 2;
				y = CCanvas.h / 2 - h / 2;
			}
			else
			{
				w = 170;
				h = 170;
				x = CCanvas.w / 2 - w / 2;
				y = CCanvas.h / 2 - h / 2;
				if (CCanvas.h < 240)
				{
					y -= 10;
				}
			}
			if (!isShow)
			{
				cmx = x;
				cmtoX = 0;
			}
			nItem = ClanImage.vClanImage.size();
			scrMain = new Scroll();
			scrMain.setStyle(nItem, WIDTH, x, y + disStart, w, h - disStart, true, 1);
			scrMain.cmy = (scrMain.cmtoY = 0);
			select = 0;
			if (CCanvas.isTouch)
			{
				select = -1;
				left.x = x;
				left.y = y + h + 5;
				right.x = x + w - 68;
				right.y = y + h + 5;
			}
		}

		public void show(bool isGetName)
		{
			if (CPlayer.myPlayer.clan != null)
			{
				isUpdate = true;
			}
			isShow = true;
			this.isGetName = isGetName;
			init();
			cmx = (cmtoX = 0);
		}

		public void showRequest(int msgID)
		{
			isShow = true;
			isRequest = true;
			this.msgID = msgID;
			init();
		}

		public void hide()
		{
			cmtoX = x + w;
			scrMain = null;
		}

		public void paintPeans(mGraphics g)
		{
		}

		public void paintIcon(mGraphics g)
		{
			g.translate(-cmx, 0);
			CScreen.paintBorderRect(g, x, y - 17, w, h + 17);
			mFont.tahoma_7b_white.drawString(g, L.select_clan_icon() + " (" + (currPage + 1) + "/" + maxPage + ")", x + w / 2, y - 7, 2);
			g.setClip(x, y + disStart - 5, w, h - disStart - 5);
			if (maxPage > 1 && CCanvas.isTouch && scrMain != null)
			{
				if (scrMain.cmy < -50)
				{
					CCanvas.paintShukiren(x + w / 2, y + 30, g);
				}
				else if (scrMain.cmy < 0)
				{
					mFont.tahoma_7_grey.drawString(g, L.getDown(), x + w / 2, y + 15, 2);
				}
				else if (scrMain.cmyLim >= 0)
				{
					if (scrMain.cmy > scrMain.cmyLim + 50)
					{
						CCanvas.paintShukiren(x + w / 2, y + h - 30, g);
					}
					else if (scrMain.cmy > scrMain.cmyLim)
					{
						mFont.tahoma_7_grey.drawString(g, L.getUp(), x + w / 2, y + h - 25, 2);
					}
				}
			}
			if (scrMain != null)
			{
				g.translate(0, -scrMain.cmy);
			}
			for (int i = 0; i < nItem; i++)
			{
				int num = x + 10;
				int num2 = y + i * WIDTH + disStart;
				if (num2 + WIDTH - ((scrMain != null) ? scrMain.cmy : 0) < y + disStart || num2 - ((scrMain != null) ? scrMain.cmy : 0) > y + disStart + h)
				{
					continue;
				}
				ClanImage clanImage = (ClanImage)ClanImage.vClanImage.elementAt(i);
				if (clanImage.idImage >= 0)
				{
					SmallImage.drawSmallImage(g, clanImage.idImage, num, num2 + 3, 0, 0, true);
				}
				else
				{
					g.setColor(0);
					if (clanColor[i + 1] == 0)
					{
						g.setColor(16777215);
					}
					g.fillRect(num - 1, num2 - 1 + 3, 14, 8, true);
					g.setColor(clanColor[i + 1]);
					g.fillRect(num, num2 + 3, 12, 6, true);
				}
				mFont mFont2 = mFont.tahoma_7_white;
				if (i == lastSelect)
				{
					mFont2 = mFont.tahoma_7b_white;
				}
				if (clanImage.name != null)
				{
					mFont2.drawString(g, clanImage.name, num + 20, num2, 0);
				}
				if (clanImage.xu > 0)
				{
					mFont2.drawString(g, clanImage.xu + " " + L.xu(), num + w - 20, num2, mFont.RIGHT);
				}
				else if (clanImage.luong > 0)
				{
					mFont2.drawString(g, clanImage.luong + " " + L.luong(), num + w - 20, num2, mFont.RIGHT);
				}
				else
				{
					mFont2.drawString(g, L.free(), num + w - 20, num2, mFont.RIGHT);
				}
			}
			g.translate(-g.getTranslateX(), -g.getTranslateY());
			g.setClip(0, 0, CCanvas.w, CCanvas.h);
			CCanvas.paintz.paintCmdBar(g, left, center, right);
		}

		public void paint(mGraphics g)
		{
			if (!isRequest)
			{
				paintIcon(g);
			}
			else
			{
				paintPeans(g);
			}
		}

		public void update()
		{
			if (scrMain != null)
			{
				if (maxPage > 1 && scrMain.justRelease)
				{
					if (scrMain.cmy < -50)
					{
						scrMain.justRelease = false;
						if (currPage <= 0)
						{
							GameService.gI().getClan((sbyte)((CPlayer.myPlayer.clan == null) ? 1 : 3), -1, null, (sbyte)(maxPage - 1));
						}
						else
						{
							GameService.gI().getClan((sbyte)((CPlayer.myPlayer.clan == null) ? 1 : 3), -1, null, (sbyte)(currPage - 1));
						}
					}
					else if (scrMain.cmy > scrMain.cmyLim + 50)
					{
						scrMain.justRelease = false;
						if (currPage >= maxPage - 1)
						{
							GameService.gI().getClan((sbyte)((CPlayer.myPlayer.clan == null) ? 1 : 3), -1, null, 0);
						}
						else
						{
							GameService.gI().getClan((sbyte)((CPlayer.myPlayer.clan == null) ? 1 : 3), -1, null, (sbyte)(currPage + 1));
						}
					}
				}
				scrMain.updatecm();
			}
			if (cmx != cmtoX)
			{
				cmvx = cmtoX - cmx << 2;
				cmdx += cmvx;
				cmx += cmdx >> 3;
				cmdx &= 15;
			}
			if (Math.abs(cmtoX - cmx) < 10)
			{
				cmx = cmtoX;
			}
			if (cmx >= x + w - 10 && cmtoX >= x + w - 10)
			{
				isShow = false;
			}
		}

		public void updateKey()
		{
			if (left != null && (CCanvas.keyPressed[12] || CScreen.getCmdPointerLast(left)))
			{
				left.performAction();
			}
			if (right != null && (CCanvas.keyPressed[13] || CScreen.getCmdPointerLast(right)))
			{
				right.performAction();
			}
			if (center != null && (CCanvas.keyPressed[5] || CScreen.getCmdPointerLast(center)))
			{
				center.performAction();
			}
			if (!isGetName)
			{
				if (scrMain == null)
				{
					return;
				}
				if (CCanvas.isTouch)
				{
					scrMain.updateKey();
					select = scrMain.selectedItem;
				}
				if (CCanvas.keyPressed[2])
				{
					CCanvas.keyPressed[2] = false;
					select--;
					if (select < 0)
					{
						if (maxPage > 1)
						{
							if (currPage <= 0)
							{
								GameService.gI().getClan((sbyte)((CPlayer.myPlayer.clan == null) ? 1 : 3), -1, null, (sbyte)(maxPage - 1));
							}
							else
							{
								GameService.gI().getClan((sbyte)((CPlayer.myPlayer.clan == null) ? 1 : 3), -1, null, (sbyte)(currPage - 1));
							}
							return;
						}
						select = nItem - 1;
					}
					scrMain.moveTo(select * scrMain.ITEM_SIZE);
				}
				if (CCanvas.keyPressed[8])
				{
					CCanvas.keyPressed[8] = false;
					select++;
					if (select > nItem - 1)
					{
						if (maxPage > 1)
						{
							if (currPage >= maxPage - 1)
							{
								GameService.gI().getClan((sbyte)((CPlayer.myPlayer.clan == null) ? 1 : 3), -1, null, 0);
							}
							else
							{
								GameService.gI().getClan((sbyte)((CPlayer.myPlayer.clan == null) ? 1 : 3), -1, null, (sbyte)(currPage + 1));
							}
							return;
						}
						select = 0;
					}
					scrMain.moveTo(select * scrMain.ITEM_SIZE);
				}
				if (select != -1)
				{
					lastSelect = select;
				}
			}
			CCanvas.clearKeyHold();
			CCanvas.clearKeyPressed();
		}

		public void perform(int idAction, object p)
		{
			if (idAction == 2)
			{
				hide();
			}
			if (idAction != 1 || isGetName)
			{
				return;
			}
			if (!isRequest)
			{
				if (lastSelect >= 0)
				{
					hide();
					if (CPlayer.myPlayer.clan == null)
					{
						GameService.gI().getClan(2, ((ClanImage)ClanImage.vClanImage.elementAt(lastSelect)).idImage, text, -1);
					}
					else
					{
						GameService.gI().getClan(4, ((ClanImage)ClanImage.vClanImage.elementAt(lastSelect)).idImage, string.Empty, -1);
					}
				}
			}
			else if (lastSelect >= 0)
			{
				Item item = (Item)vItems.elementAt(select);
			}
		}
	}
}
