Exemplo n.º 1
0
 void CheckMuteState()
 {
     if (Mute)
     {
         _muteKey.ChangeState(PYButtonState.Idle);
     }
     else
     {
         _muteKey.ChangeState(PYButtonState.Pressed);
     }
 }
Exemplo n.º 2
0
        void OnRelasedKeyButton(PYButton sender, bool isMouseOver)
        {
            CancelDefaultInvokes();
            EnableButtons();

            // If user clicked in a disabled key
            // the pressedKey var will be null, so just return
            if (_pressedKey == null)
            {
                return;
            }

            PKKeyButton keyButton = (sender != null) ? (PKKeyButton)sender : null;

            if ((keyButton != null) &&
                ((isMouseOver && sender == _pressedKey.OwnGameObject)))
            {
                if (OnKeyUp != null)
                {
                    OnKeyUp(_pressedKey.Text);
                }
            }

            _pressedKey.ChangeState(PYButtonState.Idle);
            _pressedKey = null;

            EnableButtons();
            CheckMuteState();
        }
Exemplo n.º 3
0
        public void DisableKey(PKKeyButton key, bool conditionToDisable)
        {
            if (conditionToDisable)
            {
                key.ChangeState(PYButtonState.Disabled);

                if (_pressedKey == key)
                {
                    _pressedKey = null;
                }
            }
            else
            {
                key.ChangeState(PYButtonState.Idle);
            }
        }
Exemplo n.º 4
0
        void TouchManagerOnClick(PYButton sender)
        {
            if (!_isEnabled)
            {
                return;
            }

            for (int i = 0; i < _keys.Length; i++) // Identify wich key was clicked
            {
                if (sender.OwnGameObject == _keys[i].OwnGameObject &&
                    _keys[i].State != PYButtonState.Disabled)
                {
                    _pressedKey = _keys[i];
                    _pressedKey.ChangeState(PYButtonState.Pressed);
                    if (OnKeyDown != null)
                    {
                        OnKeyDown(_keys[i].Text);
                    }

                    break;
                }
            }

            if (_pressedKey == null) // If clicked key is null, do nothing
            {
                return;
            }

            PKKeyButton keyButton = (sender != null) ? (PKKeyButton)sender : null;

            if ((keyButton != null) &&
                ((sender.OwnGameObject == _pressedKey.OwnGameObject)))
            {
                _launchTextChange = true;

                PlayKeySound();
                PlayKeyVoice();

                if (_pressedKey != null && OnType != null)
                {
                    OnType(_pressedKey);
                }

                switch (_pressedKey.Type)
                {
                case PKKeyType.Letter:
                    if (Text.Length >= 20)
                    {
                        break;
                    }
                    if (CursorPosition < Text.Length)
                    {
                        Text = Text.Substring(0, CursorPosition) + _pressedKey.Text + Text.Substring(CursorPosition);
                        ChangeDisplayCursorPosition(1);
                        if (OnTextChange != null)
                        {
                            OnTextChange(Text);
                        }
                    }
                    else
                    {
                        Text += _pressedKey.Text;
                        if (OnTextChange != null)
                        {
                            OnTextChange(Text);
                        }
                    }

                    if (CursorPosition >= Text.Length - 1 && CursorPosition < Display.MaxChars)
                    {
                        ChangeDisplayCursorPosition(1);
                    }
                    else
                    {
                        ChangeDisplayCursorPosition(0);
                    }

                    //voltar para a pagina normal autamaticamente
                    if (!IsNormalPage)
                    {
                        KeyActionSpecial(0);
                    }

                    break;

                case PKKeyType.Space:
                    KeyActionSpace();

                    break;

                case PKKeyType.Backspace:
                    if (!_hasAutomaticPressed)
                    {
                        KeyActionBackspace();
                    }
                    _hasAutomaticPressed = false;

                    break;

                case PKKeyType.Confirm:
                    KeyActionConfirm();
                    _launchTextChange = false;
                    break;

                case PKKeyType.Cancel:
                    KeyActionCancel();
                    _launchTextChange = false;
                    break;

                case PKKeyType.Special:
                    KeyActionSpecial();
                    _launchTextChange = false;
                    break;

                case PKKeyType.CursorNavigationLeft:
                    if (!_hasAutomaticPressed)
                    {
                        KeyActionCursorNavigation(-1);
                    }
                    _hasAutomaticPressed = false;
                    _launchTextChange    = false;
                    break;

                case PKKeyType.CursorNavigationRight:
                    if (!_hasAutomaticPressed)
                    {
                        KeyActionCursorNavigation(1);
                    }
                    _hasAutomaticPressed = false;
                    _launchTextChange    = false;
                    break;

                case PKKeyType.ClearAllText:
                    ClearText();
                    break;

                case PKKeyType.Mute:
                    Mute = !Mute;
                    _launchTextChange = false;
                    break;

                case PKKeyType.Point:
                    if (CursorPosition < Text.Length)
                    {
                        StringBuilder sb = new StringBuilder(Text + "");
                        sb[CursorPosition] = ".".ToCharArray()[0];
                        Text = sb.ToString();
                        if (OnTextChange != null)
                        {
                            OnTextChange(Text);
                        }
                    }
                    else
                    {
                        Text += ".";
                        if (OnTextChange != null)
                        {
                            OnTextChange(Text);
                        }
                    }

                    if (CursorPosition >= Text.Length - 1 && CursorPosition < Display.MaxChars)
                    {
                        ChangeDisplayCursorPosition(1);
                    }
                    else
                    {
                        ChangeDisplayCursorPosition(0);
                    }

                    if (!IsNormalPage)     //Back to normal page automaticaly
                    {
                        KeyActionSpecial();
                    }

                    break;
                }
            }

            // If user keep holding the key, we execute the action automatic
            // based in the timeTick
            if (_pressedKey != null)
            {
                if (_pressedKey.Type == PKKeyType.Backspace)
                {
                    if (!IsInvoking("KeyActionBackspace"))
                    {
                        InvokeRepeating("KeyActionBackspace", TimeTickPressed, TimeTickPressed);
                    }
                }
                else if (_pressedKey.Type == PKKeyType.CursorNavigationLeft)
                {
                    if (!IsInvoking("KeyActionCursorNavigationLeft"))
                    {
                        InvokeRepeating("KeyActionCursorNavigationLeft", TimeTickPressed, TimeTickPressed);
                    }
                }
                else if (_pressedKey.Type == PKKeyType.CursorNavigationRight)
                {
                    if (!IsInvoking("KeyActionCursorNavigationRight"))
                    {
                        InvokeRepeating("KeyActionCursorNavigationRight", TimeTickPressed, TimeTickPressed);
                    }
                }
            }
        }