Torque3D Documentation / _generateds / variableGroup.cpp

variableGroup.cpp

Engine/source/gui/editor/inspector/variableGroup.cpp

More...

Public Variables

Public Functions

ConsoleDocClass(GuiInspectorVariableGroup , "@brief Inspector support <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> variable groups in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiVariableInspector.\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
DefineEngineMethod(GuiInspectorVariableGroup , addInspectorField , void , (GuiInspectorField *field) , (nullAsType< GuiInspectorField * >()) , "addInspectorField( GuiInspectorFieldObject )" )
DefineEngineMethod(GuiInspectorVariableGroup , createInspectorField , GuiInspectorField * , () , "createInspectorField()" )

Detailed Description

Public Variables

ExprEvalState gEvalState 

Public Functions

ConsoleDocClass(GuiInspectorVariableGroup , "@brief Inspector support <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> variable groups in <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">GuiVariableInspector.\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )

DefineEngineMethod(GuiInspectorVariableGroup , addInspectorField , void , (GuiInspectorField *field) , (nullAsType< GuiInspectorField * >()) , "addInspectorField( GuiInspectorFieldObject )" )

DefineEngineMethod(GuiInspectorVariableGroup , createInspectorField , GuiInspectorField * , () , "createInspectorField()" )

IMPLEMENT_CONOBJECT(GuiInspectorVariableGroup )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  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#include "platform/platform.h"
 24#include "gui/editor/inspector/variableGroup.h"
 25#include "gui/editor/inspector/variableField.h"
 26#include "gui/editor/guiInspector.h"
 27#include "gui/buttons/guiIconButtonCtrl.h"
 28#include "console/consoleInternal.h"
 29
 30extern ExprEvalState gEvalState;
 31
 32//-----------------------------------------------------------------------------
 33// GuiInspectorVariableGroup
 34//-----------------------------------------------------------------------------
 35//
 36//
 37IMPLEMENT_CONOBJECT(GuiInspectorVariableGroup);
 38
 39ConsoleDocClass( GuiInspectorVariableGroup,
 40   "@brief Inspector support for variable groups in a GuiVariableInspector.\n\n"
 41   "Editor use only.\n\n"
 42   "@internal"
 43);
 44
 45GuiInspectorVariableGroup::GuiInspectorVariableGroup() 
 46{
 47}
 48
 49GuiInspectorVariableGroup::~GuiInspectorVariableGroup()
 50{  
 51}
 52
 53GuiInspectorField* GuiInspectorVariableGroup::constructField( S32 fieldType )
 54{
 55   return Parent::constructField(fieldType);
 56}
 57
 58bool GuiInspectorVariableGroup::inspectGroup()
 59{
 60   // to prevent crazy resizing, we'll just freeze our stack for a sec..
 61   mStack->freeze(true);
 62
 63   bool bNewItems = false;
 64
 65   if (!mSearchString.equal(""))
 66   {
 67      Vector<String> names;
 68
 69      gEvalState.globalVars.exportVariables(mSearchString, &names, NULL);
 70
 71      for (U32 i = 0; i < names.size(); i++)
 72      {
 73         const String &varName = names[i];
 74
 75         // If the field already exists, just update it
 76         GuiInspectorVariableField *field = dynamic_cast<GuiInspectorVariableField*>(findField(varName));
 77         if (field != NULL)
 78         {
 79            field->updateValue();
 80            continue;
 81         }
 82
 83         bNewItems = true;
 84
 85         field = new GuiInspectorVariableField();
 86         field->init(mParent, this);
 87         field->setInspectorField(NULL, StringTable->insert(varName));
 88
 89         if (field->registerObject())
 90         {
 91            mChildren.push_back(field);
 92            mStack->addObject(field);
 93         }
 94         else
 95            delete field;
 96      }
 97   }
 98
 99   for (U32 i = 0; i < mFields.size(); i++)
100   {
101      bNewItems = true;
102
103      GuiInspectorField *fieldGui = findField(mFields[i]->mFieldName);
104      if (fieldGui != NULL)
105      {
106         fieldGui->updateValue();
107         continue;
108      }
109
110      //first and foremost, nab the field type and check if it's a custom field or not.
111      //If it's not a custom field, proceed below, if it is, hand it off to script to be handled by the component
112      if (mFields[i]->mFieldType == -1)
113      {
114         if (isMethod("onConstructField"))
115         {
116            //ensure our stack variable is bound if we need it
117            Con::evaluatef("%d.stack = %d;", this->getId(), mStack->getId());
118
119            Con::executef(this, "onConstructField", mFields[i]->mFieldName,
120               mFields[i]->mFieldLabel, mFields[i]->mFieldTypeName, mFields[i]->mFieldDescription,
121               mFields[i]->mDefaultValue, mFields[i]->mDataValues, mFields[i]->mSetCallbackName, mFields[i]->mOwnerObject);
122         }
123         continue;
124      }
125
126      bNewItems = true;
127
128      fieldGui = constructField(mFields[i]->mFieldType);
129      if (fieldGui == NULL)
130         fieldGui = new GuiInspectorField();
131
132      fieldGui->init(mParent, this);
133
134      fieldGui->setSpecialEditField(true);
135
136      if (mFields[i]->mOwnerObject)
137      {
138         fieldGui->setTargetObject(mFields[i]->mOwnerObject);
139      }
140      else
141      {
142         //check if we're binding to a global var first, if we have no owner
143         if (mFields[i]->mFieldName[0] != '$')
144         {
145            fieldGui->setTargetObject(mParent);
146         }
147      }
148
149      fieldGui->setSpecialEditVariableName(mFields[i]->mFieldName);
150      fieldGui->setSpecialEditCallbackName(mFields[i]->mSetCallbackName);
151
152      fieldGui->setInspectorField(NULL, mFields[i]->mFieldLabel);
153      fieldGui->setDocs(mFields[i]->mFieldDescription);
154
155      if(mFields[i]->mSetCallbackName != StringTable->EmptyString())
156         fieldGui->setSpecialEditCallbackName(mFields[i]->mSetCallbackName);
157
158      /*if (mFields[i]->mSetCallbackName != StringTable->EmptyString())
159      {
160         fieldGui->on.notify()
161      }*/
162         
163      if (fieldGui->registerObject())
164      {
165#ifdef DEBUG_SPEW
166         Platform::outputDebugString("[GuiInspectorVariableGroup] Adding field '%s'",
167            field->pFieldname);
168#endif
169
170         if (mFields[i]->mOwnerObject)
171         {
172            String val = mFields[i]->mOwnerObject->getDataField(mFields[i]->mFieldName, NULL);
173
174            if(val.isEmpty())
175               fieldGui->setValue(mFields[i]->mDefaultValue);
176            else
177               fieldGui->setValue(val);
178         }
179         else
180         {
181            fieldGui->setValue(mFields[i]->mDefaultValue);
182         }
183
184         fieldGui->setActive(mFields[i]->mEnabled);
185
186         mChildren.push_back(fieldGui);
187         mStack->addObject(fieldGui);
188      }
189      else
190      {
191         SAFE_DELETE(fieldGui);
192      }
193   }
194   
195   mStack->freeze(false);
196   mStack->updatePanes();
197
198   // If we've no new items, there's no need to resize anything!
199   if( bNewItems == false && !mChildren.empty() )
200      return true;
201
202   sizeToContents();
203
204   setUpdate();
205
206   return true;
207}
208
209void GuiInspectorVariableGroup::clearFields()
210{
211   mFields.clear();
212}
213
214void GuiInspectorVariableGroup::addField(VariableField* field)
215{
216   bool found = false;
217
218   for (U32 i = 0; i < mFields.size(); i++)
219   {
220      if (mFields[i]->mFieldName == field->mFieldName)
221      {
222         found = true;
223         break;
224      }
225   }
226
227   if(!found)
228      mFields.push_back(field);
229}
230
231void GuiInspectorVariableGroup::addInspectorField(GuiInspectorField* field)
232{
233   mStack->addObject(field);
234   mChildren.push_back(field);
235   mStack->updatePanes();
236}
237
238GuiInspectorField* GuiInspectorVariableGroup::createInspectorField()
239{
240   GuiInspectorField* newField = new GuiInspectorField();
241
242   newField->init(mParent, this);
243
244   newField->setSpecialEditField(true);
245
246   if (newField->registerObject())
247   {
248      return newField;
249   }
250
251   return NULL;
252}
253
254DefineEngineMethod(GuiInspectorVariableGroup, createInspectorField, GuiInspectorField*, (),, "createInspectorField()")
255{
256   return object->createInspectorField();
257}
258
259DefineEngineMethod(GuiInspectorVariableGroup, addInspectorField, void, (GuiInspectorField* field), (nullAsType<GuiInspectorField*>()), "addInspectorField( GuiInspectorFieldObject )")
260{
261   object->addInspectorField(field);
262}
263