using System;

public abstract class CScreen
{
	public const sbyte CMD_LEFT = 0;

	public const sbyte CMD_RIGHT = 1;

	public const sbyte CMD_CENTER = 2;

	public static int w;

	public static int h;

	public static int ITEM_HEIGHT;

	public Command left;

	public Command center;

	public Command right;

	public bool menuScroll;

	public int cmtoX;

	public int cmx;

	public int cmdx;

	public int cmvx;

	public int cmxLim;

	public static int cmdW = 76;

	public static int cmdH = 25;

	public int midCommandW = 32;

	public static Image imgInfoPopup;

	public static Image cup;

	public static Image imgCmd;

	public static Image cmd;

	public static Image popup00;

	public static Image popup01;

	public static Image popup02;

	public static Image popup03;

	public static Image popup04;

	public static Image popup05;

	public static Image popup06;

	public static Image popup07;

	public static Image popup10;

	public static Image popup11;

	public static Image popup12;

	public static Image popup13;

	public static Image popup14;

	public static Image popup15;

	public static Image popup16;

	public static Image popup17;

	public static Image btn0left;

	public static Image btn0right;

	public static Image btn0mid;

	public static Image btn1left;

	public static Image btn1right;

	public static Image btn1mid;

	public static bool isMoto;

	public static bool isBB;

	public static bool isNX;

	public static CScreen lastSCreen;

	public static int currKey;

	public static bool keyUp;

	public static bool keyDown;

	public static bool keyLeft;

	public static bool keyRight;

	public static bool keyFire;

	public static int keyTouch = -1;

	public CScreen()
	{
	}

	public static void loadImage()
	{
		try
		{
			cup = CCanvas.loadImage("/cup.png");
			imgCmd = CCanvas.loadImage("/gui2/cmd.png");
			popup00 = CCanvas.loadImage("/gui2/popup00.png");
			popup01 = CCanvas.loadImage("/gui2/popup01.png");
			popup02 = CCanvas.loadImage("/gui2/popup02.png");
			popup03 = CCanvas.loadImage("/gui2/popup03.png");
			popup04 = CCanvas.loadImage("/gui2/popup04.png");
			popup05 = CCanvas.loadImage("/gui2/popup05.png");
			popup06 = CCanvas.loadImage("/gui2/popup06.png");
			popup07 = CCanvas.loadImage("/gui2/popup07.png");
			popup10 = CCanvas.loadImage("/gui2/popup10.png");
			popup11 = CCanvas.loadImage("/gui2/popup11.png");
			popup12 = CCanvas.loadImage("/gui2/popup12.png");
			popup13 = CCanvas.loadImage("/gui2/popup13.png");
			popup14 = CCanvas.loadImage("/gui2/popup14.png");
			popup15 = CCanvas.loadImage("/gui2/popup15.png");
			popup16 = CCanvas.loadImage("/gui2/popup16.png");
			popup17 = CCanvas.loadImage("/gui2/popup17.png");
			btn0left = CCanvas.loadImage("/gui2/btn0left.png");
			btn0mid = CCanvas.loadImage("/gui2/btn0mid.png");
			btn0right = CCanvas.loadImage("/gui2/btn0right.png");
			btn1left = CCanvas.loadImage("/gui2/btn1left.png");
			btn1mid = CCanvas.loadImage("/gui2/btn1mid.png");
			btn1right = CCanvas.loadImage("/gui2/btn1right.png");
		}
		catch (Exception)
		{
			Cout.LogTryCatch("loadImage cscreen");
		}
	}

	public static void paintCmd(mGraphics g)
	{
		for (int i = 0; i < w / 50 + 1; i++)
		{
			g.drawImage(imgCmd, i * 50, h - 20, 0, false);
		}
	}

