entityGroup.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. Con::executef(this, "inspectObject", target->getIdString());
  62. }
  63. return true;
  64. }
  65. void GuiInspectorEntityGroup::updateAllFields()
  66. {
  67. // We overload this to just reinspect the group.
  68. inspectGroup();
  69. }
  70. void GuiInspectorEntityGroup::onMouseMove(const GuiEvent &event)
  71. {
  72. //mParent->mOverDivider = false;
  73. }
  74. ConsoleMethod(GuiInspectorEntityGroup, inspectGroup, bool, 2, 2, "Refreshes the dynamic fields in the inspector.")
  75. {
  76. return object->inspectGroup();
  77. }
  78. void GuiInspectorEntityGroup::clearFields()
  79. {
  80. }
  81. SimFieldDictionary::Entry* GuiInspectorEntityGroup::findDynamicFieldInDictionary(StringTableEntry fieldName)
  82. {
  83. SimFieldDictionary * fieldDictionary = mParent->getInspectObject()->getFieldDictionary();
  84. for (SimFieldDictionaryIterator ditr(fieldDictionary); *ditr; ++ditr)
  85. {
  86. SimFieldDictionary::Entry * entry = (*ditr);
  87. if (entry->slotName == fieldName)
  88. return entry;
  89. }
  90. return NULL;
  91. }
  92. void GuiInspectorEntityGroup::addDynamicField()
  93. {
  94. }
  95. AbstractClassRep::Field* GuiInspectorEntityGroup::findObjectBehaviorField(Component* target, String fieldName)
  96. {
  97. AbstractClassRep::FieldList& fieldList = target->getClassRep()->mFieldList;
  98. for (AbstractClassRep::FieldList::iterator itr = fieldList.begin();
  99. itr != fieldList.end(); ++itr)
  100. {
  101. AbstractClassRep::Field* field = &(*itr);
  102. String fldNm(field->pFieldname);
  103. if (fldNm == fieldName)
  104. return field;
  105. }
  106. return NULL;
  107. }
  108. ConsoleMethod(GuiInspectorEntityGroup, addDynamicField, void, 2, 2, "obj.addDynamicField();")
  109. {
  110. object->addDynamicField();
  111. }
  112. ConsoleMethod(GuiInspectorEntityGroup, removeDynamicField, void, 3, 3, "")
  113. {
  114. }