WebUI

https://i.imgur.com/Sh88Q32.png

Class for spawning a web browser in the screen. The browser will fill up the whole screen and is automatically resized.

Attention

There is a known bug causing WebUI files (.js and .css at least) not being reloaded when modified. Restarting the game seems to solve the problem for now. The developer of this Library already knows and is working on a solution.

Tip

This HTML implementation is built upon same core as WebKit/Safari. And currently does not support HTML5 videos and audios.

Note

This is a Client only Class.

Usage

-- Using a local file
my_ui = WebUI(
    "Awesome UI", -- Name
    "file:///UI/Index.html", -- Path relative to this package (Client/)
    true, -- Is Visible
)

-- Using a Web URL
my_browser = WebUI(
    "Awesome Site", -- Name
    "http://nanos.world", -- Web's URL
    true, -- Is Visible
)

Constructor Parameters

Type

Name

Default

string

Name

string

Path (URL or file:///relative/to/client/folder.html)

boolean

IsVisible

true

Functions

Returns

Name

Description

BringToFront()

Puts this WebUI in the front of all WebUIs

CallEvent(string EventName, any… Arguments)

Calls an Event on the Browser’s JavaScript

Destroy()

Destroys this Browser

LoadURL(string URL)

Loads a new File/URL in this Browser

SetFocus()

Enables the focus on this browser (i.e. can receives keyboard and mouse input). Note: only one browser can have focus per time. When you click at the screen/WebUI the focus is got automatically as well

SetVisible(boolean IsVisible)

Toggles the visibiliy

boolean

IsValid()

Returns if this entity is Valid

number

GetID()

Gets the network ID of this entity

string

GetType()

Returns the type of this Actor

Events

Name

Arguments

Description

Failed

number ErrorCode, string Message

When this page fails to load

Ready

When this page is fully loaded

Note

It is only allowed to pass number, string and boolean between WebUI and your Package.

Examples

-- creates a browser
my_ui = WebUI("Awesome UI", "file:///UI/Index.html")

-- register for an Event from the Browser created
my_ui:on("MyEventFromJS", function(my_text)
    Package:Log("Event received from Browser! " .. my_text)
    -- outputs "Event received from Browser! hello nanos world from JavaScript!"
end)

-- calls an Event in the Browser
my_ui:CallEvent("MyEventFromLua", {"hello nanos world from lua!"})
// registers for events from Lua
Events.on("MyEventFromLua", function(param1) {
    console.log("Event received from Lua!" + param1);
    // outputs "Event received from Lua! hello nanos world from lua!"
})

// calls an Event on Lua
Events.Call("MyEventFromJS", "hello nanos world from JavaScript!");