// assumptions about helicopter builds:
// * AG10 toggles the rotor engine power. (with appropriate RPM set by default)
// * AG9 is unmapped.
// * Main throttle controls collective.

runoncepath("lib/stabilize_helicopter").
runoncepath("lib/ui").

clearguis().

global done is false.
on AG9 {
  set done to true.
  return true.
}

// Top-level elements.
local iface is gui(250, 300).
set iface:X to 200.
set iface:Y to 700.
local top is iface:AddVLayout().
local rows is List(MakeRow(top)).

set rows[0]:AddButton("HOVER"):onClick to {
  Hover().
}.

set rows[0]:AddButton("LAND"):onClick to {
  // todo: consider a more elaborate landing script that adjusts
  // velocity as a function of altitude.
  when SHIP:STATUS = "LANDED" then {
    set done to true.
    set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.5.
    toggle AG10.
    BRAKES on.
  }
  Hover(-5).
}.

iface:show().

wait until false.