guiInspector.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 _GUISTACKCTRL_H_
  34. #include "gui/containers/guiStackCtrl.h"
  35. #endif
  36. #ifndef _H_GUIDEFAULTCONTROLRENDER_
  37. #include "gui/guiDefaultControlRender.h"
  38. #endif
  39. #ifndef _GUITICKCTRL_H_
  40. #include "gui/guiTickCtrl.h"
  41. #endif
  42. #ifndef _GUISCROLLCTRL_H_
  43. #include "gui/containers/guiScrollCtrl.h"
  44. #endif
  45. #ifndef _GUITEXTEDITCTRL_H_
  46. #include "gui/guiTextEditCtrl.h"
  47. #endif
  48. #ifndef _GUIBITMAPBUTTON_H_
  49. #include "gui/buttons/guiBitmapButtonCtrl.h"
  50. #endif
  51. #ifndef _GUIPOPUPCTRL_H_
  52. #include "gui/guiPopUpCtrl.h"
  53. #endif
  54. #include "gui/containers/guiRolloutCtrl.h"
  55. // Forward Declare GuiInspectorGroup
  56. class GuiInspectorGroup;
  57. // Forward Declare GuiInspectorField
  58. class GuiInspectorField;
  59. // Forward Declare GuiInspectorDatablockField
  60. class GuiInspectorDatablockField;
  61. class GuiInspector : public GuiStackControl
  62. {
  63. private:
  64. typedef GuiStackControl Parent;
  65. public:
  66. // Members
  67. Vector<GuiInspectorGroup*> mGroups;
  68. SimObjectPtr<SimObject> mTarget;
  69. GuiInspector();
  70. ~GuiInspector();
  71. DECLARE_CONOBJECT(GuiInspector);
  72. virtual void parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent);
  73. void inspectObject( SimObject *object );
  74. inline SimObject *getInspectObject() { return mTarget.isNull() ? NULL : mTarget; };
  75. void setName( const char* newName );
  76. void clearGroups();
  77. bool onAdd();
  78. bool findExistentGroup( StringTableEntry groupName );
  79. };
  80. class GuiInspectorField : public GuiControl
  81. {
  82. private:
  83. typedef GuiControl Parent;
  84. public:
  85. // Static Caption Width (in percentage) for all inspector fields
  86. static S32 smCaptionWidth;
  87. // Members
  88. StringTableEntry mCaption;
  89. GuiInspectorGroup* mParent;
  90. SimObjectPtr<SimObject> mTarget;
  91. AbstractClassRep::Field* mField;
  92. StringTableEntry mFieldArrayIndex;
  93. // Constructed Field Edit Control
  94. GuiControl* mEdit;
  95. GuiInspectorField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, AbstractClassRep::Field* field );
  96. GuiInspectorField();
  97. ~GuiInspectorField();
  98. DECLARE_CONOBJECT(GuiInspectorField);
  99. virtual void setTarget( SimObjectPtr<SimObject> target ) { mTarget = target; };
  100. virtual void setParent( GuiInspectorGroup* parent ) { mParent = parent; };
  101. virtual void setInspectorField( AbstractClassRep::Field *field, const char*arrayIndex = NULL );
  102. protected:
  103. void registerEditControl( GuiControl *ctrl );
  104. public:
  105. virtual GuiControl* constructEditControl();
  106. virtual void updateValue( const char* newValue );
  107. virtual StringTableEntry getFieldName();
  108. virtual void setData( const char* data );
  109. virtual const char* getData();
  110. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  111. virtual bool onAdd();
  112. virtual void onRender(Point2I offset, const RectI &updateRect);
  113. };
  114. class GuiInspectorGroup : public GuiRolloutCtrl
  115. {
  116. private:
  117. typedef GuiRolloutCtrl Parent;
  118. public:
  119. // Members
  120. SimObjectPtr<SimObject> mTarget;
  121. SimObjectPtr<GuiInspector> mParent;
  122. Vector<GuiInspectorField*> mChildren;
  123. GuiStackControl* mStack;
  124. // Constructor/Destructor/Conobject Declaration
  125. GuiInspectorGroup();
  126. GuiInspectorGroup( SimObjectPtr<SimObject> target, StringTableEntry groupName, SimObjectPtr<GuiInspector> parent );
  127. ~GuiInspectorGroup();
  128. DECLARE_CONOBJECT(GuiInspectorGroup);
  129. virtual GuiInspectorField* constructField( S32 fieldType );
  130. virtual GuiInspectorField* findField( StringTableEntry fieldName );
  131. // Publicly Accessible Information about this group
  132. StringTableEntry getGroupName() { return mCaption; };
  133. SimObjectPtr<SimObject> getGroupTarget() { return mTarget; };
  134. SimObjectPtr<GuiInspector> getContentCtrl() { return mParent; };
  135. bool onAdd();
  136. virtual bool inspectGroup();
  137. virtual void animateToContents();
  138. protected:
  139. // overridable method that creates our inner controls.
  140. virtual bool createContent();
  141. };
  142. class GuiInspectorDynamicField : public GuiInspectorField
  143. {
  144. private:
  145. typedef GuiInspectorField Parent;
  146. SimObjectPtr<GuiControl> mRenameCtrl;
  147. public:
  148. SimFieldDictionary::Entry* mDynField;
  149. GuiInspectorDynamicField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, SimFieldDictionary::Entry* field );
  150. GuiInspectorDynamicField() {};
  151. ~GuiInspectorDynamicField() {};
  152. DECLARE_CONOBJECT(GuiInspectorDynamicField);
  153. virtual void setData( const char* data );
  154. virtual const char* getData();
  155. virtual StringTableEntry getFieldName() { return ( mDynField != NULL ) ? mDynField->slotName : StringTable->EmptyString; };
  156. // Override onAdd so we can construct our custom field name edit control
  157. virtual bool onAdd();
  158. // Rename a dynamic field
  159. void renameField( StringTableEntry newFieldName );
  160. // Create an edit control to overlay the field name (for renaming dynamic fields)
  161. GuiControl* constructRenameControl();
  162. // Override parentResized so we can resize our renaming control
  163. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  164. };
  165. class GuiInspectorDynamicGroup : public GuiInspectorGroup
  166. {
  167. private:
  168. typedef GuiInspectorGroup Parent;
  169. GuiControl* mAddCtrl;
  170. public:
  171. DECLARE_CONOBJECT(GuiInspectorDynamicGroup);
  172. GuiInspectorDynamicGroup() { /*mNeedScroll=false;*/ };
  173. GuiInspectorDynamicGroup( SimObjectPtr<SimObject> target, StringTableEntry groupName, SimObjectPtr<GuiInspector> parent ) : GuiInspectorGroup( target, groupName, parent) { /*mNeedScroll=false;*/};
  174. //////////////////////////////////////////////////////////////////////////
  175. // inspectGroup is overridden in GuiInspectorDynamicGroup to inspect an
  176. // objects FieldDictionary (dynamic fields) instead of regular persistent
  177. // fields.
  178. bool inspectGroup();
  179. // For scriptable dynamic field additions
  180. void addDynamicField();
  181. // Clear our fields (delete them)
  182. void clearFields();
  183. // Find an already existent field by name in the dictionary
  184. virtual SimFieldDictionary::Entry* findDynamicFieldInDictionary( StringTableEntry fieldName );
  185. protected:
  186. // create our inner controls when we add
  187. virtual bool createContent();
  188. };
  189. //////////////////////////////////////////////////////////////////////////
  190. // GuiInspectorDatablockField - custom field type for datablock enumeration
  191. //////////////////////////////////////////////////////////////////////////
  192. class GuiInspectorDatablockField : public GuiInspectorField
  193. {
  194. private:
  195. typedef GuiInspectorField Parent;
  196. AbstractClassRep *mDesiredClass;
  197. public:
  198. DECLARE_CONOBJECT(GuiInspectorDatablockField);
  199. GuiInspectorDatablockField( StringTableEntry className );
  200. GuiInspectorDatablockField() { mDesiredClass = NULL; };
  201. void setClassName( StringTableEntry className );
  202. //////////////////////////////////////////////////////////////////////////
  203. // Override able methods for custom edit fields (Both are REQUIRED)
  204. //////////////////////////////////////////////////////////////////////////
  205. virtual GuiControl* constructEditControl();
  206. };
  207. #endif