afxGuiSubstitutionField.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. #ifdef TORQUE_TOOLS
  25. #include "afx/arcaneFX.h"
  26. #include "gui/editor/inspector/customField.h"
  27. #include "gui/editor/guiInspector.h"
  28. #include "afx/ui/afxGuiSubstitutionField.h"
  29. IMPLEMENT_CONOBJECT( afxGuiSubstitutionField );
  30. ConsoleDocClass( afxGuiSubstitutionField,
  31. "@brief A customized variation of GuiInspectorField.\n\n"
  32. "A customized variation of GuiInspectorField.\n"
  33. "@ingroup AFX\n"
  34. );
  35. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  36. afxGuiSubstitutionField::afxGuiSubstitutionField( GuiInspector* inspector,
  37. GuiInspectorGroup* parent,
  38. SimFieldDictionary::Entry* field)
  39. {
  40. mInspector = inspector;
  41. mParent = parent;
  42. setBounds(0,0,100,20);
  43. subs_string = StringTable->insert("");
  44. }
  45. afxGuiSubstitutionField::afxGuiSubstitutionField()
  46. {
  47. mInspector = NULL;
  48. mParent = NULL;
  49. subs_string = StringTable->insert("");
  50. }
  51. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  52. void afxGuiSubstitutionField::setData( const char* data, bool callbacks )
  53. {
  54. if ( mField == NULL)
  55. return;
  56. const U32 numTargets = mInspector->getNumInspectObjects();
  57. //if( callbacks && numTargets > 1 )
  58. // Con::executef( mInspector, "beginCompoundUndo" );
  59. if (data[0] != '$' && data[1] != '$')
  60. {
  61. data = StringTable->insert(avar("$$ %s", data), true);
  62. }
  63. else
  64. {
  65. data = StringTable->insert(data, true);
  66. }
  67. for( U32 i = 0; i < numTargets; ++ i )
  68. {
  69. SimObject* target = mInspector->getInspectObject( i );
  70. SimDataBlock* datablock = dynamic_cast<SimDataBlock*>(target);
  71. if (datablock)
  72. datablock->addSubstitution(mField->pFieldname, 0, data);
  73. }
  74. //if( callbacks && numTargets > 1 )
  75. // Con::executef( mInspector, "endCompoundUndo" );
  76. // Force our edit to update
  77. updateValue();
  78. }
  79. const char* afxGuiSubstitutionField::getData( U32 inspectObjectIndex )
  80. {
  81. if( mField == NULL)
  82. return "";
  83. SimObject* target = mInspector->getInspectObject(inspectObjectIndex);
  84. SimDataBlock* datablock = dynamic_cast<SimDataBlock*>(target);
  85. if (datablock)
  86. {
  87. const char* current_subs = datablock->getSubstitution(mField->pFieldname, 0);
  88. if (current_subs)
  89. return StringTable->insert(avar("$$ %s", current_subs));
  90. }
  91. return StringTable->insert( "" );
  92. }
  93. /// Update this controls value to reflect that of the inspected field.
  94. void afxGuiSubstitutionField::updateValue()
  95. {
  96. if( mInspector->getNumInspectObjects() > 1 )
  97. {
  98. // ??
  99. return;
  100. }
  101. SimObject* target = mInspector->getInspectObject(0);
  102. SimDataBlock* datablock = dynamic_cast<SimDataBlock*>(target);
  103. if (datablock)
  104. {
  105. const char* current_subs = datablock->getSubstitution(mField->pFieldname, 0);
  106. if (current_subs)
  107. {
  108. setValue(StringTable->insert(avar("$$ %s", current_subs)));
  109. return;
  110. }
  111. }
  112. setValue(StringTable->insert("$$ -- undefined --"));
  113. }
  114. void afxGuiSubstitutionField::setToolTip( StringTableEntry data )
  115. {
  116. mEdit->setDataField( StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile" );
  117. mEdit->setDataField( StringTable->insert("hovertime"), NULL, "1000" );
  118. mEdit->setDataField( StringTable->insert("tooltip"), NULL, data );
  119. }
  120. bool afxGuiSubstitutionField::onAdd()
  121. {
  122. if( !Parent::onAdd() )
  123. return false;
  124. return true;
  125. }
  126. GuiControl* afxGuiSubstitutionField::constructEditControl()
  127. {
  128. if (mField->doNotSubstitute)
  129. {
  130. GuiTextEditCtrl* retCtrl = new GuiTextEditCtrl();
  131. retCtrl->setDataField( StringTable->insert("profile"), NULL, "GuiInspectorTextEditProfile" );
  132. // Register the object
  133. retCtrl->registerObject();
  134. retCtrl->setText( StringTable->insert("n/a") );
  135. retCtrl->setActive(false);
  136. return retCtrl;
  137. }
  138. GuiControl* retCtrl = new GuiTextEditCtrl();
  139. retCtrl->setDataField( StringTable->insert("profile"), NULL, "GuiInspectorTextEditProfile" );
  140. // Register the object
  141. retCtrl->registerObject();
  142. char szBuffer[512];
  143. dSprintf( szBuffer, 512, "%d.apply(%d.getText());",getId(), retCtrl->getId() );
  144. retCtrl->setField("AltCommand", szBuffer );
  145. retCtrl->setField("Validate", szBuffer );
  146. return retCtrl;
  147. }
  148. void afxGuiSubstitutionField::setValue( const char* newValue )
  149. {
  150. if (!mField->doNotSubstitute)
  151. {
  152. GuiTextEditCtrl *ctrl = dynamic_cast<GuiTextEditCtrl*>( mEdit );
  153. if ( ctrl != NULL )
  154. ctrl->setText( newValue );
  155. }
  156. }
  157. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  158. // protected:
  159. void afxGuiSubstitutionField::_executeSelectedCallback()
  160. {
  161. Con::executef( mInspector, "onFieldSelected", mCaption, ConsoleBaseType::getType(mField->type)->getTypeName(), "Substitution Statement" );
  162. }
  163. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  164. #endif