using System;
using System.IO;
using Assets.src.rpg;
using Assets.src.screen;

public class CCanvas : IActionListener
{
	public static bool open3Hour;

	public static RegisterScreen registerScr;

	public static bool lowGraphic = false;

	public static bool isLoading;

	public static bool isTouch = false;

	public static bool isTouchControl;

	public static bool isTouchControlSmallScreen;

	public static bool isTouchControlLargeScreen;

	public static bool isConnectFail;

	public static int curPos = 0;

	public static Position[] arrPos = new Position[4];

	public static CCanvas instance;

	public static bool isRunning = true;

	public static int gameTick;

	public static long currSystemTick;

	public static int w;

	public static int h;

	public static int hh;

	public static int hw;

	public static CScreen curScr;

	public static SplashScr splashScr;

	public static GameScr gameScr;

	public static PrepareScr prepareScr;

	public static ServerListScreen serverScreen;

	public static CreateCharScr initCharScreen;

	public static bool isVirHorizontal;

	public static InputDlg inputDlg;

	public static Menu menu;

	public static bool isMoto;

	public static bool isWifi = false;

	public static bool isBB;

	public static bool isSony;

	public static Command cmdMenu;

	public static MsgDlg msgdlg = new MsgDlg();

	public static Dialog currentDialog;

	public static Panel panel;

	public static Panel panel2;

	public static MyVector currentPopup = new MyVector();

	public static InfoPopup infoPopup;

	public static int waitSendMessage;

	public static Paint paintz;

	public static sbyte[] fileData5;

	public static bool[] keyPressed = new bool[14];

	public static bool[] keyReleased = new bool[14];

	public static bool[] keyHold = new bool[14];

	public static int px;

	public static int py;

	public static int pxFirst;

	public static int pyFirst;

	public static int pxLast;

	public static int pyLast;

	public static int pxMouse;

	public static int pyMouse;

	public static bool isPointerDown;

	public static bool isPointerClick;

	public static bool isPointerJustRelease;

	public static bool isPointerJustDown = false;

	public static IconManager iconMn;

	public static int nBigImage;

	public static Image[] imgBusy;

	private static int clearOldData;

	public static bool isPlaySound = true;

	public static Part[] parts;

	public static bool exitByHand;

	public static GameScrRPG gameScrRPG;

	public static bool lockNotify;

	public static int tNotify;

	public static int timeOpenKeyBoard;

	public static bool isFocusPanel2;

	public bool onDisconnected;

	public static int tToWait;

	private int t;

	public mGraphics g = new mGraphics();

	public static Image img12;

	private static long lastTimePress = 0L;

	public static int keyAsciiPress;

	public static bool isMoveNumberPad = true;

	public static bool keyHasJustRelease;

	public static sbyte tileMapVersion;

	public static sbyte mapIconVersion;

	public static sbyte mapValuesVersion;

	public static sbyte playerVersion;

	public static sbyte equipVersion;

	public static sbyte levelCVersion;

	private bool isTestMap;

	public static Image imgTest;

	public static MyRandom r = new MyRandom();

	public static bool isWaitingData;

	public static int startTick;

	public static int iHuongdan;

	public static sbyte typeNapThe;

	public static bool isPayment;

	public static string[] huongdan1;

	public static string[] huongdan2;

	public static string paymentTitle1;

	public static string paymentTitle2;

	private static int waitTick;

	public static bool isResume;

	public CCanvas()
	{
		clearOldData = Rms.loadRMSInt(MyMidlet.version);
		if (clearOldData != 1)
		{
			Main.main.doClearRMS();
			Rms.saveRMSInt(MyMidlet.version, 1);
		}
		initGame();
	}

	public static void resetTrans(mGraphics g)
	{
		g.translate(-g.getTranslateX(), -g.getTranslateY());
		g.setClip(0, 0, w, h);
	}

