using System;

public class LoginScr : CScreen, IActionListener
{
	public TField tU;

	public TField tP;

	private int focus;

	private int xC;

	private int wC;

	private int yL;

	private int defYL;

	public static Image lgGame;

	public static Image stone;

	public int plX;

	public int plY;

	public int lY;

	public int lX;

	public int logoDes;

	public int lineX;

	public int lineY;

	public static bool isWait;

	public static int currTime = 0;

	public static int maxTime = 15;

	public bool isDemo;

	public bool isPlane;

	public bool isCloud;

	public bool isForward;

	public bool isMenu;

	public int demoStat;

	public static bool isLoadData = false;

	public static Image imgVMB;

	public static int startTimeOut;

	private string numSupport = string.Empty;

	private int xLog;

	private int yLog;

	public int cmy = -1500;

	public static Image imgCheck;

	public static Image missile = Bullet.rocket2;

	public Command cmdRes;

	public Command cmdBackFromRegister;

	public static LoginScr instance;

	private Command cmdSignIn;

	private Command cmdMenu;

	private Command cmdForward;

	private Command cmdRemember;

	private Command cmdYes;

	private Command cmdNo;

	private Command cmdSelect;

	private Command cmdOK;

	private Command cmdForgetPass;

	public bool isLogin2;

	private bool isRes;

	private int dyLogo;

	private int dyT;

	private int ty = 17;

	private int deltaX;

	private int tX;

	private bool activeFall;

	private bool explore;

	private bool logoII;

	public int[] xB = new int[2]
	{
		CCanvas.w + 15,
		CCanvas.w + 15
	};

	public int[] yB = new int[2];

	private int speed;

	private int tII;

	public static short timeLogin;

	public static long lastTimeLogin;

	public static long currTimeLogin;

	public static bool isLoadDataOk;

	private int finishDemo;

	public static int remember;

	public static int volume = 50;

	public static string serverName = string.Empty;

	public new int keyTouch = -1;

	public LoginScr()
	{
		initDemoData();
		isDemo = false;
		if (GameScr.sm == null)
		{
			GameScr.sm = new SmokeManager();
		}
		GameScr.sm.addSmoke(-100f, -100f, 19);
		GameScr.exs = new MyVector("GameScr.exs");
		new Explosion(-100, -100, 0);
		yLog = CCanvas.hh - 30;
		plX = -100;
		plY = cmy + 60;
		lX = -100;
		lY = plY + 120;
		yB[0] = lY - 39;
		yB[1] = -1450;
		defYL = CCanvas.hh - 80;
		MM.mapHeight = CCanvas.h;
		wC = ((CCanvas.w < 200) ? 140 : 160);
		xC = (CCanvas.w - wC >> 1) + 29;
		cmdBackFromRegister = new Command(L.cancel(), this, 10021, null);
		cmdRes = new Command(L.reg(), this, 1002, null);
		tU = new TField();
		tU.y = CCanvas.hh - CScreen.ITEM_HEIGHT - 9;
		tU.width = wC;
		tU.height = CScreen.ITEM_HEIGHT + 2;
		tU.isFocus = true;
		tU.setIputType(TField.INPUT_TYPE_ANY);
		if (mSystem.isIphone && mSystem.isAppStore)
		{
			tU.name = L.id();
		}
		else
		{
			tU.name = L.email() + "/" + L.phone();
		}
		tP = new TField();
		tP.y = CCanvas.hh - 4;
		tP.width = wC;
		tP.height = CScreen.ITEM_HEIGHT + 2;
		tP.isFocus = false;
		tP.setIputType(TField.INPUT_TYPE_PASSWORD);
		tP.name = L.pass();
		tU.strInfo = L.id();
		tP.strInfo = L.pass();
		tU.setText(CRes.loadRMS_String("armyUser"));
		tP.setText(CRes.loadRMS_String("armyPass"));
		remember = 1;
		resetTF();
		logoDes = ((CCanvas.w < 200) ? (tU.y - 20) : (yLog - 30));
		focus = 0;
		cmdSignIn = new Command(L.signIn(), this, 1000, null);
		cmdMenu = new Command("Menu", this, 1001, null);
		if (CCanvas.isTouch)
		{
			cmdSignIn.x = CCanvas.w / 2 + 8;
			cmdMenu.x = CCanvas.w / 2 - CScreen.cmdW - 8;
			if (CScreen.h >= 200)
			{
				cmdSignIn.y = yLog + 110;
				cmdMenu.y = yLog + 110;
			}
			cmdBackFromRegister.x = CCanvas.w / 2 + 3;
			cmdBackFromRegister.y = yLog + 110;
			cmdRes.x = CCanvas.w / 2 - 84;
			cmdRes.y = cmdMenu.y;
		}
		cmdForward = new Command(L.forward(), this, 1009, null);
		if (!CCanvas.isTouch && mGraphics.zoomLevel == 1)
		{
			center = new Command(L.select(), this, 1010, null);
		}
		cmdRemember = new Command(L.remember(), this, 1011, null);
		cmdYes = new Command(L.soundOn(), this, 1012, null);
		cmdNo = new Command(L.soundOff(), this, 1013, null);
		isDemo = false;
		isMenu = true;
		lY = logoDes + 2;
		logoII = true;
		cmy = 0;
		if (!CCanvas.isTouch)
		{
			right = tU.cmdClear;
		}
		else
		{
			right = null;
		}
		cmdOK = new Command(L.ok(), this, 2008, null);
		cmdOK.x = CCanvas.w / 2 - 84;
		cmdOK.y = cmdSignIn.y;
		cmdForgetPass = new Command(L.forgotPass(), this, 1003, null);
		cmdForgetPass.x = CCanvas.w / 2 + 3;
		cmdForgetPass.y = cmdSignIn.y;
		center = cmdOK;
		left = cmdForgetPass;
		lY = ((CCanvas.w < 200) ? (tU.y - 30) : (yLog - 30));
		if (Rms.loadRMSString("userAo") != null && !Rms.loadRMSString("userAo").Equals(string.Empty))
		{
			isLogin2 = true;
		}
		else
		{
			isLogin2 = false;
		}
	}

