Torque3D Documentation / _generateds / afxGuiSubstitutionField.cpp

afxGuiSubstitutionField.cpp

Engine/source/afx/ui/afxGuiSubstitutionField.cpp

More...

Public Functions

ConsoleDocClass(afxGuiSubstitutionField , "@brief A customized variation of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiInspectorField.\n\n</a>" "A customized variation of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiInspectorField.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(afxGuiSubstitutionField , "@brief A customized variation of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiInspectorField.\n\n</a>" "A customized variation of <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiInspectorField.\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" )

IMPLEMENT_CONOBJECT(afxGuiSubstitutionField )

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