Major UI refactor.

This commit is contained in:
Anna Rose 2021-08-08 00:15:28 -04:00
parent f5e80f3687
commit 9a899211fe
5 changed files with 146 additions and 143 deletions

View File

@ -2,10 +2,15 @@ runoncepath("0:/lib/boot").
parameter debug is false. parameter debug is false.
local compiled is List(
"/lib/stabilize_helicopter",
"/lib/ui"
).
Bootstrap( Bootstrap(
"/boot/helicopter", "/boot/helicopter",
"/prog/helicopter", "/prog/helicopter",
list("/lib/stabilize_helicopter"), compiled,
list("/lib/ui"), List(), // no copied files
debug debug
). ).

View File

@ -7,11 +7,11 @@ local compiled is list(
"/lib/navigation", "/lib/navigation",
"/lib/node", "/lib/node",
"/lib/stabilize_rocket", "/lib/stabilize_rocket",
"/lib/ui",
"/lib/throttle" "/lib/throttle"
). ).
local copied is list( local copied is list(
"/lib/ui",
"/lib/sensors" "/lib/sensors"
). ).

View File

@ -1,14 +1,53 @@
function makeRow { function MakeRow {
parameter p. parameter p.
return p:AddHLayout(). return p:AddHLayout().
} }
function makeButton { function MakeButton {
parameter p. parameter p.
parameter l. parameter l.
parameter f. parameter f is {}.
local b is p:AddButton(l). local b is p:AddButton(l).
set b:onClick to f. set b:onClick to f.
return b. return b.
} }
function MakeMenu {
parameter stack. // the stack where menu stuff goes
parameter btn. // the button that should show this menu
parameter options.
parameter execLabel.
parameter callback.
parameter preback is { parameter nil. }.
local top is stack:AddVLayout().
local sbox is top:AddScrollBox().
local optionList is Lex().
for option in options {
local row is MakeRow(sbox).
local name is option[0].
local type is option[1].
local field is 0.
if type = "SCALAR" {
row:AddLabel(name).
set field to row:AddTextField(option[2]).
} else if type = "BOOL" {
set field to row:AddCheckBox(name, option[2]).
} else if type = "RO" {
row:AddLabel(name).
set field to row:AddLabel(option[2]).
} else {
print "WARNING: Unsupported type passed to MakeMenu".
}
optionList:Add(name, field).
}
set btn:onClick to {
preback(optionList).
stack:ShowOnly(top).
}.
set top:AddButton(execLabel):onClick to callback:Bind(optionList).
}

View File

