UISystem. UISystemPlugin

UI System Global Object

Constructor

new UISystemPlugin(contextopt)

Create the global UI system object

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

Members

activateOnPress

Properties
TypeDescription
boolean

Activate when mouse is pressed down instead of clicked

activeObject :UIObject|undefined

Type:
  • UIObject | undefined
Properties
TypeDescription
UIObject | undefined

Object user is currently interacting with

confirmDialog :UIObject|undefined

Type:
  • UIObject | undefined
Properties
TypeDescription
UIObject | undefined

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 :Color|undefined

Type:
  • Color | undefined
Properties
TypeDescription
Color | undefined

Uses a gradient fill combined with color

defaultHandleSlice :TileSlice|undefined

Type:
  • TileSlice | undefined
Properties
TypeDescription
TileSlice | undefined

Style to draw slider handles with, undefined for the slider's own slice

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

defaultSlice :TileSlice|undefined

Type:
  • TileSlice | undefined
Properties
TypeDescription
TileSlice | undefined

Style to draw UI elements with in place of their rectangle, tinted by their color, undefined for rectangles; needs the drawUtilities plugin

defaultSoundClick :Sound|undefined

Type:
  • Sound | undefined
Properties
TypeDescription
Sound | undefined

Default sound when interactive UI element is clicked

defaultSoundPress :Sound|undefined

Type:
  • Sound | undefined
Properties
TypeDescription
Sound | undefined

Default sound when interactive UI element is pressed

defaultSoundRelease :Sound|undefined

Type:
  • Sound | undefined
Properties
TypeDescription
Sound | undefined

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 :UIObject|undefined

Type:
  • UIObject | undefined
Properties
TypeDescription
UIObject | undefined

Top most object user is over

keyInputObject :UIObject|undefined

Object to send keyboard input to (typically a UITextInput), which keeps the keys from the game while set. The keyboard listeners are only attached while this is set, so games that never use text input pay no event-handling cost. To end typing in a field, call its stopEditing(), which also fires its onChange and release sound

Type:
  • UIObject | undefined

lastHoverObject :UIObject|undefined

Type:
  • UIObject | undefined
Properties
TypeDescription
UIObject | undefined

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
number

Which way keys and gamepads move the selection: 0 horizontal, 1 vertical, 2 both

Properties
TypeDescription
boolean

True if user last used navigation instead of mouse

Type:
  • UIObject | undefined
Properties
TypeDescription
UIObject | undefined

Object currently selected by navigation (gamepad or keyboard)

Properties
TypeDescription
Timer

Cool down timer for navigation inputs

uiContext

Properties
TypeDescription
CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D

Context to render UI elements to

uiObjects :Array.<UIObject>

Type:
  • Array.<UIObject>
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
shadowOffsetVector2<optional>

drawSlice(slice, pos, size, coloropt)

Draw a TileSlice to the UI context, in place of a rectangle

Parameters:
NameTypeAttributesDescription
sliceTileSlice
posVector2
sizeVector2
colorColor<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
align'left' | 'center' | 'right'<optional>
center
fontstring<optional>
uiSystem.defaultFont
fontStylestring<optional>
applyMaxWidthboolean<optional>
true
textShadowVector2<optional>
shadowColorColor<optional>
shadowBlurnumber<optional>
0
shadowOffsetVector2<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
shadowOffsetVector2<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() → {number}

Get other axis navigation direction from gamepad or keyboard

Returns:
Type: 
number

getNavigationWasPressed() → {boolean}

Get if navigation button was pressed from gamepad or keyboard

Returns:
Type: 
boolean

isMouseOverUI() → {boolean}

Check if the mouse is over a visible UI object that can be hovered, or anywhere while the confirm dialog is open, so a game can leave world clicks on the UI alone, on touch too. The UI uses up a click before objects update and gameUpdatePost, so read world clicks there, or check this in gameUpdate, which runs first. Positions are from the last UI update.

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, or the exit key or gamepad B closes it

sizeVector2<optional>

Size of the confirmation dialog, the title and buttons are placed by it

exitKeystring<optional>
Escape

Key that closes the menu as No, gamepad B (button 1) does too

Returns:

The confirmation menu object

Type: 
UIObject