Example #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());
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        /// <summary>
        /// Create the connection UI.
        /// </summary>
        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 - 210f;
            var y = 1080f - 100f;

            const float labelHeight = 20f;
            const float logoHeight  = 74f;

            new ImageComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(240f, logoHeight),
                TextureManager.HkmpLogo
                );

            y -= logoHeight / 2f + 20f;

            new TextComponent(
                _connectGroup,
                new Vector2(x + TextIndentWidth, y),
                new Vector2(212f, labelHeight),
                "Username",
                UiManager.NormalFontSize,
                alignment: TextAnchor.MiddleLeft
                );

            y -= labelHeight + 14f;

            _usernameInput = new InputComponent(
                _connectGroup,
                new Vector2(x, y),
                _modSettings.Username,
                "Username",
                characterLimit: 20
                );

            y -= InputComponent.DefaultHeight + 20f;

            new TextComponent(
                _connectGroup,
                new Vector2(x + TextIndentWidth, y),
                new Vector2(212f, labelHeight),
                "Server IP and port",
                UiManager.NormalFontSize,
                alignment: TextAnchor.MiddleLeft
                );

            y -= labelHeight + 14f;

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

            y -= InputComponent.DefaultHeight + 8f;

            var joinPort = _modSettings.ConnectPort;

            _portInput = new PortInputComponent(
                _connectGroup,
                new Vector2(x, y),
                joinPort == -1 ? "" : joinPort.ToString(),
                "Port"
                );

            y -= InputComponent.DefaultHeight + 20f;

            _connectionButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                ConnectText
                );
            _connectionButton.SetOnPress(OnConnectButtonPressed);

            y -= ButtonComponent.DefaultHeight + 8f;

            _serverButton = new ButtonComponent(
                _connectGroup,
                new Vector2(x, y),
                StartHostingText
                );
            _serverButton.SetOnPress(OnStartButtonPressed);

            y -= ButtonComponent.DefaultHeight + 8f;

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

            settingsButton.SetOnPress(() => {
                _connectGroup.SetActive(false);
                _settingsGroup.SetActive(true);
            });

            y -= ButtonComponent.DefaultHeight + 8f;

            _feedbackText = new TextComponent(
                _connectGroup,
                new Vector2(x, y),
                new Vector2(240f, labelHeight),
                new Vector2(0.5f, 1f),
                "",
                UiManager.SubTextFontSize,
                alignment: TextAnchor.UpperCenter
                );
            _feedbackText.SetActive(false);
        }