remapDlg.tscript 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. function OptRemapInputCtrl::onAxisEvent( %this, %device, %action, %axisVal)
  2. {
  3. if(%device $= "mouse")
  4. return;
  5. if(!startsWith(%device,$remapListDevice))
  6. return;
  7. if(%axisVal != 1 && %axisVal != -1) //we want full presses on sticks to be sure
  8. return;
  9. Canvas.popDialog( RemapDlg );
  10. %this.doRemap(%device, %action, %axisVal);
  11. }
  12. function OptRemapInputCtrl::onInputEvent( %this, %device, %action )
  13. {
  14. if(!startsWith(%device,$remapListDevice) && %action !$= "escape" && %action !$= "btn_start")
  15. {
  16. return;
  17. }
  18. else
  19. {
  20. Canvas.popDialog( RemapDlg );
  21. if(%action $= "escape" || %action $= "btn_start")
  22. return;
  23. %this.doRemap(%device, %action, 0);
  24. }
  25. }
  26. function OptRemapInputCtrl::doRemap(%this, %device, %action, %axisVal)
  27. {
  28. %cmd = $RemapCmd[%this.index];
  29. %name = $RemapName[%this.index];
  30. %actionMap = $RemapActionMap[%this.index];
  31. echo("OptRemapInputCtrl::onInputEvent() - remapping details: " @ %cmd @ ", " @ %name @ ", " @ %actionMap @ " remapped to: " @ %device @ ", " @ %action);
  32. // Grab the friendly display name for this action
  33. // which we'll use when prompting the user below.
  34. %mapName = getMapDisplayName( %device, %action );
  35. // Get the current command this action is mapped to.
  36. %prevMap = %actionMap.getCommand( %device, %action );
  37. //TODO: clear all existant keybinds to a command and then bind it so we only have a single one at all times
  38. unbindExtraActions( %cmd, %actionMap, %device, 0 );
  39. unbindExtraActions( %cmd, %actionMap, %device, 1 );
  40. // If nothing was mapped to the previous command
  41. // mapping then it's easy... just bind it.
  42. // If the previous command is the same as the
  43. // current then they hit the same input as what
  44. // was already assigned.
  45. if ( %prevMap $= "" || %prevMap $= %cmd )
  46. {
  47. //unbindExtraActions( %cmd, %actionMap, 1 );
  48. %actionMap.bind( %device, %action, %cmd );
  49. OptionsMenu.populateKBMControls();
  50. OptionsMenu.populateGamepadControls();
  51. return;
  52. }
  53. // Look for the index of the previous mapping.
  54. %prevMapIndex = findRemapCmdIndex( %prevMap );
  55. // If we get a negative index then the previous
  56. // mapping was to an item that isn't included in
  57. // the mapping list... so we cannot unmap it.
  58. if ( %prevMapIndex == -1 )
  59. {
  60. MessageBoxOK( "Remap Failed", "\"" @ %mapName @ "\" is already bound to a non-remappable command!" );
  61. return;
  62. }
  63. // Setup the forced remapping callback command.
  64. %callback = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @
  65. %cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");";
  66. // Warn that we're about to remove the old mapping and
  67. // replace it with another.
  68. %prevCmdName = $RemapName[%prevMapIndex];
  69. //Canvas.pushDialog( RemapConfirmDlg );
  70. %remapWarnText = "\"" @ %mapName @ "\" is already bound to \"" @ %prevCmdName @ "\"! Do you wish to replace this mapping?";
  71. %doRemapCommand = "redoMapping(" @ %device @ ", " @ %actionMap @ ", \"" @ %action @ "\", \"" @
  72. %cmd @ "\", " @ %prevMapIndex @ ", " @ %this.index @ ");";
  73. %cancelCommand = "";
  74. MessageBoxYesNo( "Key already in use", %remapWarnText, %doRemapCommand, %cancelCommand );
  75. }
  76. /// This unbinds actions beyond %count associated to the
  77. /// particular actionMap %commmand.
  78. function unbindExtraActions( %command, %actionMap, %device, %count )
  79. {
  80. %temp = %actionMap.getBinding( %command );
  81. if ( %temp $= "" )
  82. return;
  83. %count = getFieldCount( %temp ) - ( %count * 2 );
  84. for ( %i = 0; %i < %count; %i += 2 )
  85. {
  86. %amDevice = getField( %temp, %i + 0 );
  87. %action = getField( %temp, %i + 1 );
  88. if(%device !$= "" || %device $= %amDevice)
  89. %actionMap.unbind( %device, %action );
  90. }
  91. }