	public new static void loadImage()
	{
		imgCheck = CCanvas.loadImage("/gui/remember.png");
	}

	public static LoginScr gI()
	{
		if (instance == null)
		{
			instance = new LoginScr();
		}
		return instance;
	}

	public override void show()
	{
		CCanvas.splashScr = null;
		resetTF();
		base.show();
	}

	public string getUrlUpdateGame()
	{
		return "http://wap.teamobi.com?info=checkupdate&game=3&version=" + MyMidlet.version + "&provider=" + MyMidlet.PROVIDER;
	}

	public static void connect()
	{
		if (!Session_ME.gI().isConnected())
		{
			Session_ME.gI().connect(MyMidlet.IP, MyMidlet.PORT);
		}
	}

	protected void doForgetPass(string user)
	{
		perform(1014, user);
	}

	private void initDemoData()
	{
		demoStat = 0;
		volume = Rms.loadRMSInt("sound");
	}

	protected void doRegister()
	{
		if (tU.getText().Equals(string.Empty))
		{
			CCanvas.startOKDlg(L.userBlank());
			return;
		}
		char[] array = tU.getText().ToCharArray();
		if (tP.getText().Equals(string.Empty))
		{
			CCanvas.startOKDlg(L.passwordBlank());
			return;
		}
		if (tU.getText().Length < 5)
		{
			CCanvas.startOKDlg(L.accTooShort());
			return;
		}
		int num = 0;
		CCanvas.msgdlg.setInfo(L.plsCheckAcc() + L.id() + ": " + tU.getText() + "\n" + L.password() + ": " + tP.getText(), new Command(L.ACCEPT(), this, 4000, null), null, new Command(L.NO(), CCanvas.instance, 8882, null));
		CCanvas.currentDialog = CCanvas.msgdlg;
	}

	protected void doRegister(string user)
	{
		CCanvas.startWaitDlg(L.connecting());
		connect();
		CCanvas.startWaitDlg(L.pleaseWait());
		GameService.gI().requestRegister(user, tP.getText(), Rms.loadRMSString("userAo"));
		Rms.saveRMSString("user", user);
		Rms.saveRMSString("pass", tP.getText());
	}

	public void doLogin()
	{
		CRes.outz("user ao= " + Rms.loadRMSString("userAo"));
		string text = tU.getText().ToLower().Trim();
		string text2 = tP.getText().ToLower().Trim();
		if (text != null && !text.Equals(string.Empty))
		{
			isLogin2 = false;
		}
		else if (Rms.loadRMSString("userAo") != null && !Rms.loadRMSString("userAo").Equals(string.Empty))
		{
			isLogin2 = true;
		}
		else
		{
			isLogin2 = false;
		}
		if (isLogin2)
		{
			text = Rms.loadRMSString("userAo");
			text2 = "a";
		}
		CRes.outz("user = " + text + " pass= " + text2);
		if (text == null || text2 == null || MyMidlet.version == null || text.Equals(string.Empty))
		{
			return;
		}
		if (text2.Equals(string.Empty))
		{
			focus = 1;
			tU.isFocus = false;
			tP.isFocus = true;
			if (!CCanvas.isTouch)
			{
				right = tP.cmdClear;
			}
			return;
		}
		connect();
		GameService.gI().login(text, text2, MyMidlet.version, (sbyte)(isLogin2 ? 1 : 0));
		CCanvas.startWaitDlgWithoutCancel(L.pleaseWait());
		focus = 0;
		if (!isLogin2)
		{
			actRegisterLeft();
		}
	}

