Custom Window

This is a draft for a possible API to allow scripts to create windows. It may or may not end up being implemented.

Contents

Window Class

All windows created by this API will have the same Window Class which is a new Window Class that doesn't yet exist in OpenTTD. For now call it WC_SCRIPT.

Construct a window type

Scripts can construct window types using:

GSScriptWindowType::Create(widgets)

This method returns an ID that identifiers this window type.

The widgets parameter is a nested table/array that describes the nested widget tree. (further work is needed to establish a specification for this.)

Open a window

When using GSScriptWindow, the Window Class is implicitly set to WC_SCRIPT.

To open a Window this method is used. The location parameter is an enum of window placements (Center, FreeSpot, ..). Since the same window type might be reused in similar but still slightly different situations, some widget texts may need to be customized when displaying the window. For this purpose there need to be possible to pass pairs of widgets and texts along when calling Open.

GSScriptWindow::Open(window_number, window_type, location, widget_texts);

Example of a possible widget_texts table: (5 and 6 are widget IDs)

{
  _5 = {
    text = GSText(GSText.STR_HELLO, GSCompany.GetName(1)),
    enabled = false
  }
  _6 = {
    text = ..
  }
}

Events

Events occur when a user at some client clicks on a button. (some other widgets may also generate a 'done' signal)

Possibilities