field.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. #ifndef _GUI_INSPECTOR_FIELD_H_
  23. #define _GUI_INSPECTOR_FIELD_H_
  24. #include "gui/core/guiCanvas.h"
  25. #include "gui/shiny/guiTickCtrl.h"
  26. #include "gui/controls/guiTextEditCtrl.h"
  27. #include "gui/buttons/guiBitmapButtonCtrl.h"
  28. #include "gui/controls/guiPopUpCtrl.h"
  29. #include "gui/containers/guiRolloutCtrl.h"
  30. class GuiInspectorGroup;
  31. class GuiInspector;
  32. /// The GuiInspectorField control is a representation of a single abstract
  33. /// field for a given ConsoleObject derived object. It handles creation
  34. /// getting and setting of it's fields data and editing control.
  35. ///
  36. /// Creation of custom edit controls is done through this class and is
  37. /// dependent upon the dynamic console type, which may be defined to be
  38. /// custom for different types.
  39. ///
  40. /// @note GuiInspectorField controls must have a GuiInspectorGroup as their
  41. /// parent.
  42. class GuiInspectorField : public GuiControl
  43. {
  44. public:
  45. typedef GuiControl Parent;
  46. friend class GuiInspectorGroup;
  47. protected:
  48. /// The text to display as the field name.
  49. StringTableEntry mCaption;
  50. /// The group to which this field belongs.
  51. GuiInspectorGroup* mParent;
  52. /// The GuiInspector that the group is in to which this field belongs.
  53. GuiInspector* mInspector;
  54. ///
  55. AbstractClassRep::Field* mField;
  56. ///
  57. StringTableEntry mFieldArrayIndex;
  58. ///
  59. String mFieldDocs;
  60. ///
  61. GuiControl* mEdit;
  62. ///
  63. RectI mCaptionRect;
  64. ///
  65. RectI mEditCtrlRect;
  66. ///
  67. bool mHighlighted;
  68. //These are so we can special-case our height for additional room on certain field-types
  69. bool mUseHeightOverride;
  70. U32 mHeightOverride;
  71. //An override that lets us bypass inspector-dependent logic for setting/getting variables/fields
  72. bool mSpecialEditField;
  73. //An override to make sure this field is associated to an object that isn't expressly
  74. //the one the inspector is inspecting. Such as an entity's component.
  75. SimObject* mTargetObject;
  76. //Special edit field, variable name - the variable or field name targeted
  77. StringTableEntry mVariableName;
  78. //Special edit field, callback name - if defined, we'll do a callback to the function listed here when editing the field
  79. StringTableEntry mCallbackName;
  80. //Special edit field, variable type
  81. StringTableEntry mVariableType;
  82. virtual void _registerEditControl(GuiControl* ctrl, StringTableEntry suffix = "");
  83. virtual void _executeSelectedCallback();
  84. void _setFieldDocs( StringTableEntry docs );
  85. public:
  86. explicit GuiInspectorField();
  87. ///
  88. GuiInspectorField( GuiInspector *inspector, GuiInspectorGroup* parent, AbstractClassRep::Field* field );
  89. virtual ~GuiInspectorField();
  90. ///
  91. virtual void init( GuiInspector *inspector, GuiInspectorGroup *group );
  92. ///
  93. virtual void setInspectorField( AbstractClassRep::Field *field,
  94. StringTableEntry caption = NULL,
  95. const char *arrayIndex = NULL );
  96. ///
  97. virtual GuiControl* constructEditControl();
  98. /// Chooses and sets the GuiControlProfile.
  99. virtual void setInspectorProfile();
  100. /// Sets this control's caption text, usually set within setInspectorField,
  101. /// this is exposed in case someone wants to override the normal caption.
  102. virtual void setCaption( StringTableEntry caption ) { mCaption = caption; }
  103. virtual StringTableEntry getCaption() { return mCaption; }
  104. void setEditControl(GuiControl* editCtrl);
  105. void setHeightOverride(bool useOverride, U32 heightOverride);
  106. virtual void setDocs(String docs) { mFieldDocs = docs; }
  107. /// Returns pointer to this InspectorField's edit ctrl.
  108. virtual GuiControl* getEditCtrl() { return mEdit; }
  109. /// Sets the value of this GuiInspectorField (not the actual field)
  110. /// This means the EditCtrl unless overridden.
  111. virtual void setValue( const char* newValue );
  112. /// Get the currently value of this control (not the actual field)
  113. virtual const char* getValue() { return NULL; }
  114. /// Update this controls value to reflect that of the inspected field.
  115. virtual void updateValue();
  116. /// Return the name of the field being edited.
  117. virtual StringTableEntry getFieldName();
  118. /// Return the name of the console type that this field uses.
  119. virtual StringTableEntry getFieldType();
  120. /// Return the name without the array index that may potentially be present.
  121. virtual StringTableEntry getRawFieldName();
  122. ///
  123. StringTableEntry getArrayIndex() const { return mFieldArrayIndex; }
  124. /// Called from within setData to allow child classes
  125. /// to perform their own verification.
  126. virtual bool verifyData( StringTableEntry data ) { return true; }
  127. void setWordData(const S32& wordIndex, const char* data, bool callbacks);
  128. /// Set value of the field we are inspecting
  129. virtual void setData( const char* data, bool callbacks = true );
  130. /// Reset the field value to its default value based on default-constructed objects.
  131. ///
  132. /// @note If multiple objects are inspected, this will take the default value from
  133. /// the first object and set all fields to this value.
  134. virtual void resetData();
  135. /// Get value of the field we are inspecting.
  136. ///
  137. /// @note The string returned by this method may be a transient string allocated
  138. /// internally by the console. For any non-transient needs, this string has
  139. /// to be copied to locally owned memory.
  140. /// @note This method always returns the value of the field in the first
  141. /// inspected object.
  142. virtual const char* getData( U32 inspectObjectIndex = 0 );
  143. /// Update the inspected field to match the value of this control.
  144. virtual void updateData() {};
  145. ///
  146. virtual bool updateRects();
  147. ///
  148. virtual void setHLEnabled( bool enabled );
  149. /// Return true if all inspected objects have the same value for this
  150. /// field.
  151. bool hasSameValueInAllObjects();
  152. /// Return the inspector object that this field belongs to.
  153. GuiInspector* getInspector() const { return mInspector; }
  154. // GuiControl.
  155. bool onAdd() override;
  156. bool resize(const Point2I &newPosition, const Point2I &newExtent) override;
  157. void onRender(Point2I offset, const RectI &updateRect) override;
  158. void setFirstResponder( GuiControl *firstResponder ) override;
  159. void onMouseDown( const GuiEvent &event ) override;
  160. void onRightMouseUp( const GuiEvent &event ) override;
  161. void setTargetObject(SimObject* obj) { mTargetObject = obj; }
  162. SimObject* getTargetObject() { return mTargetObject; }
  163. void setSpecialEditField(bool isSpecialEditField) { mSpecialEditField = isSpecialEditField; }
  164. void setSpecialEditVariableName(StringTableEntry varName) { mVariableName = varName; }
  165. StringTableEntry getSpecialEditVariableName() { return mVariableName; }
  166. void setSpecialEditVariableType(StringTableEntry varType) { mVariableType = varType; }
  167. StringTableEntry getSpecialEditVariableType() { return mVariableType; }
  168. void setSpecialEditCallbackName(StringTableEntry callName) { mCallbackName = callName; }
  169. DECLARE_CONOBJECT( GuiInspectorField );
  170. DECLARE_CATEGORY( "Gui Editor" );
  171. };
  172. #endif // _GUI_INSPECTOR_FIELD_H_