	public static string getIMEI()
	{
		return mSystem.getIMEI();
	}

	public void actRegisterLeft()
	{
		if (isLogin2)
		{
			doLogin();
			return;
		}
		isRes = false;
		tP.isFocus = false;
		tU.isFocus = true;
	}

	public void Effect()
	{
		dyT += 3;
		lY += dyT;
		if (lY > logoDes)
		{
			lY = logoDes;
			dyT = -ty;
			ty -= 4;
		}
	}

	public override void update()
	{
		if (timeLogin > 0)
		{
			CCanvas.startWaitDlgWithoutCancel(L.pleaseWait());
			currTimeLogin = mSystem.currentTimeMillis();
			if (currTimeLogin - lastTimeLogin >= 1000)
			{
				timeLogin--;
				if (timeLogin == 0)
				{
					Session_ME.gI().close();
					gI().doLogin();
				}
				lastTimeLogin = currTimeLogin;
			}
		}
		if (GameScr.isLoadingDone())
		{
			isLoadDataOk = true;
			GameService.gI().loadDataOk();
			GameScr.isLoadData = false;
			GameScr.isLoadItem = false;
			GameScr.isLoadMapData = false;
			return;
		}
		if (cmy > 0)
		{
			cmy = 0;
		}
		if (isForward)
		{
			speed = 15;
		}
		else
		{
			speed = 0;
		}
		if (isLogin2 && !isRes)
		{
			tU.isPaintCarret = false;
			tP.isPaintCarret = false;
			tU.update();
			tP.update();
		}
		else
		{
			tU.update();
			tP.update();
		}
		if (TouchScreenKeyboard.visible)
		{
			mGraphics.addYWhenOpenKeyBoard = 0;
		}
		if (CCanvas.isTouch)
		{
			if (isRes)
			{
				center = cmdRes;
				left = cmdBackFromRegister;
			}
			else
			{
				center = cmdOK;
				left = cmdForgetPass;
			}
		}
		else if (isRes)
		{
			center = cmdRes;
			left = cmdBackFromRegister;
		}
		else
		{
			center = cmdOK;
			left = cmdForgetPass;
		}
		base.update();
	}

	public override void keyPressed(int keyCode)
	{
		if (tU.isFocus)
		{
			tU.keyPressed(keyCode);
		}
		else if (tP.isFocus)
		{
			tP.keyPressed(keyCode);
		}
		base.keyPressed(keyCode);
	}

	public void paintBackG(mGraphics g)
	{
		if (ServerListScreen.loadScreen)
		{
			BackgroundNew.paintBGGameScr(g);
			return;
		}
		g.setColor(0);
		g.fillRect(0, 0, CScreen.w, CScreen.h, false);
	}

	public void paintMenuLogin(mGraphics g)
	{
		paintBackG(g);
		int num = 105;
		int num2 = ((CCanvas.w < 200) ? 160 : 180);
		if (CCanvas.currentDialog == null)
		{
			CScreen.paintBorderRect(g, xLog, yLog - 10, num2, num);
			if (MyMidlet.BIG_PROVIDER == 0)
			{
				g.drawImage(GameScr.logoGame, CCanvas.w / 2, lY, 3, false);
				tU.paint(g);
				tP.paint(g);
			}
		}
		mFont.tahoma_7b_white.drawString(g, serverName, CCanvas.w - 5, 5, 1);
		mFont.tahoma_7b_white.drawString(g, MyMidlet.version, 5, 5, 0);
	}

	public override void paint(mGraphics g)
	{
		int num = 4;
		int num2 = num * 32 + 23 + 33;
		if (num2 >= CCanvas.w)
		{
			num--;
			num2 = num * 32 + 23 + 33;
		}
		xLog = CCanvas.w / 2 - num2 / 2;
		int num3 = yLog;
		tU.x = xLog + 10;
		tU.y = num3 + 20;
		tP.x = xLog + 10;
		tP.y = num3 + 55;
		Camera.x++;
		g.translate(0, -cmy);
		paintMenuLogin(g);
		if (isWait)
		{
			CCanvas.msgdlg.setInfo(L.download() + " " + currTime + "%", null, null, null);
		}
		CCanvas.resetTrans(g);
		base.paint(g);
	}

