guiInspector.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. SimObjectPtr<SimObject> mTarget;
  75. GuiInspector();
  76. ~GuiInspector();
  77. static void initPersistFields();
  78. DECLARE_CONOBJECT(GuiInspector);
  79. virtual void inspectPostApply();
  80. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  81. virtual void parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent);
  82. void inspectObject( SimObject *object );
  83. inline SimObject *getInspectObject() { return mTarget.isNull() ? NULL : mTarget; };
  84. void setName( const char* newName );
  85. void clearGroups();
  86. bool findExistentGroup( StringTableEntry groupName );
  87. inline bool hideField(const char* fieldName) { return std::find(mHiddenFieldList.begin(), mHiddenFieldList.end(), fieldName) != mHiddenFieldList.end(); };
  88. inline void clearHiddenField() { mHiddenFieldList.clear(); };
  89. inline void addHiddenField(const char* fieldName) { mHiddenFieldList.push_back(fieldName); };
  90. GuiControlProfile *mGroupPanelProfile;
  91. GuiControlProfile *mGroupGridProfile;
  92. GuiControlProfile *mLabelProfile;
  93. GuiControlProfile *mTextEditProfile;
  94. GuiControlProfile *mDropDownProfile;
  95. GuiControlProfile *mDropDownItemProfile;
  96. GuiControlProfile *mScrollProfile;
  97. GuiControlProfile *mBackgroundProfile;
  98. GuiControlProfile *mThumbProfile;
  99. GuiControlProfile *mArrowProfile;
  100. GuiControlProfile *mTrackProfile;
  101. GuiControlProfile *mCheckboxProfile;
  102. GuiControlProfile *mButtonProfile;
  103. bool onWake();
  104. void onSleep();
  105. S32 mScrollBarThickness;
  106. bool mShowArrowButtons;
  107. bool mUseConstantHeightThumb;
  108. Point2I mFieldCellSize;
  109. Point2I mControlOffset;
  110. };
  111. class GuiInspectorField : public GuiControl
  112. {
  113. private:
  114. typedef GuiControl Parent;
  115. public:
  116. // Members
  117. GuiInspectorGroup* mGroup;
  118. SimObjectPtr<SimObject> mTarget;
  119. AbstractClassRep::Field* mField;
  120. StringTableEntry mFieldArrayIndex;
  121. // Constructed Field Edit Control
  122. GuiControl* mEdit;
  123. GuiInspectorField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, AbstractClassRep::Field* field );
  124. GuiInspectorField();
  125. ~GuiInspectorField();
  126. DECLARE_CONOBJECT(GuiInspectorField);
  127. virtual void setTarget( SimObjectPtr<SimObject> target ) { mTarget = target; };
  128. virtual void setInspectorGroup( GuiInspectorGroup* grp ) { mGroup = grp; };
  129. virtual void setInspectorField( AbstractClassRep::Field *field, const char*arrayIndex = NULL );
  130. protected:
  131. void registerEditControl( GuiControl *ctrl );
  132. public:
  133. virtual GuiControl* constructEditControl(S32 width);
  134. virtual void updateValue( const char* newValue );
  135. virtual StringTableEntry getFieldName();
  136. virtual void setData( const char* data );
  137. virtual const char* getData();
  138. virtual bool onAdd();
  139. };
  140. class GuiInspectorGroup : public GuiPanelCtrl
  141. {
  142. private:
  143. typedef GuiPanelCtrl Parent;
  144. public:
  145. // Members
  146. SimObjectPtr<SimObject> mTarget;
  147. SimObjectPtr<GuiInspector> mInspector;
  148. Vector<GuiInspectorField*> mChildren;
  149. GuiGridCtrl* mGrid;
  150. // Constructor/Destructor/Conobject Declaration
  151. GuiInspectorGroup();
  152. GuiInspectorGroup( SimObjectPtr<SimObject> target, StringTableEntry groupName, SimObjectPtr<GuiInspector> inspector );
  153. DECLARE_CONOBJECT(GuiInspectorGroup);
  154. virtual GuiInspectorField* constructField( S32 fieldType );
  155. virtual GuiInspectorField* findField( StringTableEntry fieldName );
  156. // Publicly Accessible Information about this group
  157. StringTableEntry getGroupName() { return mText; };
  158. SimObjectPtr<SimObject> getGroupTarget() { return mTarget; };
  159. SimObjectPtr<GuiInspector> getContentCtrl() { return mInspector; };
  160. bool onAdd();
  161. virtual bool inspectGroup();
  162. protected:
  163. // overridable method that creates our inner controls.
  164. virtual bool createContent();
  165. };
  166. class GuiInspectorDynamicField : public GuiInspectorField
  167. {
  168. private:
  169. typedef GuiInspectorField Parent;
  170. SimObjectPtr<GuiControl> mRenameCtrl;
  171. public:
  172. SimFieldDictionary::Entry* mDynField;
  173. GuiInspectorDynamicField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, SimFieldDictionary::Entry* field );
  174. GuiInspectorDynamicField() {};
  175. ~GuiInspectorDynamicField() {};
  176. DECLARE_CONOBJECT(GuiInspectorDynamicField);
  177. virtual void setData( const char* data );
  178. virtual const char* getData();
  179. virtual StringTableEntry getFieldName() { return ( mDynField != NULL ) ? mDynField->slotName : StringTable->EmptyString; };
  180. // Override onAdd so we can construct our custom field name edit control
  181. virtual bool onAdd();
  182. // Rename a dynamic field
  183. void renameField( StringTableEntry newFieldName );
  184. // Create an edit control to overlay the field name (for renaming dynamic fields)
  185. GuiControl* constructRenameControl();
  186. // Override parentResized so we can resize our renaming control
  187. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  188. };
  189. class GuiInspectorDynamicGroup : public GuiInspectorGroup
  190. {
  191. private:
  192. typedef GuiInspectorGroup Parent;
  193. GuiControl* mAddCtrl;
  194. public:
  195. DECLARE_CONOBJECT(GuiInspectorDynamicGroup);
  196. GuiInspectorDynamicGroup() { /*mNeedScroll=false;*/ };
  197. GuiInspectorDynamicGroup(SimObjectPtr<SimObject> target, StringTableEntry groupName, SimObjectPtr<GuiInspector> parent) : GuiInspectorGroup(target, groupName, parent) {};
  198. //////////////////////////////////////////////////////////////////////////
  199. // inspectGroup is overridden in GuiInspectorDynamicGroup to inspect an
  200. // objects FieldDictionary (dynamic fields) instead of regular persistent
  201. // fields.
  202. bool inspectGroup();
  203. // For scriptable dynamic field additions
  204. void addDynamicField();
  205. // Clear our fields (delete them)
  206. void clearFields();
  207. // Find an already existent field by name in the dictionary
  208. virtual SimFieldDictionary::Entry* findDynamicFieldInDictionary( StringTableEntry fieldName );
  209. protected:
  210. // create our inner controls when we add
  211. virtual bool createContent();
  212. };
  213. //////////////////////////////////////////////////////////////////////////
  214. // GuiInspectorDatablockField - custom field type for datablock enumeration
  215. //////////////////////////////////////////////////////////////////////////
  216. class GuiInspectorDatablockField : public GuiInspectorField
  217. {
  218. private:
  219. typedef GuiInspectorField Parent;
  220. AbstractClassRep *mDesiredClass;
  221. public:
  222. DECLARE_CONOBJECT(GuiInspectorDatablockField);
  223. GuiInspectorDatablockField( StringTableEntry className );
  224. GuiInspectorDatablockField() { mDesiredClass = NULL; };
  225. void setClassName( StringTableEntry className );
  226. //////////////////////////////////////////////////////////////////////////
  227. // Override able methods for custom edit fields (Both are REQUIRED)
  228. //////////////////////////////////////////////////////////////////////////
  229. virtual GuiControl* constructEditControl();
  230. };
  231. #endif