Example #1
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();
        }
Example #2
0
        public PageHostGame(MainGame mainGame) : base(mainGame)
        {
            Arranger arranger = new Arranger(true, 2, 'C', ScaleManager.InterfaceScale * 2);

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

            ipField = new PatchField(2, 13, Vector2.Zero, ScaleManager.InterfaceScale, "IP", "Starting...", null, false);
            addField(ipField);
            arranger.addObject(ipField, 0);

            backButton = new PatchButton(5, Vector2.Zero, buttonPatch, ScaleManager.InterfaceScale, "Back", () => {
                AudioHelper.play(ContentStore.soundPop);
                mainGame.menuController.changeActivePage(mainGame.preHostGame);
                UltraServer.Instance.network.CloseServer();
                UltraClient.Instance.network.CloseClient();
                for (int i = 1; i <= 6; i++)
                {
                    NineGridRow row              = joinedGrid.getRow(i.ToString());
                    row.getCell("player").Text   = "...";
                    row.getCell("player").Colour = Color.White;
                }
                ClientDataStore.Instance.resetPlayers();
            });
            addButton(backButton);
            arranger.addObject(backButton, 0);

            joinedGrid = new NineGrid(Vector2.Zero, ScaleManager.InterfaceScale, ScaleManager.LargeFont, new string[] { "player" }, new int[] { 13 });
            NineGridRow header = joinedGrid.addRow("header");

            header.getCell("player").Text      = "Players";
            header.getCell("player").Alignment = 'C';
            for (int i = 1; i <= 6; i++)
            {
                NineGridRow playerRow = joinedGrid.addRow(i.ToString());
                playerRow.getCell("player").Text      = ("...");
                playerRow.getCell("player").Alignment = 'C';
            }
            addMovable(joinedGrid);
            arranger.addObject(joinedGrid, 1);

            beginButton = new PatchButton(13, Vector2.Zero, buttonPatch, ScaleManager.InterfaceScale, "Begin!", () => {
                AudioHelper.play(ContentStore.soundPop);

                int playerCount = UltraServer.Instance.network.Players.GetPlayers().Count;
                if ((playerCount < 3 && SettingsHelper.Instance.PlayerCountCheck) || (!SettingsHelper.Instance.PlayerCountCheck && playerCount == 0))
                {
                    if (!SettingsHelper.Instance.PlayerCountCheck)
                    {
                        mainGame.GeneralMessageQueue.Enqueue("At least 1 more player must join!");
                        return;
                    }

                    if (3 - playerCount > 1)
                    {
                        mainGame.GeneralMessageQueue.Enqueue("At least " + (3 - playerCount) + " more players must join!");
                    }
                    else
                    {
                        mainGame.GeneralMessageQueue.Enqueue("At least " + (3 - playerCount) + " more player must join!");
                    }

                    return;
                }

                if (mainGame.HostOnly)
                {
                    mainGame.gameIsRunning = true;
                    UltraServer.Instance.network.SendStartGameMessage();
                    GameScheduler.initialise(UltraServer.Instance.network.Players.GetPlayers(), UltraServer.Instance.network, UltraServer.Instance);
                    UltraServer.Instance.HostStarted();
                }
                else
                {
                    UltraServer.Instance.network.SendStartGameMessage();
                    GameScheduler.initialise(UltraServer.Instance.network.Players.GetPlayers(), UltraServer.Instance.network, UltraServer.Instance);
                }

                Thread schedulerThread = new Thread(new ThreadStart(GameScheduler.schedulerThread));
                schedulerThread.Start();
            });
            addButton(beginButton);
            arranger.addObject(beginButton, 1);

            arranger.performArrangements();
        }