controlsMenu.tscript 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // =============================================================================
  2. // KEYBINDS MENU
  3. // =============================================================================
  4. function ControlsMenuDefaultsButton::onClick(%this)
  5. {
  6. //For this to work with module-style, we have to figure that somewhere, we'll set where our default keybind script is at.
  7. //This can be hardcoded in your actual project.
  8. //exec($KeybindPath);
  9. //ControlsMenu.reload();
  10. }
  11. function getMapDisplayName( %device, %action )
  12. {
  13. if ( %device $= "keyboard" )
  14. return( %action );
  15. else if ( strstr( %device, "mouse" ) != -1 )
  16. {
  17. // Substitute "mouse" for "button" in the action string:
  18. %pos = strstr( %action, "button" );
  19. if ( %pos != -1 )
  20. {
  21. %mods = getSubStr( %action, 0, %pos );
  22. %object = getSubStr( %action, %pos, 1000 );
  23. %instance = getSubStr( %object, strlen( "button" ), 1000 );
  24. return( %mods @ "mouse" @ ( %instance + 1 ) );
  25. }
  26. else
  27. error( "Mouse input object other than button passed to getDisplayMapName!" );
  28. }
  29. else if ( strstr( %device, "joystick" ) != -1 )
  30. {
  31. // Substitute "joystick" for "button" in the action string:
  32. %pos = strstr( %action, "button" );
  33. if ( %pos != -1 )
  34. {
  35. %mods = getSubStr( %action, 0, %pos );
  36. %object = getSubStr( %action, %pos, 1000 );
  37. %instance = getSubStr( %object, strlen( "button" ), 1000 );
  38. return( %mods @ "joystick" @ ( %instance + 1 ) );
  39. }
  40. else
  41. {
  42. %pos = strstr( %action, "pov" );
  43. if ( %pos != -1 )
  44. {
  45. %wordCount = getWordCount( %action );
  46. %mods = %wordCount > 1 ? getWords( %action, 0, %wordCount - 2 ) @ " " : "";
  47. %object = getWord( %action, %wordCount - 1 );
  48. switch$ ( %object )
  49. {
  50. case "upov": %object = "POV1 up";
  51. case "dpov": %object = "POV1 down";
  52. case "lpov": %object = "POV1 left";
  53. case "rpov": %object = "POV1 right";
  54. case "upov2": %object = "POV2 up";
  55. case "dpov2": %object = "POV2 down";
  56. case "lpov2": %object = "POV2 left";
  57. case "rpov2": %object = "POV2 right";
  58. default: %object = "";
  59. }
  60. return( %mods @ %object );
  61. }
  62. else
  63. error( "Unsupported Joystick input object passed to getDisplayMapName!" );
  64. }
  65. }
  66. else if ( strstr( %device, "gamepad" ) != -1 )
  67. {
  68. return %action;
  69. %pos = strstr( %action, "button" );
  70. if ( %pos != -1 )
  71. {
  72. %mods = getSubStr( %action, 0, %pos );
  73. %object = getSubStr( %action, %pos, 1000 );
  74. %instance = getSubStr( %object, strlen( "button" ), 1000 );
  75. return( %mods @ "joystick" @ ( %instance + 1 ) );
  76. }
  77. else
  78. {
  79. %pos = strstr( %action, "thumb" );
  80. if ( %pos != -1 )
  81. {
  82. //%instance = getSubStr( %action, strlen( "thumb" ), 1000 );
  83. //return( "thumb" @ ( %instance + 1 ) );
  84. return %action;
  85. }
  86. else
  87. error( "Unsupported gamepad input object passed to getDisplayMapName!" );
  88. }
  89. }
  90. return( "" );
  91. }
  92. function buildFullMapString( %index, %actionMap, %deviceType )
  93. {
  94. %name = $RemapName[%index];
  95. %cmd = $RemapCmd[%index];
  96. %temp = %actionMap.getBinding( %cmd );
  97. if ( %temp $= "" )
  98. return %name TAB "";
  99. %mapString = "";
  100. %count = getFieldCount( %temp );
  101. for ( %i = 0; %i < %count; %i += 2 )
  102. {
  103. if ( %mapString !$= "" )
  104. continue;
  105. //%mapString = %mapString @ ", ";
  106. %device = getField( %temp, %i + 0 );
  107. %object = getField( %temp, %i + 1 );
  108. if (startsWith(%device,"mouse"))
  109. %deviceType = "mouse";
  110. if(%deviceType !$= "" && !startsWith(%device, %deviceType))
  111. continue;
  112. %mapString = %mapString @ getMapDisplayName( %device, %object );
  113. }
  114. return %name TAB %mapString;
  115. }
  116. function ControlsMenuRebindButton::onClick(%this)
  117. {
  118. %name = $RemapName[%this.keybindIndex];
  119. RemapDlg-->OptRemapText.text = "Re-bind \"" @ %name @ "\" to..." ;
  120. OptRemapInputCtrl.index = %this.keybindIndex;
  121. OptRemapInputCtrl.optionIndex = %this.optionIndex;
  122. Canvas.pushDialog( RemapDlg );
  123. }
  124. function findRemapCmdIndex( %command )
  125. {
  126. for ( %i = 0; %i < $RemapCount; %i++ )
  127. {
  128. if ( %command $= $RemapCmd[%i] )
  129. return( %i );
  130. }
  131. return( -1 );
  132. }
  133. function redoMapping( %device, %actionMap, %action, %cmd, %oldIndex, %newIndex )
  134. {
  135. //%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
  136. %actionMap.bind( %device, %action, %cmd );
  137. OptionsMenu.populateKBMControls();
  138. OptionsMenu.populateGamepadControls();
  139. }