예제 #1
0
        private void OnClientDisconnect()
        {
            // Disable the feedback text
            _clientFeedbackText.SetActive(false);

            // Disable the disconnect button
            _disconnectButton.SetActive(false);

            // Enable the connect button
            _connectButton.SetActive(true);
        }
예제 #2
0
        private void OnStartButtonPressed()
        {
            // Disable feedback text leftover from other actions
            _clientFeedbackText.SetActive(false);

            var portString = _portInput.GetInput();
            int port;

            if (!int.TryParse(portString, out port))
            {
                // Let the user know that the entered port is incorrect
                _serverFeedbackText.SetColor(Color.red);
                _serverFeedbackText.SetText("Invalid port");
                _serverFeedbackText.SetActive(true);

                return;
            }

            // Input value was valid, so we can store it in the settings
            Logger.Get().Info(this, $"Saving host port {port} in global settings");
            _modSettings.HostPort = port;

            // Start the server in networkManager
            _serverManager.Start(port);

            // Disable the start button
            _startButton.SetActive(false);

            // Enable the stop button
            _stopButton.SetActive(true);

            // Let the user know that the server has been started
            _serverFeedbackText.SetColor(Color.green);
            _serverFeedbackText.SetText("Started server");
            _serverFeedbackText.SetActive(true);
        }
예제 #3
0
        private void CreateConnectUi()
        {
            // Now we can start adding individual components to our UI
            // Keep track of current x and y of objects we want to place
            var x = 1920f - 210.0f;
            var y = 1080f - 75.0f;

            new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "Multiplayer",
                FontManager.UIFontRegular,
                24
                );

            y -= 30;

            new DividerComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 1)
                );

            y -= 30;

            new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "Join Server",
                FontManager.UIFontRegular,
                18
                );

            y -= 40;

            _addressInput = new HiddenInputComponent(
                _connectGroup,
                new Vector2(x, y),
                _modSettings.JoinAddress,
                "IP Address"
                );

            y -= 40;

            var joinPort = _modSettings.JoinPort;

            _portInput = new InputComponent(
                _connectGroup,
                new Vector2(x, y),
                joinPort == -1 ? "" : joinPort.ToString(),
                "Port",
                characterValidation: InputField.CharacterValidation.Integer
                );

            y -= 40;

            var username = _modSettings.Username;

            _usernameInput = new InputComponent(
                _connectGroup,
                new Vector2(x, y),
                username,
                "Username"
                );

            y -= 40;

            var clientSettingsButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Settings"
                );

            clientSettingsButton.SetOnPress(() => {
                _connectGroup.SetActive(false);
                _clientSettingsGroup.SetActive(true);
            });

            y -= 40;

            _connectButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Connect"
                );
            _connectButton.SetOnPress(OnConnectButtonPressed);

            _disconnectButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Disconnect"
                );
            _disconnectButton.SetOnPress(OnDisconnectButtonPressed);
            _disconnectButton.SetActive(false);

            y -= 40;

            _clientFeedbackText = new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "",
                FontManager.UIFontBold,
                15
                );
            _clientFeedbackText.SetActive(false);

            y -= 30;

            new DividerComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 1)
                );

            y -= 30;

            new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "Host Server",
                FontManager.UIFontRegular,
                18
                );

            y -= 40;

            var serverSettingsButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Host Settings"
                );

            serverSettingsButton.SetOnPress(() => {
                _connectGroup.SetActive(false);
                _serverSettingsGroup.SetActive(true);
            });

            y -= 40;

            _startButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Start Hosting"
                );
            _startButton.SetOnPress(OnStartButtonPressed);

            _stopButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                "Stop Hosting"
                );
            _stopButton.SetOnPress(OnStopButtonPressed);
            _stopButton.SetActive(false);

            y -= 40;

            _serverFeedbackText = new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(200, 30),
                "",
                FontManager.UIFontBold,
                15
                );
            _serverFeedbackText.SetActive(false);

            // Register a callback for when the connection is successful or failed or disconnects
            _clientManager.RegisterOnDisconnect(OnClientDisconnect);
            _clientManager.RegisterOnConnect(OnSuccessfulConnect);
            _clientManager.RegisterOnConnectFailed(OnFailedConnect);
        }