Constructor
new UISystemPlugin(contextopt)
Create the global UI system object
| Name | Type | Attributes | Description |
|---|---|---|---|
context | CanvasRenderingContext2D | | <optional> |
- Source
// create the ui plugin object
new UISystemPlugin;Members
activateOnPress
Properties| Type | Description |
|---|---|
| boolean | Activate when mouse is pressed down instead of clicked |
- Source
activeObject :UIObject|undefined
- UIObject |
undefined
| Type | Description |
|---|---|
| UIObject | | Object user is currently interacting with |
- Source
confirmDialog :UIObject|undefined
- UIObject |
undefined
| Type | Description |
|---|---|
| UIObject | | Current confirm menu being shown |
- Source
defaultButtonColor
Properties| Type | Description |
|---|---|
| Color | Default button color for UI elements |
- Source
defaultColor
Properties| Type | Description |
|---|---|
| Color | Default fill color for UI elements |
- Source
defaultCornerRadius
Properties| Type | Description |
|---|---|
| number | Default rounded rect corner radius for UI elements |
- Source
defaultDisabledColor
Properties| Type | Description |
|---|---|
| Color | Default color for disabled UI elements |
- Source
defaultFont
Properties| Type | Description |
|---|---|
| string | Default font for UI elements |
- Source
defaultGradientColor :Color|undefined
- Color |
undefined
| Type | Description |
|---|---|
| Color | | Uses a gradient fill combined with color |
- Source
defaultHandleSlice :TileSlice|undefined
- TileSlice |
undefined
| Type | Description |
|---|---|
| TileSlice | | Style to draw slider handles with, undefined for the slider's own slice |
- Source
defaultHoverColor
Properties| Type | Description |
|---|---|
| Color | Default hover color for UI elements |
- Source
defaultLineColor
Properties| Type | Description |
|---|---|
| Color | Default outline color for UI elements |
- Source
defaultLineWidth
Properties| Type | Description |
|---|---|
| number | Default line width for UI elements |
- Source
defaultShadowBlur
Properties| Type | Description |
|---|---|
| number | Size of shadow blur |
- Source
defaultShadowColor
Properties| Type | Description |
|---|---|
| Color | Color for shadow |
- Source
defaultShadowOffset
Properties| Type | Description |
|---|---|
| Vector2 | Offset of shadow blur |
- Source
defaultSlice :TileSlice|undefined
- TileSlice |
undefined
| Type | Description |
|---|---|
| TileSlice | | Style to draw UI elements with in place of their rectangle, tinted by their color, undefined for rectangles; needs the drawUtilities plugin |
- Source
defaultSoundClick :Sound|undefined
- Sound |
undefined
| Type | Description |
|---|---|
| Sound | | Default sound when interactive UI element is clicked |
- Source
defaultSoundPress :Sound|undefined
- Sound |
undefined
| Type | Description |
|---|---|
| Sound | | Default sound when interactive UI element is pressed |
- Source
defaultSoundRelease :Sound|undefined
- Sound |
undefined
| Type | Description |
|---|---|
| Sound | | Default sound when interactive UI element is released |
- Source
defaultTextColor
Properties| Type | Description |
|---|---|
| Color | Default text color for UI elements |
- Source
defaultTextFitScale
Properties| Type | Description |
|---|---|
| number | Default scale to use for fitting text to object |
- Source
hoverObject :UIObject|undefined
- UIObject |
undefined
| Type | Description |
|---|---|
| UIObject | | Top most object user is over |
- Source
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
- UIObject |
undefined
- Source
lastHoverObject :UIObject|undefined
- UIObject |
undefined
| Type | Description |
|---|---|
| UIObject | | Hover object at start of update |
- Source
nativeHeight
Properties| Type | Description |
|---|---|
| number | If set ui coords will be renormalized to this canvas height |
- Source
navigationDelay
Properties| Type | Description |
|---|---|
| number | Time between navigation inputs in seconds |
- Source
navigationDirection
Properties| Type | Description |
|---|---|
| number | Which way keys and gamepads move the selection: 0 horizontal, 1 vertical, 2 both |
- Source
navigationMode
Properties| Type | Description |
|---|---|
| boolean | True if user last used navigation instead of mouse |
- Source
navigationObject :UIObject|undefined
- UIObject |
undefined
| Type | Description |
|---|---|
| UIObject | | Object currently selected by navigation (gamepad or keyboard) |
- Source
navigationTimer
Properties| Type | Description |
|---|---|
| Timer | Cool down timer for navigation inputs |
- Source
uiContext
Properties| Type | Description |
|---|---|
| CanvasRenderingContext2D | | Context to render UI elements to |
- Source
uiObjects :Array.<UIObject>
- Array.<UIObject>
| Type | Description |
|---|---|
| Array.<UIObject> | List of all UI elements |
- Source
Methods
drawLine(posA, posB, lineWidthopt, lineColoropt)
Draw a line to the UI context
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
posA | Vector2 | |||
posB | Vector2 | |||
lineWidth | number | <optional> | uiSystem.defaultLineWidth | |
lineColor | Color | <optional> | uiSystem.defaultLineColor |
- Source
drawRect(pos, size, coloropt, lineWidthopt, lineColoropt, cornerRadiusopt, gradientColoropt, shadowColoropt, shadowBluropt, shadowOffsetopt)
Draw a rectangle to the UI context
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | |||
color | Color | <optional> | ||
lineWidth | number | <optional> | 0 | |
lineColor | Color | <optional> | ||
cornerRadius | number | <optional> | 0 | |
gradientColor | Color | <optional> | ||
shadowColor | Color | <optional> | ||
shadowBlur | number | <optional> | 0 | |
shadowOffset | Vector2 | <optional> |
- Source
drawSlice(slice, pos, size, coloropt)
Draw a TileSlice to the UI context, in place of a rectangle
| Name | Type | Attributes | Description |
|---|---|---|---|
slice | TileSlice | ||
pos | Vector2 | ||
size | Vector2 | ||
color | Color | <optional> |
- Source
drawText(text, pos, size, coloropt, lineWidthopt, lineColoropt, alignopt, fontopt, fontStyleopt, applyMaxWidthopt, textShadowopt, shadowColoropt, shadowBluropt, shadowOffsetopt)
Draw text to the UI context
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
text | string | |||
pos | Vector2 | |||
size | Vector2 | |||
color | Color | <optional> | uiSystem.defaultColor | |
lineWidth | number | <optional> | uiSystem.defaultLineWidth | |
lineColor | Color | <optional> | uiSystem.defaultLineColor | |
align | 'left' | | <optional> | center | |
font | string | <optional> | uiSystem.defaultFont | |
fontStyle | string | <optional> | ||
applyMaxWidth | boolean | <optional> | true | |
textShadow | Vector2 | <optional> | ||
shadowColor | Color | <optional> | ||
shadowBlur | number | <optional> | 0 | |
shadowOffset | Vector2 | <optional> |
- Source
drawTile(pos, size, tileInfo, coloropt, angleopt, mirroropt, shadowColoropt, shadowBluropt, shadowOffsetopt)
Draw a tile to the UI context
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | |||
tileInfo | TileInfo | |||
color | Color | <optional> | uiSystem.defaultColor | |
angle | number | <optional> | 0 | |
mirror | boolean | <optional> | false | |
shadowColor | Color | <optional> | ||
shadowBlur | number | <optional> | 0 | |
shadowOffset | Vector2 | <optional> |
- Source
getNavigableObjects() → {Array.<UIObject>}
Get all navigable UI objects sorted by navigationIndex
- Source
- Type:
- Array.<UIObject>
getNavigationDirection() → {number}
Get navigation direction from gamepad or keyboard
- Source
- Type:
- number
getNavigationOtherDirection() → {number}
Get other axis navigation direction from gamepad or keyboard
- Source
- Type:
- number
getNavigationWasPressed() → {boolean}
Get if navigation button was pressed from gamepad or keyboard
- Source
- 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.
- Source
- Type:
- boolean
screenToNative(pos) → {Vector2}
Convert a screen space position to native UI position
| Name | Type | Description |
|---|---|---|
pos | Vector2 |
- Source
- Type:
- Vector2
setupDragAndDrop(onDropopt, onDragEnteropt, onDragLeaveopt, onDragOveropt)
Setup drag and drop event handlers Automatically prevents defaults and calls the given functions
| Name | Type | Attributes | Description |
|---|---|---|---|
onDrop | DragAndDropCallback | <optional> | when a file is dropped |
onDragEnter | DragAndDropCallback | <optional> | when a file is dragged onto the window |
onDragLeave | DragAndDropCallback | <optional> | when a file is dragged off the window |
onDragOver | DragAndDropCallback | <optional> | continuously when dragging over |
- Source
showConfirmDialog(textopt, yesCallbackopt, noCallbackopt, sizeopt, exitKeyopt) → {UIObject}
Show a confirmation dialog with Yes/No buttons Centers the dialog on the screen with darkened background
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
text | string | <optional> | Are you sure? | The message to display |
yesCallback | function | <optional> | Called when Yes is clicked | |
noCallback | function | <optional> | Called when No is clicked, or the exit key or gamepad B closes it | |
size | Vector2 | <optional> | Size of the confirmation dialog, the title and buttons are placed by it | |
exitKey | string | <optional> | Escape | Key that closes the menu as No, gamepad B (button 1) does too |
- Source
The confirmation menu object
- Type:
- UIObject