Beispiel #1
0
        public void JoinSelectedGame(bool online)
        {
            if (OnlineGameListData == null || OnlineGameListData.Length < OnlineGameList.SelectedIndex + 1)
            {
                return;
            }

            PublicGameInfo selectedGame;

            if (online)
            {
                selectedGame = OnlineGameListData[OnlineGameList.SelectedIndex];
            }
            else
            {
                selectedGame = LocalGameListData[LocalGameList.SelectedIndex];
            }

            IPAddress host = null;

            if (!IPAddress.TryParse(selectedGame.HostAddress, out host))
            {
                return;
            }

            var overlay = MessageOverlay.ShowWaitMessage("Connecting to Game...", onCancel: () => { Ballz.The().Network.Disconnect(); });

            Ballz.The().Network.ConnectToServer(host, selectedGame.HostPort, onSuccess: () => {
                Ballz.The().Logic.OpenMenu(new LobbyMenu(isHost: false));
                overlay.Hide();
            });
        }
Beispiel #2
0
        public static MessageOverlay Show(string header, string message = null, string buttonText = "OK", Action onButton = null, InputMessage.MessageType buttonKey = InputMessage.MessageType.ControlsAction)
        {
            if (Ballz.The().MessageOverlay != null)
            {
                return(null);
            }

            MessageOverlay overlay = new MessageOverlay(header, message, buttonText, onButton, buttonKey);

            UserInterface.AddEntity(overlay);

            return(overlay);
        }
Beispiel #3
0
    public static void ShowAlert(string header, string message = null, string footer = "Enter to continue", Action onEnter = null)
    {
        if (Ballz.The().MessageOverlay != null)
                return;

            MessageOverlay overlay = new MessageOverlay
            {
                HeaderText = header,
                MessageText = message,
                FooterText = footer
            };

            if (onEnter != null)
                overlay.OnEnter = onEnter;

            Ballz.The().MessageOverlay = overlay;
    }
Beispiel #4
0
        public JoinByIpMenu() : base("Join by IP")
        {
            AddItem(new Label("Host IP Address:"));
            IpInput.Value = "127.0.0.1";
            AddItem(IpInput);
            AddItem(new Label("Host Port:"));

            PortInput.Value = "16116";
            AddItem(PortInput);

            JoinButton.OnClick += (e) =>
            {
                IPAddress host;

                if (!IPAddress.TryParse(IpInput.Value, out host))
                {
                    MessageOverlay.ShowError("Invalid IP Address format. Please enter a valid IP address, such as 192.168.0.13 (IPv4) or 2001:4860:4860::8844 (IPv6)");
                    return;
                }

                int port = 0;
                if (!int.TryParse(PortInput.Value, out port) || port < 0 || port > 65536)
                {
                    MessageOverlay.ShowError("Invalid Port number. Please specify a number between 0 and 65536");
                    return;
                }

                var overlay = MessageOverlay.ShowWaitMessage("Connecting", "Please Wait", onCancel: () => { Ballz.The().Network.Disconnect(); });

                Ballz.The().Network.ConnectToServer(
                    host,
                    port,
                    onSuccess: () => {
                    Ballz.The().Logic.OpenMenu(new LobbyMenu(isHost: false));
                    overlay.Hide();
                },
                    onFail: () => {
                    overlay.Hide();
                    MessageOverlay.ShowError("Could not connect to host.");
                }
                    );
            };
            AddItem(JoinButton);

            AddItem(new BackButton());
        }