	public static void readFileLevel(sbyte[] data)
	{
		DataInputStream dataInputStream = null;
		try
		{
			dataInputStream = ((data != null) ? new DataInputStream(data) : new DataInputStream(Rms.loadRMS("dataLevel")));
			sbyte b = dataInputStream.readByte();
			CRes.outz("lent ex= " + b);
			CPlayer.strLevel = new string[b];
			CPlayer.expToLevel = new int[b];
			CPlayer.levelImage = new short[b];
			for (int i = 0; i < b; i++)
			{
				CPlayer.strLevel[i] = dataInputStream.readUTF();
				CPlayer.expToLevel[i] = dataInputStream.readInt();
				CPlayer.levelImage[i] = dataInputStream.readShort();
				CRes.outz("level img= " + CPlayer.levelImage[i]);
			}
		}
		catch (Exception)
		{
		}
	}

	public static void readPart(sbyte[] data)
	{
		DataInputStream dataInputStream = null;
		try
		{
			dataInputStream = ((data != null) ? new DataInputStream(data) : new DataInputStream(Rms.loadRMS("dataPart")));
			int num = dataInputStream.readShort();
			parts = new Part[num];
			CRes.outz("sum= " + num);
			for (int i = 0; i < num; i++)
			{
				int type = dataInputStream.readByte();
				parts[i] = new Part(type);
				for (int j = 0; j < parts[i].pi.Length; j++)
				{
					parts[i].pi[j] = new PartImage();
					parts[i].pi[j].id = dataInputStream.readShort();
					parts[i].pi[j].dx = dataInputStream.readByte();
					parts[i].pi[j].dy = dataInputStream.readByte();
				}
			}
		}
		catch (Exception ex)
		{
			Cout.LogTryCatch("readPart :" + ex.StackTrace.ToString());
		}
		finally
		{
			try
			{
				dataInputStream.close();
			}
			catch (IOException ex2)
			{
				Cout.LogTryCatch("readPart2 :" + ex2.StackTrace.ToString());
			}
		}
	}

	public void start()
	{
	}

	public static bool isWaiting()
	{
		return false;
	}

	public void initGame()
	{
		BackgroundNew.lowGraphic = Rms.loadRMSInt("graphic") == 1;
		int num = Rms.loadRMSInt("drag");
		CPlayer.hasDrag = ((num != 1 && num != -1) ? true : false);
		GameScr.isDrawChat = ((Rms.loadRMSInt("drawchat") != 1) ? true : false);
		MotherCanvas.instance.setChildCanvas(this);
		w = MotherCanvas.instance.getWidthz();
		h = MotherCanvas.instance.getHeightz();
		hw = w / 2;
		hh = h / 2;
		isTouch = true;
		if (w >= 240)
		{
			isTouchControl = true;
		}
		if (w < 320)
		{
			isTouchControlSmallScreen = true;
		}
		if (w >= 320)
		{
			isTouchControlLargeScreen = true;
		}
		instance = this;
		screenInit(true);
		CScreen.cmdH = 26;
		menu = new Menu();
		panel = new Panel();
		CMap.getHole();
		CMap.initHoleMask();
		CScreen.loadImage();
		GameScr.loadImage();
		BackgroundNew.lowGraphic = Rms.loadRMSInt("graphic") == 1;
		loadImage();
		AnimateEffect.loadImage();
		PrepareScr.loadImage();
		Panel.loadImage();
		TField.loadImage();
		InfoPopup.loadImage();
		Airplane.loadImage();
		CPlayer.loadImage();
		Smoke.loadImage();
		Menu.loadImage();
		Hint.loadImage();
		Bullet.loadImage();
		mSystem.loadImage();
		Boss.loadImage();
		BM.loadImage();
		Item.loadImage();
		LoginScr.loadImage();
		MM.loadImage();
		MenuScr.loadImage();
		Explosion.loadOnce();
		MenuScr.load();
		CPlayer.initIronMan();
		img12 = loadImage("/gui2/12+.png");
		BackgroundNew.cloudX = new int[5]
		{
			CScreen.w / 2 - 40,
			CScreen.w / 2 + 40,
			CScreen.w / 2 - 100,
			CScreen.w / 2 - 80,
			CScreen.w / 2 - 120
		};
		BackgroundNew.cloudY = new int[5] { 130, 100, 150, 140, 80 };
		mSystem.disableSound = Rms.loadRMSInt("dissound") == 1;
	}

