customField.cpp 4.4 KB

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