User Interfaces#
UI.AddWindow adds a window to the game’s UI, and the window’s methods add widgets to it.
This script shows the altitude of the active vehicle, and sets its throttle and engines from the
window until the Done button is clicked:
window = ksa.UI.add_window("Throttle")
altitude = window.add_label("")
throttle = window.add_slider("Throttle", 0, 1)
row = window.add_row()
engine = row.add_toggle("Engine")
done = row.add_button("Done")
flight = vehicle.flight
while not done.clicked:
altitude.content = f"Altitude: {flight.mean_altitude:.0f} m"
if throttle.changed:
throttle.changed = False
vehicle.control.throttle = throttle.value
if engine.changed:
engine.changed = False
vehicle.control.engine_on = engine.checked
time.sleep(0.1)
window.remove()
A window lays out its widgets one per line, and fits its size to them until Size is set. A
Row lays out its widgets from left to right.
Events#
A widget records each click or edit in a property that stays true until the script sets it to
false: Button.Clicked, and Changed on the toggle, input field, slider and dropdown. A
script polls these, or waits on them with a stream or an event. Setting a widget’s value from a
script leaves Changed unchanged.
Lifetime#
The windows are removed when the client that added them disconnects, along with their widgets.
Remove removes one widget, or a window and its widgets, and UI.Clear removes every window.
A call through a removed widget raises ObjectDestroyedException.
The windows are hidden with the game’s UI. Closing a window makes it invisible, and setting
Visible shows it again.