ui.lua

This script contains UI related functions like for moving the mouse or the view or clicking on fields and UI elements.

Note

Do not use any of these functions for multiplayer scenarios or winconditions, because a game will likely desync then.

scroll_to_map_pixel(map_pixel)

Make a nice moving transition to center on the ‘map_pixel’, which is a table that must contain ‘x’ and ‘y’ keys. The function will return as soon as the transition is completed.

Parameters:map_pixel (table) – pixel to focus on.
scroll_to_field(field)

Make a nice moving transition to center the ‘field’ on screen. The function will return as soon as the transition is completed.

Parameters:field (wl.map.Field) – Field to center the view on
Returns:the prior center map pixel of the MapView as a table containing ‘x’ and ‘y’ keys.
mouse_to_pixel(x, y)

Make a nice moving transition for the mouse to the given pixels relative to the top left corner of the screen. The function will return as soon as the transition is completed.

Parameters:
  • x (integer) – x position to move the mouse to
  • y (integer) – y position to move the mouse to
mouse_to_field(field)

Move the mouse on the given field. Makes sure that the field is inside the current view area by scrolling the view if necessary. The function will return as soon as the transition is completed.

Parameters:field (wl.map.Field) – Field to mouse to
mouse_to_panel(panel)

Move the mouse to the center of the given ui element. The function will return as soon as the transition is completed.

Parameters:panel (wl.ui.Panel) – Panel to mouse to
click_building(player, building_name)

Click on the first building of type ‘building_name’ owned by ‘player’.

Parameters:
  • player (wl.game.Player) – Player to search building for.
  • building_name (string) – Building name to look for.
Returns:

true if a building was clicked

click_button(name)

Searches through all open windows for a button named ‘name’ and, if found, clicks it.

Parameters:name (string.) – Name of the button to click.
Returns:true if a button was clicked
close_windows()

Closes all open windows.

wait_for_roadbuilding()

Sleeps while player is in roadbuilding mode.

wait_for_roadbuilding_and_scroll(field)

Sleeps while player is in roadbuilding mode, then calls scroll_to_field(field).

Returns:The return value of scroll_to_field.