	private void loadImage()
	{
		if (GameScr.imgBlack == null)
		{
			GameScr.imgBlack = loadImage("/gui2/black.png");
		}
		if (imgBusy == null)
		{
			imgBusy = new Image[5];
			for (int i = 0; i < imgBusy.Length; i++)
			{
				imgBusy[i] = loadImage("/gui2/busy" + i + ".png");
			}
		}
	}

	public static CCanvas gI()
	{
		return instance;
	}

	public static Image loadImageRMS(string path)
	{
		path = Main.res + "/x" + mGraphics.zoomLevel + path;
		path = cutPng(path);
		Image image = null;
		try
		{
			image = Image.createImage(path);
		}
		catch (Exception ex)
		{
			try
			{
				string[] array = CRes.split(path, "/", 0);
				string text = array[array.Length - 1];
				CRes.outz("rms Path= " + text);
				sbyte[] array2 = Rms.loadRMS(text);
				if (array2 != null)
				{
					CRes.outz("--data lent= " + array2.Length);
					image = Image.createImage(array2, 0, array2.Length);
					CRes.outz("rms path= " + text + "img w= " + image.getWidth() + " imgH= " + image.getHeight());
					array2 = null;
				}
			}
			catch (Exception)
			{
				Cout.LogTryCatch("-----loadImageRMS: " + ex.StackTrace);
			}
		}
		return image;
	}

	public static Image loadImage2(string path)
	{
		path = Main.res + path;
		path = cutPng(path);
		Image result = null;
		try
		{
			result = Image.createImage(path);
		}
		catch (Exception ex)
		{
			try
			{
				CRes.outz("path load = " + path);
			}
			catch (Exception)
			{
				Cout.LogTryCatch("loadImage2: " + ex.StackTrace);
			}
		}
		return result;
	}

	public static Image loadImage(string path)
	{
		path = Main.res + "/x" + mGraphics.zoomLevel + path;
		path = cutPng(path);
		Image result = null;
		try
		{
			result = Image.createImage(path);
		}
		catch (Exception)
		{
			Cout.LogTryCatch("Bi loi load hih:  " + path);
		}
		return result;
	}

	public static string cutPng(string str)
	{
		string result = str;
		if (str.Contains(".png"))
		{
			result = str.Replace(".png", string.Empty);
		}
		return result;
	}

	public void screenInit(bool setV)
	{
		MotherCanvas.instance.setChildCanvas(this);
		w = MotherCanvas.instance.getWidthz();
		h = MotherCanvas.instance.getHeightz();
		CScreen.w = w;
		CScreen.h = h;
		hh = h / 2;
		hw = w / 2;
		splashScr = new SplashScr();
		gameScrRPG = new GameScrRPG();
		splashScr.show();
	}

	public static void loadScreen()
	{
		infoPopup = new InfoPopup();
		prepareScr = new PrepareScr();
		inputDlg = new InputDlg();
		serverScreen = new ServerListScreen();
		GameScr.mm = new MM();
		paintz = new Paint();
		iconMn = new IconManager();
	}

	public int getGameAction(int keyCode)
	{
		return getGameAction(keyCode);
	}

	public void input()
	{
		if (menu.showMenu)
		{
			menu.updateMenuKey();
		}
		else if (currentDialog != null)
		{
			currentDialog.update();
		}
		else if (!InfoDlg.isShow)
		{
			if (keyPressed[12] && keyPressed[13])
			{
				GameService.gI().disconnect();
			}
			if (!panel.isShow)
			{
				curScr.input();
			}
		}
	}

	public static void closeKeyBoard()
	{
		mGraphics.addYWhenOpenKeyBoard = 0;
		timeOpenKeyBoard = 0;
		Main.closeKeyBoard();
	}

	public void onDisconnectedz()
	{
		onDisconnected = true;
	}

