UISystem. UISystemPlugin

UI System Global Object

Constructor

new UISystemPlugin(contextopt)

Create the global UI system object

Parameters:
NameTypeAttributesDescription
contextCanvasRenderingContext2D<optional>
Example
// create the ui plugin object
 new UISystemPlugin;

Members

activateOnPress

Properties
TypeDescription
boolean

Activate when mouse is pressed down instead of clicked

activeObject

Properties
TypeDescription
UIObject

Object user is currently interacting with

confirmDialog

Properties
TypeDescription
UIObject

Current confirm menu being shown

defaultButtonColor

Properties
TypeDescription
Color

Default button color for UI elements

defaultColor

Properties
TypeDescription
Color

Default fill color for UI elements

defaultCornerRadius

Properties
TypeDescription
number

Default rounded rect corner radius for UI elements

defaultDisabledColor

Properties
TypeDescription
Color

Default color for disabled UI elements

defaultFont

Properties
TypeDescription
string

Default font for UI elements

defaultGradientColor

Properties
TypeDescription
Color

Uses a gradient fill combined with color

defaultHoverColor

Properties
TypeDescription
Color

Default hover color for UI elements

defaultLineColor

Properties
TypeDescription
Color

Default outline color for UI elements

defaultLineWidth

Properties
TypeDescription
number

Default line width for UI elements

defaultShadowBlur

Properties
TypeDescription
number

Size of shadow blur

defaultShadowColor

Properties
TypeDescription
Color

Color for shadow

defaultShadowOffset

Properties
TypeDescription
Vector2

Offset of shadow blur

defaultSoundClick

Properties
TypeDescription
Sound

Default sound when interactive UI element is clicked

defaultSoundPress

Properties
TypeDescription
Sound

Default sound when interactive UI element is pressed

defaultSoundRelease

Properties
TypeDescription
Sound

Default sound when interactive UI element is released

defaultTextColor

Properties
TypeDescription
Color

Default text color for UI elements

defaultTextFitScale

Properties
TypeDescription
number

Default scale to use for fitting text to object

hoverObject

Properties
TypeDescription
UIObject

Top most object user is over

lastHoverObject

Properties
TypeDescription
UIObject

Hover object at start of update

nativeHeight

Properties
TypeDescription
number

If set ui coords will be renormalized to this canvas height

Properties
TypeDescription
number

Time between navigation inputs in seconds

Properties
TypeDescription
boolean

should the navigation be horizontal, vertical, or both?

Properties
TypeDescription
boolean

True if user last used navigation instead of mouse

Properties
TypeDescription
UIObject

Object currently selected by navigation (gamepad or keyboard)

Properties
TypeDescription
Timer

Cooldown timer for navigation inputs

uiContext

Properties
TypeDescription
CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D

Context to render UI elements to

uiObjects

Properties
TypeDescription
Array.<UIObject>

List of all UI elements

Methods

drawLine(posA, posB, lineWidthopt, lineColoropt)

Draw a line to the UI context

Parameters:
NameTypeAttributesDefaultDescription
posAVector2
posBVector2
lineWidthnumber<optional>
uiSystem.defaultLineWidth
lineColorColor<optional>
uiSystem.defaultLineColor

drawRect(pos, size, coloropt, lineWidthopt, lineColoropt, cornerRadiusopt, gradientColoropt, shadowColoropt, shadowBluropt, shadowOffsetopt)

Draw a rectangle to the UI context

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2
colorColor<optional>
lineWidthnumber<optional>
0
lineColorColor<optional>
cornerRadiusnumber<optional>
0
gradientColorColor<optional>
shadowColorColor<optional>
shadowBlurnumber<optional>
0
shadowOffsetColor<optional>

drawText(text, pos, size, coloropt, lineWidthopt, lineColoropt, alignopt, fontopt, fontStyleopt, applyMaxWidthopt, textShadowopt, shadowColoropt, shadowBluropt, shadowOffsetopt)

Draw text to the UI context

Parameters:
NameTypeAttributesDefaultDescription
textstring
posVector2
sizeVector2
colorColor<optional>
uiSystem.defaultColor
lineWidthnumber<optional>
uiSystem.defaultLineWidth
lineColorColor<optional>
uiSystem.defaultLineColor
alignstring<optional>
center
fontstring<optional>
uiSystem.defaultFont
fontStylestring<optional>
applyMaxWidthboolean<optional>
true
textShadowVector2<optional>
shadowColorColor<optional>
shadowBlurnumber<optional>
0
shadowOffsetColor<optional>

drawTile(pos, size, tileInfo, coloropt, angleopt, mirroropt, shadowColoropt, shadowBluropt, shadowOffsetopt)

Draw a tile to the UI context

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2
tileInfoTileInfo
colorColor<optional>
uiSystem.defaultColor
anglenumber<optional>
0
mirrorboolean<optional>
false
shadowColorColor<optional>
shadowBlurnumber<optional>
0
shadowOffsetColor<optional>

getNavigableObjects() → {Array.<UIObject>}

Get all navigable UI objects sorted by navigationIndex

Returns:
Type: 
Array.<UIObject>

getNavigationDirection() → {number}

Get navigation direction from gamepad or keyboard

Returns:
Type: 
number

getNavigationOtherDirection() → {Vector2}

Get other axis navigation direction from gamepad or keyboard

Returns:
Type: 
Vector2

getNavigationWasPressed() → {boolean}

Get if navigation button was pressed from gamepad or keyboard

Returns:
Type: 
boolean

screenToNative(pos) → {Vector2}

Convert a screen space position to native UI position

Parameters:
NameTypeDescription
posVector2
Returns:
Type: 
Vector2

setupDragAndDrop(onDropopt, onDragEnteropt, onDragLeaveopt, onDragOveropt)

Setup drag and drop event handlers Automatically prevents defaults and calls the given functions

Parameters:
NameTypeAttributesDescription
onDropDragAndDropCallback<optional>

when a file is dropped

onDragEnterDragAndDropCallback<optional>

when a file is dragged onto the window

onDragLeaveDragAndDropCallback<optional>

when a file is dragged off the window

onDragOverDragAndDropCallback<optional>

continuously when dragging over

showConfirmDialog(textopt, yesCallbackopt, noCallbackopt, sizeopt, exitKeyopt) → {UIObject}

Show a confirmation dialog with Yes/No buttons Centers the dialog on the screen with darkened background

Parameters:
NameTypeAttributesDefaultDescription
textstring<optional>
Are you sure?

The message to display

yesCallbackfunction<optional>

Called when Yes is clicked

noCallbackfunction<optional>

Called when No is clicked

sizeVector2<optional>

Size of the confirmation dialog

exitKeystring<optional>
Escape

Key that can exit the menu

Returns:

The confirmation menu object

Type: 
UIObject