SilverMenu is the Menu per se. A menu is composed by several Pages which in turn are composed by GUI elements such as SilverBackground, SilverText, SilverButton.

SilverMenuManager is the entity that handles the drawing and the updates of the SilverMenu.

SilverMenuContentManager is responsible for loading the SilverMenu resource file along with the images/fonts that are needed for each of the GUI elements.

 

 

Using the SilverMenuPipeline provided is easy to add a menu

  1. Add the SilverMenuPipeline reference to your project.
  2. Create a XML of the SilverMenu in your content project.
  3. Change the content processor of the XML file to SilverMenu Processor.
  4. Change the content importer of the XML file to XNA SilverMenu importer.

And that’s it, you’re ready to use the SilverMenu in your application.

 

To setup your menu in code you’ll have to:

  1. Create an instance of a SilverMenuContentManager.
  2. Create an instance of a SilverMenuManager and assign a SilverMenuContentManager.
  3. Load the menu resource file.
using SilverMenu;

public Game1()
{
	// other code here

	Content.RootDirectory = "Content";
	Content = new SilverMenuContentManager(Content.ServiceProvider, Content.RootDirectory);
}

private SilverMenuManager m_manager;

protected override void LoadContent()
{
	// other code here

	m_manager = new SilverMenuManager(Content as SilverMenuContentManager);
	m_manager.LoadMenu("Sample");
}

 

 

To see it in action you’ll have to:

  1. Call the SilverMenuManager’s DoTransition method when you want to change to a new page.
  2. Call the SilverMenuManager’s Update method to update each gui elements involved in a transition.
  3. Call the SilverMenuManager’s Draw method to draw the gui elements.

 

protected override void LoadContent()
{
	//other code here

	m_manager.DoTransition("home");
}

protected override void Update(GameTime gameTime)
{
	float delta = (float) gameTime.ElapsedGameTime.TotalSeconds;

	m_manager.Update(delta);
	base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
	GraphicsDevice.Clear(Color.CornflowerBlue);
	spriteBatch.Begin();
	m_manager.Draw(spriteBatch);
	spriteBatch.End();
	base.Draw(gameTime);
}

 

 

A menu is created using XML. Here's a sample of a menu with two pages:

 

<?xml version="1.0" encoding="utf-8" ?>
<SilverMenu>
<Version>0.1</Version>
<Page id="home">
<TransitionTime>1.0</TransitionTime>
<Elements>
<Background id="bg0">
<Source>bg01</Source>
<Rect>0 0 800 480</Rect>
</Background>
<Background id="bg1">
<Source>bg02</Source>
<Rect>800 0 800 480</Rect>
</Background>
<Button id="btn0">
<Source>button</Source>
<Text>Some text</Text>
<Rect>0 0 100 100</Rect>
</Button>
<Text id="silvermenu">
<Font>segoe</Font>
<Text>Silver Menu</Text>
<Position>100 100</Position>
</Text>
</Elements>
</Page>
<Page id="play">
<TransitionTime>1.0</TransitionTime>
<Elements>
<Background id="bg0">
<Source>bg01</Source>
<Rect>-500 0 800 480</Rect>
</Background>
<Background id="bg1">
<Source>bg02</Source>
<Rect>300 0 800 480</Rect>
</Background>
<Text id="silvermenu">
<Font>segoe</Font>
<Text>Silver Menu</Text>
<Position>-400 100</Position>
</Text>
</Elements>
</Page>
</SilverMenu>

Last edited Jan 10, 2011 at 9:00 PM by RikSabino, version 3

Comments

No comments yet.