guiInspector.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. #ifndef _GUI_INSPECTOR_H_
  23. #define _GUI_INSPECTOR_H_
  24. #ifndef _CONSOLE_BASE_TYPE_H_
  25. #include "console/consoleBaseType.h"
  26. #endif
  27. #ifndef _GUICONTROL_H_
  28. #include "gui/guiControl.h"
  29. #endif
  30. #ifndef _GUICANVAS_H_
  31. #include "gui/guiCanvas.h"
  32. #endif
  33. #ifndef _H_GUIDEFAULTCONTROLRENDER_
  34. #include "gui/guiDefaultControlRender.h"
  35. #endif
  36. #ifndef _GUISCROLLCTRL_H_
  37. #include "gui/containers/guiScrollCtrl.h"
  38. #endif
  39. #ifndef _GUITEXTEDITCTRL_H_
  40. #include "gui/guiTextEditCtrl.h"
  41. #endif
  42. #ifndef _GUIBUTTONCTRL_H_
  43. #include "gui/buttons/guiButtonCtrl.h"
  44. #endif
  45. #ifndef _GUIDROPDOWNCTRL_H_
  46. #include "gui/buttons/guiDropDownCtrl.h"
  47. #endif
  48. #ifndef _GUICHAINCTRL_H_
  49. #include "gui/containers/guiChainCtrl.h"
  50. #endif
  51. #ifndef _GUIGRIDCTRL_H_
  52. #include "gui/containers/guiGridCtrl.h"
  53. #endif
  54. #ifndef _GUIPANELCTRL_H_
  55. #include "gui/containers/guiPanelCtrl.h"
  56. #endif
  57. #include <string>
  58. #include <vector>
  59. #include <algorithm>
  60. // Forward Declare GuiInspectorGroup
  61. class GuiInspectorGroup;
  62. // Forward Declare GuiInspectorField
  63. class GuiInspectorField;
  64. // Forward Declare GuiInspectorDatablockField
  65. class GuiInspectorDatablockField;
  66. class GuiInspector : public GuiChainCtrl
  67. {
  68. private:
  69. typedef GuiChainCtrl Parent;
  70. vector<string> mHiddenFieldList;
  71. public:
  72. // Members
  73. Vector<GuiInspectorGroup*> mGroups;
  74. Vector<StringTableEntry> mOpenGroupList;
  75. SimObjectPtr<SimObject> mTarget;
  76. GuiInspector();
  77. ~GuiInspector();
  78. static void initPersistFields();
  79. DECLARE_CONOBJECT(GuiInspector);
  80. virtual void inspectPostApply();
  81. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  82. virtual void parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent);
  83. void inspectObject( SimObject *object );
  84. inline SimObject *getInspectObject() { return mTarget.isNull() ? NULL : mTarget; };
  85. void setName( const char* newName );
  86. void clearGroups();
  87. bool findExistentGroup( StringTableEntry groupName );
  88. inline bool hideField(const char* fieldName) { return std::find(mHiddenFieldList.begin(), mHiddenFieldList.end(), fieldName) != mHiddenFieldList.end(); };
  89. inline void clearHiddenField() { mHiddenFieldList.clear(); };
  90. inline void addHiddenField(const char* fieldName) { mHiddenFieldList.push_back(fieldName); };
  91. void checkOpenGroupList(GuiInspectorGroup* group);
  92. GuiControlProfile* mGroupPanelProfile;
  93. GuiControlProfile* mGroupGridProfile;
  94. GuiControlProfile* mLabelProfile;
  95. GuiControlProfile* mTextEditProfile;
  96. GuiControlProfile* mDropDownProfile;
  97. GuiControlProfile* mDropDownItemProfile;
  98. GuiControlProfile* mScrollProfile;
  99. GuiControlProfile* mBackgroundProfile;
  100. GuiControlProfile* mThumbProfile;
  101. GuiControlProfile* mArrowProfile;
  102. GuiControlProfile* mTrackProfile;
  103. GuiControlProfile* mCheckboxProfile;
  104. GuiControlProfile* mButtonProfile;
  105. GuiControlProfile* mColorPopupProfile;
  106. GuiControlProfile* mColorPopupPanelProfile;
  107. GuiControlProfile* mColorPopupPickerProfile;
  108. GuiControlProfile* mColorPopupSelectorProfile;
  109. bool onWake();
  110. void onSleep();
  111. S32 mScrollBarThickness;
  112. bool mShowArrowButtons;
  113. bool mUseConstantHeightThumb;
  114. Point2I mFieldCellSize;
  115. Point2I mControlOffset;
  116. };
  117. class GuiInspectorField : public GuiControl
  118. {
  119. private:
  120. typedef GuiControl Parent;
  121. public:
  122. // Members
  123. GuiInspectorGroup* mGroup;
  124. SimObjectPtr<SimObject> mTarget;
  125. AbstractClassRep::Field* mField;
  126. StringTableEntry mFieldArrayIndex;
  127. // Constructed Field Edit Control
  128. GuiControl* mEdit;
  129. GuiInspectorField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, AbstractClassRep::Field* field );
  130. GuiInspectorField();
  131. ~GuiInspectorField();
  132. DECLARE_CONOBJECT(GuiInspectorField);
  133. virtual void setTarget( SimObjectPtr<SimObject> target ) { mTarget = target; };
  134. virtual void setInspectorGroup( GuiInspectorGroup* grp ) { mGroup = grp; };
  135. virtual void setInspectorField( AbstractClassRep::Field *field, const char*arrayIndex = NULL );
  136. protected:
  137. void registerEditControl( GuiControl *ctrl );
  138. public:
  139. virtual GuiControl* constructEditControl(S32 width);
  140. virtual void updateValue( const char* newValue );
  141. virtual StringTableEntry getFieldName();
  142. virtual void setData( const char* data );
  143. virtual const char* getData();
  144. virtual bool onAdd();
  145. };
  146. class GuiInspectorGroup : public GuiPanelCtrl
  147. {
  148. private:
  149. typedef GuiPanelCtrl Parent;
  150. public:
  151. // Members
  152. SimObjectPtr<SimObject> mTarget;
  153. SimObjectPtr<GuiInspector> mInspector;
  154. Vector<GuiInspectorField*> mChildren;
  155. GuiGridCtrl* mGrid;
  156. // Constructor/Destructor/Conobject Declaration
  157. GuiInspectorGroup();
  158. GuiInspectorGroup( SimObjectPtr<SimObject> target, StringTableEntry groupName, SimObjectPtr<GuiInspector> inspector );
  159. DECLARE_CONOBJECT(GuiInspectorGroup);
  160. virtual GuiInspectorField* constructField( S32 fieldType );
  161. virtual GuiInspectorField* findField( StringTableEntry fieldName );
  162. // Publicly Accessible Information about this group
  163. StringTableEntry getGroupName() { return mText; };
  164. SimObjectPtr<SimObject> getGroupTarget() { return mTarget; };
  165. SimObjectPtr<GuiInspector> getContentCtrl() { return mInspector; };
  166. bool onAdd();
  167. virtual bool inspectGroup();
  168. protected:
  169. // overridable method that creates our inner controls.
  170. virtual bool createContent();
  171. };
  172. class GuiInspectorDynamicField : public GuiInspectorField
  173. {
  174. private:
  175. typedef GuiInspectorField Parent;
  176. SimObjectPtr<GuiControl> mRenameCtrl;
  177. public:
  178. SimFieldDictionary::Entry* mDynField;
  179. GuiInspectorDynamicField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, SimFieldDictionary::Entry* field );
  180. GuiInspectorDynamicField() {};
  181. ~GuiInspectorDynamicField() {};
  182. DECLARE_CONOBJECT(GuiInspectorDynamicField);
  183. virtual void setData( const char* data );
  184. virtual const char* getData();
  185. virtual StringTableEntry getFieldName() { return ( mDynField != NULL ) ? mDynField->slotName : StringTable->EmptyString; };
  186. // Override onAdd so we can construct our custom field name edit control
  187. virtual bool onAdd();
  188. // Rename a dynamic field
  189. void renameField( StringTableEntry newFieldName );
  190. // Create an edit control to overlay the field name (for renaming dynamic fields)
  191. GuiControl* constructRenameControl();
  192. // Override parentResized so we can resize our renaming control
  193. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  194. };
  195. class GuiInspectorDynamicGroup : public GuiInspectorGroup
  196. {
  197. private:
  198. typedef GuiInspectorGroup Parent;
  199. GuiControl* mAddCtrl;
  200. public:
  201. DECLARE_CONOBJECT(GuiInspectorDynamicGroup);
  202. GuiInspectorDynamicGroup() { /*mNeedScroll=false;*/ };
  203. GuiInspectorDynamicGroup(SimObjectPtr<SimObject> target, StringTableEntry groupName, SimObjectPtr<GuiInspector> parent) : GuiInspectorGroup(target, groupName, parent) {};
  204. //////////////////////////////////////////////////////////////////////////
  205. // inspectGroup is overridden in GuiInspectorDynamicGroup to inspect an
  206. // objects FieldDictionary (dynamic fields) instead of regular persistent
  207. // fields.
  208. bool inspectGroup();
  209. // For scriptable dynamic field additions
  210. void addDynamicField();
  211. // Clear our fields (delete them)
  212. void clearFields();
  213. // Find an already existent field by name in the dictionary
  214. virtual SimFieldDictionary::Entry* findDynamicFieldInDictionary( StringTableEntry fieldName );
  215. protected:
  216. // create our inner controls when we add
  217. virtual bool createContent();
  218. };
  219. //////////////////////////////////////////////////////////////////////////
  220. // GuiInspectorDatablockField - custom field type for datablock enumeration
  221. //////////////////////////////////////////////////////////////////////////
  222. class GuiInspectorDatablockField : public GuiInspectorField
  223. {
  224. private:
  225. typedef GuiInspectorField Parent;
  226. AbstractClassRep *mDesiredClass;
  227. public:
  228. DECLARE_CONOBJECT(GuiInspectorDatablockField);
  229. GuiInspectorDatablockField( StringTableEntry className );
  230. GuiInspectorDatablockField() { mDesiredClass = NULL; };
  231. void setClassName( StringTableEntry className );
  232. //////////////////////////////////////////////////////////////////////////
  233. // Override able methods for custom edit fields (Both are REQUIRED)
  234. //////////////////////////////////////////////////////////////////////////
  235. virtual GuiControl* constructEditControl();
  236. };
  237. #endif