예제 #1
0
        /// <summary>
        /// Allows each screen to run logic.
        /// </summary>
        public override void Update(GameTime gameTime)
        {
            UpdateTouchPanelSize();

            // Read the keyboard and gamepad.
            if (!SuppressInputUpdate)
            {
                _input.Update(gameTime);
            }
            SuppressInputUpdate = false;

            // Make a copy of the master screen list, to avoid confusion if
            // the process of updating one screen adds or removes others.
            _tempScreensList.Clear();

            foreach (GameScreen screen in _screens)
            {
                _tempScreensList.Add(screen);
            }

            bool otherScreenHasFocus  = !Game.IsActive;
            bool coveredByOtherScreen = false;

            // Loop as long as there are screens waiting to be updated.
            while (_tempScreensList.Count > 0)
            {
                // Pop the topmost screen off the waiting list.
                GameScreen screen = _tempScreensList[_tempScreensList.Count - 1];

                _tempScreensList.RemoveAt(_tempScreensList.Count - 1);

                // Update the screen.
                screen.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

                if (screen.ScreenState == ScreenState.TransitionOn ||
                    screen.ScreenState == ScreenState.Active)
                {
                    // If this is the first active screen we came across,
                    // give it a chance to handle input.
                    if (!otherScreenHasFocus)
                    {
                        screen.HandleInput(gameTime, _input);

                        otherScreenHasFocus = true;
                    }

                    // If this is an active non-popup, inform any subsequent
                    // screens that they are covered by it.
                    if (!screen.IsPopup)
                    {
                        coveredByOtherScreen = true;
                    }
                }
            }

            ScrollableGame.End();

            // Print debug trace?
            if (_traceEnabled)
            {
                TraceScreens();
            }
        }
예제 #2
0
        public override void Update(GameTime gameTime)
        {
            if (!Enabled)
            {
                return;
            }

            bool scrollDrag = false;

            if (_scroll != null)
            {
                _scroll.Update(gameTime);
                scrollDrag = _scroll.Draging || _scroll.Hits;
            }

            if (!scrollDrag)
            {
                // Select for Drag
                if (ScrollableGame.CheckLeftPressed(true))
                {
                    if (_rect.Contains(ScrollableGame.MousePoint))
                    {
                        _draging           = true;
                        _draggedDifInicial = _draggedDif = ScrollableGame.MousePos;
                    }
                }

                // Dragging
                if (_draging && ScrollableGame.CheckLeftDown())
                {
                    if (Horizontal)
                    {
                        var pos = ScrollableGame.MousePos.X - _draggedDif.X;
                        _draggedDif = ScrollableGame.MousePos;
                        PosDif     -= (int)pos;

                        if (Math.Abs(ScrollableGame.MousePos.X - _draggedDifInicial.X) > 5)
                        {
                            Button.CancelClick = true;
                        }

                        var widthDif = ContentSize - Width;

                        if (widthDif <= 0 || PosDif < 0)
                        {
                            PosDif = 0;
                        }
                        else if (widthDif > 0 && PosDif > widthDif)
                        {
                            PosDif = widthDif;
                        }

                        if (widthDif > 0)
                        {
                            Percentage = PosDif / widthDif;
                        }
                    }
                    else
                    {
                        var pos = ScrollableGame.MousePos.Y - _draggedDif.Y;
                        _draggedDif = ScrollableGame.MousePos;
                        PosDif     -= (int)pos;

                        if (Math.Abs(ScrollableGame.MousePos.Y - _draggedDifInicial.Y) > 5)
                        {
                            Button.CancelClick = true;
                        }

                        var heightDif = ContentSize - Height;

                        if (heightDif <= 0 || PosDif < 0)
                        {
                            PosDif = 0;
                        }
                        else if (heightDif > 0 && PosDif > heightDif)
                        {
                            PosDif = heightDif;
                        }

                        if (heightDif > 0)
                        {
                            Percentage = PosDif / heightDif;
                        }
                    }
                }

                // Drop
                if (ScrollableGame.CheckLeftReleased()
#if SILVERLIGHT
                    || !_rect.Contains(ScrollableGame.MousePoint)
#endif
                    )
                {
                    _draging = false;
#if SILVERLIGHT
                    Microsoft.Xna.Framework.Input.Mouse.LeftButtonDown = false;
#endif
                }

                ScrollableGame.Begin(this);

                if (_scrollable != null)
                {
                    _scrollable.Update(gameTime);
                }

                ScrollableGame.End(this);
            }

            UpdateContentSize();

            base.Update(gameTime);
        }