Class UiControls
UiControls holds and manages all of the controls for a UiSystem. UiControls supports keyboard, mouse, gamepad and touch input using an underlying InputHandler.
public class UiControls
- Inheritance
-
UiControls
- Inherited Members
Constructors
UiControls(UiSystem, InputHandler)
Creates a new instance of the ui controls. You should rarely have to invoke this manually, since the UiSystem handles it.
public UiControls(UiSystem system, InputHandler inputHandler = null)
Parameters
system
UiSystemThe ui system to control with these controls
inputHandler
InputHandlerThe input handler to use for controlling, or null to create a new one.
Fields
DownButtons
A Keybind that acts as the buttons that select a Element that is below the currently selected element.
public readonly Keybind DownButtons
Field Value
GamepadButtons
public readonly Keybind GamepadButtons
Field Value
GamepadIndex
The zero-based index of the Microsoft.Xna.Framework.Input.GamePad used for gamepad input. If this index is lower than 0, every connected gamepad will trigger input.
public int GamepadIndex
Field Value
HandleGamepad
Set this to false to disable gamepad input for these ui controls. Note that this does not disable gamepad input for the underlying InputHandler.
public bool HandleGamepad
Field Value
HandleKeyboard
Set this to false to disable keyboard input for these ui controls. Note that this does not disable keyboard input for the underlying InputHandler.
public bool HandleKeyboard
Field Value
HandleMouse
Set this to false to disable mouse input for these ui controls. Note that this does not disable mouse input for the underlying InputHandler.
public bool HandleMouse
Field Value
HandleTouch
Set this to false to disable touch input for these ui controls. Note that this does not disable touch input for the underlying InputHandler.
public bool HandleTouch
Field Value
Input
The input handler that is used for querying input
public readonly InputHandler Input
Field Value
IsInputOurs
This value ist true if the InputHandler was created by this ui controls instance, or if it was passed in. If the input handler was created by this instance, its Update() method should be called by us.
protected readonly bool IsInputOurs
Field Value
Keybinds
All Keybind instances used by these ui controls. This can be used to easily serialize and deserialize all ui keybinds.
public readonly Keybind[] Keybinds
Field Value
- Keybind[]
KeyboardButtons
A list of Microsoft.Xna.Framework.Input.Keys, Microsoft.Xna.Framework.Input.Buttons and/or MouseButton that act as the buttons on the keyboard which perform the OnPressed action. If the Shift is held, these buttons perform OnSecondaryPressed.
public readonly Keybind KeyboardButtons
Field Value
LeftButtons
A Keybind that acts as the buttons that select a Element that is to the left of the currently selected element.
public readonly Keybind LeftButtons
Field Value
RightButtons
A Keybind that acts as the buttons that select a Element that is to the right of the currently selected element.
public readonly Keybind RightButtons
Field Value
SecondaryGamepadButtons
A Keybind that acts as the buttons on a gamepad that perform the OnSecondaryPressed action.
public readonly Keybind SecondaryGamepadButtons
Field Value
System
The UiSystem that this ui controls instance is controlling
protected readonly UiSystem System
Field Value
UpButtons
A Keybind that acts as the buttons that select a Element that is above the currently selected element.
public readonly Keybind UpButtons
Field Value
Properties
ActiveRoot
The RootElement that is currently active. The active root element is the one with the highest Priority that CanBeActive.
public RootElement ActiveRoot { get; protected set; }
Property Value
IsAutoNavMode
If this value is true, the ui controls are in automatic navigation mode. The state of automatic navigation is usually based on the current NavType. This means that the SelectionIndicator will be drawn around the SelectedElement.
public bool IsAutoNavMode { get; set; }
Property Value
MousedElement
The Element that the mouse is currently over.
public Element MousedElement { get; protected set; }
Property Value
NavType
The current UiControls.NavigationType of these ui controls, which represents the last type of interaction that was used to interact with the underlying UiSystem.
public UiControls.NavigationType NavType { get; set; }
Property Value
SelectedElement
The element that is currently selected. This is the SelectedElement of the ActiveRoot.
public Element SelectedElement { get; }
Property Value
TouchedElement
The Element that is currently touched.
public Element TouchedElement { get; protected set; }
Property Value
Methods
GetElementUnderPos(Vector2)
Returns the Element in the underlying UiSystem that is currently below the given position. Throughout the ui system, this is used for mouse input querying.
public virtual Element GetElementUnderPos(Vector2 position)
Parameters
position
Vector2The position to query
Returns
- Element
The element under the position, or null if there isn't one
GetGamepadNextElement(Direction2)
Returns the next element that should be selected during gamepad navigation, based on the Direction2 that we're looking for elements in.
protected virtual Element GetGamepadNextElement(Direction2 direction)
Parameters
direction
Direction2The direction that we're looking for next elements in
Returns
- Element
The first element found in that area
GetSelectedElement(RootElement)
Returns the selected element for the given root element. A property equivalent to this method is SelectedElement.
public Element GetSelectedElement(RootElement root)
Parameters
root
RootElementThe root element whose selected element to return
Returns
- Element
The given root's selected element, or null if the root doesn't exist, or if there is no selected element for that root.
GetTabNextElement(bool)
Returns the next element to select when pressing the Microsoft.Xna.Framework.Input.Keys.Tab key during keyboard navigation.
If the backward
boolean is true, the previous element should be returned instead.
protected virtual Element GetTabNextElement(bool backward)
Parameters
Returns
- Element
The next or previous element to select
PressElement(Element, bool)
Causes the passed element to be pressed, invoking its OnPressed or OnSecondaryPressed through OnElementPressed or OnElementSecondaryPressed.
public void PressElement(Element element, bool secondary = false)
Parameters
element
ElementThe element to press.
secondary
boolWhether the secondary action should be invoked, rather than the primary one.
SelectElement(RootElement, Element, bool?, NavigationType?)
Selects the given element that is a child of the given root element. Optionally, automatic navigation can be forced on, causing the SelectionIndicator to be drawn around the element. A simpler version of this method is SelectElement(Element, bool?, NavigationType?).
public void SelectElement(RootElement root, Element element, bool? autoNav = null, UiControls.NavigationType? navType = null)
Parameters
root
RootElementThe root element of the Element
element
ElementThe element to select, or null to deselect the selected element.
autoNav
bool?Whether automatic navigation should be forced on. If this is null, the automatic navigation state will stay the same.
navType
UiControls.NavigationType?An optional UiControls.NavigationType to set. If this is null, the navigation type will stay the same.
SetMousedElement(Element)
Sets the MousedElement to the given value, calling the appropriate events.
public void SetMousedElement(Element element)
Parameters
element
ElementThe element to set as moused
SetTouchedElement(Element)
Sets the TouchedElement to the given value, calling the appropriate events.
public void SetTouchedElement(Element element)
Parameters
element
ElementThe element to set as touched
Update()
Update this ui controls instance, causing the underlying InputHandler to be updated, as well as ui input to be queried.
public virtual void Update()
Events
AutoNavModeChanged
An event that is raised when IsAutoNavMode is changed. This can be used for custom actions like hiding the mouse cursor when automatic navigation is enabled.
public event Action<bool> AutoNavModeChanged
Event Type
NavTypeChanged
An event that is raised when NavType is changed. It receives the previous navigation type, as well as the newly set navigation type.
public event Action<UiControls.NavigationType, UiControls.NavigationType> NavTypeChanged