entityGroup.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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. #include "gui/buttons/guiIconButtonCtrl.h"
  23. #include "gui/editor/guiInspector.h"
  24. #include "gui/editor/inspector/entityGroup.h"
  25. #include "core/strings/stringUnit.h"
  26. #include "T3D/components/component.h"
  27. #include "console/engineAPI.h"
  28. IMPLEMENT_CONOBJECT(GuiInspectorEntityGroup);
  29. ConsoleDocClass(GuiInspectorEntityGroup,
  30. "@brief Used to inspect an object's FieldDictionary (dynamic fields) instead "
  31. "of regular persistent fields.\n\n"
  32. "Editor use only.\n\n"
  33. "@internal"
  34. );
  35. bool GuiInspectorEntityGroup::onAdd()
  36. {
  37. if (!Parent::onAdd())
  38. return false;
  39. return true;
  40. }
  41. //-----------------------------------------------------------------------------
  42. // GuiInspectorEntityGroup - add custom controls
  43. //-----------------------------------------------------------------------------
  44. bool GuiInspectorEntityGroup::createContent()
  45. {
  46. if(!Parent::createContent())
  47. return false;
  48. Con::evaluatef("%d.stack = %d;", this->getId(), mStack->getId());
  49. Con::executef(this, "createContent");
  50. return true;
  51. }
  52. //-----------------------------------------------------------------------------
  53. // GuiInspectorEntityGroup - inspectGroup override
  54. //-----------------------------------------------------------------------------
  55. bool GuiInspectorEntityGroup::inspectGroup()
  56. {
  57. const U32 numTargets = mParent->getNumInspectObjects();
  58. if (numTargets == 1)
  59. {
  60. Entity* target = dynamic_cast<Entity*>(mParent->getInspectObject(0));
  61. if(target)
  62. Con::executef(this, "inspectObject", target->getIdString());
  63. }
  64. return true;
  65. }
  66. void GuiInspectorEntityGroup::updateAllFields()
  67. {
  68. // We overload this to just reinspect the group.
  69. inspectGroup();
  70. }
  71. void GuiInspectorEntityGroup::onMouseMove(const GuiEvent &event)
  72. {
  73. //mParent->mOverDivider = false;
  74. }
  75. ConsoleMethod(GuiInspectorEntityGroup, inspectGroup, bool, 2, 2, "Refreshes the dynamic fields in the inspector.")
  76. {
  77. return object->inspectGroup();
  78. }
  79. void GuiInspectorEntityGroup::clearFields()
  80. {
  81. }
  82. SimFieldDictionary::Entry* GuiInspectorEntityGroup::findDynamicFieldInDictionary(StringTableEntry fieldName)
  83. {
  84. SimFieldDictionary * fieldDictionary = mParent->getInspectObject()->getFieldDictionary();
  85. for (SimFieldDictionaryIterator ditr(fieldDictionary); *ditr; ++ditr)
  86. {
  87. SimFieldDictionary::Entry * entry = (*ditr);
  88. if (entry->slotName == fieldName)
  89. return entry;
  90. }
  91. return NULL;
  92. }
  93. void GuiInspectorEntityGroup::addDynamicField()
  94. {
  95. }
  96. AbstractClassRep::Field* GuiInspectorEntityGroup::findObjectBehaviorField(Component* target, String fieldName)
  97. {
  98. AbstractClassRep::FieldList& fieldList = target->getClassRep()->mFieldList;
  99. for (AbstractClassRep::FieldList::iterator itr = fieldList.begin();
  100. itr != fieldList.end(); ++itr)
  101. {
  102. AbstractClassRep::Field* field = &(*itr);
  103. String fldNm(field->pFieldname);
  104. if (fldNm == fieldName)
  105. return field;
  106. }
  107. return NULL;
  108. }
  109. ConsoleMethod(GuiInspectorEntityGroup, addDynamicField, void, 2, 2, "obj.addDynamicField();")
  110. {
  111. object->addDynamicField();
  112. }
  113. ConsoleMethod(GuiInspectorEntityGroup, removeDynamicField, void, 3, 3, "")
  114. {
  115. }