Easily add some scrolling to your GameStateManagement, all you need to do is replace the MenuScreen.cs in the "Screens" folder with this code (I will soon create a walkthrough tutorial on what all is happening and whatnot later, for now i just wanted to share this feature):
MenuScreen.cs
Add these to the top in the fields section
Code:
#region Fields
List<MenuEntry> menuEntries = new List<MenuEntry>();
int selectedEntry = 0;
int varY = 0;
int varY2 = 40;
int lineheight = 0;
int topnumber = 0;
int bottomnumber = 0;
string menuTitle;
#endregion
Replace the handle input part with this, to show what to do once a user presses something.
Code:
#region Handle Input
/// <summary>
/// Responds to user input, changing the selected entry and accepting
/// or cancelling the menu.
/// </summary>
public override void HandleInput(InputState input)
{
// Move to the previous menu entry?
if (input.MenuUp)
{
selectedEntry--;
if (selectedEntry < 0)
{
selectedEntry = menuEntries.Count - 1;
varY2 -= (lineheight * (selectedEntry - 8));
}
if (selectedEntry > 8)
varY2 += lineheight;
}
// Move to the next menu entry?
if (input.MenuDown)
{
selectedEntry++;
if (selectedEntry >= menuEntries.Count)
selectedEntry = 0;
if (selectedEntry > 8)
varY2 -= lineheight;
}
// Accept or cancel the menu?
if (input.MenuSelect)
{
OnSelectEntry(selectedEntry);
}
if (selectedEntry < 10)
{
varY2 = 40;
bottomnumber = 13;
}
topnumber = selectedEntry - 10;
if (selectedEntry > 8)
bottomnumber = selectedEntry + 4;
}
replace the draw part with this:
Code:
/// <summary>
/// Draws the menu.
/// </summary>
public override void Draw(GameTime gameTime)
{
SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
SpriteFont font = ScreenManager.Font;
Vector2 position = new Vector2(10, varY2);
// 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);
if (ScreenState == ScreenState.TransitionOn)
position.X -= transitionOffset * 256;
else
position.X += transitionOffset * 512;
spriteBatch.Begin();
// Draw each menu entry in turn.
for (int i = 0; i < menuEntries.Count; i++)
{
MenuEntry menuEntry = menuEntries[i];
bool isSelected = IsActive && (i == selectedEntry);
varY = (i * (menuEntry.GetHeight(this)));
lineheight = (menuEntry.GetHeight(this));
if (i > topnumber && i < bottomnumber)
menuEntry.Draw(this, position, isSelected, gameTime, selectedEntry);
position.Y += (menuEntry.GetHeight(this));
}
// Draw the menu title.
Vector2 titlePosition = new Vector2(10, 10);
Vector2 titleOrigin = font.MeasureString(menuTitle) / 2;
Color titleColor = new Color(192, 192, 192, TransitionAlpha);
float titleScale = 1.25f;
titlePosition.Y -= transitionOffset * 100;
spriteBatch.DrawString(font, menuTitle, titlePosition, titleColor, 0,
Vector2.Zero, titleScale, SpriteEffects.None, 0);
spriteBatch.End();
}
#endregion
}
Now your done with MenuScreen.cs file
Edit the MenuEntry.cs
change the Draw Code to this.
Code:
/// <summary>
/// Draws the menu entry. This can be overridden to customize the appearance.
/// </summary>
public virtual void Draw(MenuScreen screen, Vector2 position,
bool isSelected, Color hovercolor, Color menucolor, Color barcolor, GameTime gameTime, int select, Texture2D hoverbartext, int menunumber, bool userSettings, bool randomcolors)
{
Color color = isSelected ? Yellow : White;
// Pulsate the size of the selected menu entry.
double time = gameTime.TotalGameTime.TotalSeconds;
float pulsate = (float)Math.Sin(time * 6) + 1;
int recty = ((int)(position.Y));
int rectymainmenu = ((int)(position.Y) + 10);
Rectangle position2 = new Rectangle(0, recty+2, 240, 18);
Rectangle position2mainmenu = new Rectangle(0, rectymainmenu, 240, 35);
Rectangle position2loader = new Rectangle(0, rectymainmenu-10, 240, 40);
float scale = 1 + pulsate * 0.05f * selectionFade;
// Modify the alpha to fade text out during transitions.
color = new Color(color.R, color.G, color.B, screen.TransitionAlpha);
// Draw text, centered on the middle of each line.
ScreenManager screenManager = screen.ScreenManager;
SpriteBatch spriteBatch = screenManager.SpriteBatch;
SpriteFont font = screenManager.Segoe12;
Vector2 origin = new Vector2(0, (font.LineSpacing / 2) + select);
spriteBatch.DrawString(font, text, position, color);
}
i have changed it to a small tutorial on what all to change and whatnot, somebody please try this and tell me if anything goes wrong, i mostly worked off of my ZuneTools coding.