customField.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/editor/inspector/customField.h"
  23. #include "gui/editor/guiInspector.h"
  24. //-----------------------------------------------------------------------------
  25. // GuiInspectorCustomField - Child class of GuiInspectorField
  26. //-----------------------------------------------------------------------------
  27. IMPLEMENT_CONOBJECT( GuiInspectorCustomField );
  28. ConsoleDocClass( GuiInspectorCustomField,
  29. "@brief A control that allows to edit the custom properties (text) of one or more SimObjects.\n\n"
  30. "Editor use only.\n\n"
  31. "@internal"
  32. );
  33. GuiInspectorCustomField::GuiInspectorCustomField( GuiInspector *inspector,
  34. GuiInspectorGroup* parent,
  35. SimFieldDictionary::Entry* field )
  36. {
  37. mInspector = inspector;
  38. mParent = parent;
  39. setBounds(0,0,100,20);
  40. }
  41. GuiInspectorCustomField::GuiInspectorCustomField()
  42. {
  43. mInspector = NULL;
  44. mParent = NULL;
  45. }
  46. void GuiInspectorCustomField::setData( const char* data, bool callbacks )
  47. {
  48. mCustomValue = data;
  49. // Force our edit to update
  50. updateValue();
  51. }
  52. const char* GuiInspectorCustomField::getData( U32 inspectObjectIndex )
  53. {
  54. return mCustomValue;
  55. }
  56. void GuiInspectorCustomField::updateValue()
  57. {
  58. setValue( mCustomValue );
  59. }
  60. void GuiInspectorCustomField::setDoc( const char* doc )
  61. {
  62. mDoc = StringTable->insert( doc, true );
  63. }
  64. void GuiInspectorCustomField::setToolTip( StringTableEntry data )
  65. {
  66. static StringTableEntry sTooltipProfile = StringTable->insert( "tooltipProfile" );
  67. static StringTableEntry sHoverTime = StringTable->insert( "hovertime" );
  68. static StringTableEntry sTooltip = StringTable->insert( "tooltip" );
  69. mEdit->setDataField( sTooltipProfile, NULL, "GuiToolTipProfile" );
  70. mEdit->setDataField( sHoverTime, NULL, "1000" );
  71. mEdit->setDataField( sTooltip, NULL, data );
  72. }
  73. bool GuiInspectorCustomField::onAdd()
  74. {
  75. if( !Parent::onAdd() )
  76. return false;
  77. return true;
  78. }
  79. void GuiInspectorCustomField::setInspectorField( AbstractClassRep::Field *field,
  80. StringTableEntry caption,
  81. const char*arrayIndex )
  82. {
  83. // Override the base just to be sure it doesn't get called.
  84. // We don't use an AbstractClassRep::Field...
  85. // mField = field;
  86. // mCaption = StringTable->EmptyString();
  87. // mRenameCtrl->setText( getFieldName() );
  88. }
  89. GuiControl* GuiInspectorCustomField::constructEditControl()
  90. {
  91. GuiControl* retCtrl = new GuiTextCtrl();
  92. static StringTableEntry sProfile = StringTable->insert( "profile" );
  93. retCtrl->setDataField( sProfile, NULL, "GuiInspectorTextEditProfile" );
  94. // Register the object
  95. retCtrl->registerObject();
  96. return retCtrl;
  97. }
  98. void GuiInspectorCustomField::setValue( const char* newValue )
  99. {
  100. GuiTextCtrl *ctrl = dynamic_cast<GuiTextCtrl*>( mEdit );
  101. if( ctrl != NULL )
  102. ctrl->setText( newValue );
  103. }
  104. void GuiInspectorCustomField::_executeSelectedCallback()
  105. {
  106. Con::executef( mInspector, "onFieldSelected", mCaption, ConsoleBaseType::getType(TypeCaseString)->getTypeName(), mDoc );
  107. }