@ -4,6 +4,9 @@
// * Main throttle controls collective. // * Main throttle controls collective.
runoncepath("lib/stabilize_helicopter"). runoncepath("lib/stabilize_helicopter").
runoncepath("lib/ui").
clearguis().
global done is false. global done is false.
on AG9 { on AG9 {
@ -11,22 +14,18 @@ on AG9 {
return true. return true.
} }
clearguis(). // 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)).
// Main UI. set rows[0]:AddButton("HOVER"):onClick to {
local interface is gui(250, 300).
set interface:X to 200.
set interface:Y to 700.
// Main menu elements in here.
local y is interface:AddVLayout().
local x is y:AddHLayout().
set x:AddButton("HOVER"):onClick to {
Hover(). Hover().
}. }.
set x:AddButton("LAND"):onClick to { set rows[0]:AddButton("LAND"):onClick to {
// todo: consider a more elaborate landing script that adjusts // todo: consider a more elaborate landing script that adjusts
// velocity as a function of altitude. // velocity as a function of altitude.
when SHIP:STATUS = "LANDED" then { when SHIP:STATUS = "LANDED" then {
@ -38,6 +37,6 @@ set x:AddButton("LAND"):onClick to {
Hover(-5). Hover(-5).
}. }.
interface:show(). iface:show().
wait until false. wait until false.

View File

@ -15,16 +15,16 @@ on AG9 {
return true. return true.
} }
// Main UI. // Top-level menu structure.
local iface is gui(250, 300). local iface is gui(250, 300).
set iface:X to 200. set iface:X to 200.
set iface:Y to 700. set iface:Y to 700.
// Main menu elements in here.
local top is iface:AddVLayout(). local top is iface:AddVLayout().
local row is makeRow(top). local rows is list(MakeRow(top), MakeRow(top), MakeRow(top)).
local stk is iface:AddStack().
local btn is row:AddButton("TERM"). // Buttons and menus.
local btn is rows[0]:AddButton("TERM").
set btn:TOGGLE to true. set btn:TOGGLE to true.
set btn:ONTOGGLE to { set btn:ONTOGGLE to {
parameter d. parameter d.
@ -36,131 +36,91 @@ set btn:ONTOGGLE to {
} }
}. }.
makeButton(row, "CONF", { stk:ShowOnly(panes["conf"]). }). MakeMenu(
stk,
set row to makeRow(top). MakeButton(rows[0], "CONF"),
List(
makeButton(row, "HOVER", { Hover(). }). List("Torque Epsilon Max", "SCALAR", "0.001"),
makeButton(row, "LAND", { Land(). }). List("Max Stopping Time", "SCALAR", "2.0")
),
set row to makeRow(top). "Apply",
{
makeButton(row, "LNCH", { stk:ShowOnly(panes["launch"]). }). parameter options.
set STEERINGMANAGER:TORQUEEPSILONMAX to options["Torque Epsilon Max"]:TEXT:ToNumber().
makeButton(row, "NODE", { set STEERINGMANAGER:MAXSTOPPINGTIME to options["Max Stopping Time"]:TEXT:ToNumber().
if HASNODE {
set nodeDV:TEXT to NEXTNODE:DELTAV:MAG:ToString.
set nodeBT:TEXT to BurnTime(NEXTNODE:DELTAV:MAG):ToString.
} else {
set nodeDV:TEXT to "No Node".
set nodeBT:TEXT to "No Node".
} }
stk:ShowOnly(panes["node"]).
}).
makeButton(row, "TWR", { stk:ShowOnly(panes["twr"]). }).
local stk is iface:AddStack().
local panes is Lex().
// Build launch menu
local top is stk:AddVLayout().
panes:Add("launch", top).
local box is top:AddScrollBox().
set row to makeRow(box).
row:AddLabel("Target Apoapsis").
local targetApo is row:AddTextField("80000"). // todo: config params should go into a nested lexicon
set row to makeRow(box).
row:AddLabel("Atmo TWR").
local targetTWR is row:AddTextField("1.6").
set row to makeRow(box).
row:AddLabel("Initial Pitch").
local initialPitch is row:AddTextField("85").
set row to makeRow(box).
row:AddLabel("Minimum Pitch").
local minimumPitch is row:AddTextField("5").
set row to makeRow(box).
row:AddLabel("Gravity Turn Alt").
local gravTurnStart is row:AddTextField("8000").
set row to makeRow(box).
row:AddLabel("Gravity Turn Pitch").
local gravPitch is row:AddTextField("75").
makeButton(top, "Execute", {
Launch(
targetApo:TEXT:ToNumber(),
targetTWR:TEXT:ToNumber(),
gravTurnStart:TEXT:ToNumber(),
gravPitch:TEXT:ToNumber(),
initialPitch:TEXT:ToNumber(),
minimumPitch:TEXT:ToNumber()
). ).
}).
// End Launch Menu
// Build conf menu MakeButton(rows[1], "HOVER", { Hover(). }).
local top is stk:AddVLayout(). MakeButton(rows[1], "LAND", { Land(). }).
panes:Add("conf", top).
set box to top:AddScrollbox(). MakeMenu(
stk,
set row to makeRow(box). MakeButton(rows[2], "LNCH"),
row:AddLabel("Torque Epsilon Max"). List(
local maxEpsilon is row:AddTextField("0.001"). List("Target Apoapsis", "SCALAR", "80000"),
List("Atmo TWR", "SCALAR", "1.8"),
set row to makeRow(box). List("Initial Pitch", "SCALAR", "85"),
row:AddLabel("Max Stopping Time"). List("Minimum Pitch", "SCALAR", "5"),
local maxStopTime is row:AddTextField("2.0"). List("Gravity Turn Alt", "SCALAR", "8000"),
List("Gravity Turn Pitch", "SCALAR", "75")
makeButton(top, "Apply", { ),
set STEERINGMANAGER:TORQUEEPSILONMAX to maxEpsilon:TEXT:ToNumber(). "Execute",
set STEERINGMANAGER:MAXSTOPPINGTIME to maxStopTime:TEXT:ToNumber(). {
}). parameter options.
// end conf menu Launch(
options["Target Apoapsis"]:TEXT:ToNumber(),
// twr menu options["Atmo TWR"]:TEXT:ToNumber(),
local top is stk:AddVLayout(). options["Gravity Turn Alt"]:TEXT:ToNumber(),
panes:Add("twr", top). options["Gravity Turn Pitch"]:TEXT:ToNumber(),
options["Initial Pitch"]:TEXT:ToNumber(),
set row to makeRow(top). options["Minimum Pitch"]:TEXT:ToNumber()
row:AddLabel("Target TWR"). ).
local twrLock is row:AddTextField("1.6").
makeButton(top, "Lock TWR", {
local done is false.
on AG9 {
set done to true.
} }
).
MakeMenu(
stk,
MakeButton(rows[2], "NODE"),
List(
List("Node dV", "RO", "0"),
List("Node Burn Time", "RO", "0")
),
"Execute",
{
parameter options.
ExecNode().
},
{
parameter options.
if HASNODE {
set options["Node dV"]:TEXT to NEXTNODE:DELTAV:MAG:ToString.
set options["Node Burn Time"]:TEXT to BurnTime(NEXTNODE:DELTAV:MAG):ToString.
} else {
set options["Node dV"]:TEXT to "No Node".
set options["Node Burn Time"]:TEXT to "No Node".
}
}
).
MakeMenu(
stk,
MakeButton(rows[2], "TWR"),
List(
List("Target TWR", "SCALAR", "1.6")
),
"Lock TWR",
{
parameter options.
local done is false.
print "Locking throttle to target TWR.". print "Locking throttle to target TWR.".
local tgt is twrLock:TEXT:ToNumber(). local tgt is options["Target TWR"]:TEXT:ToNumber().
lock THROTTLE to ThrottleToTWR(tgt). lock THROTTLE to ThrottleToTWR(tgt).
wait until done. wait until done.
print "Throttle unlocked.". print "Throttle unlocked.".
}). set done to false.
// end twr menu }
).
// node menu
local top is stk:AddVLayout().
panes:Add("node", top).
set row to makeRow(top).
row:AddLabel("Node dV").
local nodeDV is row:AddLabel().
set row to makeRow(top).
row:AddLabel("Node Burn Time").
local nodeBT is row:AddLabel().
makeButton(top, "Execute", { ExecNode(). }).
// end node menu
iface:show(). iface:show().
wait until false. wait until false.