	public virtual void paint(mGraphics g)
	{
		g.translate(-g.getTranslateX(), -g.getTranslateY());
		g.setClip(0, 0, w, h);
		int num = 0;
		if (CCanvas.isTouch)
		{
			num = 12;
		}
		else
		{
			num = 3;
		}
		if (CCanvas.currentDialog == null && !CCanvas.menu.showMenu)
		{
			CCanvas.paintz.paintCmdBar(g, left, center, right);
		}
	}

	public static void paintDefaultBg(mGraphics g)
	{
	}

	public virtual void update()
	{
	}

	public bool isShowing()
	{
		return CCanvas.curScr == this;
	}

	public virtual void moveCamera()
	{
		if (cmx != cmtoX)
		{
			cmvx = cmtoX - cmx << 2;
			cmdx += cmvx;
			cmx += cmdx >> 3;
			cmdx &= 15;
		}
	}

	public virtual void input()
	{
		if (CCanvas.keyPressed[5] || getCmdPointerLast(CCanvas.curScr.center))
		{
			CCanvas.keyPressed[5] = false;
			keyTouch = -1;
			CCanvas.isPointerJustRelease = false;
			if (center != null)
			{
				center.performAction();
			}
		}
		if (CCanvas.keyPressed[12] || getCmdPointerLast(CCanvas.curScr.left))
		{
			CCanvas.keyPressed[12] = false;
			keyTouch = -1;
			CCanvas.isPointerJustRelease = false;
			if (left != null)
			{
				left.performAction();
			}
		}
		if (CCanvas.keyPressed[13] || getCmdPointerLast(CCanvas.curScr.right))
		{
			CCanvas.keyPressed[13] = false;
			keyTouch = -1;
			CCanvas.isPointerJustRelease = false;
			if (right != null)
			{
				right.performAction();
			}
		}
	}

	public static void clearKey()
	{
		for (int i = 0; i < CCanvas.keyPressed.Length; i++)
		{
			CCanvas.keyPressed[i] = (CCanvas.keyHold[i] = false);
		}
		keyUp = false;
		keyDown = false;
		keyLeft = false;
		keyRight = false;
	}

	public virtual void show()
	{
		clearKey();
		CCanvas.clearAllPointerEvent();
		CCanvas.curScr = this;
		Cout.LogError2("======Cur scr: " + CCanvas.curScr);
	}

	public void show(CScreen LastScreen)
	{
		lastSCreen = LastScreen;
		clearKey();
		CCanvas.curScr = this;
	}

	public static void paintWhitePopup(mGraphics g, int y, int x, int width, int height)
	{
		g.setColor(16777215);
		g.fillRect(x, y, width, height, false);
		g.setColor(0);
		g.drawRect(x - 1, y - 1, width + 1, height + 1, false);
	}

	public virtual void keyPressed(int keyCode)
	{
	}

	public virtual void keyReleased(int keyCode)
	{
	}

	public static bool getCmdPointerPressed(sbyte cmdType)
	{
		if (CCanvas.isPointerClick)
		{
			if (cmdType == 0)
			{
				if (CCanvas.isPointer(0, h - cmdH, cmdW, cmdH))
				{
					return true;
				}
			}
			else if (cmdType == 1)
			{
				if (CCanvas.isPointer(w - cmdW, h - cmdH, cmdW, cmdH))
				{
					return true;
				}
			}
			else if (CCanvas.isPointer(w - cmdW >> 1, h - cmdH, cmdW, cmdH))
			{
				return true;
			}
		}
		return false;
	}

	public static bool getCmdPointerLast(sbyte cmdType)
	{
		if (CCanvas.isPointerClick)
		{
			if (cmdType == 0)
			{
				if (CCanvas.isPointerLast(0, h - cmdH, cmdW, cmdH))
				{
					return true;
				}
			}
			else if (cmdType == 1)
			{
				if (CCanvas.isPointerLast(w - cmdW, h - cmdH, cmdW, cmdH))
				{
					return true;
				}
			}
			else if (CCanvas.isPointerLast(w - cmdW >> 1, h - cmdH, cmdW, cmdH))
			{
				return true;
			}
		}
		return false;
	}

