SceneObjectSet_ScriptBinding.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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(SceneObjectSet, SimObject)
  23. /*! Dumps the object data within the set
  24. @return No return value
  25. */
  26. ConsoleMethodWithDocs(SceneObjectSet, dumpObjects, ConsoleVoid, 2, 2, ())
  27. {
  28. SceneObjectSet::iterator itr;
  29. for(itr = object->begin(); itr != object->end(); itr++)
  30. {
  31. SceneObject *obj = *itr;
  32. bool isSet = dynamic_cast<SceneObjectSet *>(obj) != 0;
  33. const char *name = obj->getName();
  34. if(name)
  35. Con::printf(" %d,\"%s\": %s %s", obj->getId(), name,
  36. obj->getClassName(), isSet ? "(g)":"");
  37. else
  38. Con::printf(" %d: %s %s", obj->getId(), obj->getClassName(),
  39. isSet ? "(g)" : "");
  40. }
  41. }
  42. /*! Adds given list of objects to the SceneObjectSet.
  43. @param obj_i (i is unilimited) Variable list of objects to add
  44. @return No return value
  45. */
  46. ConsoleMethodWithDocs(SceneObjectSet, add, ConsoleVoid, 3, 0, (obj1,...))
  47. {
  48. for(S32 i = 2; i < argc; i++)
  49. {
  50. SceneObject *obj = Sim::findObject<SceneObject>(argv[i]);
  51. if(obj)
  52. object->addObject(obj);
  53. else
  54. Con::printf("Set::add: Object \"%s\" doesn't exist", argv[i]);
  55. }
  56. }
  57. /*! Removes given listy of objects from the SceneObjectSet.
  58. @param obj_i (i is unilimited) Variable list of objects to remove
  59. @return No return value
  60. */
  61. ConsoleMethodWithDocs(SceneObjectSet, remove, ConsoleVoid, 3, 0, (obj1,...))
  62. {
  63. for(S32 i = 2; i < argc; i++)
  64. {
  65. SceneObject *obj = Sim::findObject<SceneObject>(argv[i]);
  66. if(obj && object->find(object->begin(),object->end(),obj) != object->end())
  67. object->removeObject(obj);
  68. else
  69. Con::printf("Set::remove: Object \"%s\" does not exist in set", argv[i]);
  70. }
  71. }
  72. //-----------------------------------------------------------------------------
  73. /*! Deletes all the objects in the SceneObjectSet.
  74. @return No return value
  75. */
  76. ConsoleMethodWithDocs(SceneObjectSet, deleteObjects, ConsoleVoid, 2, 2, ())
  77. {
  78. object->deleteObjects();
  79. }
  80. //-----------------------------------------------------------------------------
  81. /*! Clears the SceneObjectSet
  82. @return No return value
  83. */
  84. ConsoleMethodWithDocs(SceneObjectSet, clear, ConsoleVoid, 2, 2, ())
  85. {
  86. object->clear();
  87. }
  88. //-----------------------------------------------------------------------------
  89. /*! Call a method on all objects contained in the set.
  90. @param method The name of the method to call.
  91. @param args The arguments to the method.
  92. @note This method recurses into all SimSets that are children to the set.
  93. @see callOnChildrenNoRecurse
  94. */
  95. ConsoleMethodWithDocs( SceneObjectSet, callOnChildren, ConsoleVoid, 3, 0, ( string method, string args... ))
  96. {
  97. object->callOnChildren( argv[2], argc - 3, argv + 3 );
  98. }
  99. //-----------------------------------------------------------------------------
  100. /*! Uses SceneObjectSet reorder to push child 1 before child 2 - both must already be child controls of this control
  101. @param child1 The child you wish to set first
  102. @param child2 The child you wish to set after child1
  103. @return No return value.
  104. */
  105. ConsoleMethodWithDocs(SceneObjectSet, reorderChild, ConsoleVoid, 4,4, (child1, child2))
  106. {
  107. SceneObject* pObject = Sim::findObject<SceneObject>(argv[2]);
  108. SceneObject* pTarget = Sim::findObject<SceneObject>(argv[3]);
  109. if(pObject && pTarget)
  110. {
  111. object->reOrder(pObject,pTarget);
  112. }
  113. }
  114. //-----------------------------------------------------------------------------
  115. /*! @return Returns the number of objects in the SceneObjectSet
  116. */
  117. ConsoleMethodWithDocs(SceneObjectSet, getCount, ConsoleInt, 2, 2, ())
  118. {
  119. return object->size();
  120. }
  121. //-----------------------------------------------------------------------------
  122. /*! @return Returns the ID of the desired object or -1 on failure
  123. */
  124. ConsoleMethodWithDocs(SceneObjectSet, getObject, ConsoleInt, 3, 3, (objIndex))
  125. {
  126. S32 objectIndex = dAtoi(argv[2]);
  127. if(objectIndex < 0 || objectIndex >= S32(object->size()))
  128. {
  129. Con::printf("Set::getObject index out of range.");
  130. return -1;
  131. }
  132. return ((*object)[objectIndex])->getId();
  133. }
  134. //-----------------------------------------------------------------------------
  135. /*! @return Returns true if specified object is a member of the set, and false otherwise
  136. */
  137. ConsoleMethodWithDocs(SceneObjectSet, isMember, ConsoleBool, 3, 3, (object))
  138. {
  139. SceneObject *testObject = Sim::findObject<SceneObject>(argv[2]);
  140. if(!testObject)
  141. {
  142. Con::printf("SceneObjectSet::isMember: %s is not an object.", argv[2]);
  143. return false;
  144. }
  145. for(SceneObjectSet::iterator i = object->begin(); i != object->end(); i++)
  146. {
  147. if(*i == testObject)
  148. {
  149. return true;
  150. }
  151. }
  152. return false;
  153. }
  154. //-----------------------------------------------------------------------------
  155. /*! Returns the object with given internal name
  156. @param name The internal name of the object you wish to find
  157. @param searchChildren Set this true if you wish to search all children as well.
  158. @return Returns the ID of the object.
  159. */
  160. ConsoleMethodWithDocs( SceneObjectSet, findObjectByInternalName, ConsoleInt, 3, 4, (string name, [bool searchChildren]))
  161. {
  162. StringTableEntry pcName = StringTable->insert(argv[2]);
  163. bool searchChildren = false;
  164. if (argc > 3)
  165. searchChildren = dAtob(argv[3]);
  166. SceneObject* child = object->findObjectByInternalName(pcName, searchChildren);
  167. if(child)
  168. return child->getId();
  169. return 0;
  170. }
  171. //-----------------------------------------------------------------------------
  172. /*! Brings object to front of set.
  173. @return No return value.
  174. */
  175. ConsoleMethodWithDocs(SceneObjectSet, bringToFront, ConsoleVoid, 3, 3, (object))
  176. {
  177. SceneObject *obj = Sim::findObject<SceneObject>(argv[2]);
  178. if(!obj)
  179. return;
  180. object->bringObjectToFront(obj);
  181. }
  182. //-----------------------------------------------------------------------------
  183. /*! Sends item to back of set.
  184. @return No return value.
  185. */
  186. ConsoleMethodWithDocs(SceneObjectSet, pushToBack, ConsoleVoid, 3, 3, (object))
  187. {
  188. SceneObject *obj = Sim::findObject<SceneObject>(argv[2]);
  189. if(!obj)
  190. return;
  191. object->pushObjectToBack(obj);
  192. }
  193. ConsoleMethodGroupEndWithDocs(SceneObjectSet)