Implement simple GUI.

This commit is contained in:
Casper V. Kristensen 2019-03-01 23:08:50 +01:00
parent 780aee5e7c
commit a664626468
Signed by: caspervk
GPG key ID: 289CA03790535054
3 changed files with 179 additions and 4 deletions

View file

@ -10,7 +10,7 @@ CORE:doaction("Open Terminal", true).
print "==================== BOOTING =====================". print "==================== BOOTING =====================".
wait until SHIP:loaded and SHIP:unpacked. wait until SHIP:loaded and SHIP:unpacked.
wait 0.001. // wait one physics tick wait 0. // wait one physics tick
if HOMECONNECTION:isconnected { if HOMECONNECTION:isconnected {
copy_scripts(). copy_scripts().
@ -73,3 +73,6 @@ local function should_copy {
} }
return false. return false.
} }
run "gui".

171
gui.ks Normal file
View file

@ -0,0 +1,171 @@
@LAZYGLOBAL OFF.
run once "lib/node".
run once "lib/target".
run once "lib/vectors".
run once "ascend".
run once "dock".
// Tabs bar & main frame
local window is gui(350).
local tabs_bar is window:addhlayout().
local tab_frame is window:addstack().
function add_tab {
parameter name.
local frame is tab_frame:addvbox().
local tab_button is tabs_bar:addbutton(name).
set tab_button:exclusive to true. // TODO
set tab_button:onclick to { tab_frame:showonly(frame). }.
return frame.
}
function add_parameters_layout {
parameter widget.
local layout is widget:addvlayout().
local text_parameters is layout:addhlayout().
return LEXICON(
"names", text_parameters:addvlayout(),
"inputs", text_parameters:addvlayout(),
"units", text_parameters:addvlayout(),
"checkboxes", layout:addvlayout()
).
}
function add_parameter {
parameter parameters_layout.
parameter name.
parameter default is "".
parameter unit is "".
if default:istype("Boolean") { // checkbox
return parameters_layout["checkboxes"]:addcheckbox(name, default).
}
parameters_layout["names"]:addlabel(name).
parameters_layout["units"]:addlabel(unit).
return parameters_layout["inputs"]:addtextfield(default).
}
// ASCEND GUIDANCE
{
local tab is add_tab("Ascend").
local parameters is add_parameters_layout(tab).
local target_orbit_altitude is add_parameter(parameters, "Target orbit altitude", "100", "km").
local target_orbit_inclination is add_parameter(parameters, "Target orbit inclination (0-180)", "0", "°").
local pitchover_tilt is add_parameter(parameters, "Pitchover tilt", "20", "°").
local pitchover_altitude is add_parameter(parameters, "Pitchover altitude", "1000", "m").
local pitchover_velocity is add_parameter(parameters, "Pitchover velocity", "100", "m/s").
local auto_stage is add_parameter(parameters, "Auto stage", true).
local auto_deploy_solar_panels is add_parameter(parameters, "Auto deplay solar panels", true).
local auto_deploy_fairings is add_parameter(parameters, "Auto deplay fairings", true).
local auto_extend_antennas is add_parameter(parameters, "Auto extend antennas", true).
set tab:addbutton("Launch"):onclick to {
launch(target_orbit_altitude:text:tonumber*1000,
target_orbit_inclination:text:tonumber,
pitchover_tilt:text:tonumber,
pitchover_altitude:text:tonumber,
pitchover_velocity:text:tonumber,
auto_stage:pressed,
auto_deploy_solar_panels:pressed,
auto_deploy_fairings:pressed,
auto_extend_antennas:pressed).
}.
}
// DOCKING
{
local tab is add_tab("Docking").
local local_vdraw is vdraw(V(0,0,0), V(0,0,0), CYAN).
local target_vdraw is vdraw(V(0,0,0), V(0,0,0), CYAN).
local function add_port_popup {
parameter label.
parameter draw.
parameter options is LIST().
tab:addlabel(label).
local popup is tab:addpopupmenu().
set popup:optionsuffix to "title". // make the popup display the port's :title instead of :tostring
for port in options {
popup:addoption(port).
}
set popup:onchange to {
parameter value.
set draw:show to true.
set draw:startupdater to {return value:nodeposition.}.
set draw:vecupdater to {return value:portfacing:vector.}.
}.
return popup.
}
local local_ports is add_port_popup("Local docking port", local_vdraw, SHIP:dockingports).
local target_ports is add_port_popup("Target docking port", target_vdraw).
set tab:addbutton("Refresh"):onclick to {
target_ports:clear().
if not HASTARGET {
print "No target".
return.
}
for port in target_ship():dockingports {
target_ports:addoption(port).
}
}.
local parameters is add_parameters_layout(tab).
local max_translation_speed is add_parameter(parameters, "Max translation speed", "1.0", "m/s").
local final_docking_speed is add_parameter(parameters, "Final docking speed", "0.1", "m/s").
set tab:addbutton("Dock"):onclick to {
local_ports:value:CONTROLFROM().
set TARGET to target_ports:value.
set local_vdraw:show to false.
set target_vdraw:show to false.
dock(max_translation_speed:text:tonumber,
final_docking_speed:text:tonumber).
}.
}
// MANEUVERS
{
local tab is add_tab("Maneuvers").
// TODO: Like MechJebs "circularize at apoapsis/periapsis, change inclination etc.
// tab:addbutton("Add Maneuver Node") ...
set tab:addbutton("Execute Next Maneuver Node"):onclick to { execute_burn(NEXTNODE). }.
}
// RENDEZVOUS
{
local tab is add_tab("Rendezvous").
// TODO: What about tolerance parameter?
set tab:addbutton("Kill Relative Velocity"):onclick to { kill_relative_velocity(). }.
}
// Close button
tabs_bar:addspacing(10).
local close_button is tabs_bar:addbutton("X").
window:show().
wait until close_button:pressed.
window:hide().

View file

@ -19,10 +19,11 @@ function vdraw {
// //
// Wrapper for the VECDRAW-function that doesn't hide the vector by default. // Wrapper for the VECDRAW-function that doesn't hide the vector by default.
// //
parameter start. // vector or function. For example, pass {return UP:vector.} to automatically update the draw parameter start is V(0,0,0). // vector or function. For example, pass {return UP:vector.} to automatically update the draw
parameter vector. // same as start parameter vector is V(0,0,0). // same as start
parameter color is RED. parameter color is RED.
parameter label is "". parameter label is "".
parameter show is true.
parameter scale is 1.0. parameter scale is 1.0.
parameter width is 0.2. parameter width is 0.2.
@ -32,7 +33,7 @@ function vdraw {
color, color,
label, label,
scale, scale,
true, // show show,
width width
). ).
} }