UIManager - LiruJ/GuiCookie GitHub Wiki
The UIManager allows layouts to be created easily by storing its dependencies and handling the creation of any extra dependencies needed by a Root.
Only one instance of this class is needed, and it is usually best to create it in the LoadContent function of the main game class, then immediately call RegisterElementNamespace and RegisterComponentNamespace if needed. It can then be passed to any game state that needs its own UI. For example;
protected override void LoadContent()
{
// Create the UI Manager.
uiManager = new UIManager(this);
// Register the controllers and components.
uiManager.RegisterElementNamespace(Assembly.GetExecutingAssembly(), "Example.Elements");
uiManager.RegisterComponentNamespace(Assembly.GetExecutingAssembly(), "Example.Components");
// Create the UI camera.
camera = uiManager.CreateGuiCamera();
// Load the root.
mainMenu = uiManager.CreateUIRoot<MainMenu>("Gui\\MainMenu");
}public, void
Finds all classes extending Element controllers in the given namespace and assembly, and adds them to a cache so that they may be used in layouts and templates.
The string argument should be the full namespace path using the . character as a separator; for example "Example.Elements".
public, void
Does much the same as the previous function, but instead looks for classes extending Component.
public, T
Creates a new Root of the given type T, injecting the given objects into its constructor, and loading a layout sheet from the given path.
This function first creates a new GameServiceContainer and adds every given parameter to it. Then the GraphicsDevice, ContentManager, and GameWindow are added in that order. The Root is then created and any parameters in its constructor are found within the collection.
Once the root exists, the managers are created and added to the GameServiceContainer in this order:
- InputManager
- DragAndDropManager
- TemplateManager
- ResourceManager
- StyleManager
- ComponentManager
- ElementManager
The XML layout sheet itself is then loaded and the Root is initialised and returned.
public, GuiCamera
Creates a new GuiCamera with a new SpriteBatch. This is useful when creating a new layout, as it handles dependencies automatically and returns a functional camera that will immediately work.