Example #1
0
 public override void update(GameTime gameTime)
 {
     base.update(gameTime);
     if (MainGame.Instance == null)
     {
         return;
     }
     if (UltraServer.Instance.network.DeviceIP == null)
     {
         return;
     }
     if (ipField.Text == "Starting...")
     {
         ipField.Text = IPHelper.decToSimple(UltraServer.Instance.network.DeviceIP + ":" + UltraServer.Instance.network.DevicePort);
         QRCode       = QRRenderer.QRFromString(ipField.Text);
         Console.WriteLine(QRCode.Bounds);
     }
 }
Example #2
0
        public PageJoinGame(MainGame mainGame) : base(mainGame)
        {
            Arranger arranger = new Arranger(true, 1, 'C', ScaleManager.InterfaceScale * 2);

            nameField = new PatchField(4, 15, Vector2.Zero, ScaleManager.InterfaceScale, "Name", "Enter Name...", "Enter your Name:", true);
            if (UltraClient.Instance.network.GetLastClientName() != null)
            {
                nameField.Text = UltraClient.Instance.network.GetLastClientName();
            }
            addField(nameField);
            arranger.addObject(nameField, 0);

            String lastIP      = UltraClient.Instance.network.GetLastServerIP();
            String convertedIP = "";

            try {
                convertedIP = IPHelper.decToSimple(lastIP + ":60347");
            } catch {
                Console.WriteLine("[IPHelper] Error: Invalid conversion.");
            }

            ipField = new PatchField(4, 15, Vector2.Zero, ScaleManager.InterfaceScale, "IP", (lastIP != null ? convertedIP : "Enter Server..."), "Enter the server's IP:", true);
            addField(ipField);
            arranger.addObject(ipField, 0);

            Arranger.ArrangerSpacer spacer = new Arranger.ArrangerSpacer(128 * ScaleManager.InterfaceScale, 8 * ScaleManager.InterfaceScale, false);
            addMovable(spacer);
            arranger.addObject(spacer, 0);

            scanButton = new PatchButton(15, Vector2.Zero, buttonPatch, ScaleManager.InterfaceScale, "Scan QR Code", async() => {
                if (!joinAttempted)
                {
                    AudioHelper.play(ContentStore.soundPop);
                    var scanner = new ZXing.Mobile.MobileBarcodeScanner();
                    var result  = await scanner.Scan();
                    if (result != null)
                    {
                        ipField.Text = result.ToString();
                    }
                }
            });
            addButton(scanButton);
            arranger.addObject(scanButton, 0);

            joinButton = new PatchButton(15, Vector2.Zero, buttonPatch, ScaleManager.InterfaceScale, "Join", () => {
                if (!joinAttempted)
                {
                    joinAttempted   = true;
                    joinButton.Text = "Joining...";
                    AudioHelper.play(ContentStore.soundPop);
                    string standardIP = "";
                    String ip         = "";
                    int port          = 0;

                    try {
                        standardIP = IPHelper.simpleToDec(ipField.Text, true);

                        if (standardIP.StartsWith("IP"))
                        {
                            MainGame.Instance.GeneralMessageQueue.Enqueue(standardIP);
                            joinAttempted = false;
                            SetJoinButtonText("Join");
                            AudioHelper.play(ContentStore.soundBad);
                            return;
                        }

                        ip                = IPHelper.getIP(standardIP);
                        port              = int.Parse(IPHelper.getPort(standardIP));
                        clientTask        = UltraClient.Instance.network.StartClient(ip, port, 0, new Player(nameField.Text, 2));
                        nameField.Enabled = false;
                        ipField.Enabled   = false;
                    } catch (Exception e) {
                        UltraClient.Instance.ClientJoinFailed(null);
                        Console.WriteLine("Error: " + e.Message);
                    }
                }
            });
            addButton(joinButton);
            arranger.addObject(joinButton, 0);

            backButton = new PatchButton(5, Vector2.Zero, buttonPatch, ScaleManager.InterfaceScale, "Back", () => {
                AudioHelper.play(ContentStore.soundPop);
                if (backButton.Text != "-")
                {
                    AudioHelper.play(ContentStore.soundPop);
//					UltraClient.Instance.network.SendLeaveGameMessage(UltraClient.Instance.network.Me);
//					UltraClient.Instance.network.Me = null;
//					mainGame.GeneralMessageQueue.Enqueue("You left the game!");
//					backButton.Text = "Back";
//					joinButton.Text = "Join";
//					joinAttempted = false;
                    mainGame.menuController.changeActivePage(mainGame.mainMenu);
                }
                else
                {
                    AudioHelper.play(ContentStore.soundBad);
                }
            });
            addButton(backButton);
            arranger.addObject(backButton, 0);

            arranger.performArrangements();
        }