UI - WorkAdventure Documentation
UI - WorkAdventure Documentation
Get UI website by ID
Controls
The modal iframe API
Event
Open the modal iframe
Map Editor API Example
Closing a modal
Navigation
Action bar button API
Player
Add a button in the action bar
Players Remove a button from the action bar
Scripting Internals
Using Typescript
Room API
Please note that openPopup returns an object of the Popup class. Also, the callback called when a button is clicked is passed a
Popup object.
The Popup class that represents an open popup contains a single method: close() . This will obviously close the popup when called.
class Popup {
/**
* Closes the popup
*/
close() {};
}
Example:
let helloWorldPopup;
Add a custom menu item containing the text commandDescriptor in the navbar of the menu. options attribute accepts an object
with three properties :
callback : (commandDescriptor: string) => void : A click on the custom menu will trigger the callback .
iframe: string : A click on the custom menu will open the iframe inside the menu.
allowApi?: boolean : Allow the iframe of the custom menu to use the Scripting API.
Custom menu exist only until the map is unloaded, or you leave the iframe zone of the script.
Example:
The Menu class contains two methods: remove(): void and open(): void .
remove will remove the menu when called. open will programmatically open the menu.
class Menu {
/**
* Remove the menu
*/
public remove(): void {/*...*/};
/**
* Programmatically open the menu
*/
public open(): void {/*...*/};
}
You can retrieve a menu by its key using WA.ui.getMenuCommand . You can also access the list of default menu items provided by WA.
Here is the full list of pre-registered keys: "settings", "profile", "invite", "credit", "globalMessages", "contact", "report".
WA.ui.displayActionMessage({
message: string,
callback: () => void,
type?: "message"|"warning",
}): ActionMessage
Displays a message at the bottom of the screen (that will disappear when space bar is pressed).
Example:
setTimeout(() => {
// later
triggerMessage.remove();
}, 1000)
The ActionMessage class contains a single method: remove(): Promise<void> . This will obviously remove the message when
called.
class ActionMessage {
/**
* Hides the message
*/
remove() {};
}
To do that, we need to listen for the onRemotePlayerClicked stream and make use of the remotePlayer object that is passed by as
a payload.
remotePlayer.addAction(actionName, callback) returns an Action object, which can remove itself from ActionsMenu:
Display a UI website
interface CreateUIWebsiteEvent {
url: string, // Website URL
visible?: boolean, // The website is visible or not
allowApi?: boolean, // Allow scripting API on the website
allowPolicy?: string, // The list of feature policies allowed
position: {
vertical: "top"|"middle"|"bottom",,
horizontal: "left","middle","right",
},
size: { // Size on the UI (available units: px|em|%|cm|in|pc|pt|mm|ex|vw|vh|rem and other
height: string,
width: string,
},
margin?: { // Website margin (available units: px|em|%|cm|in|pc|pt|mm|ex|vw|vh|rem and other
top?: string,
bottom?: string,
left?: string,
right?: string,
},
}
interface UIWebsite {
readonly id: string, // Unique ID
url: string, // Website URL
visible: boolean, // The website is visible or not
readonly allowApi: boolean, // Allow scripting API on the website
readonly allowPolicy: string, // The list of feature policies allowed
position: {
vertical: string, // Vertical position (top, middle, bottom)
horizontal: string, // Horizontal position (left, middle, right)
},
size: { // Size on the UI (available units: px|em|%|cm|in|pc|pt|mm|ex|vw|vh|rem a
height: string,
width: string,
},
margin?: { // Website margin (available units: px|em|%|cm|in|pc|pt|mm|ex|vw|vh|rem a
top?: string,
bottom?: string,
left?: string,
right?: string,
},
close(): Promise<void>, // Close the current website instance
}
You can open a website with the WA.ui.website.open() method. It returns an Promise<UIWebsite> instance.
myWebsite.position.vertical = "top";
INFO
The url parameter can be a relative URL. In this case, the URL is relative to the map file.
Close a UI website
You can close a website with the close function on the UIWebsite object
myWebsite.close();
WA.ui.website.getAll();
Get UI website by ID
You can get a specific website with the WA.ui.website.getById() method. It returns an Promise<UIWebsite> instance. If your
code is running inside a UIWebsite iframe, you can use WA.iframeId to obtain the id of the current iframe.
WA.ui.modal.openModal({
title: string,// mandatory, title of the iframe modal.
src: string, // mandatory, url of the iframe modal.
allow?: string, // optional by default null.
allowApi?: boolean, // optional by default false.
position?: string, // optional by default right. Reference for position: center / left / right.
closeCallback?: Function // optionall, function when the user close the modal.
}): void
Example
WA.ui.modal.openModal({
title: "WorkAdventure website",
src: 'https://workadventu.re',
allow: "fullscreen",
allowApi: true,
position: "center",
() => {
console.info('The modal was closed');
}
});
WA.ui.modal.openModal({
title: "WorkAdventure website",
src: 'https://workadventu.re',
allow: "fullscreen",
position: "right"
});
WA.ui.modal.openModal({
title: "WorkAdventure website",
src: 'https://workadventu.re',
position: "left"
});
Mobile example
If the user is in mobile definition, the modal will open in full screen:
Closing a modal
WA.ui.modal.closeModal(): void
Classic button
WA.ui.actionBar.addButton(descriptor: {
id: string,
label: string,
clickCallback: (buttonActionBar: AddButtonActionBar) => void
}): void
Action button
WA.ui.actionBar.addButton(descriptor: {
id: string,
type: 'action',
imageSrc: string,
toolTip: string,
clickCallback: (buttonActionBar: AddButtonActionBar) => void
}): void
/**
* Ennum of button type
*/
const ActionBarButtonType = {
button: "button",
action: "action",
} as const;
type ActionBarButtonType = typeof ActionBarButtonType[keyof typeof ActionBarButtonType];
interface AddButtonActionBar {
/*
* the id of the button action bar defined.
*/
id: string,
/*
* the label to display in button action bar.
*/
label: string
/*
* the type of button ('button' / 'action'). By default is 'button'.
*/
type: ActionBarButtonType,
/*
* the image of button associated, This parameter is nullable.
*/
imageSrc: string
/*
* the label displayed above the action button. This parameter is nullable.
*/
toolTip: string
}
WA.ui.actionBar.removeButton(id: string);
The open/close banner API is experimental. It means the compatibility with future versions of WorkAdventure is not guaranteed
and we might break the signature of these methods at any moment. Use at your own risk.
WA.ui.banner.openBanner({
id: string,
text: string,
bgColor?: string,
textColor?: string,
closable?: boolean,
link?: {
url: string,
label: string
}
});
WA.ui.banner.closeBanner();
WA.ui.banner.openBanner({
id: "banner-test",
text: "Banner test",
bgColor: "#000000",
textColor: "#ffffff",
closable: false,
timeToClose: 120000,
link: {
label: "Test",
url: "https://workadventu.re"
}
});
WA.ui.banner.closeBanner();
Previous Next
« State Deprecated Functions »