コード例 #1
0
        public override void Draw(MenuScreenBase screen, Vector2 position, bool isSelected, GameTime gameTime)
        {
            // Draw the selected entry in yellow, otherwise white.
            Color color = isSelected ? Color.Yellow : Color.White;

            // Pulsate the size of the selected menu entry.
            double time = gameTime.TotalGameTime.TotalSeconds;

            float pulsate = (float)Math.Sin(time * 6) + 1;

            float scale = 1 + pulsate * 0.05f * selectionFade;

            // Modify the alpha to fade text out during transitions.
            color = screen.TransitionColor(color);

            var spriteBatch = screen.ScreenManager.SpriteBatch;
            var font = screen.ScreenManager.SharedSmallFont;

            Vector2 origin = new Vector2(0, font.LineSpacing / 2);

            string text = typedText;
            if (isPassword)
                text = "".PadRight(text.Length, '*');

            if (isSelected) text += "_";

            spriteBatch.DrawString(font, text, position + new Vector2(300, 0), color, 0.0f, origin, scale, SpriteEffects.None, 0);

            base.Draw(screen, position, isSelected, gameTime);
        }
コード例 #2
0
ファイル: MenuEntry.cs プロジェクト: johankson/io2gamelib
        public virtual void Draw(MenuScreenBase screen, Vector2 position, bool isSelected, GameTime gameTime)
        {
            // Draw the selected entry in yellow, otherwise white.
            Color color = isSelected ? Color.Yellow : Color.White;

            // Pulsate the size of the selected menu entry.
            double time = gameTime.TotalGameTime.TotalSeconds;

            float pulsate = (float)Math.Sin(time * 6) + 1;

            float scale = 1 + pulsate * 0.05f * selectionFade;

            // Modify the alpha to fade text out during transitions.
            color = screen.TransitionColor(color);

            var spriteBatch = screen.ScreenManager.SpriteBatch;
            var font = screen.ScreenManager.SharedHeaderFont;

            Vector2 origin = new Vector2(0, font.LineSpacing / 2);

            spriteBatch.DrawString(font, _text, position, color, 0.0f, origin, scale, SpriteEffects.None, 0);
        }
コード例 #3
0
ファイル: MenuEntry.cs プロジェクト: johankson/io2gamelib
        /// <summary>
        /// Updates the menu entry.
        /// </summary>
        public virtual void Update(MenuScreenBase screen, bool isSelected,
                                                      GameTime gameTime)
        {
            // When the menu selection changes, entries gradually fade between
            // their selected and deselected appearance, rather than instantly
            // popping to the new state.
            float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4;

            if (isSelected)
                selectionFade = Math.Min(selectionFade + fadeSpeed, 1);
            else
                selectionFade = Math.Max(selectionFade - fadeSpeed, 0);
        }
コード例 #4
0
        public override void Update(MenuScreenBase screen, bool isSelected, Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(screen, isSelected, gameTime);

            var input = screen.ScreenManager.InputManager;

            if(isSelected && !selectedLastTime)
            {
                // Setup the input mnager to read text from keyboard
                input.TextInputBuffer = typedText;
                input.StartReadingKeysToTextBuffer();

            }

            if(!isSelected && selectedLastTime)
            {
                // Tear down input manager reading from keyboard if
                // the new selected entry isn't a TextInputMenuEntry
                if(!(screen.SelectedEntry is TextInputMenuEntry))
                    input.StopReadingKeysToTextBuffer();
            }

            if (isSelected)
            {
                // Read the buffer to local variable
                typedText = input.TextInputBuffer;
            }

            // Remember the last state for setup and tear down of the input system
            selectedLastTime = isSelected;
        }