	public void update()
	{
		try
		{
			CRes.updateOnScreenDebug();
			if (TouchScreenKeyboard.visible)
			{
				timeOpenKeyBoard++;
				if (timeOpenKeyBoard > ((!Main.isWindowsPhone) ? 10 : 5))
				{
					mGraphics.addYWhenOpenKeyBoard = 94;
				}
			}
			else
			{
				mGraphics.addYWhenOpenKeyBoard = 0;
				timeOpenKeyBoard = 0;
			}
			SmallImage.update();
			gameTick++;
			if (gameTick > 100000000)
			{
				gameTick = 0;
			}
			if (waitSendMessage > 0)
			{
				waitSendMessage--;
			}
			for (int i = 0; i < currentPopup.size(); i++)
			{
				((Popup)currentPopup.elementAt(i)).update();
			}
			if (currentDialog != null)
			{
				if (isWaitingData && LoginScr.isLoadDataOk)
				{
					isWaitingData = false;
				}
				currentDialog.update();
			}
			else if (menu.showMenu)
			{
				menu.updateMenu();
			}
			else if (panel.isShow)
			{
				panel.update();
				if (panel2 != null)
				{
					if (isFocusPanel2)
					{
						panel2.updateKey();
					}
					else
					{
						panel.updateKey();
					}
					if (panel2.isShow)
					{
						panel2.update();
						if (isPointer(panel2.X, panel2.Y, panel2.W, panel2.H))
						{
							panel2.updateKey();
						}
						else if (isPointer(panel.X + panel.W, panel.Y, w - panel.W * 2, panel.H) && isPointerJustRelease)
						{
							panel.updateKey();
							panel2.updateKey();
							if (pxLast > panel.X + panel.W && pxLast < panel2.X)
							{
								if (panel.isDetail)
								{
									panel.closeDetail();
								}
								else
								{
									panel.hide();
								}
							}
						}
					}
				}
				else
				{
					panel.updateKey();
					if (isPointer(panel.X + panel.W, panel.Y, w - panel.W, panel.H) && isPointerJustRelease && !InfoDlg.isShow)
					{
						if (panel.isDetail)
						{
							panel.closeDetail();
						}
						else
						{
							panel.hide();
						}
					}
				}
			}
			if (curScr != null && ChatPopupNR.currChatPopup != null)
			{
				ChatPopupNR.currChatPopup.update();
				if (!menu.showMenu)
				{
					ChatPopupNR.currChatPopup.updateKey();
				}
			}
			InfoDlg.update();
			input();
			curScr.update();
			keyHasJustRelease = false;
			if (lockNotify)
			{
				tNotify++;
				if (tNotify == tToWait)
				{
					tNotify = 0;
					lockNotify = false;
					mSystem.mNotify();
				}
			}
			if (MessageHandler.isLoadingDataWhenConnecOK)
			{
				GameLogicHandler.gI().onConnectOK();
				MessageHandler.isLoadingDataWhenConnecOK = false;
			}
			if (MessageHandler.isLoadingDataWhenConnecFail)
			{
				GameLogicHandler.gI().onConnectFail();
				MessageHandler.isLoadingDataWhenConnecFail = false;
			}
			if (MessageHandler.isLoadingDataWhenDisconnected)
			{
				GameLogicHandler.gI().onDisconnect();
				MessageHandler.isLoadingDataWhenDisconnected = false;
			}
		}
		catch (Exception)
		{
		}
	}

	public static void paintInfoPopup(mGraphics g)
	{
		for (int i = 0; i < currentPopup.size(); i++)
		{
			Popup popup = (Popup)currentPopup.elementAt(i);
			if (popup is InfoPopup)
			{
				((Popup)currentPopup.elementAt(i)).paint(g);
				break;
			}
		}
	}

