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 { m.update(cmdarg().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 00 01 /sim/gui/dialogs/autopilot/wing-leveler true nasal right 10 11 /sim/gui/dialogs/autopilot/dg-heading-hold true nasal 12 /autopilot/settings/heading-bug-deg true dialog-apply right 20 21 /sim/gui/dialogs/autopilot/true-heading-hold true nasal 22 /autopilot/settings/true-heading-deg true dialog-apply right 30 31 /sim/gui/dialogs/autopilot/nav1-hold true nasal hbox fill /sim/gui/dialogs/autopilot/speed-active true dialog-apply nasal table right 00 01 /sim/gui/dialogs/autopilot/speed-with-throttle true nasal 02 2 /autopilot/settings/target-speed-kt true dialog-apply right 10 11 /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 00 01 /sim/gui/dialogs/autopilot/vertical-speed-hold true nasal 02 /autopilot/settings/vertical-speed-fpm true dialog-apply right 10 11 /sim/gui/dialogs/autopilot/pitch-hold true nasal 12 /autopilot/settings/target-pitch-deg true dialog-apply right 20 21 /sim/gui/dialogs/autopilot/aoa-hold true nasal 22 /autopilot/settings/target-aoa-deg true dialog-apply right 30 31 /sim/gui/dialogs/autopilot/altitude-hold true nasal 32 /autopilot/settings/target-altitude-ft true dialog-apply right 40 41 /sim/gui/dialogs/autopilot/agl-hold true nasal 42 /autopilot/settings/target-agl-ft true dialog-apply right 50 51 /sim/gui/dialogs/autopilot/gs1-hold true nasal true