	public static bool getCmdPointerLast(Command cmd)
	{
		if (cmd == null)
		{
			return false;
		}
		if (cmd.x != 0 && cmd.y != 0)
		{
			return cmd.isPointerPressInside();
		}
		if (CCanvas.currentDialog != null)
		{
			if (CCanvas.currentDialog.center != null && CCanvas.isPointerHoldIn(CCanvas.w - cmdW >> 1, CCanvas.h - cmdH - 5, cmdW, cmdH + 10))
			{
				keyTouch = 1;
				if (cmd == CCanvas.currentDialog.center && CCanvas.isPointerClick && CCanvas.isPointerJustRelease)
				{
					return true;
				}
			}
			if (CCanvas.currentDialog.left != null && CCanvas.isPointerHoldIn(0, CCanvas.h - cmdH - 5, cmdW, cmdH + 10))
			{
				keyTouch = 0;
				if (cmd == CCanvas.currentDialog.left && CCanvas.isPointerClick && CCanvas.isPointerJustRelease)
				{
					return true;
				}
			}
			if (CCanvas.currentDialog.right != null && CCanvas.isPointerHoldIn(CCanvas.w - cmdW, CCanvas.h - cmdH - 5, cmdW, cmdH + 10))
			{
				keyTouch = 2;
				if (cmd == CCanvas.currentDialog.right && CCanvas.isPointerClick && CCanvas.isPointerJustRelease)
				{
					return true;
				}
			}
		}
		else
		{
			if (cmd == CCanvas.curScr.left && CCanvas.isPointerHoldIn(0, CCanvas.h - cmdH - 5, cmdW, cmdH + 10))
			{
				keyTouch = 0;
				if (CCanvas.isPointerClick && CCanvas.isPointerJustRelease)
				{
					return true;
				}
			}
			if (cmd == CCanvas.curScr.right && CCanvas.isPointerHoldIn(CCanvas.w - cmdW, CCanvas.h - cmdH - 5, cmdW, cmdH + 10))
			{
				keyTouch = 2;
				if (CCanvas.isPointerClick && CCanvas.isPointerJustRelease)
				{
					return true;
				}
			}
			if (cmd == CCanvas.curScr.center && CCanvas.isPointerHoldIn(CCanvas.w - cmdW >> 1, CCanvas.h - cmdH - 5, cmdW, cmdH + 10))
			{
				keyTouch = 1;
				if (CCanvas.isPointerClick && CCanvas.isPointerJustRelease)
				{
					return true;
				}
			}
		}
		return false;
	}

	public static void paintBorderRect(mGraphics g, int y, int n, int h, string title)
	{
		int num = n * 32 + 56;
		int num2 = CCanvas.w / 2 - num / 2;
		paintBorderRect(g, w - num >> 1, y, num, h);
		if (title != null && title != string.Empty)
		{
			g.setColor(12965614);
			int width = mFont.tahoma_7b_white.getWidth(title);
			g.fillRect(num2 + num / 2 - width / 2 - 5, y + 1, width + 10, 18, false);
			g.setColor(6985149);
			g.drawRect(num2 + num / 2 - width / 2 - 5, y + 1, width + 10, 17, false);
			mFont.tahoma_7b_white.drawString(g, title, num2 + num / 2, y + 3, 2);
		}
	}

	public static void paintBorderRect(mGraphics g, int x, int y, int n)
	{
		int num = 96;
		int num2 = num / 22 - 1;
		int num3 = n * 26 + 20;
		int num4 = num3 / 22 - 1;
		g.drawImage(popup00, x, y, 0, false);
		for (int i = 0; i < num2; i++)
		{
			g.drawImage(popup01, x + 22 + i * 22, y, 0, false);
			g.drawImage(popup06, x + 22 + i * 22, y + num3 - 22, 0, false);
		}
		g.drawImage(popup02, x + num - 22, y, 0, false);
		for (int j = 0; j < num4; j++)
		{
			int num5 = 0;
			if (j == num4 - 1)
			{
				num5 = num3 - 44;
				g.drawImage(popup03, x, y + num5, 0, false);
				g.drawImage(popup04, x + num - 22, y + num5, 0, false);
			}
			else
			{
				g.drawImage(popup03, x, y + 22 + j * 22, 0, false);
				g.drawImage(popup04, x + num - 22, y + 22 + j * 22, 0, false);
			}
		}
		g.drawImage(popup07, x, y + num3 - 22, 0, false);
		g.drawImage(popup05, x + num - 22, y + num3 - 22, 0, false);
		g.setColor(40416);
		g.fillRect(x + 22, y + 22, num - 44, num3 - 44, false);
	}

