Remove redundant lines and refactor UI.

This commit is contained in:
Anna Rose 2021-08-01 21:32:00 -04:00
parent 47c37558a9
commit 4da7d50167
3 changed files with 70 additions and 84 deletions

View File

@ -1,6 +1,7 @@
runoncepath("/lib/navigation"). runoncepath("/lib/navigation").
runoncepath("/lib/throttle"). runoncepath("/lib/throttle").
runoncepath("/lib/stabilize_rocket"). runoncepath("/lib/stabilize_rocket").
runoncepath("/lib/ui").
clearguis(). clearguis().
@ -21,120 +22,110 @@ function launchButtonPressed {
} }
// Main UI. // Main UI.
local interface is gui(250, 300). local iface is gui(250, 300).
set interface:X to 200. set iface:X to 200.
set interface:Y to 700. set iface:Y to 700.
// Main menu elements in here. // Main menu elements in here.
local y is interface:AddVLayout(). local top is iface:AddVLayout().
local x is y:AddHLayout(). local row is makeRow(top).
local btn is x:AddButton("TERM"). local btn is row:AddButton("TERM").
set btn:TOGGLE to true. set btn:TOGGLE to true.
set btn:ONTOGGLE to { set btn:ONTOGGLE to {
parameter activate. parameter d.
if activate { if d {
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal"). CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
} else { } else {
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal"). CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").
} }
}. }.
set x:AddButton("CONF"):onClick to { makeButton(row, "CONF", { stk:ShowOnly(panes["conf"]). }).
stk:ShowOnly(confMenu).
}.
set x to y:AddHLayout(). set row to makeRow(top).
set x:AddButton("HOVER"):onClick to { makeButton(row, "HOVER", { Hover(). }).
Hover(). makeButton(row, "LAND", { Land(). }).
}.
set x:AddButton("LAND"):onClick to { set row to makeRow(top).
Land().
}.
set x to y:AddHLayout(). makeButton(row, "LNCH", { stk:ShowOnly(panes["launch"]). }).
set x:AddButton("LNCH"):onClick to { makeButton(row, "NODE", {
stk:ShowOnly(launchmenu).
}.
set x:AddButton("NODE"):onClick to {
set nodeDV:TEXT to NEXTNODE:DELTAV:MAG:ToString. set nodeDV:TEXT to NEXTNODE:DELTAV:MAG:ToString.
set nodeBT:TEXT to BurnTime(NEXTNODE:DELTAV:MAG):ToString. set nodeBT:TEXT to BurnTime(NEXTNODE:DELTAV:MAG):ToString.
stk:ShowOnly(nodeMenu). stk:ShowOnly(panes["node"]).
}. }).
set x:AddButton("TWR"):onClick to { makeButton(row, "TWR", { stk:ShowOnly(panes["twr"]). }).
stk:ShowOnly(twrMenu).
}.
local stk is interface:AddStack(). local stk is iface:AddStack().
local panes is Lex().
// Build launch menu // Build launch menu
local launchMenu is stk:AddVLayout(). local top is stk:AddVLayout().
panes:Add("launch", top).
local launchConfig is launchMenu:AddScrollBox(). local box is launchMenu:AddScrollBox().
set sbox to launchConfig:AddHLayout(). set row to makeRow(box).
sbox:AddLabel("Target Apoapsis"). row:AddLabel("Target Apoapsis").
local targetApo is sbox:AddTextField("80000"). local targetApo is row:AddTextField("80000"). // todo: config params should go into a nested lexicon
set sbox to launchConfig:AddHLayout(). set row to makeRow(box).
sbox:AddLabel("Atmo TWR"). row:AddLabel("Atmo TWR").
local targetTWR is sbox:AddTextField("1.6"). local targetTWR is row:AddTextField("1.6").
set sbox to launchConfig:AddHLayout(). set row to makeRow(box).
sbox:AddLabel("Initial Pitch"). row:AddLabel("Initial Pitch").
local initialPitch is sBox:AddTextField("85"). local initialPitch is row:AddTextField("85").
set sbox to launchConfig:AddHLayout(). set row to makeRow(box).
sbox:AddLabel("Minimum Pitch"). row:AddLabel("Minimum Pitch").
local minimumPitch is sbox:AddTextField("5"). local minimumPitch is row:AddTextField("5").
set sbox to launchConfig:AddHLayout(). set row to makeRow(box).
sbox:AddLabel("Gravity Turn Alt"). row:AddLabel("Gravity Turn Alt").
local gravTurnStart is sbox:AddTextField("8000"). local gravTurnStart is row:AddTextField("8000").
set sbox to launchConfig:AddHLayout(). set row to makeRow(box).
sbox:AddLabel("Gravity Turn Pitch"). row:AddLabel("Gravity Turn Pitch").
local gravPitch is sbox:AddTextField("75"). local gravPitch is row:AddTextField("75").
set btn to launchMenu:AddButton("Execute").
set btn:onClick to launchButtonPressed@.
set top:AddButton("Execute"):onClick to launchButtonPressed@.
// End Launch Menu // End Launch Menu
// Build conf menu // Build conf menu
local confMenu is stk:AddVLayout(). local top is stk:AddVLayout().
panes:Add("conf", top).
local confBox is confMenu:AddScrollbox(). set box to top:AddScrollbox().
set sbox to confBox:AddHLayout(). set row to makeRow(box).
sbox:AddLabel("Torque Epsilon Max"). row:AddLabel("Torque Epsilon Max").
local maxEpsilon is sbox:AddTextField("0.001"). local maxEpsilon is row:AddTextField("0.001").
set sbox to confBox:AddHLayout(). set row to makeRow(box).
sbox:AddLabel("Max Stopping Time"). row:AddLabel("Max Stopping Time").
local maxStopTime is sbox:AddTextField("2.0"). local maxStopTime is row:AddTextField("2.0").
set btn to confMenu:AddButton("Apply"). set top:AddButton("Apply"):onClick to {
set btn:onClick to {
set STEERINGMANAGER:TORQUEEPSILONMAX to maxEpsilon:TEXT:ToNumber(). set STEERINGMANAGER:TORQUEEPSILONMAX to maxEpsilon:TEXT:ToNumber().
set STEERINGMANAGER:MAXSTOPPINGTIME to maxStopTime:TEXT:ToNumber(). set STEERINGMANAGER:MAXSTOPPINGTIME to maxStopTime:TEXT:ToNumber().
}. }.
// end conf menu // end conf menu
// twr menu // twr menu
local twrMenu is stk:AddVLayout(). local top is stk:AddVLayout().
panes:Add("twr", top).
set sbox to twrMenu:AddHLayout(). set row to makeRow(top).
sbox:AddLabel("Target TWR"). row:AddLabel("Target TWR").
local twrLock is sbox:AddTextField("1.6"). local twrLock is row:AddTextField("1.6").
set twrMenu:AddButton("Lock TWR"):onClick to { set top:AddButton("Lock TWR"):onClick to {
local done is false. local done is false.
on AG9 { on AG9 {
set done to true. set done to true.
@ -146,27 +137,25 @@ set twrMenu:AddButton("Lock TWR"):onClick to {
wait until done. wait until done.
print "Throttle unlocked.". print "Throttle unlocked.".
}. }.
// end twr menu // end twr menu
// node menu // node menu
local nodeMenu is stk:AddVLayout(). local top is stk:AddVLayout().
local nodeBox is nodeMenu:AddScrollBox(). panes:Add("node", top).
local box is nodeMenu:AddScrollBox().
set sbox to nodeBox:AddHLayout(). set row to makeRow(top).
sbox:AddLabel("Node dV"). row:AddLabel("Node dV").
local nodeDV is sbox:AddLabel(). local nodeDV is row:AddLabel().
set sbox to nodeBox:AddHLayout(). set row to makeRow(top).
sbox:AddLabel("Node Burn Time"). row:AddLabel("Node Burn Time").
local nodeBT is sbox:AddLabel(). local nodeBT is row:AddLabel().
set nodeMenu:AddButton("Execute"):onClick to { set top:AddButton("Execute"):onClick to {
run "/execnode". run "/execnode".
}. }.
// end node menu // end node menu
interface:show(). iface:show().
wait until false. wait until false.

View File

@ -1,5 +1,4 @@
// functions for calculating steering values. // functions for calculating steering values.
@lazyglobal off.
function GetPitch { function GetPitch {
parameter v is SHIP:FACING:FOREVECTOR. parameter v is SHIP:FACING:FOREVECTOR.

View File

@ -1,7 +1,5 @@
// Functions for calculating values related to throttle and thrust. // Functions for calculating values related to throttle and thrust.
@lazyglobal off.
// point gravity for TWR calculations. // point gravity for TWR calculations.
local G is 0. local G is 0.
lock G to SHIP:BODY:MU / ((SHIP:BODY:RADIUS+SHIP:ALTITUDE)^2). lock G to SHIP:BODY:MU / ((SHIP:BODY:RADIUS+SHIP:ALTITUDE)^2).