afxGuiSubstitutionField.cpp 6.2 KB

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