	public static void paintBorderRect(mGraphics g, int x, int y, int w, int h)
	{
		int num = w / 22 - 1;
		int num2 = h / 22 - 1;
		g.drawImage(popup00, x, y, 0, false);
		for (int i = 0; i < num - 1; i++)
		{
			g.drawImage(popup01, x + 22 + i * 22, y, 0, false);
			g.drawImage(popup06, x + 22 + i * 22, y + h - 22, 0, false);
		}
		g.drawImage(popup01, x + w - 44, y, 0, false);
		g.drawImage(popup06, x + w - 44, y + h - 22, 0, false);
		g.drawImage(popup02, x + w - 22, y, 0, false);
		for (int j = 0; j < num2; j++)
		{
			int num3 = 0;
			if (j == num2 - 1)
			{
				num3 = h - 44;
				g.drawImage(popup03, x, y + num3, 0, false);
				g.drawImage(popup04, x + w - 22, y + num3, 0, false);
			}
			else
			{
				g.drawImage(popup03, x, y + 22 + j * 22, 0, false);
				g.drawImage(popup04, x + w - 22, y + 22 + j * 22, 0, false);
			}
		}
		g.drawImage(popup07, x, y + h - 22, 0, false);
		g.drawImage(popup05, x + w - 22, y + h - 22, 0, false);
		g.setColor(40416);
		g.fillRect(x + 22, y + 22, w - 44, h - 44, false);
	}

	public static void paintBorderRect2(mGraphics g, int x, int y, int w, int h)
	{
		int num = w / 22 - 1;
		int num2 = h / 22 - 1;
		g.drawImage(popup10, x, y, 0, false);
		for (int i = 0; i < num - 1; i++)
		{
			g.drawImage(popup11, x + 22 + i * 22, y, 0, false);
			g.drawImage(popup16, x + 22 + i * 22, y + h - 22, 0, false);
		}
		g.drawImage(popup11, x + w - 44, y, 0, false);
		g.drawImage(popup16, x + w - 44, y + h - 22, 0, false);
		g.drawImage(popup12, x + w - 22, y, 0, false);
		for (int j = 0; j < num2; j++)
		{
			int num3 = 0;
			if (j == num2 - 1)
			{
				num3 = h - 44;
				g.drawImage(popup13, x, y + num3, 0, false);
				g.drawImage(popup14, x + w - 22, y + num3, 0, false);
			}
			else
			{
				g.drawImage(popup13, x, y + 22 + j * 22, 0, false);
				g.drawImage(popup14, x + w - 22, y + 22 + j * 22, 0, false);
			}
		}
		g.drawImage(popup17, x, y + h - 22, 0, false);
		g.drawImage(popup15, x + w - 22, y + h - 22, 0, false);
		g.setColor(16769464);
		g.fillRect(x + 22, y + 22, w - 44, h - 44, false);
	}

	public static bool isUseHighFrameRate()
	{
		if (Main.FPS >= 48)
		{
			return true;
		}
		return false;
	}

	public static bool highFrameRate()
	{
		if (Main.FPS >= 48 && CCanvas.gameTick % 2 == 0)
		{
			return true;
		}
		return false;
	}

	public static void paintDefaultPopup(int x, int y, int w, int h, mGraphics g)
	{
		paintBorderRect(g, x, y, w, h);
	}
}
