| 1 |
<?xml version="1.0"?> |
| 2 |
|
| 3 |
<PropertyList> |
| 4 |
<name>input-systems</name> |
| 5 |
<layout>vbox</layout> |
| 6 |
<resizable>true</resizable> |
| 7 |
<pref-width>600</pref-width> |
| 8 |
|
| 9 |
<nasal> |
| 10 |
<open> |
| 11 |
var DLGROOT = cmdarg(); |
| 12 |
var dlg_prefix = "/sim/gui/dialogs/" |
| 13 |
~DLGROOT.getNode("name", 1).getValue()~"/"; |
| 14 |
var systems = { |
| 15 |
"js": "Joystick", |
| 16 |
"hid": "USB HID", |
| 17 |
"linux": "Linux Event Input" |
| 18 |
}; |
| 19 |
var path_selected = props.getNode("/input/event", 1); |
| 20 |
|
| 21 |
# setup a device list |
| 22 |
# list: dialog list element to setup |
| 23 |
# input_system: 'event' or 'joystick' |
| 24 |
# class: for input_system 'event', filter devices by _class-id |
| 25 |
var setupList = func(list, input_system, class, child="device") { |
| 26 |
var list_items = props.globals.getNode(dlg_prefix~list, 1); |
| 27 |
list_items.removeChildren(); |
| 28 |
foreach (var device; props.globals.getNode("/input/"~input_system).getChildren(child)) { |
| 29 |
if (class) { |
| 30 |
var cid = device.getChild("_class-id"); |
| 31 |
if (cid and cid.getValue() == class) { |
| 32 |
list_items.addChild("value").setValue(device.getValue("name")~" ("~device.getIndex()~")"); |
| 33 |
list_items.addChild("path").setValue(device.getPath()); |
| 34 |
} |
| 35 |
} |
| 36 |
else { |
| 37 |
# name is displayed in the list |
| 38 |
list_items.addChild("value").setValue(device.getValue("name")); |
| 39 |
# path to device config |
| 40 |
list_items.addChild("path").setValue(device.getPath()); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
# populate list boxes for all three input systems |
| 46 |
setupList("js-devs", "joysticks", "", "js"); |
| 47 |
setupList("hid-devs", "hid", "FGHIDDevice"); |
| 48 |
setupList("linux-devs", "event", "FGLinuxInputDevice"); |
| 49 |
|
| 50 |
# get nodes to display last input event of selected device |
| 51 |
var last_name = props.getNode(dlg_prefix~"last-name", 1); |
| 52 |
var last_value = props.getNode(dlg_prefix~"last-value", 1); |
| 53 |
var selected_variant = props.getNode(dlg_prefix~"variant", 1); |
| 54 |
|
| 55 |
# update the info section of the dialog when an list item is clicked |
| 56 |
# see bindings below |
| 57 |
var updateInfo = func(sys) { |
| 58 |
setprop(dlg_prefix~"system", systems[sys]); |
| 59 |
var list = props.globals.getNode(dlg_prefix~sys~"-devs"); |
| 60 |
var selected = getprop(dlg_prefix~"devname"); |
| 61 |
foreach (var v; list.getChildren("value")) { |
| 62 |
if (v.getValue() == selected) { |
| 63 |
path_selected = list.getChild("path", v.getIndex()); |
| 64 |
var device_config = props.getNode(path_selected.getValue()); |
| 65 |
|
| 66 |
# link dialog elements to currently selected device |
| 67 |
last_name.unalias(); |
| 68 |
last_name.alias(path_selected.getValue()~"/last-event/name"); |
| 69 |
last_value.unalias(); |
| 70 |
last_value.alias(path_selected.getValue()~"/last-event/value"); |
| 71 |
|
| 72 |
setprop(dlg_prefix~"cfgfile", |
| 73 |
string.squeeze(device_config.getChild("source").getValue(), 75)); |
| 74 |
|
| 75 |
# update variants and open device specific dialog if available |
| 76 |
updateVariantListbox(device_config); |
| 77 |
deviceDialog(device_config); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
# update config variant listbox |
| 83 |
var updateVariantListbox = func(cfg) { |
| 84 |
var variants = cfg.getNode("config-variants", 1).getChildren("variant"); |
| 85 |
var selected = cfg.getNode("_selected-variant", 1).getValue() or ''; |
| 86 |
var list_items = props.globals.getNode(dlg_prefix~"variants", 1); |
| 87 |
list_items.removeChildren(); |
| 88 |
selected_variant.setValue(''); |
| 89 |
|
| 90 |
if (size(variants)) { |
| 91 |
foreach (var v; variants) { |
| 92 |
var id = v.getNode("id").getValue(); |
| 93 |
var description = v.getNode("description").getValue(); |
| 94 |
list_items.addChild("id").setValue(id); |
| 95 |
list_items.addChild("value").setValue(description); |
| 96 |
if (id == selected) { |
| 97 |
selected_variant.setValue(description); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
DLGROOT.setValues({ |
| 103 |
"dialog-name": DLGROOT.getNode("name", 1).getValue(), |
| 104 |
"object-name": "listvariant" |
| 105 |
}); |
| 106 |
fgcommand("dialog-update", DLGROOT); |
| 107 |
} |
| 108 |
|
| 109 |
# a device specific dialog can be opened provided that |
| 110 |
# such dialog exists in FGDATA/gui/dialogs/ |
| 111 |
# and the config contains a device-dialog tag with the name of the dialog |
| 112 |
var deviceDialog = func(cfg) { |
| 113 |
var d = cfg.getNode("device-dialog"); |
| 114 |
if (d) fgcommand("dialog-show", props.Node.new({"dialog-name": d.getValue()})); |
| 115 |
} |
| 116 |
|
| 117 |
# apply config variant |
| 118 |
var applyVariant = func() { |
| 119 |
var cfg = props.getNode(path_selected.getValue(), 1); |
| 120 |
var list = props.globals.getNode(dlg_prefix~"variants", 1); |
| 121 |
foreach (var v; list.getChildren("value")) { |
| 122 |
if (v.getValue() == selected_variant.getValue()) { |
| 123 |
cfg.getNode("_selected-variant", 1) |
| 124 |
.setValue(list.getChild("id", v.getIndex()).getValue()); |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
</open> |
| 129 |
</nasal> |
| 130 |
|
| 131 |
<group> |
| 132 |
<layout>hbox</layout> |
| 133 |
<text> |
| 134 |
<label>Input Devices</label> |
| 135 |
</text> |
| 136 |
<empty><stretch>true</stretch></empty> |
| 137 |
|
| 138 |
<button> |
| 139 |
<legend>X</legend> |
| 140 |
<key>Esc</key> |
| 141 |
<pref-width>20</pref-width> |
| 142 |
<pref-height>20</pref-height> |
| 143 |
<binding> |
| 144 |
<command>dialog-close</command> |
| 145 |
</binding> |
| 146 |
</button> |
| 147 |
</group> |
| 148 |
|
| 149 |
<hrule/> |
| 150 |
<group> |
| 151 |
<name>button-bar-top</name> |
| 152 |
<layout>hbox</layout> |
| 153 |
<button> |
| 154 |
<name>mouse-config</name> |
| 155 |
<legend>Mouse Config</legend> |
| 156 |
<key>m</key> |
| 157 |
<binding> |
| 158 |
<command>dialog-show</command> |
| 159 |
<dialog-name>mouse-config</dialog-name> |
| 160 |
</binding> |
| 161 |
</button> |
| 162 |
<button> |
| 163 |
<name>joystick-config</name> |
| 164 |
<legend>Joystick Config</legend> |
| 165 |
<key>j</key> |
| 166 |
<enable> |
| 167 |
<not><property>/sim/input/no-joystick-input</property></not> |
| 168 |
</enable> |
| 169 |
<binding> |
| 170 |
<command>dialog-show</command> |
| 171 |
<dialog-name>joystick-config</dialog-name> |
| 172 |
</binding> |
| 173 |
</button> |
| 174 |
<button> |
| 175 |
<name>hid-config</name> |
| 176 |
<legend>HID Config</legend> |
| 177 |
<enable> |
| 178 |
<not><property>/sim/input/no-hid-input</property></not> |
| 179 |
</enable> |
| 180 |
<binding> |
| 181 |
<command>dialog-show</command> |
| 182 |
<dialog-name>hid-config</dialog-name> |
| 183 |
</binding> |
| 184 |
</button> |
| 185 |
<button> |
| 186 |
<legend>Config Variant Selector</legend> |
| 187 |
<key>v</key> |
| 188 |
<binding> |
| 189 |
<command>dialog-show</command> |
| 190 |
<dialog-name>input-config-select</dialog-name> |
| 191 |
</binding> |
| 192 |
</button> |
| 193 |
</group> |
| 194 |
<hrule /> |
| 195 |
<group> |
| 196 |
<layout>hbox</layout> |
| 197 |
<group> |
| 198 |
<layout>vbox</layout> |
| 199 |
<text> |
| 200 |
<label>Input Systems Overview</label> |
| 201 |
</text> |
| 202 |
<group> |
| 203 |
<layout>hbox</layout> |
| 204 |
<text> |
| 205 |
<halign>left</halign> |
| 206 |
<label>Joystick input</label> |
| 207 |
<enable> |
| 208 |
<not><property>/sim/input/no-joystick-input</property></not> |
| 209 |
</enable> |
| 210 |
</text> |
| 211 |
<text> |
| 212 |
<label>disabled</label> |
| 213 |
<visible> |
| 214 |
<property>/sim/input/no-joystick-input</property> |
| 215 |
</visible> |
| 216 |
</text> |
| 217 |
<empty><stretch>true</stretch></empty> |
| 218 |
</group> |
| 219 |
<list> |
| 220 |
<visible> |
| 221 |
<not><property>/sim/input/no-joystick-input</property></not> |
| 222 |
</visible> |
| 223 |
<name>joysticks</name> |
| 224 |
<halign>left</halign> |
| 225 |
<pref-width>350</pref-width> |
| 226 |
<pref-height>100</pref-height> |
| 227 |
<property>/sim/gui/dialogs/input-systems/devname</property> |
| 228 |
<properties>/sim/gui/dialogs/input-systems/js-devs</properties> |
| 229 |
<binding> |
| 230 |
<command>dialog-apply</command> |
| 231 |
<object-name>joysticks</object-name> |
| 232 |
</binding> |
| 233 |
<binding> |
| 234 |
<command>nasal</command> |
| 235 |
<script> |
| 236 |
updateInfo("js"); |
| 237 |
</script> |
| 238 |
</binding> |
| 239 |
</list> |
| 240 |
<group> |
| 241 |
<layout>hbox</layout> |
| 242 |
<text> |
| 243 |
<halign>left</halign> |
| 244 |
<label>USB HID input</label> |
| 245 |
<enable> |
| 246 |
<not><property>/sim/input/no-hid-input</property></not> |
| 247 |
</enable> |
| 248 |
</text> |
| 249 |
<text> |
| 250 |
<label>disabled</label> |
| 251 |
<visible> |
| 252 |
<property>/sim/input/no-hid-input</property> |
| 253 |
</visible> |
| 254 |
</text> |
| 255 |
<empty><stretch>true</stretch></empty> |
| 256 |
</group> |
| 257 |
<list> |
| 258 |
<visible> |
| 259 |
<not><property>/sim/input/no-hid-input</property></not> |
| 260 |
</visible> |
| 261 |
<name>hids</name> |
| 262 |
<halign>left</halign> |
| 263 |
<pref-width>350</pref-width> |
| 264 |
<pref-height>100</pref-height> |
| 265 |
<property>/sim/gui/dialogs/input-systems/devname</property> |
| 266 |
<properties>/sim/gui/dialogs/input-systems/hid-devs</properties> |
| 267 |
<binding> |
| 268 |
<command>dialog-apply</command> |
| 269 |
<object-name>hids</object-name> |
| 270 |
</binding> |
| 271 |
<binding> |
| 272 |
<command>nasal</command> |
| 273 |
<script> |
| 274 |
updateInfo("hid"); |
| 275 |
</script> |
| 276 |
</binding> |
| 277 |
</list> |
| 278 |
<group> |
| 279 |
<layout>hbox</layout> |
| 280 |
<text> |
| 281 |
<halign>left</halign> |
| 282 |
<label>Linux Event input</label> |
| 283 |
<enable> |
| 284 |
<not><property>/sim/input/no-event-input</property></not> |
| 285 |
</enable> |
| 286 |
</text> |
| 287 |
<text> |
| 288 |
<label>disabled</label> |
| 289 |
<visible> |
| 290 |
<property>/sim/input/no-event-input</property> |
| 291 |
</visible> |
| 292 |
</text> |
| 293 |
<empty><stretch>true</stretch></empty> |
| 294 |
</group> |
| 295 |
<list> |
| 296 |
<visible> |
| 297 |
<not><property>/sim/input/no-event-input</property></not> |
| 298 |
</visible> |
| 299 |
<name>linux</name> |
| 300 |
<halign>left</halign> |
| 301 |
<pref-width>350</pref-width> |
| 302 |
<pref-height>100</pref-height> |
| 303 |
<property>/sim/gui/dialogs/input-systems/devname</property> |
| 304 |
<properties>/sim/gui/dialogs/input-systems/linux-devs</properties> |
| 305 |
<binding> |
| 306 |
<command>dialog-apply</command> |
| 307 |
<object-name>linux</object-name> |
| 308 |
</binding> |
| 309 |
<binding> |
| 310 |
<command>nasal</command> |
| 311 |
<script> |
| 312 |
updateInfo("linux"); |
| 313 |
</script> |
| 314 |
</binding> |
| 315 |
</list> |
| 316 |
</group> |
| 317 |
|
| 318 |
<vrule/> |
| 319 |
<group> |
| 320 |
<layout>vbox</layout> |
| 321 |
<valign>top</valign> |
| 322 |
<text> |
| 323 |
<label>Config variant</label> |
| 324 |
<halign>left</halign> |
| 325 |
</text> |
| 326 |
<list> |
| 327 |
<name>listvariant</name> |
| 328 |
<halign>left</halign> |
| 329 |
<pref-width>200</pref-width> |
| 330 |
<pref-height>150</pref-height> |
| 331 |
<property>/sim/gui/dialogs/input-systems/variant</property> |
| 332 |
<properties>/sim/gui/dialogs/input-systems/variants</properties> |
| 333 |
<binding> |
| 334 |
<command>dialog-apply</command> |
| 335 |
<object-name>listvariant</object-name> |
| 336 |
</binding> |
| 337 |
<binding> |
| 338 |
<command>nasal</command> |
| 339 |
<script>applyVariant();</script> |
| 340 |
</binding> |
| 341 |
</list> |
| 342 |
<text> |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
<name>selected-variant</name> |
| 347 |
<halign>left</halign> |
| 348 |
<live>true</live> |
| 349 |
<property>/sim/gui/dialogs/input-systems/variant</property> |
| 350 |
</text> |
| 351 |
</group> |
| 352 |
</group> |
| 353 |
<hrule /> |
| 354 |
<group> |
| 355 |
<name>devinfo</name> |
| 356 |
<layout>table</layout> |
| 357 |
<text> |
| 358 |
<row>0</row><col>0</col> |
| 359 |
<pref-width>50</pref-width> |
| 360 |
<label>Device:</label> |
| 361 |
<halign>left</halign> |
| 362 |
</text> |
| 363 |
<text> |
| 364 |
<row>0</row><col>1</col> |
| 365 |
<name>system</name> |
| 366 |
<halign>left</halign> |
| 367 |
<live>true</live> |
| 368 |
<property>/sim/gui/dialogs/input-systems/system</property> |
| 369 |
</text> |
| 370 |
<text> |
| 371 |
<row>0</row><col>2</col> |
| 372 |
<pref-width>200</pref-width> |
| 373 |
<name>devname</name> |
| 374 |
<halign>left</halign> |
| 375 |
<live>true</live> |
| 376 |
<property>/sim/gui/dialogs/input-systems/devname</property> |
| 377 |
</text> |
| 378 |
|
| 379 |
<text> |
| 380 |
<row>1</row><col>0</col> |
| 381 |
<label>Config file:</label> |
| 382 |
<halign>left</halign> |
| 383 |
</text> |
| 384 |
<text> |
| 385 |
<row>1</row><col>1</col> |
| 386 |
<colspan>3</colspan> |
| 387 |
<name>cfgfile</name> |
| 388 |
<halign>left</halign> |
| 389 |
<live>true</live> |
| 390 |
<property>/sim/gui/dialogs/input-systems/cfgfile</property> |
| 391 |
</text> |
| 392 |
<text> |
| 393 |
<row>2</row><col>0</col> |
| 394 |
<pref-width>50</pref-width> |
| 395 |
<label>Last event:</label> |
| 396 |
<halign>left</halign> |
| 397 |
<visible> |
| 398 |
<not-equals> |
| 399 |
<property>/sim/gui/dialogs/input-systems/system</property> |
| 400 |
<value>Joystick</value> |
| 401 |
</not-equals> |
| 402 |
</visible> |
| 403 |
</text> |
| 404 |
<text> |
| 405 |
<row>2</row><col>1</col> |
| 406 |
<pref-width>100</pref-width> |
| 407 |
<name>lastname</name> |
| 408 |
<halign>left</halign> |
| 409 |
<live>true</live> |
| 410 |
<property>/sim/gui/dialogs/input-systems/last-name</property> |
| 411 |
</text> |
| 412 |
<text> |
| 413 |
<row>2</row><col>2</col> |
| 414 |
<name>lastvalue</name> |
| 415 |
<halign>left</halign> |
| 416 |
<live>true</live> |
| 417 |
<property>/sim/gui/dialogs/input-systems/last-value</property> |
| 418 |
</text> |
| 419 |
<button> |
| 420 |
<legend>Debug</legend> |
| 421 |
<row>2</row><col>3</col> |
| 422 |
<pref-height>20</pref-height> |
| 423 |
<binding> |
| 424 |
<command>nasal</command> |
| 425 |
<script>gui.property_browser(path_selected.getValue());</script> |
| 426 |
</binding> |
| 427 |
</button> |
| 428 |
</group> |
| 429 |
<group> |
| 430 |
<name>button-bar-bottom</name> |
| 431 |
<layout>hbox</layout> |
| 432 |
</group> |
| 433 |
</PropertyList> |