What I did to make it easier for myself is to make a class called "Screen", and just make a List<Screen>
that holds all the different screens, so now, all I have to do to switch screen is set "Visible" to false or true on the screens I want to show or hide.
Here is part of how that class looks
public class Screen
{
public int ID;
public string Name;
public List<Form> Forms = new List<Form>();
public List<Label> Labels = new List<Label>();
public List<Button> Buttons = new List<Button>();
public List<Textbox> Textboxes = new List<Textbox>();
public List<EViewport> Viewports = new List<EViewport>();
public bool Visible;
// and a bunch of functions to add forms, buttons, do events, etc
// when adding a control, it's important that it is set to the right viewport
public Button AddButton(int _ID, string _Name, Texture2D _Sprite, int _Width, int _Height, Vector2 _Position, EViewport _Viewport, string _Text = "", bool _Visible = false)
{
Buttons.Add(new Button(_ID, _Name, _Sprite, _Width, _Height, new Vector2(_Position.X, _Position.Y), _Text, _Visible));
Button getButton = Buttons[Buttons.Count - 1];
getButton.ParentScreen = this;
getButton.ParentViewport = _Viewport;
return getButton;
}
public void Draw(SpriteBatch _spriteBatch, SpriteFont font, GameTime gameTime, Textbox focusedTextbox)
{
if (Visible)
{
// Draw only if screen is visible (this is not the full Draw function btw)
for(int j = 0; j < Viewports.Count; j++)
{
for(int i = 0; i < Buttons.Count; i++)
{
if(Buttons[i].ParentViewport.ID == Viewports[j].ID) // then draw
}
}
}
}
}
So basically all I do is add buttons, forms and viewports (because on my main menu I only need one viewport, but in-game I need 3 different viewports (one for game screen, one for UI and one for the chat) and then change their visibility like this:
storage.GetScreenByName("GameScreen").Visible = true;
(storage is just a singleton class that holds the sprite objects and screens in my game)
Oh, by the way, here's my EViewport class:
public class EViewport
{
/* Extended Viewport */
public Viewport _Viewport;
public Screen ParentScreen = new Screen();
public int ID;
public string Name;
public bool AllowResize;
public int MaxWidth;
public int MaxHeight;
public int MinHeight;
public float AspectRatio { get { return (float)MaxWidth / (float)MaxHeight; } }
public EViewport()
{
ID = -1;
}
public EViewport(int _ID, string _Name, int x, int y, int width, int height, bool _AllowResize = false, int _MinHeight = 0)
{
ID = _ID;
Name = _Name;
_Viewport = new Viewport(x, y, width, height);
AllowResize = _AllowResize;
MinHeight = _MinHeight;
MaxWidth = width;
MaxHeight = height;
}
public bool HasParentScreen()
{
return (ParentScreen.ID != -1);
}
}
I hope this helps, feel free to ask questions regarding how to implement such a system.