Esempio n. 1
0
        /// <summary>
        /// Allows the screen the chance to position the menu entries. By default
        /// all menu entries are lined up in a vertical list, centered on the screen.
        /// </summary>
        protected virtual void UpdateMenuEntryLocations()
        {
            // Make the menu slide into place during transitions, using a
            // power curve to make things look more interesting (this makes
            // the movement slow down as it nears the end).
            float transitionOffset = (float)Math.Pow(TransitionPosition, 2);

            // start at Y = 175; each X value is generated per entry
            Vector2 position = new Vector2(0f, 175f);

            // update each menu entry's location in turn
            for (int i = 0; i < menuEntries.Count; i++)
            {
                MenuEntry menuEntry = menuEntries[i];

                // each entry is to be centered horizontally
                position.X = ScreenManager.GraphicsDevice.Viewport.Width / 2 - menuEntry.GetWidth(this) / 2;

                if (ScreenState == ScreenState.TransitionOn)
                {
                    position.X -= transitionOffset * 256;
                }
                else
                {
                    position.X += transitionOffset * 512;
                }

                // set the entry's position
                menuEntry.Position = position;

                // move down for the next entry the size of this entry
                position.Y += menuEntry.GetHeight(this);
            }
        }
 protected override Rectangle GetMenuEntryHitBounds(MenuEntry entry)
 {
     return(new Rectangle((int)entry.Position.X, (int)entry.Position.Y,
                          entry.GetWidth(this), entry.GetHeight(this)));
 }
Esempio n. 3
0
        /// <summary>
        /// Allows the screen the chance to position the menu entries. By default
        /// all menu entries are lined up in a vertical list, centered on the screen.
        /// </summary>
        protected virtual void UpdateMenuEntryLocations()
        {
            // Make the menu slide into place during transitions, using a
            // power curve to make things look more interesting (this makes
            // the movement slow down as it nears the end).
            var transitionOffset = (float)Math.Pow(TransitionPosition, 2);

#if IPHONE
            float xDif = 1;
            if (ScreenManager.FixScaleIPhone)
            {
                xDif = (float)UIKit.UIScreen.MainScreen.Scale;
            }
#else
            const float xDif = 1;
#endif

            // start at Y = 175; each X value is generated per entry
            var position = new Vector2(0f, 87f * xDif);

            // update each menu entry's location in turn
            foreach (var menuEntry in menuEntries)
            {
                if (menuEntry.StartPosition.X == 0 && menuEntry.StartPosition.Y == 0)
                {
                    // each entry is to be centered horizontally
                    if (Portrait)
                    {
                        position.X = ScreenManager.Graphics.PreferredBackBufferHeight / 2 - menuEntry.GetWidth(this) / 2;
                    }
                    else
                    {
                        position.X = ScreenManager.Graphics.PreferredBackBufferWidth / 2 - menuEntry.GetWidth(this) / 2;
                    }

                    if (ScreenState == ScreenState.TransitionOn)
                    {
                        position.X -= xDif * transitionOffset * 256;
                    }
                    else
                    {
                        position.X += xDif * transitionOffset * 512;
                    }

                    // set the entry's position
                    menuEntry.Position = position;

#if IPHONE
                    int scale = 1;
                    if (ScreenManager.FixScaleIPhone)
                    {
                        scale = (int)UIKit.UIScreen.MainScreen.Scale;
                    }
#else
                    const int scale = 1;
#endif
                    // move down for the next entry the size of this entry plus our padding
                    position.Y += menuEntry.GetHeight(this) + (MenuEntryPadding * 2 * scale);
                }
                else
                {
                    Vector2 pos = menuEntry.StartPosition;

                    if (ScreenState == ScreenState.TransitionOn)
                    {
                        pos.X -= xDif * transitionOffset * 256;
                    }
                    else
                    {
                        pos.X += xDif * transitionOffset * 512;
                    }

                    menuEntry.Position = pos;
                }
            }

            if (ShowBackMenuEntry)
            {
                if (backMenuEntry.StartPosition.X == 0)
                {
                    // each entry is to be centered horizontally
                    if (Portrait)
                    {
                        position.X = ScreenManager.Graphics.PreferredBackBufferHeight / 2 - backMenuEntry.GetWidth(this) / 2;
                    }
                    else
                    {
                        position.X = ScreenManager.Graphics.PreferredBackBufferWidth / 2 - backMenuEntry.GetWidth(this) / 2;
                    }

                    if (ScreenState == ScreenState.TransitionOn)
                    {
                        position.X -= xDif * transitionOffset * 256;
                    }
                    else
                    {
                        position.X += xDif * transitionOffset * 512;
                    }

                    // set the entry's position
                    backMenuEntry.Position = position;
                }
                else
                {
                    Vector2 pos = backMenuEntry.StartPosition;

                    if (ScreenState == ScreenState.TransitionOn)
                    {
                        pos.X -= xDif * transitionOffset * 256;
                    }
                    else
                    {
                        pos.X += xDif * transitionOffset * 512;
                    }

                    // set the entry's position
                    backMenuEntry.Position = pos;
                }
            }
        }