afxGuiSubstitutionField.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #include "afx/arcaneFX.h"
  25. #include "gui/editor/inspector/customField.h"
  26. #include "gui/editor/guiInspector.h"
  27. #include "afx/ui/afxGuiSubstitutionField.h"
  28. IMPLEMENT_CONOBJECT( afxGuiSubstitutionField );
  29. ConsoleDocClass( afxGuiSubstitutionField,
  30. "@brief A customized variation of GuiInspectorField.\n\n"
  31. "A customized variation of GuiInspectorField.\n"
  32. "@ingroup AFX\n"
  33. );
  34. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  35. afxGuiSubstitutionField::afxGuiSubstitutionField( GuiInspector* inspector,
  36. GuiInspectorGroup* parent,
  37. SimFieldDictionary::Entry* field)
  38. {
  39. mInspector = inspector;
  40. mParent = parent;
  41. setBounds(0,0,100,20);
  42. subs_string = StringTable->insert("");
  43. }
  44. afxGuiSubstitutionField::afxGuiSubstitutionField()
  45. {
  46. mInspector = NULL;
  47. mParent = NULL;
  48. subs_string = StringTable->insert("");
  49. }
  50. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  51. void afxGuiSubstitutionField::setData( const char* data, bool callbacks )
  52. {
  53. if ( mField == NULL)
  54. return;
  55. const U32 numTargets = mInspector->getNumInspectObjects();
  56. //if( callbacks && numTargets > 1 )
  57. // Con::executef( mInspector, "beginCompoundUndo" );
  58. if (data[0] != '$' && data[1] != '$')
  59. {
  60. data = StringTable->insert(avar("$$ %s", data), true);
  61. }
  62. else
  63. {
  64. data = StringTable->insert(data, true);
  65. }
  66. for( U32 i = 0; i < numTargets; ++ i )
  67. {
  68. SimObject* target = mInspector->getInspectObject( i );
  69. SimDataBlock* datablock = dynamic_cast<SimDataBlock*>(target);
  70. if (datablock)
  71. datablock->addSubstitution(mField->pFieldname, 0, data);
  72. }
  73. //if( callbacks && numTargets > 1 )
  74. // Con::executef( mInspector, "endCompoundUndo" );
  75. // Force our edit to update
  76. updateValue();
  77. }
  78. const char* afxGuiSubstitutionField::getData( U32 inspectObjectIndex )
  79. {
  80. if( mField == NULL)
  81. return "";
  82. SimObject* target = mInspector->getInspectObject(inspectObjectIndex);
  83. SimDataBlock* datablock = dynamic_cast<SimDataBlock*>(target);
  84. if (datablock)
  85. {
  86. const char* current_subs = datablock->getSubstitution(mField->pFieldname, 0);
  87. if (current_subs)
  88. return StringTable->insert(avar("$$ %s", current_subs));
  89. }
  90. return StringTable->insert( "" );
  91. }
  92. /// Update this controls value to reflect that of the inspected field.
  93. void afxGuiSubstitutionField::updateValue()
  94. {
  95. if( mInspector->getNumInspectObjects() > 1 )
  96. {
  97. // ??
  98. return;
  99. }
  100. SimObject* target = mInspector->getInspectObject(0);
  101. SimDataBlock* datablock = dynamic_cast<SimDataBlock*>(target);
  102. if (datablock)
  103. {
  104. const char* current_subs = datablock->getSubstitution(mField->pFieldname, 0);
  105. if (current_subs)
  106. {
  107. setValue(StringTable->insert(avar("$$ %s", current_subs)));
  108. return;
  109. }
  110. }
  111. setValue(StringTable->insert("$$ -- undefined --"));
  112. }
  113. void afxGuiSubstitutionField::setToolTip( StringTableEntry data )
  114. {
  115. mEdit->setDataField( StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile" );
  116. mEdit->setDataField( StringTable->insert("hovertime"), NULL, "1000" );
  117. mEdit->setDataField( StringTable->insert("tooltip"), NULL, data );
  118. }
  119. bool afxGuiSubstitutionField::onAdd()
  120. {
  121. if( !Parent::onAdd() )
  122. return false;
  123. return true;
  124. }
  125. GuiControl* afxGuiSubstitutionField::constructEditControl()
  126. {
  127. if (mField->doNotSubstitute)
  128. {
  129. GuiTextEditCtrl* retCtrl = new GuiTextEditCtrl();
  130. retCtrl->setDataField( StringTable->insert("profile"), NULL, "GuiInspectorTextEditProfile" );
  131. // Register the object
  132. retCtrl->registerObject();
  133. retCtrl->setText( StringTable->insert("n/a") );
  134. retCtrl->setActive(false);
  135. return retCtrl;
  136. }
  137. GuiControl* retCtrl = new GuiTextEditCtrl();
  138. retCtrl->setDataField( StringTable->insert("profile"), NULL, "GuiInspectorTextEditProfile" );
  139. // Register the object
  140. retCtrl->registerObject();
  141. char szBuffer[512];
  142. dSprintf( szBuffer, 512, "%d.apply(%d.getText());",getId(), retCtrl->getId() );
  143. retCtrl->setField("AltCommand", szBuffer );
  144. retCtrl->setField("Validate", szBuffer );
  145. return retCtrl;
  146. }
  147. void afxGuiSubstitutionField::setValue( const char* newValue )
  148. {
  149. if (!mField->doNotSubstitute)
  150. {
  151. GuiTextEditCtrl *ctrl = dynamic_cast<GuiTextEditCtrl*>( mEdit );
  152. if ( ctrl != NULL )
  153. ctrl->setText( newValue );
  154. }
  155. }
  156. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  157. // protected:
  158. void afxGuiSubstitutionField::_executeSelectedCallback()
  159. {
  160. Con::executef( mInspector, "onFieldSelected", mCaption, ConsoleBaseType::getType(mField->type)->getTypeName(), "Substitution Statement" );
  161. }
  162. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//