joystickSettings.tscript 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. function JoystickSettingsDlg::onWake(%this)
  2. {
  3. %this.updateDevices();
  4. }
  5. function JoystickSettingsDlg::closeSettings(%this)
  6. {
  7. Canvas.popDialog(%this);
  8. Canvas.pushDialog(InputMonitorDlg);
  9. }
  10. function JoystickSettingsDlg::updateDevices(%this)
  11. {
  12. %this-->deviceArray.deleteAllObjects();
  13. %sdlDevices = 0;
  14. if (isMethod("SDLInputManager", "numJoysticks"))
  15. %sdlDevices = SDLInputManager::numJoysticks();
  16. for (%i = 0; %i < %sdlDevices; %i++)
  17. {
  18. %guiCtrl = DevicePrototype.deepClone();
  19. %this-->deviceArray.addGuiControl(%guiCtrl);
  20. %guiCtrl.visible = true;
  21. %guiCtrl.canSave = false;
  22. %openState = SDLInputManager::getDeviceOpenState(%i);
  23. if (%openState > 0)
  24. {
  25. %torqueInst = SDLInputManager::getTorqueInstFromDevice(%i);
  26. %stateStr = "Opened as " @ %torqueInst;
  27. }
  28. else
  29. %stateStr = "Closed";
  30. %guiCtrl->DeviceOpen.setText(%stateStr);
  31. if (%openState == 2)
  32. %deviceName = SDLInputManager::ControllerNameForIndex(%i);
  33. else
  34. %deviceName = SDLInputManager::JoystickNameForIndex(%i);
  35. %guiCtrl->DeviceName.setText(%deviceName);
  36. %guidStr = SDLInputManager::JoystickGetGUID(%i);
  37. %guiCtrl->DeviceGUID.setText("GUID: " @ %guidStr);
  38. // Note: all of the device values could be retrieved individually with:
  39. // SDLInputManager::JoystickNumAxes(%i), SDLInputManager::JoystickNumButtons(%i),
  40. // SDLInputManager::JoystickNumHats(%i), SDLInputManager::JoystickNumBalls(%i),
  41. // SDLInputManager::JoystickIsHaptic(%i), SDLInputManager::JoystickPowerLevel(%i)
  42. //
  43. %deviceSpecs = SDLInputManager::JoystickGetSpecs(%i);
  44. %vendorId = SDLInputManager::GetVendor(%i);
  45. %productId = SDLInputManager::GetProduct(%i);
  46. %productVersion = SDLInputManager::GetProductVersion(%i);
  47. %specStr = getField(%deviceSpecs,0) @ " Axes, " @ getField(%deviceSpecs, 1) @ " Buttons, ";
  48. %specStr = %specStr @ getField(%deviceSpecs, 2) @ " POV Hats, " @ getField(%deviceSpecs, 3) @ " Trackballs, ";
  49. if (getField(%deviceSpecs, 5))
  50. %specStr = %specStr @ "Haptic, ";
  51. %powerLevel = getField(%deviceSpecs, 6);
  52. if (%powerLevel $= "Wired")
  53. %specStr = %specStr @ "Wired";
  54. else
  55. %specStr = %specStr @ "Battery: " @ %powerLevel;
  56. %guiCtrl->DeviceSpecs.setText(%specStr);
  57. %isController = getField(%deviceSpecs, 4);
  58. %deviceType = getField(%deviceSpecs, 7);
  59. %details = "Type: " @ %deviceType @ ", Vendor ID: " @ %vendorId;
  60. %details = %details @ ", Product ID: " @ %productId @ ", Version: " @ %productVersion;
  61. %guiCtrl->DeviceDetails.setText(%details);
  62. // Setup Buttons
  63. if (%openState > 0)
  64. {
  65. %guiCtrl->button2.setText("Close Device");
  66. %guiCtrl->button2.visible = true;
  67. %guiCtrl->button2.command = "SDLInputManager::closeDevice(" @ %i @ ");";
  68. if (%openState == 2)
  69. {
  70. %guiCtrl->button1.setText("Open as Joystick");
  71. %guiCtrl->button1.visible = true;
  72. %guiCtrl->button1.command = "SDLInputManager::openAsJoystick(" @ %i @ ");";
  73. }
  74. else
  75. {
  76. %guiCtrl->button1.setText("Open as Game Controller");
  77. %guiCtrl->button1.visible = true;
  78. %guiCtrl->button1.command = "SDLInputManager::openAsController(" @ %i @ ");";
  79. }
  80. }
  81. else
  82. {
  83. %guiCtrl->button1.setText("Open as Joystick");
  84. %guiCtrl->button1.visible = true;
  85. %guiCtrl->button1.command = "SDLInputManager::openAsJoystick(" @ %i @ ");";
  86. %guiCtrl->button2.setText("Open as Game Controller");
  87. %guiCtrl->button2.visible = true;
  88. %guiCtrl->button2.command = "SDLInputManager::openAsController(" @ %i @ ");";
  89. }
  90. // After the command executes, refresh this device list
  91. %guiCtrl->button1.command = %guiCtrl->button1.command @ "JoystickSettingsDlg.updateDevices();";
  92. %guiCtrl->button2.command = %guiCtrl->button2.command @ "JoystickSettingsDlg.updateDevices();";
  93. }
  94. }