Ejemplo n.º 1
0
        /// <summary>
        /// Performs a frame update on the chat widget.
        /// </summary>
        public void Update()
        {
            var     updated = false;
            KeyCode key;

            while ((key = InputManager.Instance.GetNextKey()) != KeyCode.None)
            {
                var text = InputUtils.ToText(key);
                if (InputManager.Instance.Pressed[(int)KeyCode.LeftShift] ||
                    InputManager.Instance.Pressed[(int)KeyCode.RightShift])
                {
                    text = StringUtils.ToUpper(text);
                }

                if (key == KeyCode.Backspace)
                {
                    if (input.Length > 0)
                    {
                        input   = input.Substring(0, input.Length - 1);
                        updated = true;
                    }
                }

                if (key == KeyCode.Return)
                {
                    ProcessMessage();
                    input   = "";
                    updated = true;
                }

                if (text.Length > 0)
                {
                    input  += text;
                    updated = true;
                }
            }

            if (updated)
            {
                CreateInputTex();
            }
        }
Ejemplo n.º 2
0
        public /* override */ void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (InputUtils.MouseWithin(usernameBounds))
                {
                    selected = SelectedElement.Username;
                }
                else if (InputUtils.MouseWithin(passwordBounds))
                {
                    selected = SelectedElement.Password;
                }
                else if (InputUtils.MouseWithin(loginButtonBounds))
                {
                    AttemptLogin();
                }
                else
                {
                    selected = SelectedElement.None;
                }
            }

            while (InputManager.Instance.HasKeys())
            {
                var key  = InputManager.Instance.GetNextKey();
                var text = InputUtils.ToText(key);
                if (InputManager.Instance.Pressed[(int)KeyCode.LeftShift] ||
                    InputManager.Instance.Pressed[(int)KeyCode.RightShift])
                {
                    text = StringUtils.ToUpper(text);
                }

                switch (selected)
                {
                case SelectedElement.Username:
                    if (key == KeyCode.Backspace)
                    {
                        if (username.Length > 0)
                        {
                            username = username.Substring(0, username.Length - 1);
                            CreateUsernameTex();
                        }
                    }
                    if (text.Length > 0)
                    {
                        username += text;
                        CreateUsernameTex();
                    }
                    break;

                case SelectedElement.Password:
                    if (key == KeyCode.Backspace)
                    {
                        if (username.Length > 0)
                        {
                            password = password.Substring(0, password.Length - 1);
                            CreatePasswordTex();
                        }
                    }
                    if (text.Length > 0)
                    {
                        password += text;
                        CreatePasswordTex();
                    }

                    break;
                }
            }
        }