input-systems vbox true 600 var DLGROOT = cmdarg(); var dlg_prefix = "/sim/gui/dialogs/" ~DLGROOT.getNode("name", 1).getValue()~"/"; var systems = { "js": "Joystick", "hid": "USB HID", "linux": "Linux Event Input" }; var path_selected = props.getNode("/input/event", 1); # setup a device list # list: dialog list element to setup # input_system: 'event' or 'joystick' # class: for input_system 'event', filter devices by _class-id var setupList = func(list, input_system, class, child="device") { var list_items = props.globals.getNode(dlg_prefix~list, 1); list_items.removeChildren(); foreach (var device; props.globals.getNode("/input/"~input_system).getChildren(child)) { if (class) { var cid = device.getChild("_class-id"); if (cid and cid.getValue() == class) { list_items.addChild("value").setValue(device.getValue("name")~" ("~device.getIndex()~")"); list_items.addChild("path").setValue(device.getPath()); } } else { # name is displayed in the list list_items.addChild("value").setValue(device.getValue("name")); # path to device config list_items.addChild("path").setValue(device.getPath()); } } } # populate list boxes for all three input systems setupList("js-devs", "joysticks", "", "js"); setupList("hid-devs", "hid", "FGHIDDevice"); setupList("linux-devs", "event", "FGLinuxInputDevice"); # get nodes to display last input event of selected device var last_name = props.getNode(dlg_prefix~"last-name", 1); var last_value = props.getNode(dlg_prefix~"last-value", 1); var selected_variant = props.getNode(dlg_prefix~"variant", 1); # update the info section of the dialog when an list item is clicked # see bindings below var updateInfo = func(sys) { setprop(dlg_prefix~"system", systems[sys]); var list = props.globals.getNode(dlg_prefix~sys~"-devs"); var selected = getprop(dlg_prefix~"devname"); foreach (var v; list.getChildren("value")) { if (v.getValue() == selected) { path_selected = list.getChild("path", v.getIndex()); var device_config = props.getNode(path_selected.getValue()); # link dialog elements to currently selected device last_name.unalias(); last_name.alias(path_selected.getValue()~"/last-event/name"); last_value.unalias(); last_value.alias(path_selected.getValue()~"/last-event/value"); setprop(dlg_prefix~"cfgfile", string.squeeze(device_config.getChild("source").getValue(), 75)); # update variants and open device specific dialog if available updateVariantListbox(device_config); deviceDialog(device_config); } } } # update config variant listbox var updateVariantListbox = func(cfg) { var variants = cfg.getNode("config-variants", 1).getChildren("variant"); var selected = cfg.getNode("_selected-variant", 1).getValue() or ''; var list_items = props.globals.getNode(dlg_prefix~"variants", 1); list_items.removeChildren(); selected_variant.setValue(''); if (size(variants)) { foreach (var v; variants) { var id = v.getNode("id").getValue(); var description = v.getNode("description").getValue(); list_items.addChild("id").setValue(id); list_items.addChild("value").setValue(description); if (id == selected) { selected_variant.setValue(description); } } } DLGROOT.setValues({ "dialog-name": DLGROOT.getNode("name", 1).getValue(), "object-name": "listvariant" }); fgcommand("dialog-update", DLGROOT); } # a device specific dialog can be opened provided that # such dialog exists in FGDATA/gui/dialogs/ # and the config contains a device-dialog tag with the name of the dialog var deviceDialog = func(cfg) { var d = cfg.getNode("device-dialog"); if (d) fgcommand("dialog-show", props.Node.new({"dialog-name": d.getValue()})); } # apply config variant var applyVariant = func() { var cfg = props.getNode(path_selected.getValue(), 1); var list = props.globals.getNode(dlg_prefix~"variants", 1); foreach (var v; list.getChildren("value")) { if (v.getValue() == selected_variant.getValue()) { cfg.getNode("_selected-variant", 1) .setValue(list.getChild("id", v.getIndex()).getValue()); } } } hbox true button-bar-top hbox hbox vbox hbox left /sim/input/no-joystick-input /sim/input/no-joystick-input true /sim/input/no-joystick-input joysticks left 350 100 /sim/gui/dialogs/input-systems/devname /sim/gui/dialogs/input-systems/js-devs dialog-apply joysticks nasal hbox left /sim/input/no-hid-input /sim/input/no-hid-input true /sim/input/no-hid-input hids left 350 100 /sim/gui/dialogs/input-systems/devname /sim/gui/dialogs/input-systems/hid-devs dialog-apply hids nasal hbox left /sim/input/no-event-input /sim/input/no-event-input true /sim/input/no-event-input linux left 350 100 /sim/gui/dialogs/input-systems/devname /sim/gui/dialogs/input-systems/linux-devs dialog-apply linux nasal vbox top left listvariant left 200 150 /sim/gui/dialogs/input-systems/variant /sim/gui/dialogs/input-systems/variants dialog-apply listvariant nasal selected-variant left true /sim/gui/dialogs/input-systems/variant devinfo table 00 50 left 01 system left true /sim/gui/dialogs/input-systems/system 02 200 devname left true /sim/gui/dialogs/input-systems/devname 10 left 11 3 cfgfile left true /sim/gui/dialogs/input-systems/cfgfile 20 50 left /sim/gui/dialogs/input-systems/system Joystick 21 100 lastname left true /sim/gui/dialogs/input-systems/last-name 22 lastvalue left true /sim/gui/dialogs/input-systems/last-value button-bar-bottom hbox