autopilot vbox ## manage one AP property group with checkbox and radio buttons # Group = { new : func(name, options) { var m = { parents: [Group] }; m.name = name; m.enabled = 0; m.mode = options[0]; m.options = []; var locks = props.globals.getNode("/autopilot/locks", 1); if (locks.getNode(name) == nil or locks.getNode(name, 1).getValue() == nil) { locks.getNode(name, 1).setValue(""); } m.lock = locks.getNode(name); m.active = dlg.getNode(name ~ "-active", 1); foreach (var o; options) { var node = dlg.getNode(o); if (node == nil) { node = dlg.getNode(o, 1); node.setBoolValue(0); } append(m.options, node); if (m.lock.getValue() == o) { m.mode = o; } } m.listener = setlistener(m.lock, func(n) { m.update(n.getValue()) }, 1); return m; }, del : func { removelistener(me.listener); }, ## handle checkbox # enable : func { me.enabled = me.active.getBoolValue(); me.lock.setValue(me.enabled ? me.mode : ""); }, ## handle radiobuttons # set : func(mode) { me.mode = mode; foreach (var o; me.options) { o.setBoolValue(o.getName() == mode); } if (me.enabled) { me.lock.setValue(mode); } }, ## update checkboxes/radiobuttons state from the AP (listener callback) # update : func(mode) { me.enabled = (mode != ""); me.active.setBoolValue(me.enabled); if (mode == "") { mode = me.mode; } foreach (var o; me.options) { o.setBoolValue(o.getName() == mode); } }, }; ## create and initialize input field properties if necessary # var apset = props.globals.getNode("/autopilot/settings", 1); foreach (var p; ["heading-bug-deg", "true-heading-deg", "vertical-speed-fpm", "target-pitch-deg", "target-aoa-deg", "target-altitude-ft", "target-agl-ft", "target-speed-kt"]) { if ((var n = apset.getNode(p)) == nil or n.getType() == "NONE") { apset.getNode(p, 1).setDoubleValue(0); } } var dlg = props.globals.getNode("/sim/gui/dialogs/autopilot", 1); # - first entry ("heading" etc.) is the target property in /autopilot/locks/ *and* # the checkbox state property name (with "-active" appended); # - second entry is a list of available options for the /autopilot/locks/* property # and used as radio button state property; the first list entry is used as default # var hdg = Group.new("heading", ["dg-heading-hold", "wing-leveler", "true-heading-hold", "nav1-hold"]); var vel = Group.new("speed", ["speed-with-throttle", "speed-with-pitch-trim"]); var alt = Group.new("altitude", ["altitude-hold", "vertical-speed-hold", "pitch-hold", "aoa-hold", "agl-hold", "gs1-hold"]); hdg.del(); vel.del(); alt.del(); hbox 8 vbox hbox fill /sim/gui/dialogs/autopilot/heading-active true dialog-apply nasal table right 0 0 0 1 /sim/gui/dialogs/autopilot/wing-leveler true nasal right 1 0 1 1 /sim/gui/dialogs/autopilot/dg-heading-hold true nasal 1 2 /autopilot/settings/heading-bug-deg true dialog-apply right 2 0 /autopilot/settings/gps-driving-true-heading /autopilot/settings/gps-driving-true-heading right 2 0 2 1 /sim/gui/dialogs/autopilot/true-heading-hold true nasal /autopilot/settings/gps-driving-true-heading 2 2 /autopilot/settings/true-heading-deg true dialog-apply /autopilot/settings/gps-driving-true-heading right 2 2 %3.0f* /autopilot/settings/true-heading-deg true right 3 0 3 1 /sim/gui/dialogs/autopilot/nav1-hold true nasal hbox fill /sim/gui/dialogs/autopilot/speed-active true dialog-apply nasal table right 0 0 0 1 /sim/gui/dialogs/autopilot/speed-with-throttle true nasal 0 2 2 /autopilot/settings/target-speed-kt true dialog-apply right 1 0 1 1 /sim/gui/dialogs/autopilot/speed-with-pitch-trim true nasal vbox hbox fill /sim/gui/dialogs/autopilot/altitude-active true dialog-apply nasal table right 0 0 0 1 /sim/gui/dialogs/autopilot/vertical-speed-hold true nasal 0 2 /autopilot/settings/vertical-speed-fpm true dialog-apply right 1 0 1 1 /sim/gui/dialogs/autopilot/pitch-hold true nasal 1 2 /autopilot/settings/target-pitch-deg true dialog-apply right 2 0 2 1 /sim/gui/dialogs/autopilot/aoa-hold true nasal 2 2 /autopilot/settings/target-aoa-deg true dialog-apply right 3 0 3 1 /sim/gui/dialogs/autopilot/altitude-hold true nasal 3 2 /autopilot/settings/target-altitude-ft true dialog-apply right 4 0 4 1 /sim/gui/dialogs/autopilot/agl-hold true nasal 4 2 /autopilot/settings/target-agl-ft true dialog-apply right 5 0 5 1 /sim/gui/dialogs/autopilot/gs1-hold true nasal true hbox center /autopilot/locks/passive-mode true dialog-apply property-toggle