| 1 | <?xml version="1.0"?> |
| 2 | |
| 3 | <PropertyList> |
| 4 | <name>input-config-select</name> |
| 5 | <layout>vbox</layout> |
| 6 | <resizable>true</resizable> |
| 7 | <pref-width>350</pref-width> |
| 8 | |
| 9 | <nasal> |
| 10 | <open> |
| 11 | <![CDATA[ |
| 12 | var DLGROOT = cmdarg(); |
| 13 | var dlg_prefix = "/sim/gui/dialogs/" |
| 14 | ~DLGROOT.getNode("name", 1).getValue()~"/"; |
| 15 | |
| 16 | var devices = input_helpers.config_manager.devicesWithVariants(); |
| 17 | props.getNode(dlg_prefix~"_max_devices",1).setValue(size(devices) - 1); |
| 18 | |
| 19 | var current_device = props.getNode(dlg_prefix~"_current_device",1) |
| 20 | .initNode('', 0, "INT"); |
| 21 | |
| 22 | var selected_variant = props.getNode(dlg_prefix~"variant", 1); |
| 23 | |
| 24 | |
| 25 | # show previous device |
| 26 | var prev = func() { |
| 27 | if (current_device.getValue() > 0) |
| 28 | current_device.decrement(); |
| 29 | DLGROOT.setValues({"dialog-name": DLGROOT.getNode("name", 1).getValue()}); |
| 30 | fgcommand("dialog-close", DLGROOT); |
| 31 | fgcommand("dialog-show", DLGROOT); |
| 32 | } |
| 33 | |
| 34 | # show next device |
| 35 | var next = func() { |
| 36 | if (current_device.getValue() < size(devices) - 1) |
| 37 | current_device.increment(); |
| 38 | DLGROOT.setValues({"dialog-name": DLGROOT.getNode("name", 1).getValue()}); |
| 39 | fgcommand("dialog-close", DLGROOT); |
| 40 | fgcommand("dialog-show", DLGROOT); |
| 41 | } |
| 42 | |
| 43 | # update dialog elements |
| 44 | var update = func(device) { |
| 45 | setprop(dlg_prefix~"devname", device.getNode("name").getValue()); |
| 46 | setprop(dlg_prefix~"devpath", device.getPath()); |
| 47 | setprop(dlg_prefix~"variant", ''); |
| 48 | setprop(dlg_prefix~"has-device-dialog", 0); |
| 49 | var variants = device.getNode("config-variants", 1).getChildren("variant"); |
| 50 | var selected = device.getNode("_selected-variant", 1).getValue() or ''; |
| 51 | var list_items = props.globals.getNode(dlg_prefix~"variants", 1); |
| 52 | list_items.removeChildren(); |
| 53 | selected_variant.setValue(''); |
| 54 | |
| 55 | if (size(variants)) { |
| 56 | foreach (var v; variants) { |
| 57 | var id = v.getNode("id").getValue(); |
| 58 | var description = v.getNode("description").getValue(); |
| 59 | list_items.addChild("id").setValue(id); |
| 60 | list_items.addChild("value").setValue(description); |
| 61 | if (id == selected) { |
| 62 | selected_variant.setValue(description); |
| 63 | } |
| 64 | } |
| 65 | if (device.getNode("device-dialog")) |
| 66 | setprop(dlg_prefix~"has-device-dialog", 1); |
| 67 | } |
| 68 | DLGROOT.setValues({"dialog-name": DLGROOT.getNode("name", 1).getValue()}); |
| 69 | fgcommand("dialog-update", DLGROOT); |
| 70 | } |
| 71 | |
| 72 | # apply config variant |
| 73 | var applyVariant = func() { |
| 74 | var cfg = devices[current_device.getIntValue()]; |
| 75 | var list = props.globals.getNode(dlg_prefix~"variants", 1); |
| 76 | foreach (var v; list.getChildren("value")) { |
| 77 | if (v.getValue() == selected_variant.getValue()) { |
| 78 | cfg.getNode("_selected-variant", 1) |
| 79 | .setValue(list.getChild("id", v.getIndex()).getValue()); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | var deviceDialog = func() { |
| 85 | var d = devices[current_device.getIntValue()].getNode("device-dialog"); |
| 86 | if (d) { |
| 87 | var dname = d.getValue(); |
| 88 | if (dname) |
| 89 | fgcommand("dialog-show", props.Node.new({"dialog-name": dname})); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | # init dialog |
| 94 | update(devices[current_device.getIntValue()]); |
| 95 | ]]> |
| 96 | </open> |
| 97 | </nasal> |
| 98 | |
| 99 | <group> |
| 100 | <layout>hbox</layout> |
| 101 | <text> |
| 102 | <label>Configuration Selector</label> |
| 103 | </text> |
| 104 | <empty><stretch>true</stretch></empty> |
| 105 | <button> |
| 106 | <legend>X</legend> |
| 107 | <key>Esc</key> |
| 108 | <pref-width>20</pref-width> |
| 109 | <pref-height>20</pref-height> |
| 110 | <binding> |
| 111 | <command>dialog-close</command> |
| 112 | </binding> |
| 113 | </button> |
| 114 | </group> |
| 115 | <hrule/> |
| 116 | <group> |
| 117 | <layout>vbox</layout> |
| 118 | <valign>top</valign> |
| 119 | <text> |
| 120 | <pref-width>200</pref-width> |
| 121 | <name>devname</name> |
| 122 | <halign>left</halign> |
| 123 | <live>true</live> |
| 124 | <property>/sim/gui/dialogs/input-config-select/devname</property> |
| 125 | </text> |
| 126 | <text> |
| 127 | <pref-width>200</pref-width> |
| 128 | <name>devpath</name> |
| 129 | <halign>left</halign> |
| 130 | <live>true</live> |
| 131 | <property>/sim/gui/dialogs/input-config-select/devpath</property> |
| 132 | </text> |
| 133 | <text> |
| 134 | <label>Available variants</label> |
| 135 | <halign>left</halign> |
| 136 | </text> |
| 137 | <list> |
| 138 | <name>listvariant</name> |
| 139 | <halign>left</halign> |
| 140 | <pref-width>250</pref-width> |
| 141 | <pref-height>150</pref-height> |
| 142 | <property>/sim/gui/dialogs/input-config-select/variant</property> |
| 143 | <properties>/sim/gui/dialogs/input-config-select/variants</properties> |
| 144 | <binding> |
| 145 | <command>dialog-apply</command> |
| 146 | <object-name>listvariant</object-name> |
| 147 | </binding> |
| 148 | <binding> |
| 149 | <command>nasal</command> |
| 150 | <script>applyVariant();</script> |
| 151 | </binding> |
| 152 | </list> |
| 153 | </group> |
| 154 | <group> |
| 155 | <layout>hbox</layout> |
| 156 | <valign>top</valign> |
| 157 | <text> |
| 158 | <label>Selected:</label> |
| 159 | <halign>left</halign> |
| 160 | </text> |
| 161 | <text> |
| 162 | <pref-width>200</pref-width> |
| 163 | <name>selected</name> |
| 164 | <halign>left</halign> |
| 165 | <live>true</live> |
| 166 | <property>/sim/gui/dialogs/input-config-select/variant</property> |
| 167 | </text> |
| 168 | </group> |
| 169 | <hrule/> |
| 170 | <group> |
| 171 | <name>button-bar</name> |
| 172 | <layout>hbox</layout> |
| 173 | <button> |
| 174 | <name>prev</name> |
| 175 | <legend><</legend> |
| 176 | <enable> |
| 177 | <greater-than> |
| 178 | <property>/sim/gui/dialogs/input-config-select/_current_device</property> |
| 179 | <value type="int">0</value> |
| 180 | </greater-than> |
| 181 | </enable> |
| 182 | <binding> |
| 183 | <command>nasal</command> |
| 184 | <script>prev();</script> |
| 185 | </binding> |
| 186 | </button> |
| 187 | <button> |
| 188 | <legend>Done</legend> |
| 189 | <binding> |
| 190 | <command>dialog-close</command> |
| 191 | <dialog-name>input-config-select</dialog-name> |
| 192 | </binding> |
| 193 | </button> |
| 194 | <button> |
| 195 | <legend>Device Dialog</legend> |
| 196 | <enable> |
| 197 | <property>/sim/gui/dialogs/input-config-select/has-device-dialog</property> |
| 198 | </enable> |
| 199 | <binding> |
| 200 | <command>nasal</command> |
| 201 | <script>deviceDialog();</script> |
| 202 | </binding> |
| 203 | </button> |
| 204 | <button> |
| 205 | <name>next</name> |
| 206 | <legend>></legend> |
| 207 | <enable> |
| 208 | <less-than> |
| 209 | <property>/sim/gui/dialogs/input-config-select/_current_device</property> |
| 210 | <property>/sim/gui/dialogs/input-config-select/_max_devices</property> |
| 211 | </less-than> |
| 212 | </enable> |
| 213 | <binding> |
| 214 | <command>nasal</command> |
| 215 | <script>next();</script> |
| 216 | </binding> |
| 217 | </button> |
| 218 | </group> |
| 219 | </PropertyList> |