guiInspector.cc 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "gui/editor/guiInspector.h"
  23. #include "gui/buttons/guiButtonCtrl.h"
  24. #include "memory/frameAllocator.h"
  25. #pragma region GuiInspector
  26. //////////////////////////////////////////////////////////////////////////
  27. // GuiInspector
  28. //////////////////////////////////////////////////////////////////////////
  29. IMPLEMENT_CONOBJECT(GuiInspector);
  30. GuiInspector::GuiInspector()
  31. {
  32. mGroups.clear();
  33. mTarget = NULL;
  34. mGroupPanelProfile = NULL;
  35. setField("GroupPanelProfile", "GuiPanelProfile");
  36. mGroupGridProfile = NULL;
  37. setField("GroupGridProfile", "GuiDefaultProfile");
  38. mLabelProfile = NULL;
  39. setField("LabelProfile", "GuiDefaultProfile");
  40. mTextEditProfile = NULL;
  41. setField("TextEditProfile", "GuiTextEditProfile");
  42. mDropDownProfile = NULL;
  43. setField("DropDownProfile", "GuiDropDownProfile");
  44. mDropDownItemProfile = NULL;
  45. setField("DropDownItemProfile", "GuiListBoxProfile");
  46. mScrollProfile = NULL;
  47. setField("ScrollProfile", "GuiScrollProfile");
  48. mBackgroundProfile = NULL;
  49. setField("BackgroundProfile", "GuiDefaultProfile");
  50. mThumbProfile = NULL;
  51. setField("ThumbProfile", "GuiScrollThumbProfile");
  52. mArrowProfile = NULL;
  53. setField("ArrowProfile", "GuiScrollArrowProfile");
  54. mTrackProfile = NULL;
  55. setField("TrackProfile", "GuiScrollTrackProfile");
  56. mCheckboxProfile = NULL;
  57. setField("CheckboxProfile", "GuiCheckboxProfile");
  58. mButtonProfile = NULL;
  59. setField("ButtonProfile", "GuiButtonProfile");
  60. mUseConstantHeightThumb = false;
  61. mScrollBarThickness = 12;
  62. mShowArrowButtons = true;
  63. mFieldCellSize.set(300, 30);
  64. mControlOffset.set(10, 16);
  65. }
  66. GuiInspector::~GuiInspector()
  67. {
  68. clearGroups();
  69. }
  70. void GuiInspector::initPersistFields()
  71. {
  72. Parent::initPersistFields();
  73. addField("GroupPanelProfile", TypeGuiProfile, Offset(mGroupPanelProfile, GuiInspector));
  74. addField("GroupGridProfile", TypeGuiProfile, Offset(mGroupGridProfile, GuiInspector));
  75. addField("LabelProfile", TypeGuiProfile, Offset(mLabelProfile, GuiInspector));
  76. addField("TextEditProfile", TypeGuiProfile, Offset(mTextEditProfile, GuiInspector));
  77. addField("DropDownProfile", TypeGuiProfile, Offset(mDropDownProfile, GuiInspector));
  78. addField("DropDownItemProfile", TypeGuiProfile, Offset(mDropDownItemProfile, GuiInspector));
  79. addField("ScrollProfile", TypeGuiProfile, Offset(mScrollProfile, GuiInspector));
  80. addField("backgroundProfile", TypeGuiProfile, Offset(mBackgroundProfile, GuiInspector));
  81. addField("thumbProfile", TypeGuiProfile, Offset(mThumbProfile, GuiInspector));
  82. addField("trackProfile", TypeGuiProfile, Offset(mTrackProfile, GuiInspector));
  83. addField("arrowProfile", TypeGuiProfile, Offset(mArrowProfile, GuiInspector));
  84. addField("CheckboxProfile", TypeGuiProfile, Offset(mCheckboxProfile, GuiInspector));
  85. addField("ButtonProfile", TypeGuiProfile, Offset(mButtonProfile, GuiInspector));
  86. addField("constantThumbHeight", TypeBool, Offset(mUseConstantHeightThumb, GuiInspector));
  87. addField("scrollBarThickness", TypeS32, Offset(mScrollBarThickness, GuiInspector));
  88. addField("showArrowButtons", TypeBool, Offset(mShowArrowButtons, GuiInspector));
  89. addField("FieldCellSize", TypePoint2I, Offset(mFieldCellSize, GuiInspector));
  90. addField("ControlOffset", TypePoint2I, Offset(mControlOffset, GuiInspector));
  91. }
  92. bool GuiInspector::onWake()
  93. {
  94. if (!Parent::onWake())
  95. return false;
  96. if (mGroupPanelProfile != NULL)
  97. mGroupPanelProfile->incRefCount();
  98. if (mGroupGridProfile != NULL)
  99. mGroupGridProfile->incRefCount();
  100. if (mLabelProfile != NULL)
  101. mLabelProfile->incRefCount();
  102. if (mTextEditProfile != NULL)
  103. mTextEditProfile->incRefCount();
  104. if (mDropDownProfile != NULL)
  105. mDropDownProfile->incRefCount();
  106. if (mDropDownItemProfile != NULL)
  107. mDropDownItemProfile->incRefCount();
  108. if (mScrollProfile != NULL)
  109. mScrollProfile->incRefCount();
  110. if (mBackgroundProfile != NULL)
  111. mBackgroundProfile->incRefCount();
  112. if (mThumbProfile != NULL)
  113. mThumbProfile->incRefCount();
  114. if (mTrackProfile != NULL)
  115. mTrackProfile->incRefCount();
  116. if (mArrowProfile != NULL)
  117. mArrowProfile->incRefCount();
  118. if (mCheckboxProfile != NULL)
  119. mCheckboxProfile->incRefCount();
  120. if (mButtonProfile != NULL)
  121. mButtonProfile->incRefCount();
  122. return true;
  123. }
  124. void GuiInspector::onSleep()
  125. {
  126. Parent::onSleep();
  127. if (mGroupPanelProfile != NULL)
  128. mGroupPanelProfile->decRefCount();
  129. if (mGroupGridProfile != NULL)
  130. mGroupGridProfile->decRefCount();
  131. if (mLabelProfile != NULL)
  132. mLabelProfile->decRefCount();
  133. if (mTextEditProfile != NULL)
  134. mTextEditProfile->decRefCount();
  135. if (mDropDownProfile != NULL)
  136. mDropDownProfile->decRefCount();
  137. if (mDropDownItemProfile != NULL)
  138. mDropDownItemProfile->decRefCount();
  139. if (mScrollProfile != NULL)
  140. mScrollProfile->decRefCount();
  141. if (mBackgroundProfile != NULL)
  142. mBackgroundProfile->decRefCount();
  143. if (mThumbProfile != NULL)
  144. mThumbProfile->decRefCount();
  145. if (mTrackProfile != NULL)
  146. mTrackProfile->decRefCount();
  147. if (mArrowProfile != NULL)
  148. mArrowProfile->decRefCount();
  149. if (mCheckboxProfile != NULL)
  150. mCheckboxProfile->decRefCount();
  151. if (mButtonProfile != NULL)
  152. mButtonProfile->decRefCount();
  153. }
  154. void GuiInspector::inspectPostApply()
  155. {
  156. Parent::inspectPostApply();
  157. if (mTarget)
  158. {
  159. SimObjectPtr<SimObject> oldTarget = mTarget;
  160. mTarget = NULL;
  161. inspectObject(oldTarget);
  162. }
  163. }
  164. void GuiInspector::resize(const Point2I &newPosition, const Point2I &newExtent)
  165. {
  166. Parent::resize(Point2I(0, 0), newExtent);
  167. }
  168. void GuiInspector::parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent)
  169. {
  170. GuiControl *parent = getParent();
  171. if( parent && dynamic_cast<GuiScrollCtrl*>(parent) != NULL )
  172. {
  173. // Handle Parent Sizing (We constrain ourself to our parent's width)
  174. GuiScrollCtrl *scroll = dynamic_cast<GuiScrollCtrl*>(parent);
  175. setWidth(newParentExtent.x - scroll->scrollBarThickness());
  176. }
  177. else
  178. Parent::parentResized(oldParentExtent,newParentExtent);
  179. }
  180. bool GuiInspector::findExistentGroup( StringTableEntry groupName )
  181. {
  182. // If we have no groups, it couldn't possibly exist
  183. if( mGroups.empty() )
  184. return false;
  185. // Attempt to find it in the group list
  186. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  187. for( ; i != mGroups.end(); i++ )
  188. {
  189. if( dStricmp( (*i)->getGroupName(), groupName ) == 0 )
  190. return true;
  191. }
  192. return false;
  193. }
  194. void GuiInspector::clearGroups()
  195. {
  196. // If we're clearing the groups, we want to clear our target too.
  197. mTarget = NULL;
  198. // If we have no groups, there's nothing to clear!
  199. if( mGroups.empty() )
  200. return;
  201. // Attempt to find it in the group list
  202. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  203. for( ; i != mGroups.end(); i++ )
  204. if( (*i)->isProperlyAdded() )
  205. (*i)->deleteObject();
  206. mGroups.clear();
  207. }
  208. void GuiInspector::inspectObject( SimObject *object )
  209. {
  210. GuiCanvas *guiCanvas = getRoot();
  211. if( !guiCanvas )
  212. return;
  213. SimObjectPtr<GuiControl> currResponder = guiCanvas->getFirstResponder();
  214. // If our target is the same as our current target, just update the groups.
  215. if( mTarget == object )
  216. {
  217. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  218. for ( ; i != mGroups.end(); i++ )
  219. (*i)->inspectGroup();
  220. // Don't steal first responder
  221. if( !currResponder.isNull() )
  222. guiCanvas->setFirstResponder( currResponder );
  223. return;
  224. }
  225. // Clear our current groups
  226. clearGroups();
  227. // Set Target
  228. mTarget = object;
  229. // Always create the 'general' group (for un-grouped fields)
  230. GuiInspectorGroup* general = new GuiInspectorGroup( mTarget, "General", this );
  231. if( general != NULL )
  232. {
  233. general->registerObject();
  234. mGroups.push_back( general );
  235. addObject( general );
  236. }
  237. // Grab this objects field list
  238. AbstractClassRep::FieldList &fieldList = mTarget->getModifiableFieldList();
  239. AbstractClassRep::FieldList::iterator itr;
  240. // Iterate through, identifying the groups and create necessary GuiInspectorGroups
  241. for(itr = fieldList.begin(); itr != fieldList.end(); itr++)
  242. {
  243. if(itr->type == AbstractClassRep::StartGroupFieldType && !findExistentGroup( itr->pGroupname ) )
  244. {
  245. GuiInspectorGroup *group = new GuiInspectorGroup( mTarget, itr->pGroupname, this );
  246. if( group != NULL )
  247. {
  248. group->registerObject();
  249. mGroups.push_back( group );
  250. addObject( group );
  251. }
  252. }
  253. }
  254. // Deal with dynamic fields
  255. GuiInspectorGroup *dynGroup = new GuiInspectorDynamicGroup( mTarget, "Dynamic Fields", this);
  256. if( dynGroup != NULL )
  257. {
  258. dynGroup->registerObject();
  259. mGroups.push_back( dynGroup );
  260. addObject( dynGroup );
  261. }
  262. // If any group is still empty at this point, kill it.
  263. for(S32 i=0; i<mGroups.size(); i++)
  264. {
  265. if(mGroups[i]->mGrid->size() == 0)
  266. {
  267. mGroups[i]->deleteObject();
  268. mGroups.erase(i);
  269. i--;
  270. }
  271. }
  272. resize(getPosition(), getExtent());
  273. // Don't steal first responder
  274. if( !currResponder.isNull() )
  275. guiCanvas->setFirstResponder( currResponder );
  276. }
  277. ConsoleMethod( GuiInspector, inspect, void, 3, 3, "(obj) Goes through the object's fields and autogenerates editor boxes\n"
  278. "@return No return value.")
  279. {
  280. SimObject * target = Sim::findObject(argv[2]);
  281. if(!target)
  282. {
  283. if(dAtoi(argv[2]) > 0)
  284. Con::warnf("%s::inspect(): invalid object: %s", argv[0], argv[2]);
  285. object->clearGroups();
  286. return;
  287. }
  288. object->inspectObject(target);
  289. }
  290. ConsoleMethod( GuiInspector, getInspectObject, const char*, 2, 2, "() - Returns currently inspected object\n"
  291. "@return The Object's ID as a string.")
  292. {
  293. SimObject *pSimObject = object->getInspectObject();
  294. if( pSimObject != NULL )
  295. return pSimObject->getIdString();
  296. return "";
  297. }
  298. void GuiInspector::setName( const char* newName )
  299. {
  300. if( mTarget == NULL )
  301. return;
  302. // Only assign a new name if we provide one
  303. mTarget->assignName(newName);
  304. }
  305. ConsoleMethod( GuiInspector, setName, void, 3, 3, "(NewObjectName) Set object name.\n"
  306. "@return No return value.")
  307. {
  308. object->setName(argv[2]);
  309. }
  310. ConsoleMethod(GuiInspector, clearHiddenFields, void, 2, 2, "() Clears the list of hidden fields\n"
  311. "@return No return value.")
  312. {
  313. object->clearHiddenField();
  314. }
  315. ConsoleMethod(GuiInspector, addHiddenField, void, 3, 3, "() Adds a new field to the list of hidden fields\n"
  316. "@return No return value.")
  317. {
  318. object->addHiddenField(argv[2]);
  319. }
  320. ConsoleMethod(GuiInspector, openGroupByIndex, void, 3, 3, "(Index) Opens the group that matches the given zero-based index\n"
  321. "@return No return value.")
  322. {
  323. if (argc < 1)
  324. {
  325. return;
  326. }
  327. S32 index = dAtoi(argv[2]);
  328. if (index >= object->mGroups.size())
  329. {
  330. return;
  331. }
  332. object->mGroups[index]->setExpanded(true);
  333. }
  334. #pragma endregion
  335. #pragma region GuiInspectorField
  336. //////////////////////////////////////////////////////////////////////////
  337. // GuiInspectorField
  338. //////////////////////////////////////////////////////////////////////////
  339. // The GuiInspectorField control is a representation of a single abstract
  340. // field for a given ConsoleObject derived object. It handles creation
  341. // getting and setting of it's fields data and editing control.
  342. //
  343. // Creation of custom edit controls is done through this class and is
  344. // dependent upon the dynamic console type, which may be defined to be
  345. // custom for different types.
  346. //
  347. // Note : GuiInspectorField controls must have a GuiInspectorGroup as their
  348. // parent.
  349. IMPLEMENT_CONOBJECT(GuiInspectorField);
  350. GuiInspectorField::GuiInspectorField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, AbstractClassRep::Field* field )
  351. {
  352. if( field != NULL )
  353. mText = StringTable->insert( field->pFieldname );
  354. else
  355. mText = StringTable->EmptyString;
  356. mGroup = parent;
  357. mTarget = target;
  358. mField = field;
  359. mCanSave = false;
  360. mFieldArrayIndex = NULL;
  361. }
  362. GuiInspectorField::GuiInspectorField()
  363. {
  364. mText = StringTable->EmptyString;
  365. mGroup = NULL;
  366. mTarget = NULL;
  367. mField = NULL;
  368. mFieldArrayIndex = NULL;
  369. mCanSave = false;
  370. }
  371. GuiInspectorField::~GuiInspectorField()
  372. {
  373. }
  374. //////////////////////////////////////////////////////////////////////////
  375. // Get/Set Data Functions
  376. //////////////////////////////////////////////////////////////////////////
  377. void GuiInspectorField::setData( const char* data )
  378. {
  379. if( mField == NULL || mTarget == NULL )
  380. return;
  381. mTarget->inspectPreApply();
  382. mTarget->setDataField( mField->pFieldname, mFieldArrayIndex, data );
  383. // Force our edit to update
  384. updateValue( data );
  385. mTarget->inspectPostApply();
  386. }
  387. const char* GuiInspectorField::getData()
  388. {
  389. if( mField == NULL || mTarget == NULL )
  390. return "";
  391. return mTarget->getDataField( mField->pFieldname, mFieldArrayIndex );
  392. }
  393. void GuiInspectorField::setInspectorField( AbstractClassRep::Field *field, const char*arrayIndex )
  394. {
  395. mField = field;
  396. if( arrayIndex != NULL )
  397. {
  398. mFieldArrayIndex = StringTable->insert( arrayIndex );
  399. S32 frameTempSize = dStrlen( field->pFieldname ) + 32;
  400. FrameTemp<char> valCopy( frameTempSize );
  401. dSprintf( (char *)valCopy, frameTempSize, "%s%s", field->pFieldname, arrayIndex );
  402. mText = StringTable->insert( valCopy );
  403. }
  404. else
  405. mText = StringTable->insert( field->pFieldname );
  406. }
  407. StringTableEntry GuiInspectorField::getFieldName()
  408. {
  409. // Sanity
  410. if ( mField == NULL )
  411. return StringTable->EmptyString;
  412. // Array element?
  413. if( mFieldArrayIndex != NULL )
  414. {
  415. S32 frameTempSize = dStrlen( mField->pFieldname ) + 32;
  416. FrameTemp<char> valCopy( frameTempSize );
  417. dSprintf( (char *)valCopy, frameTempSize, "%s%s:", mField->pFieldname, mFieldArrayIndex );
  418. // Return formatted element
  419. return StringTable->insert( valCopy );
  420. }
  421. // Plain ole field name.
  422. return mField->pFieldname;
  423. };
  424. //////////////////////////////////////////////////////////////////////////
  425. // Overrideables for custom edit fields
  426. //////////////////////////////////////////////////////////////////////////
  427. GuiControl* GuiInspectorField::constructEditControl(S32 width)
  428. {
  429. GuiControl* retCtrl = new GuiTextEditCtrl();
  430. // If we couldn't construct the control, bail!
  431. if( retCtrl == NULL )
  432. return retCtrl;
  433. // Let's make it look pretty.
  434. retCtrl->setControlProfile(mGroup->mInspector->mTextEditProfile);
  435. // Don't forget to register ourselves
  436. registerEditControl( retCtrl );
  437. char szBuffer[512];
  438. dSprintf( szBuffer, 512, "%d.apply(%d.getText());",getId(), retCtrl->getId() );
  439. retCtrl->setField("AltCommand", szBuffer );
  440. retCtrl->mBounds.set(mGroup->mInspector->mControlOffset, Point2I(width - mGroup->mInspector->mControlOffset.x, 30));
  441. return retCtrl;
  442. }
  443. void GuiInspectorField::registerEditControl( GuiControl *ctrl )
  444. {
  445. if(!mTarget)
  446. return;
  447. char szName[512];
  448. dSprintf( szName, 512, "IE_%s_%d_%s_Field", ctrl->getClassName(), mTarget->getId(),mText);
  449. // Register the object
  450. ctrl->registerObject( szName );
  451. }
  452. bool GuiInspectorField::onAdd()
  453. {
  454. if( !Parent::onAdd() )
  455. return false;
  456. if( !mTarget )
  457. return false;
  458. setControlProfile(mGroup->mInspector->mLabelProfile);
  459. //Find the target width
  460. RectI innerRect = getInnerRect(Point2I(0,0), mGroup->mInspector->mFieldCellSize, NormalState, mProfile);
  461. mEdit = constructEditControl(innerRect.extent.x);
  462. if( mEdit == NULL )
  463. return false;
  464. innerRect.extent.y = mGroup->mInspector->mControlOffset.y + mEdit->getExtent().y;
  465. Point2I outerExt = getOuterExtent(innerRect.extent, NormalState, mProfile);
  466. mBounds.extent.y = outerExt.y;
  467. //Set the tool tip if possible
  468. if (mField != NULL && mField->pFieldDocs != NULL)
  469. {
  470. mEdit->setField("tooltip", mField->pFieldDocs);
  471. if (mGroup->mInspector->mTooltipProfile != NULL)
  472. {
  473. char buffer[256];
  474. dSprintf(buffer, sizeof(buffer), "%d", mGroup->mInspector->mTooltipProfile->getId());
  475. mEdit->setField("tooltipProfile", buffer);
  476. }
  477. }
  478. addObject( mEdit );
  479. // Force our editField to set it's value
  480. updateValue( getData() );
  481. return true;
  482. }
  483. void GuiInspectorField::updateValue( const char* newValue )
  484. {
  485. GuiTextEditCtrl *ctrl = dynamic_cast<GuiTextEditCtrl*>( mEdit );
  486. if( ctrl != NULL )
  487. ctrl->setText( newValue );
  488. }
  489. ConsoleMethod( GuiInspectorField, apply, void, 3,3, "(newValue) Applies the given value to the field\n"
  490. "@return No return value." )
  491. {
  492. object->setData( argv[2] );
  493. }
  494. #pragma endregion
  495. #pragma region GuiInspectorGroup
  496. //////////////////////////////////////////////////////////////////////////
  497. // GuiInspectorGroup
  498. //////////////////////////////////////////////////////////////////////////
  499. //
  500. // The GuiInspectorGroup control is a helper control that the inspector
  501. // makes use of which houses a collapsible panel type control for separating
  502. // inspected objects fields into groups. The content of the inspector is
  503. // made up of zero or more GuiInspectorGroup controls inside of a GuiChainControl
  504. //
  505. //
  506. //
  507. IMPLEMENT_CONOBJECT(GuiInspectorGroup);
  508. GuiInspectorGroup::GuiInspectorGroup()
  509. {
  510. mChildren.clear();
  511. mTarget = NULL;
  512. mInspector = NULL;
  513. mCanSave = false;
  514. mHorizSizing = horizSizingOptions::horizResizeWidth;
  515. mVertSizing = vertSizingOptions::vertResizeTop;
  516. mBounds.set(10, 0, (mInspector->getExtent().x - 20), 24);
  517. }
  518. GuiInspectorGroup::GuiInspectorGroup( SimObjectPtr<SimObject> target, StringTableEntry groupName, SimObjectPtr<GuiInspector> inspector )
  519. {
  520. mChildren.clear();
  521. mText = StringTable->insert(groupName);
  522. mTarget = target;
  523. mInspector = inspector;
  524. mCanSave = false;
  525. mHorizSizing = horizSizingOptions::horizResizeWidth;
  526. mVertSizing = vertSizingOptions::vertResizeTop;
  527. mBounds.set(10, 0, (mInspector->getExtent().x - 20), 24);
  528. }
  529. bool GuiInspectorGroup::onAdd()
  530. {
  531. if( !Parent::onAdd() )
  532. return false;
  533. setControlProfile(mInspector->mGroupPanelProfile);
  534. // Create our inner controls. Allow subclasses to provide other content.
  535. if(!createContent())
  536. return false;
  537. inspectGroup();
  538. return true;
  539. }
  540. bool GuiInspectorGroup::createContent()
  541. {
  542. // Create our field stack control
  543. mGrid = new GuiGridCtrl();
  544. if( !mGrid)
  545. return false;
  546. mGrid->setControlProfile(mInspector->mGroupGridProfile);
  547. mGrid->setCellSize(mInspector->mFieldCellSize.x, mInspector->mFieldCellSize.y);
  548. mGrid->setCellSpacing(0,0);
  549. mGrid->setCellModeX(GuiGridCtrl::CellMode::Variable);
  550. mGrid->setCellModeY(GuiGridCtrl::CellMode::Variable);
  551. mGrid->setMaxColCount(0);
  552. mGrid->mIsExtentDynamic = true;
  553. mGrid->mOrderMode = GuiGridCtrl::OrderMode::LRTB;
  554. mGrid->setWidth(getExtent().x - 20);
  555. mGrid->setPosition(Point2I(10, getExtent().y));
  556. mGrid->setField("horizSizing", "width");
  557. mGrid->setField("vertSizing", "bottom");
  558. mGrid->registerObject();
  559. addObject( mGrid );
  560. return true;
  561. }
  562. GuiInspectorField* GuiInspectorGroup::constructField( S32 fieldType )
  563. {
  564. ConsoleBaseType *cbt = ConsoleBaseType::getType(fieldType);
  565. AssertFatal(cbt, "GuiInspectorGroup::constructField - could not resolve field type!");
  566. // Alright, is it a datablock?
  567. if(cbt->isDatablock())
  568. {
  569. // This is fairly straightforward to deal with.
  570. GuiInspectorDatablockField *dbFieldClass = new GuiInspectorDatablockField( cbt->getTypeClassName() );
  571. if( dbFieldClass != NULL )
  572. {
  573. // return our new datablock field with correct datablock type enumeration info
  574. return dbFieldClass;
  575. }
  576. }
  577. // Nope, not a datablock. So maybe it has a valid inspector field override we can use?
  578. if(!cbt->getInspectorFieldType())
  579. // Nothing, so bail.
  580. return NULL;
  581. // Otherwise try to make it!
  582. ConsoleObject *co = create(cbt->getInspectorFieldType());
  583. GuiInspectorField *gif = dynamic_cast<GuiInspectorField*>(co);
  584. if(!gif)
  585. {
  586. // Wasn't appropriate type, bail.
  587. delete co;
  588. return NULL;
  589. }
  590. return gif;
  591. }
  592. GuiInspectorField *GuiInspectorGroup::findField( StringTableEntry fieldName )
  593. {
  594. // If we don't have any field children we can't very well find one then can we?
  595. if( mChildren.empty() )
  596. return NULL;
  597. Vector<GuiInspectorField*>::iterator i = mChildren.begin();
  598. for( ; i != mChildren.end(); i++ )
  599. {
  600. if( (*i)->getFieldName() != NULL && dStricmp( (*i)->getFieldName(), fieldName ) == 0 )
  601. return (*i);
  602. }
  603. return NULL;
  604. }
  605. bool GuiInspectorGroup::inspectGroup()
  606. {
  607. // We can't inspect a group without a target!
  608. if( !mTarget )
  609. return false;
  610. // to prevent crazy resizing, we'll just freeze our stack for a sec..
  611. //mStack->freeze(true);
  612. bool bNoGroup = false;
  613. // Un-grouped fields are all sorted into the 'general' group
  614. if ( dStricmp( mText, "General" ) == 0 )
  615. bNoGroup = true;
  616. AbstractClassRep::FieldList &fieldList = mTarget->getModifiableFieldList();
  617. AbstractClassRep::FieldList::iterator itr;
  618. bool bGrabItems = false;
  619. bool bNewItems = false;
  620. for(itr = fieldList.begin(); itr != fieldList.end(); itr++)
  621. {
  622. if( itr->type == AbstractClassRep::StartGroupFieldType )
  623. {
  624. // If we're dealing with general fields, always set grabItems to true (to skip them)
  625. if( bNoGroup == true || ( itr->pGroupname != NULL && dStricmp( itr->pGroupname, mText ) == 0 ))
  626. bGrabItems = true;
  627. continue;
  628. }
  629. else if ( itr->type == AbstractClassRep::EndGroupFieldType )
  630. {
  631. // If we're dealing with general fields, always set grabItems to false (to grab them)
  632. if( bNoGroup == true || ( itr->pGroupname != NULL && dStricmp( itr->pGroupname, mText ) == 0 ))
  633. bGrabItems = false;
  634. continue;
  635. }
  636. if((bGrabItems == true || (bNoGroup == true && bGrabItems == false)) && itr->type != AbstractClassRep::DepricatedFieldType )
  637. {
  638. //We are inside a group and looking for items that don't have a group. Move on.
  639. if( bNoGroup == true && bGrabItems == true )
  640. continue;
  641. // We are going to check to see if this item is an array
  642. // if so, we're going to construct a field for each array element
  643. if( itr->elementCount > 1 )
  644. {
  645. for(S32 nI = 0; nI < itr->elementCount; nI++)
  646. {
  647. FrameTemp<char> intToStr( 64 );
  648. dSprintf( intToStr, 64, "%d", nI );
  649. const char *val = mTarget->getDataField( itr->pFieldname, intToStr );
  650. if (!val)
  651. val = StringTable->EmptyString;
  652. // Copy Val and construct proper ValueName[nI] format
  653. // which is "ValueName0" for index 0, etc.
  654. S32 frameTempSize = dStrlen( val ) + 32;
  655. FrameTemp<char> valCopy( frameTempSize );
  656. dSprintf( (char *)valCopy, frameTempSize, "%s%d", itr->pFieldname, nI );
  657. // If the field already exists, just update it
  658. GuiInspectorField *field = findField( valCopy );
  659. if( field != NULL )
  660. {
  661. field->updateValue( field->getData() );
  662. continue;
  663. }
  664. bNewItems = true;
  665. field = constructField( itr->type );
  666. if( field == NULL )
  667. {
  668. field = new GuiInspectorField( this, mTarget, itr );
  669. field->setExtent(Point2I(this->getExtent().x,30));
  670. field->setInspectorField( itr, intToStr );
  671. }
  672. else
  673. {
  674. field->setExtent(Point2I(this->getExtent().x, 30));
  675. field->setTarget( mTarget );
  676. field->setInspectorGroup( this );
  677. field->setInspectorField( itr, intToStr );
  678. }
  679. field->registerObject();
  680. mChildren.push_back( field );
  681. mGrid->addObject( field );
  682. }
  683. }
  684. else
  685. {
  686. // If the field already exists, just update it
  687. GuiInspectorField *field = findField( itr->pFieldname );
  688. if( field != NULL )
  689. {
  690. field->updateValue( field->getData() );
  691. continue;
  692. }
  693. bNewItems = true;
  694. //check the hidden field list
  695. if (mInspector->hideField(itr->pFieldname))
  696. {
  697. continue;
  698. }
  699. //Time to create a new field
  700. field = constructField( itr->type );
  701. if( field == NULL )
  702. field = new GuiInspectorField( this, mTarget, itr );
  703. else
  704. {
  705. field->setTarget( mTarget );
  706. field->setInspectorGroup( this );
  707. field->setInspectorField( itr );
  708. }
  709. field->setExtent(Point2I(this->getExtent().x, 30));
  710. field->registerObject();
  711. mChildren.push_back( field );
  712. mGrid->addObject( field );
  713. }
  714. }
  715. }
  716. // If we've no new items, there's no need to resize anything!
  717. if( bNewItems == false && !mChildren.empty() )
  718. return true;
  719. //sizeToContents();
  720. setUpdate();
  721. return true;
  722. }
  723. #pragma endregion
  724. #pragma region GuiInspectorDynamicGroup
  725. IMPLEMENT_CONOBJECT(GuiInspectorDynamicGroup);
  726. //////////////////////////////////////////////////////////////////////////
  727. // GuiInspectorDynamicGroup - add custom controls
  728. //////////////////////////////////////////////////////////////////////////
  729. bool GuiInspectorDynamicGroup::createContent()
  730. {
  731. if(!Parent::createContent())
  732. return false;
  733. // add a button that lets us add new dynamic fields.
  734. GuiButtonCtrl* addFieldBtn = new GuiButtonCtrl();
  735. {
  736. SimObject* profilePtr = Sim::findObject("EditorButton");
  737. if( profilePtr != NULL )
  738. addFieldBtn->setControlProfile( dynamic_cast<GuiControlProfile*>(profilePtr) );
  739. char commandBuf[64];
  740. dSprintf(commandBuf, 64, "%d.addDynamicField();", this->getId());
  741. addFieldBtn->setField("profile", "GuiButtonDynProfile");
  742. addFieldBtn->setField("command", commandBuf);
  743. addFieldBtn->setField("text", "+");
  744. addFieldBtn->setExtent(Point2I(30, 30));
  745. addFieldBtn->registerObject("zAddButton");
  746. }
  747. // encapsulate the button in a dummy control.
  748. GuiControl* shell = new GuiControl();
  749. shell->setField( "profile", "GuiTextProfile" );
  750. shell->registerObject();
  751. shell->setField("text", "Add Field");
  752. shell->setExtent(Point2I(getExtent().x - 30,30 + 10));
  753. addFieldBtn->setPosition(Point2I((shell->getExtent().x) - 30, 0));
  754. shell->addObject(addFieldBtn);
  755. // save off the shell control, so we can push it to the bottom of the stack in inspectGroup()
  756. mAddCtrl = shell;
  757. mGrid->addObject(shell);
  758. return true;
  759. }
  760. static S32 QSORT_CALLBACK compareEntries(const void* a,const void* b)
  761. {
  762. SimFieldDictionary::Entry *fa = *((SimFieldDictionary::Entry **)a);
  763. SimFieldDictionary::Entry *fb = *((SimFieldDictionary::Entry **)b);
  764. return dStricmp(fa->slotName, fb->slotName);
  765. }
  766. //////////////////////////////////////////////////////////////////////////
  767. // GuiInspectorDynamicGroup - inspectGroup override
  768. //////////////////////////////////////////////////////////////////////////
  769. bool GuiInspectorDynamicGroup::inspectGroup()
  770. {
  771. // We can't inspect a group without a target!
  772. if( !mTarget )
  773. return false;
  774. // Clearing the fields and recreating them will more than likely be more
  775. // efficient than looking up existent fields, updating them, and then iterating
  776. // over existent fields and making sure they still exist, if not, deleting them.
  777. clearFields();
  778. // Create a vector of the fields
  779. Vector<SimFieldDictionary::Entry *> flist;
  780. // Then populate with fields
  781. SimFieldDictionary * fieldDictionary = mTarget->getFieldDictionary();
  782. for(SimFieldDictionaryIterator ditr(fieldDictionary); *ditr; ++ditr)
  783. {
  784. flist.push_back(*ditr);
  785. }
  786. dQsort(flist.address(),flist.size(),sizeof(SimFieldDictionary::Entry *),compareEntries);
  787. for(U32 i = 0; i < (U32)flist.size(); i++)
  788. {
  789. SimFieldDictionary::Entry * entry = flist[i];
  790. GuiInspectorField *field = new GuiInspectorDynamicField( this, mTarget, entry );
  791. if( field != NULL )
  792. {
  793. field->setExtent(Point2I(this->getExtent().x, 30));
  794. field->registerObject();
  795. mChildren.push_back( field );
  796. mGrid->addObject( field );
  797. }
  798. }
  799. mGrid->pushObjectToBack(mAddCtrl);
  800. setUpdate();
  801. return true;
  802. }
  803. ConsoleMethod(GuiInspectorDynamicGroup, inspectGroup, bool, 2, 2, "() Refreshes the dynamic fields in the inspector.\n"
  804. "@return Returns true on success.")
  805. {
  806. return object->inspectGroup();
  807. }
  808. void GuiInspectorDynamicGroup::clearFields()
  809. {
  810. // save mAddCtrl
  811. Sim::getGuiGroup()->addObject(mAddCtrl);
  812. // delete everything else
  813. mGrid->clear();
  814. // clear the mChildren list.
  815. mChildren.clear();
  816. // and restore.
  817. mGrid->addObject(mAddCtrl);
  818. }
  819. SimFieldDictionary::Entry* GuiInspectorDynamicGroup::findDynamicFieldInDictionary( StringTableEntry fieldName )
  820. {
  821. if( !mTarget )
  822. return NULL;
  823. SimFieldDictionary * fieldDictionary = mTarget->getFieldDictionary();
  824. for(SimFieldDictionaryIterator ditr(fieldDictionary); *ditr; ++ditr)
  825. {
  826. SimFieldDictionary::Entry * entry = (*ditr);
  827. if( dStricmp( entry->slotName, fieldName ) == 0 )
  828. return entry;
  829. }
  830. return NULL;
  831. }
  832. void GuiInspectorDynamicGroup::addDynamicField()
  833. {
  834. // We can't add a field without a target
  835. if( !mTarget || !mGrid)
  836. {
  837. Con::warnf("GuiInspectorDynamicGroup::addDynamicField - no target SimObject to add a dynamic field to.");
  838. return;
  839. }
  840. // find a field name that is not in use.
  841. // But we wont try more than 100 times to find an available field.
  842. U32 uid = 1;
  843. char buf[64] = "dynamicField";
  844. SimFieldDictionary::Entry* entry = findDynamicFieldInDictionary(buf);
  845. while(entry != NULL && uid < 100)
  846. {
  847. dSprintf(buf, sizeof(buf), "dynamicField%03d", uid++);
  848. entry = findDynamicFieldInDictionary(buf);
  849. }
  850. //Con::evaluatef( "%d.%s = \"defaultValue\";", mTarget->getId(), buf );
  851. mTarget->setDataField(StringTable->insert(buf), NULL, "defaultValue");
  852. // now we simply re-inspect the object, to see the new field.
  853. this->inspectGroup();
  854. //animateToContents();
  855. }
  856. ConsoleMethod( GuiInspectorDynamicGroup, addDynamicField, void, 2, 2, "obj.addDynamicField();" )
  857. {
  858. object->addDynamicField();
  859. }
  860. #pragma endregion
  861. #pragma region GuiInspectorDynamicField
  862. //////////////////////////////////////////////////////////////////////////
  863. // GuiInspectorDynamicField - Child class of GuiInspectorField
  864. //////////////////////////////////////////////////////////////////////////
  865. IMPLEMENT_CONOBJECT(GuiInspectorDynamicField);
  866. GuiInspectorDynamicField::GuiInspectorDynamicField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, SimFieldDictionary::Entry* field )
  867. {
  868. mGroup = parent;
  869. mTarget = target;
  870. mDynField = field;
  871. mRenameCtrl = NULL;
  872. }
  873. void GuiInspectorDynamicField::setData( const char* data )
  874. {
  875. if( mTarget == NULL || mDynField == NULL )
  876. return;
  877. char buf[1024];
  878. const char * newValue = mEdit->getScriptValue();
  879. dStrcpy( buf, newValue ? newValue : "" );
  880. collapseEscape(buf);
  881. mTarget->getFieldDictionary()->setFieldValue(mDynField->slotName, buf);
  882. // Force our edit to update
  883. updateValue( data );
  884. }
  885. const char* GuiInspectorDynamicField::getData()
  886. {
  887. if( mTarget == NULL || mDynField == NULL )
  888. return "";
  889. return mTarget->getFieldDictionary()->getFieldValue( mDynField->slotName );
  890. }
  891. void GuiInspectorDynamicField::renameField( StringTableEntry newFieldName )
  892. {
  893. if( mTarget == NULL || mDynField == NULL || mGroup == NULL || mEdit == NULL )
  894. {
  895. Con::warnf("GuiInspectorDynamicField::renameField - No target object or dynamic field data found!" );
  896. return;
  897. }
  898. if( !newFieldName )
  899. {
  900. Con::warnf("GuiInspectorDynamicField::renameField - Invalid field name specified!" );
  901. return;
  902. }
  903. // Only proceed if the name has changed
  904. if( dStricmp( newFieldName, getFieldName() ) == 0 )
  905. return;
  906. // Grab a pointer to our parent and cast it to GuiInspectorDynamicGroup
  907. GuiInspectorDynamicGroup *group = dynamic_cast<GuiInspectorDynamicGroup*>(mGroup);
  908. if( group == NULL )
  909. {
  910. Con::warnf("GuiInspectorDynamicField::renameField - Unable to locate GuiInspectorDynamicGroup parent!" );
  911. return;
  912. }
  913. // Grab our current dynamic field value
  914. const char* currentValue = getData();
  915. // Create our new field with the value of our old field and the new fields name!
  916. mTarget->setDataField( newFieldName, NULL, currentValue );
  917. // Configure our field to grab data from the new dynamic field
  918. SimFieldDictionary::Entry *newEntry = group->findDynamicFieldInDictionary( newFieldName );
  919. if( newEntry == NULL )
  920. {
  921. Con::warnf("GuiInspectorDynamicField::renameField - Unable to find new field!" );
  922. return;
  923. }
  924. // Set our old fields data to "" (which will effectively erase the field)
  925. mTarget->setDataField( getFieldName(), NULL, "" );
  926. // Assign our dynamic field pointer (where we retrieve field information from) to our new field pointer
  927. mDynField = newEntry;
  928. // Lastly we need to reassign our AltCommand fields for our value edit control
  929. char szBuffer[512];
  930. dSprintf( szBuffer, 512, "%d.%s = %d.getText();",mTarget->getId(), getFieldName(), mEdit->getId() );
  931. mEdit->setExtent(Point2I((getExtent().x / 2) - 20, 30));
  932. mEdit->setField("AltCommand", szBuffer );
  933. }
  934. ConsoleMethod( GuiInspectorDynamicField, renameField, void, 3,3, "field.renameField(newDynamicFieldName);" )
  935. {
  936. object->renameField( StringTable->insert(argv[2]) );
  937. }
  938. bool GuiInspectorDynamicField::onAdd()
  939. {
  940. if( !Parent::onAdd() )
  941. return false;
  942. mRenameCtrl = constructRenameControl();
  943. pushObjectToBack(mEdit);
  944. return true;
  945. }
  946. GuiControl* GuiInspectorDynamicField::constructRenameControl()
  947. {
  948. // Create our renaming field
  949. GuiControl* retCtrl = new GuiTextEditCtrl();
  950. // If we couldn't construct the control, bail!
  951. if( retCtrl == NULL )
  952. return retCtrl;
  953. // Let's make it look pretty.
  954. retCtrl->setField( "profile", "GuiTextEditProfile" );
  955. // Don't forget to register ourselves
  956. char szName[512];
  957. dSprintf( szName, 512, "IE_%s_%d_%s_Rename", retCtrl->getClassName(), mTarget->getId(), getFieldName() );
  958. retCtrl->registerObject( szName );
  959. // Our command will evaluate to :
  960. //
  961. // if( (editCtrl).getText() !$= "" )
  962. // (field).renameField((editCtrl).getText());
  963. //
  964. char szBuffer[512];
  965. dSprintf( szBuffer, 512, "if( %d.getText() !$= \"\" ) %d.renameField(%d.getText());",retCtrl->getId(), getId(), retCtrl->getId() );
  966. dynamic_cast<GuiTextEditCtrl*>(retCtrl)->setText( getFieldName() );
  967. retCtrl->setExtent(Point2I((getExtent().x / 2) - 20, 30));
  968. retCtrl->setField("AltCommand", szBuffer );
  969. addObject( retCtrl );
  970. // Finally, add a delete button for this field
  971. GuiButtonCtrl * delButt = new GuiButtonCtrl();
  972. if( delButt != NULL )
  973. {
  974. dSprintf(szBuffer, 512, "%d.%s = \"\";%d.inspectGroup();", mTarget->getId(), getFieldName(), mGroup->getId());
  975. delButt->setField("profile", "GuiButtonDynProfile");
  976. delButt->setField("Text", "X");
  977. delButt->setPosition(Point2I((getExtent().x - 40), 0));
  978. delButt->setField("extent", "30 30");
  979. delButt->setField("Command", szBuffer);
  980. delButt->registerObject();
  981. addObject(delButt);
  982. }
  983. return retCtrl;
  984. }
  985. void GuiInspectorDynamicField::resize( const Point2I &newPosition, const Point2I &newExtent )
  986. {
  987. Parent::resize( newPosition, newExtent );
  988. }
  989. #pragma endregion
  990. #pragma region GuiInspectorDatablockField
  991. //////////////////////////////////////////////////////////////////////////
  992. // GuiInspectorDatablockField
  993. // Field construction for datablock types
  994. //////////////////////////////////////////////////////////////////////////
  995. IMPLEMENT_CONOBJECT(GuiInspectorDatablockField);
  996. static S32 QSORT_CALLBACK stringCompare(const void *a,const void *b)
  997. {
  998. StringTableEntry sa = *(StringTableEntry*)a;
  999. StringTableEntry sb = *(StringTableEntry*)b;
  1000. return(dStricmp(sb, sa));
  1001. }
  1002. GuiInspectorDatablockField::GuiInspectorDatablockField( StringTableEntry className )
  1003. {
  1004. setClassName(className);
  1005. };
  1006. void GuiInspectorDatablockField::setClassName( StringTableEntry className )
  1007. {
  1008. // Walk the ACR list and find a matching class if any.
  1009. AbstractClassRep *walk = AbstractClassRep::getClassList();
  1010. while(walk)
  1011. {
  1012. if(!dStricmp(walk->getClassName(), className))
  1013. {
  1014. // Match!
  1015. mDesiredClass = walk;
  1016. return;
  1017. }
  1018. walk = walk->getNextClass();
  1019. }
  1020. // No dice.
  1021. Con::warnf("GuiInspectorDatablockField::setClassName - no class '%s' found!", className);
  1022. return;
  1023. }
  1024. GuiControl* GuiInspectorDatablockField::constructEditControl()
  1025. {
  1026. GuiControl* retCtrl = new GuiDropDownCtrl();
  1027. // If we couldn't construct the control, bail!
  1028. if( retCtrl == NULL )
  1029. return retCtrl;
  1030. GuiDropDownCtrl *menu = dynamic_cast<GuiDropDownCtrl*>(retCtrl);
  1031. menu->setField("text", getData());
  1032. registerEditControl( retCtrl );
  1033. // Configure it to update our value when the dropdown is closed
  1034. char szBuffer[512];
  1035. dSprintf( szBuffer, 512, "%d.%s = %d.getText();%d.inspect(%d);",mTarget->getId(), mField->pFieldname, menu->getId(), mGroup->mInspector->getId(), mTarget->getId() );
  1036. menu->setField("Command", szBuffer );
  1037. Vector<StringTableEntry> entries;
  1038. SimDataBlockGroup * grp = Sim::getDataBlockGroup();
  1039. for(SimDataBlockGroup::iterator i = grp->begin(); i != grp->end(); i++)
  1040. {
  1041. SimDataBlock * datablock = dynamic_cast<SimDataBlock*>(*i);
  1042. // Skip non-datablocks if we somehow encounter them.
  1043. if(!datablock)
  1044. continue;
  1045. // Ok, now we have to figure inheritance info.
  1046. if( datablock && datablock->getClassRep()->isClass(mDesiredClass) )
  1047. entries.push_back(datablock->getName());
  1048. }
  1049. // sort the entries
  1050. dQsort(entries.address(), entries.size(), sizeof(StringTableEntry), stringCompare);
  1051. // add them to our enum
  1052. for(U32 j = 0; j < (U32)entries.size(); j++)
  1053. menu->getList()->addItem(entries[j]);
  1054. return retCtrl;
  1055. }
  1056. #pragma endregion