Root - LiruJ/GuiCookie GitHub Wiki

Overview

The Root class is a base class for a layout, any UI layout in GuiCookie requires a form of Root.

It can be thought of as a large controller class, it handles the larger elements of the layout and ensures the overarching UI logic functions. For example; a 2D platformer may have elements for the health counter, collectibles counters, timer, and pause menu, these would all be referenced in the root class so that elements can be hidden and shown when the player pauses the game.

Root classes are not specific to a layout sheet, so they may be reused across many layouts, although such a situation is quite rare.

Managers

ElementManager

Holds the root-level elements and handles element creation.

InputManager

Handles all mouse and keyboard input.

DragAndDropManager

Keeps track of any dragged element and handles interaction between draggables and drop targets.

StyleManager

Handles the loading and storage of styles and resources.

TemplateManager

Handles the loading and storage of templates.

Properties

Attributes

IReadOnlyAttributes

Stores the attributes of the main root node.

Bounds

Bounds

The bounds of the game window, including padding.

IsMousedOver

bool

Gets a value that is true when the mouse is over an element; otherwise false.

This is neccessary when discerning between UI interactions and game interactions. For example; if your game takes input by the player clicking on things, you would want to ensure this is false as it would mean they are instead clicking on the UI.

HasSetUp

bool

Is true if the layout file has been loaded and the starting elements set up; otherwise false. This is set to true immediately before PostInitialise().

Initialsation Functions

OnCreated()

protected, virtual, void

This is called immediately after every manager property has been set, but nothing else has been loaded.

PreInitialise()

protected, virtual, void

This is called immediately before the elements are loaded from the XML layout sheet. The sheet itself will still be loaded, so the attributes, templates, styles, and bounds will be set up.

Initialise()

protected, virtual, void

This is called immediately after the elements are loaded from the XML layout sheet.

PostInitialise()

protected, virtual, void

This is the very last initialisation function to be called. All element and component setup functions will have executed by this point.

Element Functions

GetElementFromTag(string)

public, Element

Finds and returns the element with the given tag. Each tag must be unique.

This returns null if no element with the given tag exists.

GetElementFromTag<T>(string)

public, T

Finds and returns the element with the given tag, cast as the given type T.

RemoveElement(Element)

public, void

Removes the given element from the layout.

Update Functions

Update(GameTime)

public, void

Updates the input, then each element.

PreUpdate(GameTime)

protected, virtual, void

Is called immediately before the main update function.

PostUpdate(GameTime)

protected, virtual, void

Is called immediately after the main update function.

Draw Functions

Draw(IGuiCamera)

public, void

Calls the draw function on all root-level elements.

PreDraw(IGuiCamera)

protected, virtual, void

Is called immediately before the main draw function.

PostDraw(IGuiCamera)

protected, virtual, void

Is called immediately after the main draw function.

⚠️ **GitHub.com Fallback** ⚠️