Exemple #1
0
        /// <summary>
        /// Set the feedback text with the given color and content.
        /// </summary>
        /// <param name="color">The color of the text.</param>
        /// <param name="text">The content of the text.</param>
        private void SetFeedbackText(Color color, string text)
        {
            _feedbackText.SetColor(color);
            _feedbackText.SetText(text);
            _feedbackText.SetActive(true);

            if (_feedbackHideCoroutine != null)
            {
                MonoBehaviourUtil.Instance.StopCoroutine(_feedbackHideCoroutine);
            }

            _feedbackHideCoroutine = MonoBehaviourUtil.Instance.StartCoroutine(WaitHideFeedbackText());
        }
Exemple #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);
        }
Exemple #3
0
        private void OnConnectButtonPressed()
        {
            // Disable feedback text leftover from other actions
            _clientFeedbackText.SetActive(false);

            var address = _addressInput.GetInput();

            Logger.Get().Info(this, $"Connect button pressed, address: {address}");

            if (address.Length == 0)
            {
                // Let the user know that the address is empty
                _clientFeedbackText.SetColor(Color.red);
                _clientFeedbackText.SetText("Address is empty");
                _clientFeedbackText.SetActive(true);

                return;
            }

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

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

                return;
            }

            var username = _usernameInput.GetInput();

            if (username.Length == 0 || username.Length > 20)
            {
                if (username.Length > 20)
                {
                    _clientFeedbackText.SetText("Username too long");
                }
                else if (username.Length == 0)
                {
                    _clientFeedbackText.SetText("Username is empty");
                }

                // Let the user know that the username is too long
                _clientFeedbackText.SetColor(Color.red);
                _clientFeedbackText.SetActive(true);

                return;
            }

            // Input values were valid, so we can store them in the settings
            Logger.Get().Info(this, $"Saving join address {address} in global settings");
            Logger.Get().Info(this, $"Saving join port {port} in global settings");
            Logger.Get().Info(this, $"Saving join username {username} in global settings");
            _modSettings.JoinAddress = address;
            _modSettings.JoinPort    = port;
            _modSettings.Username    = username;

            // Disable the connect button while we are trying to establish a connection
            _connectButton.SetActive(false);

            _clientManager.Connect(address, port, username);
        }