actionMap_ScriptBinding.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleMethodGroupBeginWithDocs(ActionMap, SimObject)
  23. /*! Use the bind method to associate a function to a keystroke or other device input.
  24. The command bound via the bind function must be specified as a flat name with no elipses or semi-colon termination and will be called on make and break events (i.e. key press and release for a mapped key). Args: Warning: When a function is bound to a keystroke or other device input, and no other versions of the binding are provided, the function will be called even if a modifier key like CTRL, ALT, or SHIFT is also pressed.
  25. @param device Name of the device to bind the command to.
  26. @param action Name of the action to watch for.
  27. @param modifier Special modifiers (mouse only), such as dead spot, etc.
  28. @param command The function to be called on make and break.
  29. @return No return value.
  30. @sa bindCmd, getBinding, unbind
  31. */
  32. ConsoleMethodWithDocs( ActionMap, bind, ConsoleVoid, 5, 10, ( device , action , [ modifier , mod... ] , command ))
  33. {
  34. object->processBind( argc - 2, argv + 2, NULL );
  35. }
  36. /*! Use the bindObj method to associate a function to a keystroke or other device input.
  37. The command bound via the bind function must be specified as a flat name with no elipses or semi-colon termination and will be called on make and break events (i.e. key press and release for a mapped key). Args: Warning: When a function is bound to a keystroke or other device input, and no other versions of the binding are provided, the function will be called even if a modifier key like CTRL, ALT, or SHIFT is also pressed.
  38. @param device Name of the device to bind the command to.
  39. @param action Name of the action to watch for.
  40. @param modifier Special modifiers (mouse only), such as dead spot, etc.
  41. @param command The function to be called on make and break.
  42. @param object The explicit object (it defaults to NULL when you call bind() )
  43. @return No return value.
  44. @sa bindCmd, getBinding, unbind
  45. */
  46. ConsoleMethodWithDocs( ActionMap, bindObj, ConsoleVoid, 6, 11, (device, action, [modifier spec, mod...], command, object))
  47. {
  48. SimObject* obj = Sim::findObject(argv[argc - 1]);
  49. object->processBind( argc - 3, argv + 2, obj );
  50. }
  51. //------------------------------------------------------------------------------
  52. /*! Use the bindCmd method to associate up to two functions to a keystroke or other device input.
  53. The makeCmd is bound to the make event and the breakCmd is bound to the break event and in both cases, the commands are specified as complete scripts, with all arguments, elipses, and the terminating semi-colon. Either of these commands may be non-specified (NULL strings). For clarification, see 'Bind Sample' example below.
  54. @param device Name of the device to bind the command to (see 'Device Table' below).
  55. @param action Name of the action to watch for(see 'Action Table' below).
  56. @param makeCmd The function to be called on make event.
  57. @param breakCmd The function to be called on break event.
  58. @return No return value.
  59. @sa bind, getBinding, unbind
  60. */
  61. ConsoleMethodWithDocs( ActionMap, bindCmd, ConsoleVoid, 6, 6, ( device , action , makeCmd , breakCmd ))
  62. {
  63. object->processBindCmd( argv[2], argv[3], argv[4], argv[5] );
  64. }
  65. //------------------------------------------------------------------------------
  66. /*! Use the unbind method to remove a previosly specified device + action pair from the action map.
  67. @param device Name of the device to bound to a command (see 'Device Table' below).
  68. @param action Name of the action to watch for (see 'Action Table' below).
  69. @return No return value.
  70. @sa bind, bindCmd
  71. */
  72. ConsoleMethodWithDocs( ActionMap, unbind, ConsoleVoid, 4, 4, ( device , action ))
  73. {
  74. object->processUnbind( argv[2], argv[3] );
  75. }
  76. /*! Use the unbind method to remove a previosly specified device + action pair from the action map.
  77. @param device Name of the device to bound to a command (see 'Device Table' below).
  78. @param action Name of the action to watch for (see 'Action Table' below).
  79. @param object Explicit object (it defaults to NULL when you call unbind() ).
  80. @return No return value.
  81. @sa bind, bindCmd
  82. */
  83. ConsoleMethodWithDocs( ActionMap, unbindObj, ConsoleVoid, 5, 5, (device, action, object))
  84. {
  85. SimObject* obj = Sim::findObject(argv[4]);
  86. object->processUnbind( argv[2], argv[3], obj );
  87. }
  88. //------------------------------------------------------------------------------
  89. /*! Use the save method to save an entire action map specification to a file. If append is not specified, or specified as false, fileName will be overwritten, otherwise the action map will be appended to the file.
  90. @param fileName Full path to file in which to store action map definition.
  91. @param append If true, do not overwrite the file, else start from scratch.
  92. @return No return value
  93. */
  94. ConsoleMethodWithDocs( ActionMap, save, ConsoleVoid, 2, 4, ( [ fileName ] [ , append ] ))
  95. {
  96. const char* fileName = argc > 2 ? argv[2] : NULL;
  97. bool append = argc > 3 ? dAtob(argv[3]) : false;
  98. char buffer[1024];
  99. if(fileName)
  100. {
  101. if(Con::expandPath(buffer, sizeof(buffer), fileName))
  102. fileName = buffer;
  103. }
  104. object->dumpActionMap( fileName, append );
  105. }
  106. //------------------------------------------------------------------------------
  107. /*! Use the push method to activate an ActionMap and place it at the top of the non-global ActionMap stack.
  108. @return No return value.
  109. @sa pop
  110. */
  111. ConsoleMethodWithDocs( ActionMap, push, ConsoleVoid, 2, 2, ())
  112. {
  113. SimSet* pActionMapSet = Sim::getActiveActionMapSet();
  114. pActionMapSet->pushObject( object );
  115. }
  116. //------------------------------------------------------------------------------
  117. /*! Use the pop method to de-activate an ActionMap and remove it from non-global ActionMap stack.
  118. @return No return value.
  119. @sa push
  120. */
  121. ConsoleMethodWithDocs( ActionMap, pop, ConsoleVoid, 2, 2, ())
  122. {
  123. SimSet* pActionMapSet = Sim::getActiveActionMapSet();
  124. pActionMapSet->removeObject( object );
  125. }
  126. //------------------------------------------------------------------------------
  127. /*! Use the getBinding method to get the binding for a specified command.
  128. @param command The function to seek a binding for.
  129. @return Returns a string containing the binding as a field (TAB separated string), or a NULL string meaning 'no binding found'.
  130. @sa bind, bindCmd
  131. */
  132. ConsoleMethodWithDocs( ActionMap, getBinding, ConsoleString, 3, 3, ( command ))
  133. {
  134. return( object->getBinding( argv[2] ) );
  135. }
  136. //------------------------------------------------------------------------------
  137. /*! Use the getCommand method to get the function associated with a specific device + action pair.
  138. @param device Name of the device to bound to a command (see 'Device Table' below).
  139. @param action Name of the action to watch for (see 'Action Table' below).
  140. @return Returns the function name or specification associated with the specified device + action pair, or a NULL-string meaning 'no binding found'.
  141. @sa bind, bindCmd, getBinding
  142. */
  143. ConsoleMethodWithDocs( ActionMap, getCommand, ConsoleString, 4, 4, ( device , action ))
  144. {
  145. return( object->getCommand( argv[2], argv[3] ) );
  146. }
  147. //------------------------------------------------------------------------------
  148. /*! Use the Purpose method to determine if a specific device + action pair in inverted.
  149. This only applies to scrolling devices.
  150. @param device Name of the device to bound to a command (see 'Device Table' below).
  151. @param action Name of the action to watch for (see 'Action Table' below).
  152. @return Returns 1 if the mouse (or other scrolling device) is inverted, 0 otherwise.
  153. @sa bind, bindCmd
  154. */
  155. ConsoleMethodWithDocs( ActionMap, isInverted, ConsoleBool, 4, 4, ( device , action ))
  156. {
  157. return( object->isInverted( argv[2], argv[3] ) );
  158. }
  159. //------------------------------------------------------------------------------
  160. /*! Use the getScale method to get the scale associated with a specific device + action pair.
  161. @param device Name of the device to bound to a command (see 'Device Table' below).
  162. @param action Name of the action to watch for (see 'Action Table' below).
  163. @return Returns 1 if no scale is associated with the specified device + action pair, or the mapping was not found.
  164. @sa bind, bindCmd
  165. */
  166. ConsoleMethodWithDocs( ActionMap, getScale, ConsoleFloat, 4, 4, ( device , action ))
  167. {
  168. return( object->getScale( argv[2], argv[3] ) );
  169. }
  170. //------------------------------------------------------------------------------
  171. /*! Use the getDeadZone method to get the dead-zone associated with a specific device + action pair.
  172. @param device Name of the device to bound to a command (see 'Device Table' below).
  173. @param action Name of the action to watch for (see 'Action Table' below).
  174. @return Returns a dead-zone specification, or \0 0\ meaning that there is no dead-zone, or a NULL string meaning the mapping was not found.
  175. @sa bind, bindCmd
  176. */
  177. ConsoleMethodWithDocs( ActionMap, getDeadZone, ConsoleString, 4, 4, ( device , action ))
  178. {
  179. return( object->getDeadZone( argv[2], argv[3] ) );
  180. }
  181. ConsoleMethodGroupEndWithDocs(ActionMap)