SceneObjectSet_ScriptBinding.h 7.2 KB

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