	public void paint(mGraphics gx)
	{
		g = gx;
		try
		{
			curScr.paint(g);
		}
		catch (Exception)
		{
		}
		if (panel.isShow)
		{
			panel.paint(g);
			if (panel2 != null && panel2.isShow)
			{
				panel2.paint(g);
			}
			paintInfoPopup(g);
		}
		if (ChatPopupNR.currChatPopup != null)
		{
			ChatPopupNR.currChatPopup.paint(g);
		}
		InfoDlg.paint(g);
		if (currentDialog != null)
		{
			currentDialog.paint(g);
		}
		else if (menu.showMenu)
		{
			menu.paintMenu(g);
		}
		g.setClip(0, 0, 1000, 1000);
		if (curScr == serverScreen)
		{
			if (open3Hour)
			{
				g.drawImage(img12, 5, 7, 0, false);
			}
		}
		else if (curScr == gameScrRPG && open3Hour && (panel == null || (panel != null && !panel.isShow)))
		{
			g.drawImage(img12, 2, h - 70, 0, false);
			mFont.tahoma_7_white.drawString(g, "Dành cho người chơi trên 12 tuổi.", 23, h - 70, 0);
			mFont.tahoma_7_white.drawString(g, "Chơi quá 180 phút mỗi ngày ", 23, h - 60, 0);
			mFont.tahoma_7_white.drawString(g, "sẽ hại sức khỏe.", 23, h - 50, 0);
		}
		if (curScr != gameScr && curScr != gameScrRPG)
		{
			for (int i = 0; i < currentPopup.size(); i++)
			{
				Popup popup = (Popup)currentPopup.elementAt(i);
				if (popup.GetType() != typeof(InfoPopup))
				{
					((Popup)currentPopup.elementAt(i)).paint(g);
				}
			}
		}
		CRes.paintOnScreenDebug(g);
	}

