Example #1
0
        public void HandleInputChinese()
        {
            //处理从IME得到的字符
            List <Character> getChars = Platform.Current.GetChars();   // WindowInputCapturer.myCharacters;

            foreach (var getChar in getChars)
            {
                if (getChar.IsUsed == false)
                {
                    if (getChar.CharaterType == characterType.Char)
                    {
                        //sfx.AddText(getChar.Chars.ToString());
                        if (CanAdd)
                        {
                            Text += getChar.Chars.ToString();
                        }
                        Platform.Current.PlayEffect(@"Content\Sound\Move");
                    }
                    //回车等功能键触发事件也可以由KeyboardState来截取处理
                    else if (getChar.CharaterType == characterType.Enter)
                    {
                        //Text += "\r";
                        if (OnKeyEnterPress != null)
                        {
                            OnKeyEnterPress.Invoke(null, null);
                        }
                        Platform.Current.ClearChars(); //WindowInputCapturer.myCharacters.Clear();
                        break;
                    }
                    else if (getChar.CharaterType == characterType.Tab)
                    {
                        //Text += "    ";
                        if (OnKeyTabPress != null)
                        {
                            OnKeyTabPress.Invoke(null, null);
                        }
                        Platform.Current.ClearChars(); //WindowInputCapturer.myCharacters.Clear();
                        break;
                    }
                    else if (getChar.CharaterType == characterType.BackSpace)
                    {
                        Text = WordTools.BackSpaceString(Text);
                    }
                    getChar.IsUsed = true;
                }
            }
            if (getChars != null && getChars.Count > 0)
            {
            }
        }
Example #2
0
        public void HandleInput(float gameTime)
        {
            if (!Enable)
            {
                return;
            }
            EventFired = false;
            btTexture.Update(InputManager.PoX, InputManager.PoY, null);
            if (btTexture.MouseOver && InputManager.IsPressed)
            {
                if (OnButtonPress != null)
                {
                    PressButton();
                }
                if (Platform.PlatFormType == PlatFormType.Win)
                {
                    if (!Selected)
                    {
                        if (TextBoxMode == GamePanels.TextBoxMode.Chinese)
                        {
                            Platform.Current.ClearChars();                     //WindowInputCapturer.myCharacters.Clear();
                            Platform.Current.WindowInputCapturerEnable = true; //WindowInputCapturer.Enable = true;
                        }
                        else
                        {
                            Platform.Current.WindowInputCapturerEnable = false; // WindowInputCapturer.Enable = false;
                        }
                    }
                }

                if (Platform.PlatFormType == PlatFormType.iOS || Platform.PlatFormType == PlatFormType.Android || Platform.PlatFormType == PlatFormType.UWP)
                {
                    if (!Platform.Current.IsGuideVisible)
                    {
                        Platform.Current.ShowKeyBoard(PlayerIndex.One, Title, Desc, this.Text, CallbackFunction);
                        //try
                        //{
                        //Guide.BeginShowKeyboardInput(PlayerIndex.One, Title, Desc, this.Text, CallbackFunction, null);
                        //}
                        //catch(Exception ex)
                        //{
                        //}
                    }
                }
                //else if (Season.PlatForm == PlatForm.WinRT)
                //{
                //    //if (!Season.KeyBoardAvailable)
                //    //{
                //        Season.Current.ShowText(Text, CallbackFunction);
                //    //}
                //}
                bool preSelected = Selected;
                Selected = true;
                if (!preSelected && OnTextBoxSelected != null)
                {
                    OnTextBoxSelected.Invoke(null, null);
                }
            }

            btTexture.Selected = Selected;
            if (Selected)
            {
                if (Platform.PlatFormType == PlatFormType.Win || Platform.PlatFormType == PlatFormType.UWP || Platform.PlatFormType == PlatFormType.Desktop)                                                                         // || Season.PlatForm == PlatForm.MacOS || Season.PlatForm == PlatForm.Linux
                {
                    if (InputManager.HasKeys && (TextBoxMode != GamePanels.TextBoxMode.Chinese || Platform.PlatFormType == PlatFormType.Desktop || Platform.PlatFormType == PlatFormType.UWP && Platform.Current.KeyBoardAvailable)) //Season.PlatForm == PlatForm.WinRT ||
                    {
                        if (InputManager.KeyBoardState == InputManager.KeyBoardStatePre)
                        {
                            afterLastInputTime += gameTime;
                            if (afterLastInputTime < 0.1f)
                            {
                                return;
                            }
                            afterLastInputTime = 0f;
                        }
                        else
                        {
                        }
                        bool shift = false;
                        if (InputManager.KeyBoardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) ||
                            InputManager.KeyBoardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.RightShift))
                        {
                            shift = true;
                        }
                        if (InputManager.KeyBoardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Tab))
                        {
                            if (OnKeyTabPress != null)
                            {
                                OnKeyTabPress.Invoke(null, null);
                                EventFired = true;
                            }
                        }
                        else if (InputManager.KeyBoardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                        {
                            if (OnKeyEnterPress != null)
                            {
                                OnKeyEnterPress.Invoke(null, null);
                                EventFired = true;
                            }
                        }
                        else if (InputManager.KeyBoardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Back) && !String.IsNullOrEmpty(Text))
                        {
                            afterLastTextTime += gameTime;
                            if (afterLastTextTime < 0.04f)
                            {
                                return;
                            }
                            afterLastTextTime = 0f;
                            Text = Text.Remove(Text.Length - 1, 1);
                        }
                        else if (InputManager.KeyBoardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
                        {
                            afterLastTextTime += gameTime;
                            if (afterLastTextTime < 0.04f)
                            {
                                return;
                            }
                            afterLastTextTime = 0f;
                            Text = Text.Insert(Text.Length, " ");
                        }
                        else
                        {
                            string tex = InputManager.ConvertKeyToChar(shift);
                            if (!String.IsNullOrEmpty(tex))
                            {
                                afterLastTextTime += gameTime;
                                if (afterLastTextTime < 0.1f && !String.IsNullOrEmpty(Text) && Text.ToCharArray()[Text.Length - 1].ToString() == tex)
                                {
                                    return;
                                }
                                //if (!String.IsNullOrEmpty (Text) && Text.ToCharArray ()[Text.Length-1].ToString() == tex) {
                                //	return;
                                //}
                                afterLastTextTime = 0f;
                                Text += tex;
                                Platform.Current.PlayEffect(@"Content\Sound\Move");
                            }
                        }
                        ViewText = Text;
                    }
                }
            }
        }