Torque3D Documentation / _generateds / variableInspector.cpp

variableInspector.cpp

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

More...

Public Functions

ConsoleDocClass(GuiVariableInspector , "@brief GUI dedicated <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> variable viewing/<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">manipulation\n\n</a>" "Mostly used in console system, internal use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" " @internal" )
DefineEngineMethod(GuiVariableInspector , addCallbackField , void , (const char *name, const char *label, const char *typeName, const char *description, const char *defaultValue, const char *dataValues, const char *callbackName, SimObject *ownerObj) , ("", "", "", "", "", "", nullAsType< SimObject * >()) , "addField( fieldName/varName, fieldLabel, fieldTypeName, description, <a href="/coding/file/pointer_8h/#pointer_8h_1a3db30c1795eb39d4452f8698f4a67f05">defaultValue</a>, defaultValues, callbackName, ownerObject )" )
DefineEngineMethod(GuiVariableInspector , addField , void , (const char *name, const char *label, const char *typeName, const char *description, const char *defaultValue, const char *dataValues, SimObject *ownerObj) , ("","","","","", "", nullAsType< SimObject * >()) , "addField( fieldName/varName, fieldLabel, fieldTypeName, description, <a href="/coding/file/pointer_8h/#pointer_8h_1a3db30c1795eb39d4452f8698f4a67f05">defaultValue</a>, defaultValues, ownerObject )" )
DefineEngineMethod(GuiVariableInspector , clearFields , void , () , "clearFields()" )
DefineEngineMethod(GuiVariableInspector , endGroup , void , () , "endGroup()" )
DefineEngineMethod(GuiVariableInspector , loadVars , void , (const char *searchString) , "loadVars( searchString )" )
DefineEngineMethod(GuiVariableInspector , setAutoUpdate , void , (bool doAutoUpdate) , (true) , "setAutoUpdate( doAutoUpdate ) - Dictates <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the inspector automatically updates when changes happen, or <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> it must be called manually" )
DefineEngineMethod(GuiVariableInspector , setFieldEnabled , void , (const char *fieldName, bool isEnabled) , (true) , "setFieldEnabled( fieldName, isEnabled )" )
DefineEngineMethod(GuiVariableInspector , setGroupExpanded , void , (const char *groupName, bool isExpanded) , ("", false) , "setGroupExpanded()" )
DefineEngineMethod(GuiVariableInspector , setGroupsExpanded , void , (bool isExpanded) , (false) , "setGroupsExpanded()" )
DefineEngineMethod(GuiVariableInspector , startGroup , void , (const char *name) , "startGroup( groupName )" )
DefineEngineMethod(GuiVariableInspector , update , void , () , "update()" )

Detailed Description

Public Functions

ConsoleDocClass(GuiVariableInspector , "@brief GUI dedicated <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> variable viewing/<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">manipulation\n\n</a>" "Mostly used in console system, internal use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" " @internal" )

DefineEngineMethod(GuiVariableInspector , addCallbackField , void , (const char *name, const char *label, const char *typeName, const char *description, const char *defaultValue, const char *dataValues, const char *callbackName, SimObject *ownerObj) , ("", "", "", "", "", "", nullAsType< SimObject * >()) , "addField( fieldName/varName, fieldLabel, fieldTypeName, description, <a href="/coding/file/pointer_8h/#pointer_8h_1a3db30c1795eb39d4452f8698f4a67f05">defaultValue</a>, defaultValues, callbackName, ownerObject )" )

DefineEngineMethod(GuiVariableInspector , addField , void , (const char *name, const char *label, const char *typeName, const char *description, const char *defaultValue, const char *dataValues, SimObject *ownerObj) , ("","","","","", "", nullAsType< SimObject * >()) , "addField( fieldName/varName, fieldLabel, fieldTypeName, description, <a href="/coding/file/pointer_8h/#pointer_8h_1a3db30c1795eb39d4452f8698f4a67f05">defaultValue</a>, defaultValues, ownerObject )" )

DefineEngineMethod(GuiVariableInspector , clearFields , void , () , "clearFields()" )

DefineEngineMethod(GuiVariableInspector , endGroup , void , () , "endGroup()" )

DefineEngineMethod(GuiVariableInspector , loadVars , void , (const char *searchString) , "loadVars( searchString )" )

DefineEngineMethod(GuiVariableInspector , setAutoUpdate , void , (bool doAutoUpdate) , (true) , "setAutoUpdate( doAutoUpdate ) - Dictates <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> the inspector automatically updates when changes happen, or <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> it must be called manually" )

DefineEngineMethod(GuiVariableInspector , setFieldEnabled , void , (const char *fieldName, bool isEnabled) , (true) , "setFieldEnabled( fieldName, isEnabled )" )

DefineEngineMethod(GuiVariableInspector , setGroupExpanded , void , (const char *groupName, bool isExpanded) , ("", false) , "setGroupExpanded()" )

DefineEngineMethod(GuiVariableInspector , setGroupsExpanded , void , (bool isExpanded) , (false) , "setGroupsExpanded()" )

DefineEngineMethod(GuiVariableInspector , startGroup , void , (const char *name) , "startGroup( groupName )" )

DefineEngineMethod(GuiVariableInspector , update , void , () , "update()" )

IMPLEMENT_CONOBJECT(GuiVariableInspector )

  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
 24#include "gui/editor/inspector/variableInspector.h"
 25#include "console/engineAPI.h"
 26
 27GuiVariableInspector::GuiVariableInspector() : mAutoUpdate(true)
 28{
 29}
 30
 31GuiVariableInspector::~GuiVariableInspector()
 32{
 33}
 34
 35IMPLEMENT_CONOBJECT(GuiVariableInspector);
 36
 37ConsoleDocClass( GuiVariableInspector,
 38   "@brief GUI dedicated to variable viewing/manipulation\n\n"
 39   "Mostly used in console system, internal use only.\n\n"
 40   "@internal"
 41);
 42
 43void GuiVariableInspector::loadVars( String searchStr )
 44{     
 45   clearGroups();
 46
 47   GuiInspectorVariableGroup *group = new GuiInspectorVariableGroup();
 48
 49   group->setHeaderHidden( true );
 50   group->setCanCollapse( false );
 51   group->mParent = this;
 52   group->setCaption( "Global Variables" );
 53   group->mSearchString = searchStr;
 54
 55   group->registerObject();
 56   mGroups.push_back( group );
 57   addObject( group );
 58 
 59   group->inspectGroup();
 60}
 61
 62void GuiVariableInspector::update()
 63{
 64   for (U32 g = 0; g < mGroups.size(); g++)
 65   {
 66      mGroups[g]->clearFields();
 67   }
 68
 69   for (U32 i = 0; i < mFields.size(); i++)
 70   {
 71      //first, get the var's group name. if the group exists, we'll add to it's list
 72      GuiInspectorVariableGroup *group = nullptr;
 73
 74      for (U32 g = 0; g < mGroups.size(); g++)
 75      {
 76         if (mGroups[g]->getCaption().equal(mFields[i].mGroup))
 77         {
 78            group = static_cast<GuiInspectorVariableGroup*>(mGroups[g]);
 79            break;
 80         }
 81      }
 82
 83      if (group == nullptr)
 84      {
 85         group = new GuiInspectorVariableGroup();
 86
 87         group->setHeaderHidden(false);
 88         group->setCanCollapse(true);
 89         group->mParent = this;
 90         group->setCaption(mFields[i].mGroup);
 91
 92         group->registerObject();
 93         mGroups.push_back(group);
 94         addObject(group);
 95      }
 96      
 97      group->addField(&mFields[i]);
 98   }
 99
100   //And now, cue our update for the groups themselves
101   for (U32 g = 0; g < mGroups.size(); g++)
102   {
103      mGroups[g]->inspectGroup();
104   }
105}
106
107void GuiVariableInspector::startGroup(const char* name)
108{
109   if (!mCurrentGroup.isEmpty())
110      return;
111
112   mCurrentGroup = name;
113}
114
115void GuiVariableInspector::endGroup()
116{
117   mCurrentGroup = "";
118}
119
120void GuiVariableInspector::setGroupExpanded(const char* groupName, bool isExpanded)
121{
122   String name = groupName;
123   for (U32 g = 0; g < mGroups.size(); g++)
124   {
125      if (mGroups[g]->getGroupName() == name)
126      {
127         if (isExpanded)
128            mGroups[g]->expand();
129         else
130            mGroups[g]->collapse();
131      }
132   }
133}
134
135void GuiVariableInspector::setGroupsExpanded(bool isExpanded)
136{
137   for (U32 g = 0; g < mGroups.size(); g++)
138   {
139      if (isExpanded)
140         mGroups[g]->expand();
141      else
142         mGroups[g]->collapse();
143   }
144}
145
146void GuiVariableInspector::addField(const char* name, const char* label, const char* typeName, const char* description, 
147   const char* defaultValue, const char* dataValues, const char* callbackName, SimObject* ownerObj)
148{
149   VariableField newField;
150   newField.mFieldName = StringTable->insert(name);
151   newField.mFieldLabel = StringTable->insert(label);
152   newField.mFieldTypeName = StringTable->insert(typeName);
153   newField.mFieldDescription = StringTable->insert(description);
154   newField.mDefaultValue = StringTable->insert(defaultValue);
155   newField.mDataValues = String(dataValues);
156   newField.mGroup = mCurrentGroup;
157   newField.mSetCallbackName = StringTable->insert(callbackName);
158   newField.mEnabled = true;
159
160   newField.mOwnerObject = ownerObj;
161
162   //establish the field on the ownerObject(if we have one)
163   //This way, we can let the field hook into the object's field and modify it when changed
164   if (newField.mOwnerObject != nullptr)
165   {
166      if (!newField.mOwnerObject->isField(newField.mFieldName))
167      {
168         newField.mOwnerObject->setDataField(newField.mFieldName, NULL, newField.mDefaultValue);
169      }
170   }
171
172   //
173   //find the field type
174   S32 fieldTypeMask = -1;
175
176   if (newField.mFieldTypeName == StringTable->insert("int"))
177      fieldTypeMask = TypeS32;
178   else if (newField.mFieldTypeName == StringTable->insert("float"))
179      fieldTypeMask = TypeF32;
180   else if (newField.mFieldTypeName == StringTable->insert("vector"))
181      fieldTypeMask = TypePoint3F;
182   else if (newField.mFieldTypeName == StringTable->insert("vector2"))
183      fieldTypeMask = TypePoint2F;
184   //else if (fieldType == StringTable->insert("material"))
185   //   fieldTypeMask = TypeMaterialName;
186   else if (newField.mFieldTypeName == StringTable->insert("image"))
187      fieldTypeMask = TypeImageFilename;
188   else if (newField.mFieldTypeName == StringTable->insert("shape"))
189      fieldTypeMask = TypeShapeFilename;
190   else if (newField.mFieldTypeName == StringTable->insert("bool"))
191      fieldTypeMask = TypeBool;
192   else if (newField.mFieldTypeName == StringTable->insert("object"))
193      fieldTypeMask = TypeSimObjectPtr;
194   else if (newField.mFieldTypeName == StringTable->insert("string"))
195      fieldTypeMask = TypeString;
196   else if (newField.mFieldTypeName == StringTable->insert("colorI"))
197      fieldTypeMask = TypeColorI;
198   else if (newField.mFieldTypeName == StringTable->insert("colorF"))
199      fieldTypeMask = TypeColorF;
200   else if (newField.mFieldTypeName == StringTable->insert("ease"))
201      fieldTypeMask = TypeEaseF;
202   else if (newField.mFieldTypeName == StringTable->insert("command"))
203      fieldTypeMask = TypeCommand;
204   else if (newField.mFieldTypeName == StringTable->insert("filename"))
205      fieldTypeMask = TypeStringFilename;
206   else
207      fieldTypeMask = -1;
208
209   newField.mFieldType = fieldTypeMask;
210   //
211
212   mFields.push_back(newField);
213
214   if(mAutoUpdate)
215      update();
216}
217
218void GuiVariableInspector::addCallbackField(const char* name, const char* label, const char* typeName, const char* description,
219   const char* defaultValue, const char* dataValues, const char* callbackName, SimObject* ownerObj)
220{
221   addField(name, label, typeName, description, defaultValue, dataValues, callbackName, ownerObj);
222}
223
224void GuiVariableInspector::clearFields()
225{
226   mGroups.clear();
227   mFields.clear();
228   clear();
229   
230   update();
231}
232
233void GuiVariableInspector::setFieldEnabled(const char* name, bool enabled)
234{
235   String fieldName = name;
236   for (U32 i = 0; i < mFields.size(); i++)
237   {
238      if (fieldName.equal(mFields[i].mFieldName, String::NoCase))
239      {
240         mFields[i].mEnabled = enabled;
241         update();
242         return;
243      }
244   }
245}
246
247DefineEngineMethod(GuiVariableInspector, startGroup, void, (const char* name),, "startGroup( groupName )")
248{
249   object->startGroup(name);
250}
251
252DefineEngineMethod(GuiVariableInspector, endGroup, void, (),, "endGroup()")
253{
254   object->endGroup();
255}
256
257DefineEngineMethod(GuiVariableInspector, setGroupExpanded, void, (const char* groupName, bool isExpanded), ("", false), "setGroupExpanded()")
258{
259   object->setGroupExpanded(groupName, isExpanded);
260}
261
262DefineEngineMethod(GuiVariableInspector, setGroupsExpanded, void, (bool isExpanded), (false), "setGroupsExpanded()")
263{
264   object->setGroupsExpanded(isExpanded);
265}
266
267
268DefineEngineMethod(GuiVariableInspector, addField, void, (const char* name, const char* label, const char* typeName, 
269   const char* description, const char* defaultValue, const char* dataValues, SimObject* ownerObj),
270   ("","","","","", "", nullAsType<SimObject*>()), "addField( fieldName/varName, fieldLabel, fieldTypeName, description, defaultValue, defaultValues, ownerObject )")
271{
272   if (dStrEqual(name, "") || dStrEqual(typeName, ""))
273      return;
274
275   object->addField(name, label, typeName, description, defaultValue, dataValues, "", ownerObj);
276}
277
278DefineEngineMethod(GuiVariableInspector, addCallbackField, void, (const char* name, const char* label, const char* typeName,
279   const char* description, const char* defaultValue, const char* dataValues, const char* callbackName, SimObject* ownerObj),
280   ("", "", "", "", "", "", nullAsType<SimObject*>()), "addField( fieldName/varName, fieldLabel, fieldTypeName, description, defaultValue, defaultValues, callbackName, ownerObject )")
281{
282   if (dStrEqual(name, "") || dStrEqual(typeName, ""))
283      return;
284
285   object->addCallbackField(name, label, typeName, description, defaultValue, dataValues, callbackName, ownerObj);
286}
287
288DefineEngineMethod(GuiVariableInspector, update, void, (), , "update()")
289{
290   object->update();
291}
292
293DefineEngineMethod(GuiVariableInspector, clearFields, void, (), , "clearFields()")
294{
295   object->clearFields();
296}
297
298DefineEngineMethod(GuiVariableInspector, setFieldEnabled, void, (const char* fieldName, bool isEnabled), (true), "setFieldEnabled( fieldName, isEnabled )")
299{
300   object->setFieldEnabled(fieldName, isEnabled);
301}
302
303DefineEngineMethod( GuiVariableInspector, loadVars, void, ( const char * searchString ), , "loadVars( searchString )" )
304{
305   object->loadVars( searchString );
306}
307
308DefineEngineMethod(GuiVariableInspector, setAutoUpdate, void, (bool doAutoUpdate), (true), "setAutoUpdate( doAutoUpdate ) - Dictates if the inspector automatically updates when changes happen, or if it must be called manually")
309{
310   object->setAutoUpdate(doAutoUpdate);
311}
312