customField.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. mDoc = StringTable->insert("no Docs Found!");
  43. }
  44. GuiInspectorCustomField::GuiInspectorCustomField()
  45. {
  46. mInspector = NULL;
  47. mParent = NULL;
  48. mDoc = StringTable->insert("no Docs Found!");
  49. }
  50. void GuiInspectorCustomField::setData( const char* data, bool callbacks )
  51. {
  52. mCustomValue = data;
  53. // Force our edit to update
  54. updateValue();
  55. }
  56. const char* GuiInspectorCustomField::getData( U32 inspectObjectIndex )
  57. {
  58. return mCustomValue;
  59. }
  60. void GuiInspectorCustomField::updateValue()
  61. {
  62. setValue( mCustomValue );
  63. }
  64. void GuiInspectorCustomField::setDoc( const char* doc )
  65. {
  66. mDoc = StringTable->insert( doc, true );
  67. }
  68. void GuiInspectorCustomField::setToolTip( StringTableEntry data )
  69. {
  70. static StringTableEntry sTooltipProfile = StringTable->insert( "tooltipProfile" );
  71. static StringTableEntry sHoverTime = StringTable->insert( "hovertime" );
  72. static StringTableEntry sTooltip = StringTable->insert( "tooltip" );
  73. mEdit->setDataField( sTooltipProfile, NULL, "GuiToolTipProfile" );
  74. mEdit->setDataField( sHoverTime, NULL, "1000" );
  75. mEdit->setDataField( sTooltip, NULL, data );
  76. }
  77. bool GuiInspectorCustomField::onAdd()
  78. {
  79. if( !Parent::onAdd() )
  80. return false;
  81. return true;
  82. }
  83. void GuiInspectorCustomField::setInspectorField( AbstractClassRep::Field *field,
  84. StringTableEntry caption,
  85. const char*arrayIndex )
  86. {
  87. // Override the base just to be sure it doesn't get called.
  88. // We don't use an AbstractClassRep::Field...
  89. // mField = field;
  90. // mCaption = StringTable->EmptyString();
  91. // mRenameCtrl->setText( getFieldName() );
  92. }
  93. GuiControl* GuiInspectorCustomField::constructEditControl()
  94. {
  95. GuiControl* retCtrl = new GuiTextCtrl();
  96. static StringTableEntry sProfile = StringTable->insert( "profile" );
  97. retCtrl->setDataField( sProfile, NULL, "GuiInspectorTextEditProfile" );
  98. // Register the object
  99. retCtrl->registerObject();
  100. return retCtrl;
  101. }
  102. void GuiInspectorCustomField::setValue( const char* newValue )
  103. {
  104. GuiTextCtrl *ctrl = dynamic_cast<GuiTextCtrl*>( mEdit );
  105. if( ctrl != NULL )
  106. ctrl->setText( newValue );
  107. }
  108. void GuiInspectorCustomField::_executeSelectedCallback()
  109. {
  110. Con::executef( mInspector, "onFieldSelected", mCaption, ConsoleBaseType::getType(TypeCaseString)->getTypeName(), mDoc );
  111. }