controlsMenu.tscript 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 fillRemapList()
  117. {
  118. %device = $remapListDevice;
  119. OptionsMenuSettingsList.clear();
  120. //build out our list of action maps
  121. %actionMapCount = ActionMapGroup.getCount();
  122. %actionMapList = "";
  123. for(%i=0; %i < %actionMapCount; %i++)
  124. {
  125. %actionMap = ActionMapGroup.getObject(%i);
  126. if(%actionMap == GlobalActionMap.getId())
  127. continue;
  128. %actionMapName = %actionMap.humanReadableName $= "" ? %actionMap.getName() : %actionMap.humanReadableName;
  129. //see if we have any actual listed remappable keys for this movemap. if so, drop it from the listing
  130. %hasRemaps = false;
  131. for ( %r = 0; %r < $RemapCount; %r++ )
  132. {
  133. %testMapName = $RemapActionMap[%r].humanReadableName $= "" ? $RemapActionMap[%r].getName() : $RemapActionMap[%r].humanReadableName;
  134. if(%actionMapName $= %testMapName)
  135. {
  136. //got a match to at least one, so we're ok to continue
  137. %hasRemaps = true;
  138. break;
  139. }
  140. }
  141. if(!%hasRemaps)
  142. continue;
  143. if(%actionMapList $= "")
  144. %actionMapList = %actionMapName;
  145. else
  146. %actionMapList = %actionMapList TAB %actionMapName;
  147. }
  148. //If we didn't find any valid actionMaps, then just exit out
  149. if(%actionMapList $= "")
  150. return;
  151. if($activeRemapControlSet $= "")
  152. $activeRemapControlSet = getField(%actionMapList, 0);
  153. OptionsMenuSettingsList.addOptionRow("Control Set", "$activeRemapControlSet", %actionMapList, false, "controlSetChanged", true, "Which keybind control set to edit", $activeRemapControlSet);
  154. for ( %i = 0; %i < $RemapCount; %i++ )
  155. {
  156. if(%device !$= "" && %device !$= $RemapDevice[%i])
  157. continue;
  158. %actionMapName = $RemapActionMap[%i].humanReadableName $= "" ? $RemapActionMap[%i].getName() : $RemapActionMap[%i].humanReadableName;
  159. if($activeRemapControlSet !$= %actionMapName)
  160. continue;
  161. %keyMap = buildFullMapString( %i, $RemapActionMap[%i], %device );
  162. %description = $RemapDescription[%i];
  163. %buttonImageAsset = getButtonBitmap(%device, getField(%keyMap, 1));
  164. OptionsMenuSettingsList.addKeybindRow(getField(%keyMap, 0), %buttonImageAsset, "doKeyRemap", true, %description, %i);
  165. }
  166. //OptionsMenuSettingsList.refresh();
  167. //OptionsMenu.addRow( %i, %this.buildFullMapString( %i ) );
  168. }
  169. function controlSetChanged()
  170. {
  171. $activeRemapControlSet = OptionsMenuSettingsList.getObject(0).getCurrentOption();
  172. fillRemapList();
  173. }
  174. function ControlsMenuRebindButton::onClick(%this)
  175. {
  176. %name = $RemapName[%this.keybindIndex];
  177. RemapDlg-->OptRemapText.text = "Re-bind \"" @ %name @ "\" to..." ;
  178. OptRemapInputCtrl.index = %this.keybindIndex;
  179. OptRemapInputCtrl.optionIndex = %this.optionIndex;
  180. Canvas.pushDialog( RemapDlg );
  181. }
  182. function findRemapCmdIndex( %command )
  183. {
  184. for ( %i = 0; %i < $RemapCount; %i++ )
  185. {
  186. if ( %command $= $RemapCmd[%i] )
  187. return( %i );
  188. }
  189. return( -1 );
  190. }
  191. function redoMapping( %device, %actionMap, %action, %cmd, %oldIndex, %newIndex )
  192. {
  193. //%actionMap.bind( %device, %action, $RemapCmd[%newIndex] );
  194. %actionMap.bind( %device, %action, %cmd );
  195. fillRemapList();
  196. }