Пример #1
0
        public override void OnDeselected(MenuElement nextElement)
        {
            base.OnDeselected(nextElement);

            TextInputEXT.StopTextInput();
            TextInputEXT.TextInput -= OnTextInput;
            Page.Parent.Parent.Game.OnStateChange -= OnStateChange;
        }
Пример #2
0
        public void SetTextInputState(bool enabled)
        {
            if (!enabled)
            {
                TextInputEXT.StopTextInput();
                return;
            }

            if (!IsTextInputRegistered)
            {
                IsTextInputRegistered     = true;
                TextInputEXT.TextInput   += TextInputEXT_TextInput;
                TextInputEXT.TextEditing += TextInputEXT_TextEditing;
            }
            TextInputEXT.StartTextInput();
        }
Пример #3
0
 private void OnStateChange(object sender, Game.ChangeStateEventArgs e)
 {
     TextInputEXT.TextInput -= OnTextInput;
     TextInputEXT.StopTextInput();
     ((Game)sender).OnStateChange -= OnStateChange;
 }
Пример #4
0
        public void Update(Game game)
        {
            if (!Disabled && ((Rectangle.Value.Contains(game.Input.MousePosition) && !Rectangle.Value.Contains(game.Input.PreviousMousePosition)) || (Game.Input.KeyPressed(Keys.S) && !_isSearching)))
            {
                Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, Math.Min((int)TotalArea.Y, MaxHeight)), TweenEaseType.EaseOutQuad, 0.1f);
                _screenFade.TweenTo(1, TweenEaseType.EaseOutQuad, 0.1f);

                if (Game.Input.KeyPressed(Keys.S))
                {
                    _isSearching = true;
                    _quitQueued  = true;

                    TextInputEXT.TextInput += OnSearchInput;
                    TextInputEXT.StartTextInput();
                    game.OnStateChange += RemoveSearchInput;
                }
            }
            else if (_quitQueued || (!Rectangle.Value.Contains(game.Input.MousePosition) && Rectangle.Value.Contains(game.Input.PreviousMousePosition)))
            {
                if (_isScrolling || _isSearching)
                {
                    _quitQueued = true;
                }
                else
                {
                    if (!Rectangle.Value.Contains(game.Input.MousePosition))
                    {
                        Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, 28), TweenEaseType.EaseOutQuad, 0.1f);
                        _screenFade.TweenTo(0, TweenEaseType.EaseOutQuad, 0.1f);
                    }

                    _quitQueued = false;
                }
            }

            if (_isSearching && game.Input.KeyPressed(Keys.Tab))
            {
                string s = _searchTerm.ToLowerInvariant().Trim().Replace(" ", "");

                foreach (Category category in Categories)
                {
                    Tile searched = Search(s, category);

                    if (searched != null)
                    {
                        _searchTerm = searched.Name(null, _environment);
                        break;
                    }
                }
            }

            if (_isSearching && game.Input.KeyPressed(Keys.Enter))
            {
                _searchTerm = _searchTerm.ToLowerInvariant().Trim().Replace(" ", "");

                foreach (Category category in Categories)
                {
                    Tile searched = Search(_searchTerm, category);
                    if (searched != null)
                    {
                        SelectedTile = searched;
                        if (SelectionChanged != null)
                        {
                            SelectionChanged(this, SelectedTile);
                        }
                    }
                }

                _isSearching = false;
                _searchTerm  = "";

                TextInputEXT.TextInput -= OnSearchInput;
                TextInputEXT.StopTextInput();
                game.OnStateChange -= RemoveSearchInput;
            }
            else if (_isSearching && game.Input.KeyPressed(Keys.Escape))
            {
                _isSearching            = false;
                _searchTerm             = "";
                TextInputEXT.TextInput -= OnSearchInput;
                TextInputEXT.StopTextInput();
                game.OnStateChange -= RemoveSearchInput;
            }

            if (IsHovered && CanInteractWith)
            {
                float changed = _scrollTarget;

                if (game.Input.KeyPressed(Keys.Home))
                {
                    _scrollTarget = 0;
                }

                if (game.Input.KeyPressed(Keys.PageUp))
                {
                    _scrollTarget = Scroll - 180;
                }
                if (game.Input.KeyPressed(Keys.PageDown))
                {
                    _scrollTarget = Scroll + 180;
                }

                if (game.Input.KeyPressed(Keys.End))
                {
                    _scrollTarget = ScrollableAmount;
                }

                if (changed != _scrollTarget)
                {
                    if (_scrollTarget < 0)
                    {
                        _scrollTarget = 0;
                    }
                    if (_scrollTarget > ScrollableAmount)
                    {
                        _scrollTarget = ScrollableAmount;
                    }
                }
            }

            if (CanInteractWith)
            {
                if (_scrollTarget != -1)
                {
                    Scroll = MathHelper.Lerp(Scroll, _scrollTarget, (float)Game.DeltaTime * 14f);
                    if (Math.Abs(Scroll - _scrollTarget) <= 0.75f)
                    {
                        _scrollTarget = -1;
                    }
                }
                else if (Rectangle.Value.Contains(game.Input.MousePosition))
                {
                    if ((game.Input.MouseScroll < 0 && Scroll < ScrollableAmount) ||
                        (game.Input.MouseScroll > 0 && Scroll > 0))
                    {
                        Scroll -= game.Input.MouseScroll / 4f;
                    }

                    if (game.Input.Key(Keys.Up) && Scroll > 0)
                    {
                        Scroll = Math.Max(0, Scroll - ((float)game.DeltaTime * 140f));
                    }
                    if (game.Input.Key(Keys.Down) && Scroll < ScrollableAmount)
                    {
                        Scroll = Math.Min(ScrollableAmount, Scroll + ((float)game.DeltaTime * 140f));
                    }
                }

                if (_isScrolling)
                {
                    float at         = game.Input.MousePosition.Y - (Rectangle.Value.Top + 8);
                    float percentage = at / (Rectangle.Value.Height - 16);
                    Scroll = percentage * ScrollableAmount;

                    if (game.Input.MouseReleased(Engine.MouseButton.Left))
                    {
                        _isScrolling = false;
                    }
                }

                Scroll = MathHelper.Clamp(Scroll, 0, ScrollableAmount);
            }
        }
Пример #5
0
 private void RemoveSearchInput(object sender, Game.ChangeStateEventArgs e)
 {
     TextInputEXT.TextInput -= OnSearchInput;
     TextInputEXT.StopTextInput();
     Game.OnStateChange -= RemoveSearchInput;
 }
Пример #6
0
 public override void OnLeave(GameState nextState)
 {
     TextInputEXT.TextInput -= OnTextInput;
     TextInputEXT.StopTextInput();
 }
Пример #7
0
 private void OnStateChange(object sender, Engine.Game.ChangeStateEventArgs e)
 {
     TextInputEXT.StopTextInput();
     TextInputEXT.TextInput -= OnTextInput;
 }