	public void focusUpdate()
	{
		if (focus == 0)
		{
			tU.isFocus = true;
			tP.isFocus = false;
		}
		if (focus == 1)
		{
			tU.isFocus = false;
			tP.isFocus = true;
		}
		if (focus == 2)
		{
			tU.isFocus = false;
			tP.isFocus = false;
		}
	}

	public override void input()
	{
		if (!CCanvas.isTouch)
		{
			if (tU.isFocus)
			{
				right = tU.cmdClear;
			}
			else
			{
				right = tP.cmdClear;
			}
		}
		if (isMenu)
		{
			if (CCanvas.keyPressed[2])
			{
				focus--;
				if (focus < 0)
				{
					focus = 1;
				}
			}
			if (CCanvas.keyPressed[8])
			{
				focus++;
				if (focus > 1)
				{
					focus = 0;
				}
			}
		}
		if (isDemo)
		{
			if (CCanvas.keyPressed[13])
			{
				isForward = true;
				CScreen.clearKey();
			}
		}
		else if (isForward)
		{
			return;
		}
		if (CCanvas.keyPressed[2] || CCanvas.keyPressed[8])
		{
			CCanvas.clearKeyPressed();
			if (!isLogin2 || isRes)
			{
				if (focus == 1)
				{
					tU.isFocus = false;
					tP.isFocus = true;
					if (!CCanvas.isTouch)
					{
						right = tP.cmdClear;
					}
					else
					{
						right = null;
					}
				}
				else if (focus == 0)
				{
					tU.isFocus = true;
					tP.isFocus = false;
					if (!CCanvas.isTouch)
					{
						right = tP.cmdClear;
					}
					else
					{
						right = null;
					}
				}
				else
				{
					tU.isFocus = false;
					tP.isFocus = false;
				}
			}
		}
		if (CCanvas.isPointerJustRelease)
		{
			if (CCanvas.isPointerHoldIn(tU.x, tU.y, tU.width, tU.height))
			{
				focus = 0;
				focusUpdate();
			}
			else if (CCanvas.isPointerHoldIn(tP.x, tP.y, tP.width, tP.height))
			{
				focus = 1;
				focusUpdate();
			}
		}
		if (Main.isPC && CCanvas.keyPressed[5] && right != null)
		{
			right.performAction();
		}
		base.input();
		CScreen.clearKey();
	}

	public void resetTF()
	{
		tU.x = -xC;
		tP.x = CCanvas.w + xC;
		tU.isFocus = true;
		tP.isFocus = false;
	}

	public void actRegister()
	{
		CCanvas.endDlg();
		isRes = true;
		tP.isFocus = false;
		tU.isFocus = true;
	}

	public void backToRegister()
	{
		if (isLogin2)
		{
			MyVector myVector = new MyVector("do show menu account");
			myVector.addElement(new Command(L.changeAcc(), this, 3000, null));
			myVector.addElement(new Command(L.reg(), this, 3001, null));
			CCanvas.menu.startAt(myVector, 0);
		}
		else
		{
			MyVector myVector2 = new MyVector("do show menu account 2");
			myVector2.addElement(new Command(L.changeAcc(), this, 3003, null));
			myVector2.addElement(new Command(L.changePass(), this, 3002, null));
			CCanvas.menu.startAt(myVector2, 0);
		}
	}