	public void keyPressedz(int keyCode)
	{
		keyHasJustRelease = false;
		lastTimePress = mSystem.currentTimeMillis();
		if ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 122) || keyCode == 10 || keyCode == 8 || keyCode == 13 || keyCode == 32 || keyCode == 31)
		{
			keyAsciiPress = keyCode;
		}
		mapKeyPress(keyCode);
	}

	public void mapKeyPress(int keyCode)
	{
		CRes.outz("key code = " + keyCode);
		if (currentDialog != null)
		{
			currentDialog.keyPress(keyCode);
			keyAsciiPress = 0;
			return;
		}
		curScr.keyPressed(keyCode);
		switch (keyCode)
		{
		case 48:
			keyHold[0] = true;
			keyPressed[0] = true;
			break;
		case 49:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[1] = true;
				keyPressed[1] = true;
			}
			break;
		case 51:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[3] = true;
				keyPressed[3] = true;
			}
			break;
		case 55:
			keyHold[7] = true;
			keyPressed[7] = true;
			break;
		case 57:
			keyHold[9] = true;
			keyPressed[9] = true;
			break;
		case 42:
			keyHold[10] = true;
			keyPressed[10] = true;
			break;
		case 35:
			keyHold[11] = true;
			keyPressed[11] = true;
			break;
		case -21:
		case -6:
			keyHold[12] = true;
			keyPressed[12] = true;
			break;
		case -22:
		case -7:
			keyHold[13] = true;
			keyPressed[13] = true;
			break;
		case -5:
		case 10:
			keyHold[5] = true;
			keyPressed[5] = true;
			break;
		case -38:
		case -1:
			keyHold[2] = true;
			keyPressed[2] = true;
			break;
		case -39:
		case -2:
			keyHold[8] = true;
			keyPressed[8] = true;
			break;
		case -3:
			keyHold[4] = true;
			keyPressed[4] = true;
			break;
		case -4:
			keyHold[6] = true;
			keyPressed[6] = true;
			break;
		case 50:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[2] = true;
				keyPressed[2] = true;
			}
			break;
		case 52:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[4] = true;
				keyPressed[4] = true;
			}
			break;
		case 54:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[6] = true;
				keyPressed[6] = true;
			}
			break;
		case 56:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[8] = true;
				keyPressed[8] = true;
			}
			break;
		case 53:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[5] = true;
				keyPressed[5] = true;
			}
			break;
		}
	}

	public void keyReleasedz(int keyCode)
	{
		keyHasJustRelease = true;
		keyAsciiPress = 0;
		mapKeyRelease(keyCode);
	}

	public void mapKeyRelease(int keyCode)
	{
		switch (keyCode)
		{
		case 48:
			keyHold[0] = false;
			keyReleased[0] = true;
			break;
		case 49:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[1] = false;
				keyReleased[1] = true;
			}
			break;
		case 51:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[3] = false;
				keyReleased[3] = true;
			}
			break;
		case 55:
			keyHold[7] = false;
			keyReleased[7] = true;
			break;
		case 57:
			keyHold[9] = false;
			keyReleased[9] = true;
			break;
		case 42:
			keyHold[10] = false;
			keyReleased[10] = true;
			break;
		case 35:
			keyHold[11] = false;
			keyReleased[11] = true;
			break;
		case -21:
		case -6:
			keyHold[12] = false;
			keyReleased[12] = true;
			break;
		case -22:
		case -7:
			keyHold[13] = false;
			keyReleased[13] = true;
			break;
		case -5:
		case 10:
			keyHold[5] = false;
			keyReleased[5] = true;
			break;
		case -38:
		case -1:
			keyHold[2] = false;
			break;
		case -39:
		case -2:
			keyHold[8] = false;
			break;
		case -3:
			keyHold[4] = false;
			break;
		case -4:
			keyHold[6] = false;
			break;
		case 50:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[2] = false;
				keyReleased[2] = true;
			}
			break;
		case 52:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[4] = false;
				keyReleased[4] = true;
			}
			break;
		case 54:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[6] = false;
				keyReleased[6] = true;
			}
			break;
		case 56:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[8] = false;
				keyReleased[8] = true;
			}
			break;
		case 53:
			if (curScr == GameScr.instance && isMoveNumberPad)
			{
				keyHold[5] = false;
				keyReleased[5] = true;
			}
			break;
		}
	}

	public static void saveData(string name, sbyte[] data)
	{
		Rms.saveRMS(name, data);
	}

	public static sbyte[] loadData(string name)
	{
		return Rms.loadRMS(name);
	}

	public static void saveVersion(string name, sbyte version)
	{
		CRes.saveRMSInt(name, version);
	}

	public static int loadVersion(string name)
	{
		return Rms.loadRMSInt(name);
	}

	public static Image cutImage(Image img, int pos)
	{
		int width = img.getWidth();
		int[] rgbData = new int[width * width];
		img.getRGB(ref rgbData, 0, width, 0, pos * width, width, width);
		return Image.createRGBImage(rgbData, width, width, true);
	}

	public static bool isPointer(int x, int y, int w, int h)
	{
		if (!isPointerDown && !isPointerClick)
		{
			return false;
		}
		if (px >= x && px <= x + w && py >= y && py <= y + h)
		{
			return true;
		}
		return false;
	}

	public static bool isPointerLast(int x, int y, int w, int h)
	{
		if (!isPointerDown && !isPointerClick)
		{
			return false;
		}
		if (pxLast >= x && pxLast <= x + w && pyLast >= y && pyLast <= y + h)
		{
			return true;
		}
		return false;
	}

	public void pointerMouse(int x, int y)
	{
		pxMouse = x;
		pyMouse = y;
	}

	public void pointerDragged(int x, int y)
	{
		if (!panel.isShow && (CRes.abs(x - pxLast) >= 10 || CRes.abs(y - pyLast) >= 10))
		{
			isPointerClick = false;
		}
		px = x;
		py = y;
		curPos++;
		if (curPos > 3)
		{
			curPos = 0;
		}
		arrPos[curPos] = new Position(x, y);
	}

	public static bool isHoldPress()
	{
		if (mSystem.currentTimeMillis() - lastTimePress >= 800)
		{
			return true;
		}
		return false;
	}

	public void pointerPressed(int x, int y)
	{
		isPointerJustRelease = false;
		isPointerJustDown = true;
		isPointerDown = true;
		isPointerClick = true;
		pxFirst = x;
		pyFirst = y;
		pxLast = x;
		pyLast = y;
		px = x;
		py = y;
	}

	public void pointerReleased(int x, int y)
	{
		isPointerDown = false;
		isPointerJustRelease = true;
		CScreen.keyTouch = -1;
		px = x;
		py = y;
	}

	public static bool isPointerHoldIn(int x, int y, int w, int h)
	{
		if (!isPointerDown && !isPointerJustRelease)
		{
			return false;
		}
		if (px >= x && px <= x + w && py >= y && py <= y + h)
		{
			return true;
		}
		return false;
	}

	public static bool isMouseFocus(int x, int y, int w, int h)
	{
		if (pxMouse >= x && pxMouse <= x + w && pyMouse >= y && pyMouse <= y + h)
		{
			return true;
		}
		return false;
	}

	public static void startOKDlg(string info)
	{
		ChatPopupNR.currChatPopup = null;
		msgdlg.setInfo(info, null, new Command("OK", instance, 1000, null), null);
		currentDialog = msgdlg;
		Music.play(Music.POPUP, 10f);
	}

	public static void startOKDlg(string info, Command cmd)
	{
		ChatPopupNR.currChatPopup = null;
		if (info.Equals(L.pleaseWait()) && !panel.isShow)
		{
			startWaitDlgWithoutCancel(info);
			return;
		}
		cmd.caption = "OK";
		msgdlg.setInfo(info, null, cmd, null);
		currentDialog = msgdlg;
		Music.play(Music.POPUP, 10f);
	}

	public static void startOKDlg2(string info, Command cmd)
	{
		ChatPopupNR.currChatPopup = null;
		if (info.Equals(L.pleaseWait()) && !panel.isShow)
		{
			startWaitDlgWithoutCancel(info);
			return;
		}
		msgdlg.setInfo(info, null, cmd, null);
		currentDialog = msgdlg;
		Music.play(Music.POPUP, 10f);
	}

	public static void doNapThe(sbyte type)
	{
		iHuongdan = 0;
		typeNapThe = type;
		ChatPopupNR.addChatPopup("Nạp " + ((typeNapThe != 0) ? "ngọc" : "vàng") + " từ thẻ cào", 100000, 35, 1);
		MyVector myVector = new MyVector("menu");
		myVector.addElement(new Command("Hướng dẫn", instance, 9001, null));
		myVector.addElement(new Command("Nạp thẻ", instance, 9002, null));
		myVector.addElement(new Command(L.close(), instance, 9004, null));
		menu.startAt(myVector, 0);
		if (InfoDlg.isShow)
		{
			InfoDlg.hide();
		}
		if (panel.isDetail)
		{
			panel.closeDetail();
		}
	}

	public static void startYesNoDlg(string info, int iYes, object pYes, int iNo, object pNo)
	{
		ChatPopupNR.currChatPopup = null;
		msgdlg.setInfo(info, new Command(L.yes(), instance, iYes, pYes), new Command(string.Empty, instance, iYes, pYes), new Command(L.no(), instance, iNo, pNo));
		currentDialog = msgdlg;
		if (menu.showMenu)
		{
			menu.showMenu = false;
		}
		Music.play(Music.POPUP, 10f);
	}

	public static void startYesNoDlg(string info, Command cmdYes, Command cmdNo)
	{
		ChatPopupNR.currChatPopup = null;
		msgdlg.setInfo(info, cmdYes, null, cmdNo);
		currentDialog = msgdlg;
		if (menu.showMenu)
		{
			menu.showMenu = false;
		}
		Music.play(Music.POPUP, 10f);
	}

	public static void startWaitDlg(string info)
	{
		ChatPopupNR.currChatPopup = null;
		startWaitDlgWithoutCancel(info);
	}

	public static int random(int a, int b)
	{
		return a + r.nextInt(b - a);
	}

	public static void startWaitDlgWithoutCancel(string info)
	{
		ChatPopupNR.currChatPopup = null;
		startTick = gameTick;
		msgdlg.setInfo(info, null, null, null);
		msgdlg.isWait = true;
		currentDialog = msgdlg;
	}

	public static void startWaitFirstTime(string info)
	{
		ChatPopupNR.currChatPopup = null;
		startWaitDlgWithoutCancel(info);
		isWaitingData = true;
	}

	public static void endDlg()
	{
		currentDialog = null;
	}

	public void stopGame()
	{
		isRunning = false;
		if (gameScr != null)
		{
			GameService.gI().leaveBoard();
		}
	}

	public static void clearAllPointerEvent()
	{
		isPointerClick = false;
		isPointerDown = false;
		isPointerJustDown = false;
		isPointerJustRelease = false;
		if (gameScrRPG != null)
		{
			gameScrRPG.lastSingleClick = 0L;
		}
	}

	public static void clearKeyPressed()
	{
		for (int i = 0; i < keyPressed.Length; i++)
		{
			keyPressed[i] = false;
		}
		isPointerJustRelease = false;
	}

	public static void clearKeyHold()
	{
		for (int i = 0; i < keyHold.Length; i++)
		{
			keyHold[i] = false;
		}
	}

	public void perform(int idAction, object p)
	{
		if (idAction == 1000)
		{
			currentDialog = null;
		}
		if (idAction == 1001)
		{
			currentDialog = null;
		}
		if (idAction == 8882)
		{
			endDlg();
		}
		if (idAction == 8885)
		{
			MyMidlet.instance.exit();
		}
		if (idAction == 101023)
		{
			if (curScr == gameScr)
			{
				gameScr.exitGiuaChung();
				endDlg();
			}
			else
			{
				Music.sTopSoundBG(0);
				Main.numberQuit = 0;
			}
		}
		if (idAction == 9001)
		{
			string[] array = ((typeNapThe != 0) ? huongdan2 : huongdan1);
			if (array != null)
			{
				if (iHuongdan < array.Length)
				{
					startOKDlg2(array[iHuongdan], new Command((iHuongdan != array.Length - 1) ? L.CONTINUE() : L.ok(), this, (iHuongdan != array.Length - 1) ? 9001 : 1000, null));
					iHuongdan++;
				}
				ChatPopupNR.currChatPopup = null;
			}
		}
		if (idAction == 9002)
		{
			inputDlg = new InputDlg();
			inputDlg.setPayment((typeNapThe != 0) ? paymentTitle2 : paymentTitle1, new Command("Nạp " + ((typeNapThe != 0) ? "ngọc" : "vàng"), this, 9003, null), new Command(L.close(), this, 1000, null));
			inputDlg.show();
			ChatPopupNR.currChatPopup = null;
		}
		if (idAction == 9003)
		{
			if (inputDlg.tfInput.getText().Equals(string.Empty))
			{
				inputDlg.tfInput.isFocus = true;
				inputDlg.tfInput2.isFocus = false;
			}
			else if (inputDlg.tfInput2.getText().Equals(string.Empty))
			{
				inputDlg.tfInput2.isFocus = true;
				inputDlg.tfInput.isFocus = false;
			}
			else
			{
				currentDialog = null;
				GameService.gI().doPayment(inputDlg.tfInput2.getText(), inputDlg.tfInput.getText(), typeNapThe);
			}
			ChatPopupNR.currChatPopup = null;
		}
		if (idAction == 9004)
		{
			ChatPopupNR.currChatPopup = null;
		}
		if (idAction == 88820)
		{
			string[] array2 = (string[])p;
			if (PM.getMyPlayer2().npcFocus == null)
			{
				return;
			}
			int menuSelectedItem = menu.menuSelectedItem;
			if (array2.Length > 1)
			{
				MyVector myVector = new MyVector("vSub");
				for (int i = 0; i < array2.Length - 1; i++)
				{
					myVector.addElement(new Command(array2[i + 1], instance, 88821, menuSelectedItem));
				}
				menu.startAt(myVector, 3);
			}
			else
			{
				ChatPopupNR.addChatPopup(string.Empty, 100000, 35, 1);
				GameService.gI().menu(PM.getMyPlayer2().npcFocus.template.npcTemplateId, menuSelectedItem, 0);
			}
		}
		if (idAction == 88821)
		{
			int menuId = (int)p;
			ChatPopupNR.addChatPopup(string.Empty, 100000, 35, 1);
			GameService.gI().menu(PM.getMyPlayer2().npcFocus.template.npcTemplateId, menuId, menu.menuSelectedItem);
		}
	}

	public static void paintShukiren(int x, int y, mGraphics g)
	{
		int num = waitTick % imgBusy.Length;
		waitTick++;
		if (waitTick == 1000)
		{
			waitTick = 0;
		}
		g.drawImage(imgBusy[num], x, y, 3, false);
	}

	public static bool isPaint(int x, int y)
	{
		if (x < Camera.x)
		{
			return false;
		}
		if (x > Camera.x + BackgroundNew.gW)
		{
			return false;
		}
		if (y < Camera.y)
		{
			return false;
		}
		if (y > Camera.y + BackgroundNew.gH + 30)
		{
			return false;
		}
		return true;
	}

	public static void checkBackButton()
	{
		startYesNoDlg(L.wantExit(), new Command(L.yes(), instance, 8885, null), new Command(L.no(), instance, 8882, null));
	}
}