	public void perform(int idAction, object p)
	{
		if (idAction == 10020)
		{
			CCanvas.endDlg();
		}
		if (idAction == 10019)
		{
			CCanvas.endDlg();
			Session_ME.gI().close();
			isRes = false;
			tP.isFocus = false;
			tU.isFocus = true;
			show();
		}
		if (idAction == 2002)
		{
			connect();
			CCanvas.startWaitDlgWithoutCancel(L.pleaseWait());
			string text = Rms.loadRMSString("userAo");
			if (text == null || text.Equals(string.Empty))
			{
				GameService.gI().login2(string.Empty);
			}
			else
			{
				gI().isLogin2 = true;
				GameService.gI().login(text, string.Empty, MyMidlet.version, 1);
				CCanvas.startWaitDlgWithoutCancel(L.pleaseWait());
			}
		}
		if (idAction == 2001)
		{
			CCanvas.endDlg();
		}
		if (idAction == 1000 && MyMidlet.BIG_PROVIDER == 0)
		{
			doLogin();
		}
		if (idAction == 1002)
		{
			doRegister();
		}
		if (idAction == 1003)
		{
			if (CCanvas.curScr == instance)
			{
				CCanvas.inputDlg.setInfo(L.phone() + "/" + L.email(), new Command(string.Empty, this, 1004, null), new Command(L.close(), this, 1005, null), TField.INPUT_TYPE_ANY);
				CCanvas.inputDlg.show();
				CCanvas.inputDlg.tfInput.doChangeToTextBox(false);
			}
			else
			{
				doForgetPass(MyMidlet.myInfo.name);
			}
		}
		if (idAction == 1004)
		{
			string text2 = CCanvas.inputDlg.tfInput.getText();
			if (text2.Equals(string.Empty))
			{
				return;
			}
			doForgetPass(text2);
		}
		if (idAction == 1005)
		{
			CCanvas.endDlg();
		}
		if (idAction == 1006)
		{
			if (!numSupport.Equals(string.Empty))
			{
				try
				{
					MyMidlet.instance.platformRequest("tel:" + numSupport);
				}
				catch (Exception ex)
				{
					Cout.LogTryCatch("perform  idAction == 1006: " + ex.StackTrace);
				}
			}
			else
			{
				if (!Session_ME.connected)
				{
					CCanvas.startWaitDlg(L.connecting());
					connect();
				}
				else
				{
					CCanvas.startWaitDlg(L.pleaseWait());
				}
				GameService.gI().requestService(5, null);
			}
		}
		if (idAction == 1007)
		{
			Rms.delRMS();
		}
		if (idAction == 1008)
		{
			if (ServerListScreen.loadScreen)
			{
				CCanvas.serverScreen.show();
			}
			else
			{
				CCanvas.serverScreen.show2();
			}
		}
		if (idAction == 2008)
		{
			Rms.saveRMSString("armyUser", tU.getText().Trim());
			Rms.saveRMSString("armyPass", tP.getText().Trim());
			if (ServerListScreen.loadScreen)
			{
				CCanvas.serverScreen.show();
			}
			else
			{
				CCanvas.serverScreen.show2();
			}
		}
		if (idAction == 1001)
		{
			MyVector myVector = new MyVector();
			myVector.addElement(new Command(L.reg(), this, 1002, null));
			myVector.addElement(new Command(L.xoadulieu(), this, 1007, null));
			if (ServerListScreen.nameServer.Length > 1)
			{
				myVector.addElement(new Command(L.chonmaychu(), this, 1008, null));
			}
			CCanvas.menu.startAt(myVector, 0);
		}
		if (idAction == 1009)
		{
			isForward = true;
		}
		if (idAction == 1014)
		{
			string arg = (string)p;
			if (!Session_ME.connected)
			{
				connect();
			}
			CCanvas.startWaitDlg(L.pleaseWait());
			GameService.gI().forgetPass(arg);
		}
		if (idAction == 1015)
		{
			CCanvas.startOKDlg(L.usingPhone2());
		}
		if (idAction == 1016)
		{
			focus = 1;
			tU.isFocus = false;
			tP.isFocus = true;
			if (!CCanvas.isTouch)
			{
				right = tP.cmdClear;
			}
			else
			{
				right = null;
			}
			CCanvas.endDlg();
		}
		if (idAction == 1018)
		{
			CCanvas.endDlg();
			focus = 1;
			tP.setText(string.Empty);
			tU.isFocus = false;
			tP.isFocus = true;
			if (!CCanvas.isTouch)
			{
				right = tP.cmdClear;
			}
			else
			{
				right = null;
			}
		}
		if (idAction == 1019)
		{
			CCanvas.endDlg();
			focus = 1;
			tU.isFocus = false;
			tP.isFocus = true;
			if (!CCanvas.isTouch)
			{
				right = tP.cmdClear;
			}
			else
			{
				right = null;
			}
		}
		if (idAction == 8882)
		{
			CCanvas.endDlg();
		}
		if (idAction == 4000)
		{
			doRegister(tU.getText());
		}
		if (idAction == 10021)
		{
			actRegisterLeft();
		}
		if (idAction == 3000)
		{
			CCanvas.startYesNoDlg(L.note(), new Command(L.yes(), this, 10019, null), new Command(L.no(), this, 10020, null));
		}
		if (idAction == 3001)
		{
			Session_ME.gI().close();
			actRegister();
			show();
		}
		if (idAction == 3002)
		{
			MenuScr.gI().doChangePass();
		}
		if (idAction == 3003)
		{
			show();
			Session_ME.gI().close();
		}
	}
}
