guiInspector.cc 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  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. Parent::parentResized(oldParentExtent,newParentExtent);
  171. }
  172. bool GuiInspector::findExistentGroup( StringTableEntry groupName )
  173. {
  174. // If we have no groups, it couldn't possibly exist
  175. if( mGroups.empty() )
  176. return false;
  177. // Attempt to find it in the group list
  178. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  179. for( ; i != mGroups.end(); i++ )
  180. {
  181. if( dStricmp( (*i)->getGroupName(), groupName ) == 0 )
  182. return true;
  183. }
  184. return false;
  185. }
  186. void GuiInspector::clearGroups()
  187. {
  188. // If we're clearing the groups, we want to clear our target too.
  189. mTarget = NULL;
  190. // If we have no groups, there's nothing to clear!
  191. if( mGroups.empty() )
  192. return;
  193. // Attempt to find it in the group list
  194. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  195. for( ; i != mGroups.end(); i++ )
  196. if( (*i)->isProperlyAdded() )
  197. (*i)->deleteObject();
  198. mGroups.clear();
  199. GuiControl* firstRes = getFirstResponder();
  200. clearFirstResponder(firstRes);
  201. }
  202. void GuiInspector::inspectObject( SimObject *object )
  203. {
  204. GuiCanvas *guiCanvas = getRoot();
  205. if( !guiCanvas )
  206. return;
  207. SimObjectPtr<GuiControl> currResponder = guiCanvas->getFirstResponder();
  208. // If our target is the same as our current target, just update the groups.
  209. if( mTarget == object )
  210. {
  211. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  212. for ( ; i != mGroups.end(); i++ )
  213. (*i)->inspectGroup();
  214. // Don't steal first responder
  215. if( !currResponder.isNull() )
  216. guiCanvas->setFirstResponder( currResponder );
  217. return;
  218. }
  219. // Clear our current groups
  220. clearGroups();
  221. // Set Target
  222. mTarget = object;
  223. // Always create the 'general' group (for un-grouped fields)
  224. GuiInspectorGroup* general = new GuiInspectorGroup( mTarget, "General", this );
  225. if( general != NULL )
  226. {
  227. general->registerObject();
  228. mGroups.push_back( general );
  229. addObject( general );
  230. }
  231. // Grab this objects field list
  232. AbstractClassRep::FieldList &fieldList = mTarget->getModifiableFieldList();
  233. AbstractClassRep::FieldList::iterator itr;
  234. // Iterate through, identifying the groups and create necessary GuiInspectorGroups
  235. for(itr = fieldList.begin(); itr != fieldList.end(); itr++)
  236. {
  237. if(itr->type == AbstractClassRep::StartGroupFieldType && !findExistentGroup( itr->pGroupname ) )
  238. {
  239. GuiInspectorGroup *group = new GuiInspectorGroup( mTarget, itr->pGroupname, this );
  240. if( group != NULL )
  241. {
  242. group->registerObject();
  243. mGroups.push_back( group );
  244. addObject( group );
  245. }
  246. }
  247. }
  248. // Deal with dynamic fields
  249. GuiInspectorGroup *dynGroup = new GuiInspectorDynamicGroup( mTarget, "Dynamic Fields", this);
  250. if( dynGroup != NULL )
  251. {
  252. dynGroup->registerObject();
  253. mGroups.push_back( dynGroup );
  254. addObject( dynGroup );
  255. }
  256. // If any group is still empty at this point, kill it.
  257. for(S32 i=0; i<mGroups.size(); i++)
  258. {
  259. if(mGroups[i]->mGrid->size() == 0)
  260. {
  261. mGroups[i]->deleteObject();
  262. mGroups.erase(i);
  263. i--;
  264. }
  265. }
  266. resize(getPosition(), getExtent());
  267. // Don't steal first responder
  268. if( !currResponder.isNull() )
  269. guiCanvas->setFirstResponder( currResponder );
  270. }
  271. ConsoleMethod( GuiInspector, inspect, void, 3, 3, "(obj) Goes through the object's fields and autogenerates editor boxes\n"
  272. "@return No return value.")
  273. {
  274. SimObject * target = Sim::findObject(argv[2]);
  275. if(!target)
  276. {
  277. if(dAtoi(argv[2]) > 0)
  278. Con::warnf("%s::inspect(): invalid object: %s", argv[0], argv[2]);
  279. object->clearGroups();
  280. return;
  281. }
  282. object->inspectObject(target);
  283. }
  284. ConsoleMethod( GuiInspector, getInspectObject, const char*, 2, 2, "() - Returns currently inspected object\n"
  285. "@return The Object's ID as a string.")
  286. {
  287. SimObject *pSimObject = object->getInspectObject();
  288. if( pSimObject != NULL )
  289. return pSimObject->getIdString();
  290. return "";
  291. }
  292. ConsoleMethod(GuiInspector, clear, const char*, 2, 2, "() - Uninspects\n"
  293. "@return Not used.")
  294. {
  295. object->clearGroups();
  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. if (mGroup->mInspector->isMethod("onPreApply"))
  383. {
  384. Con::executef(mGroup->mInspector, 3, "onPreApply", Con::getIntArg(mTarget->getId()));
  385. }
  386. mTarget->setDataField( mField->pFieldname, mFieldArrayIndex, data );
  387. // Force our edit to update
  388. updateValue( data );
  389. mTarget->inspectPostApply();
  390. if (mGroup->mInspector->isMethod("onPostApply"))
  391. {
  392. Con::executef(mGroup->mInspector, 3, "onPostApply", Con::getIntArg(mTarget->getId()));
  393. }
  394. }
  395. const char* GuiInspectorField::getData()
  396. {
  397. if( mField == NULL || mTarget == NULL )
  398. return "";
  399. return mTarget->getDataField( mField->pFieldname, mFieldArrayIndex );
  400. }
  401. void GuiInspectorField::setInspectorField( AbstractClassRep::Field *field, const char*arrayIndex )
  402. {
  403. mField = field;
  404. if( arrayIndex != NULL )
  405. {
  406. mFieldArrayIndex = StringTable->insert( arrayIndex );
  407. S32 frameTempSize = dStrlen( field->pFieldname ) + 32;
  408. FrameTemp<char> valCopy( frameTempSize );
  409. dSprintf( (char *)valCopy, frameTempSize, "%s%s", field->pFieldname, arrayIndex );
  410. mText = StringTable->insert( valCopy );
  411. }
  412. else
  413. mText = StringTable->insert( field->pFieldname );
  414. }
  415. StringTableEntry GuiInspectorField::getFieldName()
  416. {
  417. // Sanity
  418. if ( mField == NULL )
  419. return StringTable->EmptyString;
  420. // Array element?
  421. if( mFieldArrayIndex != NULL )
  422. {
  423. S32 frameTempSize = dStrlen( mField->pFieldname ) + 32;
  424. FrameTemp<char> valCopy( frameTempSize );
  425. dSprintf( (char *)valCopy, frameTempSize, "%s%s:", mField->pFieldname, mFieldArrayIndex );
  426. // Return formatted element
  427. return StringTable->insert( valCopy );
  428. }
  429. // Plain ole field name.
  430. return mField->pFieldname;
  431. };
  432. //////////////////////////////////////////////////////////////////////////
  433. // Overrideables for custom edit fields
  434. //////////////////////////////////////////////////////////////////////////
  435. GuiControl* GuiInspectorField::constructEditControl(S32 width)
  436. {
  437. GuiControl* retCtrl = new GuiTextEditCtrl();
  438. // If we couldn't construct the control, bail!
  439. if( retCtrl == NULL )
  440. return retCtrl;
  441. // Let's make it look pretty.
  442. retCtrl->setControlProfile(mGroup->mInspector->mTextEditProfile);
  443. // Don't forget to register ourselves
  444. registerEditControl( retCtrl );
  445. char szBuffer[512];
  446. dSprintf( szBuffer, 512, "%d.apply(%d.getText());",getId(), retCtrl->getId() );
  447. retCtrl->setField("AltCommand", szBuffer );
  448. retCtrl->mBounds.set(mGroup->mInspector->mControlOffset, Point2I(width - mGroup->mInspector->mControlOffset.x, 30));
  449. return retCtrl;
  450. }
  451. void GuiInspectorField::registerEditControl( GuiControl *ctrl )
  452. {
  453. if(!mTarget)
  454. return;
  455. char szName[512];
  456. dSprintf( szName, 512, "IE_%s_%d_%s_Field", ctrl->getClassName(), mTarget->getId(),mText);
  457. // Register the object
  458. ctrl->registerObject( szName );
  459. }
  460. bool GuiInspectorField::onAdd()
  461. {
  462. if( !Parent::onAdd() )
  463. return false;
  464. if( !mTarget )
  465. return false;
  466. setControlProfile(mGroup->mInspector->mLabelProfile);
  467. //Find the target width
  468. Point2I origin = Point2I(0,0);
  469. RectI innerRect = getInnerRect(origin, mGroup->mInspector->mFieldCellSize, NormalState, mProfile);
  470. mEdit = constructEditControl(innerRect.extent.x);
  471. if( mEdit == NULL )
  472. return false;
  473. innerRect.extent.y = mGroup->mInspector->mControlOffset.y + mEdit->getExtent().y;
  474. Point2I outerExt = getOuterExtent(innerRect.extent, NormalState, mProfile);
  475. mBounds.extent.y = outerExt.y;
  476. //Set the tool tip if possible
  477. if (mField != NULL && mField->pFieldDocs != NULL)
  478. {
  479. mEdit->setField("tooltip", mField->pFieldDocs);
  480. if (mGroup->mInspector->mTooltipProfile != NULL)
  481. {
  482. char buffer[256];
  483. dSprintf(buffer, sizeof(buffer), "%d", mGroup->mInspector->mTooltipProfile->getId());
  484. mEdit->setField("tooltipProfile", buffer);
  485. }
  486. }
  487. addObject( mEdit );
  488. // Force our editField to set it's value
  489. updateValue( getData() );
  490. return true;
  491. }
  492. void GuiInspectorField::updateValue( const char* newValue )
  493. {
  494. GuiTextEditCtrl *ctrl = dynamic_cast<GuiTextEditCtrl*>( mEdit );
  495. if( ctrl != NULL )
  496. ctrl->setText( newValue );
  497. }
  498. ConsoleMethod( GuiInspectorField, apply, void, 3,3, "(newValue) Applies the given value to the field\n"
  499. "@return No return value." )
  500. {
  501. object->setData( argv[2] );
  502. }
  503. #pragma endregion
  504. #pragma region GuiInspectorGroup
  505. //////////////////////////////////////////////////////////////////////////
  506. // GuiInspectorGroup
  507. //////////////////////////////////////////////////////////////////////////
  508. //
  509. // The GuiInspectorGroup control is a helper control that the inspector
  510. // makes use of which houses a collapsible panel type control for separating
  511. // inspected objects fields into groups. The content of the inspector is
  512. // made up of zero or more GuiInspectorGroup controls inside of a GuiChainControl
  513. //
  514. //
  515. //
  516. IMPLEMENT_CONOBJECT(GuiInspectorGroup);
  517. GuiInspectorGroup::GuiInspectorGroup()
  518. {
  519. mChildren.clear();
  520. mTarget = NULL;
  521. mInspector = NULL;
  522. mCanSave = false;
  523. mHorizSizing = horizSizingOptions::horizResizeWidth;
  524. mVertSizing = vertSizingOptions::vertResizeTop;
  525. mBounds.set(10, 0, (mInspector->getExtent().x - 20), 24);
  526. }
  527. GuiInspectorGroup::GuiInspectorGroup( SimObjectPtr<SimObject> target, StringTableEntry groupName, SimObjectPtr<GuiInspector> inspector )
  528. {
  529. mChildren.clear();
  530. mText = StringTable->insert(groupName);
  531. mTarget = target;
  532. mInspector = inspector;
  533. mCanSave = false;
  534. mHorizSizing = horizSizingOptions::horizResizeWidth;
  535. mVertSizing = vertSizingOptions::vertResizeTop;
  536. mBounds.set(10, 0, (mInspector->getExtent().x - 20), 24);
  537. }
  538. bool GuiInspectorGroup::onAdd()
  539. {
  540. if( !Parent::onAdd() )
  541. return false;
  542. setControlProfile(mInspector->mGroupPanelProfile);
  543. // Create our inner controls. Allow subclasses to provide other content.
  544. if(!createContent())
  545. return false;
  546. inspectGroup();
  547. return true;
  548. }
  549. bool GuiInspectorGroup::createContent()
  550. {
  551. // Create our field stack control
  552. mGrid = new GuiGridCtrl();
  553. if( !mGrid)
  554. return false;
  555. mGrid->setControlProfile(mInspector->mGroupGridProfile);
  556. mGrid->setCellSize(mInspector->mFieldCellSize.x, mInspector->mFieldCellSize.y);
  557. mGrid->setCellSpacing(0,0);
  558. mGrid->setCellModeX(GuiGridCtrl::CellMode::Variable);
  559. mGrid->setCellModeY(GuiGridCtrl::CellMode::Variable);
  560. mGrid->setMaxColCount(0);
  561. mGrid->mIsExtentDynamic = true;
  562. mGrid->mOrderMode = GuiGridCtrl::OrderMode::LRTB;
  563. mGrid->setWidth(getExtent().x - 20);
  564. mGrid->setPosition(Point2I(10, getExtent().y));
  565. mGrid->setField("horizSizing", "width");
  566. mGrid->setField("vertSizing", "bottom");
  567. mGrid->registerObject();
  568. addObject( mGrid );
  569. return true;
  570. }
  571. GuiInspectorField* GuiInspectorGroup::constructField( S32 fieldType )
  572. {
  573. ConsoleBaseType *cbt = ConsoleBaseType::getType(fieldType);
  574. AssertFatal(cbt, "GuiInspectorGroup::constructField - could not resolve field type!");
  575. // Alright, is it a datablock?
  576. if(cbt->isDatablock())
  577. {
  578. // This is fairly straightforward to deal with.
  579. GuiInspectorDatablockField *dbFieldClass = new GuiInspectorDatablockField( cbt->getTypeClassName() );
  580. if( dbFieldClass != NULL )
  581. {
  582. // return our new datablock field with correct datablock type enumeration info
  583. return dbFieldClass;
  584. }
  585. }
  586. // Nope, not a datablock. So maybe it has a valid inspector field override we can use?
  587. if(!cbt->getInspectorFieldType())
  588. // Nothing, so bail.
  589. return NULL;
  590. // Otherwise try to make it!
  591. ConsoleObject *co = create(cbt->getInspectorFieldType());
  592. GuiInspectorField *gif = dynamic_cast<GuiInspectorField*>(co);
  593. if(!gif)
  594. {
  595. // Wasn't appropriate type, bail.
  596. delete co;
  597. return NULL;
  598. }
  599. return gif;
  600. }
  601. GuiInspectorField *GuiInspectorGroup::findField( StringTableEntry fieldName )
  602. {
  603. // If we don't have any field children we can't very well find one then can we?
  604. if( mChildren.empty() )
  605. return NULL;
  606. Vector<GuiInspectorField*>::iterator i = mChildren.begin();
  607. for( ; i != mChildren.end(); i++ )
  608. {
  609. if( (*i)->getFieldName() != NULL && dStricmp( (*i)->getFieldName(), fieldName ) == 0 )
  610. return (*i);
  611. }
  612. return NULL;
  613. }
  614. bool GuiInspectorGroup::inspectGroup()
  615. {
  616. // We can't inspect a group without a target!
  617. if( !mTarget )
  618. return false;
  619. // to prevent crazy resizing, we'll just freeze our stack for a sec..
  620. //mStack->freeze(true);
  621. bool bNoGroup = false;
  622. // Un-grouped fields are all sorted into the 'general' group
  623. if ( dStricmp( mText, "General" ) == 0 )
  624. bNoGroup = true;
  625. AbstractClassRep::FieldList &fieldList = mTarget->getModifiableFieldList();
  626. AbstractClassRep::FieldList::iterator itr;
  627. bool bGrabItems = false;
  628. bool bNewItems = false;
  629. for(itr = fieldList.begin(); itr != fieldList.end(); itr++)
  630. {
  631. if( itr->type == AbstractClassRep::StartGroupFieldType )
  632. {
  633. // If we're dealing with general fields, always set grabItems to true (to skip them)
  634. if( bNoGroup == true || ( itr->pGroupname != NULL && dStricmp( itr->pGroupname, mText ) == 0 ))
  635. bGrabItems = true;
  636. continue;
  637. }
  638. else if ( itr->type == AbstractClassRep::EndGroupFieldType )
  639. {
  640. // If we're dealing with general fields, always set grabItems to false (to grab them)
  641. if( bNoGroup == true || ( itr->pGroupname != NULL && dStricmp( itr->pGroupname, mText ) == 0 ))
  642. bGrabItems = false;
  643. continue;
  644. }
  645. if((bGrabItems == true || (bNoGroup == true && bGrabItems == false)) && itr->type != AbstractClassRep::DepricatedFieldType )
  646. {
  647. //We are inside a group and looking for items that don't have a group. Move on.
  648. if( bNoGroup == true && bGrabItems == true )
  649. continue;
  650. // We are going to check to see if this item is an array
  651. // if so, we're going to construct a field for each array element
  652. if( itr->elementCount > 1 )
  653. {
  654. for(S32 nI = 0; nI < itr->elementCount; nI++)
  655. {
  656. FrameTemp<char> intToStr( 64 );
  657. dSprintf( intToStr, 64, "%d", nI );
  658. const char *val = mTarget->getDataField( itr->pFieldname, intToStr );
  659. if (!val)
  660. val = StringTable->EmptyString;
  661. // Copy Val and construct proper ValueName[nI] format
  662. // which is "ValueName0" for index 0, etc.
  663. S32 frameTempSize = dStrlen( val ) + 32;
  664. FrameTemp<char> valCopy( frameTempSize );
  665. dSprintf( (char *)valCopy, frameTempSize, "%s%d", itr->pFieldname, nI );
  666. // If the field already exists, just update it
  667. GuiInspectorField *field = findField( valCopy );
  668. if( field != NULL )
  669. {
  670. field->updateValue( field->getData() );
  671. continue;
  672. }
  673. bNewItems = true;
  674. field = constructField( itr->type );
  675. if( field == NULL )
  676. {
  677. field = new GuiInspectorField( this, mTarget, itr );
  678. field->setExtent(Point2I(this->getExtent().x,30));
  679. field->setInspectorField( itr, intToStr );
  680. }
  681. else
  682. {
  683. field->setExtent(Point2I(this->getExtent().x, 30));
  684. field->setTarget( mTarget );
  685. field->setInspectorGroup( this );
  686. field->setInspectorField( itr, intToStr );
  687. }
  688. field->registerObject();
  689. mChildren.push_back( field );
  690. mGrid->addObject( field );
  691. }
  692. }
  693. else
  694. {
  695. // If the field already exists, just update it
  696. GuiInspectorField *field = findField( itr->pFieldname );
  697. if( field != NULL )
  698. {
  699. field->updateValue( field->getData() );
  700. continue;
  701. }
  702. bNewItems = true;
  703. //check the hidden field list
  704. if (mInspector->hideField(itr->pFieldname))
  705. {
  706. continue;
  707. }
  708. //Time to create a new field
  709. field = constructField( itr->type );
  710. if( field == NULL )
  711. field = new GuiInspectorField( this, mTarget, itr );
  712. else
  713. {
  714. field->setTarget( mTarget );
  715. field->setInspectorGroup( this );
  716. field->setInspectorField( itr );
  717. }
  718. field->setExtent(Point2I(this->getExtent().x, 30));
  719. field->registerObject();
  720. mChildren.push_back( field );
  721. mGrid->addObject( field );
  722. }
  723. }
  724. }
  725. // If we've no new items, there's no need to resize anything!
  726. if( bNewItems == false && !mChildren.empty() )
  727. return true;
  728. //sizeToContents();
  729. setUpdate();
  730. return true;
  731. }
  732. #pragma endregion
  733. #pragma region GuiInspectorDynamicGroup
  734. IMPLEMENT_CONOBJECT(GuiInspectorDynamicGroup);
  735. //////////////////////////////////////////////////////////////////////////
  736. // GuiInspectorDynamicGroup - add custom controls
  737. //////////////////////////////////////////////////////////////////////////
  738. bool GuiInspectorDynamicGroup::createContent()
  739. {
  740. if(!Parent::createContent())
  741. return false;
  742. // add a button that lets us add new dynamic fields.
  743. GuiButtonCtrl* addFieldBtn = new GuiButtonCtrl();
  744. {
  745. SimObject* profilePtr = Sim::findObject("EditorButton");
  746. if( profilePtr != NULL )
  747. addFieldBtn->setControlProfile( dynamic_cast<GuiControlProfile*>(profilePtr) );
  748. char commandBuf[64];
  749. dSprintf(commandBuf, 64, "%d.addDynamicField();", this->getId());
  750. addFieldBtn->setField("profile", "GuiButtonProfile");
  751. addFieldBtn->setField("command", commandBuf);
  752. addFieldBtn->setField("text", "+");
  753. addFieldBtn->setExtent(Point2I(30, 30));
  754. addFieldBtn->registerObject("zAddButton");
  755. }
  756. // encapsulate the button in a dummy control.
  757. GuiControl* shell = new GuiControl();
  758. shell->setField( "profile", "GuiTextProfile" );
  759. shell->registerObject();
  760. shell->setField("text", "Add Field");
  761. shell->setExtent(Point2I(getExtent().x - 30,30 + 10));
  762. addFieldBtn->setPosition(Point2I((shell->getExtent().x) - 30, 0));
  763. shell->addObject(addFieldBtn);
  764. // save off the shell control, so we can push it to the bottom of the stack in inspectGroup()
  765. mAddCtrl = shell;
  766. mGrid->addObject(shell);
  767. return true;
  768. }
  769. static S32 QSORT_CALLBACK compareEntries(const void* a,const void* b)
  770. {
  771. SimFieldDictionary::Entry *fa = *((SimFieldDictionary::Entry **)a);
  772. SimFieldDictionary::Entry *fb = *((SimFieldDictionary::Entry **)b);
  773. return dStricmp(fa->slotName, fb->slotName);
  774. }
  775. //////////////////////////////////////////////////////////////////////////
  776. // GuiInspectorDynamicGroup - inspectGroup override
  777. //////////////////////////////////////////////////////////////////////////
  778. bool GuiInspectorDynamicGroup::inspectGroup()
  779. {
  780. // We can't inspect a group without a target!
  781. if( !mTarget )
  782. return false;
  783. // Clearing the fields and recreating them will more than likely be more
  784. // efficient than looking up existent fields, updating them, and then iterating
  785. // over existent fields and making sure they still exist, if not, deleting them.
  786. clearFields();
  787. // Create a vector of the fields
  788. Vector<SimFieldDictionary::Entry *> flist;
  789. // Then populate with fields
  790. SimFieldDictionary * fieldDictionary = mTarget->getFieldDictionary();
  791. for(SimFieldDictionaryIterator ditr(fieldDictionary); *ditr; ++ditr)
  792. {
  793. flist.push_back(*ditr);
  794. }
  795. dQsort(flist.address(),flist.size(),sizeof(SimFieldDictionary::Entry *),compareEntries);
  796. for(U32 i = 0; i < (U32)flist.size(); i++)
  797. {
  798. SimFieldDictionary::Entry * entry = flist[i];
  799. GuiInspectorField *field = new GuiInspectorDynamicField( this, mTarget, entry );
  800. if( field != NULL )
  801. {
  802. field->setExtent(Point2I(this->getExtent().x, 30));
  803. field->registerObject();
  804. mChildren.push_back( field );
  805. mGrid->addObject( field );
  806. }
  807. }
  808. mGrid->pushObjectToBack(mAddCtrl);
  809. setUpdate();
  810. return true;
  811. }
  812. ConsoleMethod(GuiInspectorDynamicGroup, inspectGroup, bool, 2, 2, "() Refreshes the dynamic fields in the inspector.\n"
  813. "@return Returns true on success.")
  814. {
  815. return object->inspectGroup();
  816. }
  817. void GuiInspectorDynamicGroup::clearFields()
  818. {
  819. // save mAddCtrl
  820. Sim::getGuiGroup()->addObject(mAddCtrl);
  821. // delete everything else
  822. mGrid->clear();
  823. // clear the mChildren list.
  824. mChildren.clear();
  825. // and restore.
  826. mGrid->addObject(mAddCtrl);
  827. }
  828. SimFieldDictionary::Entry* GuiInspectorDynamicGroup::findDynamicFieldInDictionary( StringTableEntry fieldName )
  829. {
  830. if( !mTarget )
  831. return NULL;
  832. SimFieldDictionary * fieldDictionary = mTarget->getFieldDictionary();
  833. for(SimFieldDictionaryIterator ditr(fieldDictionary); *ditr; ++ditr)
  834. {
  835. SimFieldDictionary::Entry * entry = (*ditr);
  836. if( dStricmp( entry->slotName, fieldName ) == 0 )
  837. return entry;
  838. }
  839. return NULL;
  840. }
  841. void GuiInspectorDynamicGroup::addDynamicField()
  842. {
  843. // We can't add a field without a target
  844. if( !mTarget || !mGrid)
  845. {
  846. Con::warnf("GuiInspectorDynamicGroup::addDynamicField - no target SimObject to add a dynamic field to.");
  847. return;
  848. }
  849. // find a field name that is not in use.
  850. // But we wont try more than 100 times to find an available field.
  851. U32 uid = 1;
  852. char buf[64] = "dynamicField";
  853. SimFieldDictionary::Entry* entry = findDynamicFieldInDictionary(buf);
  854. while(entry != NULL && uid < 100)
  855. {
  856. dSprintf(buf, sizeof(buf), "dynamicField%03d", uid++);
  857. entry = findDynamicFieldInDictionary(buf);
  858. }
  859. //Con::evaluatef( "%d.%s = \"defaultValue\";", mTarget->getId(), buf );
  860. mTarget->setDataField(StringTable->insert(buf), NULL, "defaultValue");
  861. // now we simply re-inspect the object, to see the new field.
  862. this->inspectGroup();
  863. //animateToContents();
  864. }
  865. ConsoleMethod( GuiInspectorDynamicGroup, addDynamicField, void, 2, 2, "obj.addDynamicField();" )
  866. {
  867. object->addDynamicField();
  868. }
  869. #pragma endregion
  870. #pragma region GuiInspectorDynamicField
  871. //////////////////////////////////////////////////////////////////////////
  872. // GuiInspectorDynamicField - Child class of GuiInspectorField
  873. //////////////////////////////////////////////////////////////////////////
  874. IMPLEMENT_CONOBJECT(GuiInspectorDynamicField);
  875. GuiInspectorDynamicField::GuiInspectorDynamicField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, SimFieldDictionary::Entry* field )
  876. {
  877. mGroup = parent;
  878. mTarget = target;
  879. mDynField = field;
  880. mRenameCtrl = NULL;
  881. }
  882. void GuiInspectorDynamicField::setData( const char* data )
  883. {
  884. if( mTarget == NULL || mDynField == NULL )
  885. return;
  886. char buf[1024];
  887. const char * newValue = mEdit->getScriptValue();
  888. dStrcpy( buf, newValue ? newValue : "" );
  889. collapseEscape(buf);
  890. mTarget->getFieldDictionary()->setFieldValue(mDynField->slotName, buf);
  891. // Force our edit to update
  892. updateValue( data );
  893. }
  894. const char* GuiInspectorDynamicField::getData()
  895. {
  896. if( mTarget == NULL || mDynField == NULL )
  897. return "";
  898. return mTarget->getFieldDictionary()->getFieldValue( mDynField->slotName );
  899. }
  900. void GuiInspectorDynamicField::renameField( StringTableEntry newFieldName )
  901. {
  902. if( mTarget == NULL || mDynField == NULL || mGroup == NULL || mEdit == NULL )
  903. {
  904. Con::warnf("GuiInspectorDynamicField::renameField - No target object or dynamic field data found!" );
  905. return;
  906. }
  907. if( !newFieldName )
  908. {
  909. Con::warnf("GuiInspectorDynamicField::renameField - Invalid field name specified!" );
  910. return;
  911. }
  912. // Only proceed if the name has changed
  913. if( dStricmp( newFieldName, getFieldName() ) == 0 )
  914. return;
  915. // Grab a pointer to our parent and cast it to GuiInspectorDynamicGroup
  916. GuiInspectorDynamicGroup *group = dynamic_cast<GuiInspectorDynamicGroup*>(mGroup);
  917. if( group == NULL )
  918. {
  919. Con::warnf("GuiInspectorDynamicField::renameField - Unable to locate GuiInspectorDynamicGroup parent!" );
  920. return;
  921. }
  922. // Grab our current dynamic field value
  923. const char* currentValue = getData();
  924. // Create our new field with the value of our old field and the new fields name!
  925. mTarget->setDataField( newFieldName, NULL, currentValue );
  926. // Configure our field to grab data from the new dynamic field
  927. SimFieldDictionary::Entry *newEntry = group->findDynamicFieldInDictionary( newFieldName );
  928. if( newEntry == NULL )
  929. {
  930. Con::warnf("GuiInspectorDynamicField::renameField - Unable to find new field!" );
  931. return;
  932. }
  933. // Set our old fields data to "" (which will effectively erase the field)
  934. mTarget->setDataField( getFieldName(), NULL, "" );
  935. // Assign our dynamic field pointer (where we retrieve field information from) to our new field pointer
  936. mDynField = newEntry;
  937. // Lastly we need to reassign our AltCommand fields for our value edit control
  938. char szBuffer[512];
  939. dSprintf( szBuffer, 512, "%d.%s = %d.getText();",mTarget->getId(), getFieldName(), mEdit->getId() );
  940. mEdit->setExtent(Point2I((getExtent().x / 2) - 20, 30));
  941. mEdit->setField("AltCommand", szBuffer );
  942. }
  943. ConsoleMethod( GuiInspectorDynamicField, renameField, void, 3,3, "field.renameField(newDynamicFieldName);" )
  944. {
  945. object->renameField( StringTable->insert(argv[2]) );
  946. }
  947. bool GuiInspectorDynamicField::onAdd()
  948. {
  949. if( !Parent::onAdd() )
  950. return false;
  951. mRenameCtrl = constructRenameControl();
  952. pushObjectToBack(mEdit);
  953. return true;
  954. }
  955. GuiControl* GuiInspectorDynamicField::constructRenameControl()
  956. {
  957. // Create our renaming field
  958. GuiControl* retCtrl = new GuiTextEditCtrl();
  959. // If we couldn't construct the control, bail!
  960. if( retCtrl == NULL )
  961. return retCtrl;
  962. // Let's make it look pretty.
  963. retCtrl->setField( "profile", "GuiTextEditProfile" );
  964. // Don't forget to register ourselves
  965. char szName[512];
  966. dSprintf( szName, 512, "IE_%s_%d_%s_Rename", retCtrl->getClassName(), mTarget->getId(), getFieldName() );
  967. retCtrl->registerObject( szName );
  968. // Our command will evaluate to :
  969. //
  970. // if( (editCtrl).getText() !$= "" )
  971. // (field).renameField((editCtrl).getText());
  972. //
  973. char szBuffer[512];
  974. dSprintf( szBuffer, 512, "if( %d.getText() !$= \"\" ) %d.renameField(%d.getText());",retCtrl->getId(), getId(), retCtrl->getId() );
  975. dynamic_cast<GuiTextEditCtrl*>(retCtrl)->setText( getFieldName() );
  976. retCtrl->setExtent(Point2I((getExtent().x / 2) - 20, 30));
  977. retCtrl->setField("AltCommand", szBuffer );
  978. addObject( retCtrl );
  979. // Finally, add a delete button for this field
  980. GuiButtonCtrl * delButt = new GuiButtonCtrl();
  981. if( delButt != NULL )
  982. {
  983. dSprintf(szBuffer, 512, "%d.%s = \"\";%d.inspectGroup();", mTarget->getId(), getFieldName(), mGroup->getId());
  984. delButt->setField("profile", "GuiButtonProfile");
  985. delButt->setField("Text", "X");
  986. delButt->setPosition(Point2I((getExtent().x - 40), 0));
  987. delButt->setField("extent", "30 30");
  988. delButt->setField("Command", szBuffer);
  989. delButt->registerObject();
  990. addObject(delButt);
  991. }
  992. return retCtrl;
  993. }
  994. void GuiInspectorDynamicField::resize( const Point2I &newPosition, const Point2I &newExtent )
  995. {
  996. Parent::resize( newPosition, newExtent );
  997. }
  998. #pragma endregion
  999. #pragma region GuiInspectorDatablockField
  1000. //////////////////////////////////////////////////////////////////////////
  1001. // GuiInspectorDatablockField
  1002. // Field construction for datablock types
  1003. //////////////////////////////////////////////////////////////////////////
  1004. IMPLEMENT_CONOBJECT(GuiInspectorDatablockField);
  1005. static S32 QSORT_CALLBACK stringCompare(const void *a,const void *b)
  1006. {
  1007. StringTableEntry sa = *(StringTableEntry*)a;
  1008. StringTableEntry sb = *(StringTableEntry*)b;
  1009. return(dStricmp(sb, sa));
  1010. }
  1011. GuiInspectorDatablockField::GuiInspectorDatablockField( StringTableEntry className )
  1012. {
  1013. setClassName(className);
  1014. };
  1015. void GuiInspectorDatablockField::setClassName( StringTableEntry className )
  1016. {
  1017. // Walk the ACR list and find a matching class if any.
  1018. AbstractClassRep *walk = AbstractClassRep::getClassList();
  1019. while(walk)
  1020. {
  1021. if(!dStricmp(walk->getClassName(), className))
  1022. {
  1023. // Match!
  1024. mDesiredClass = walk;
  1025. return;
  1026. }
  1027. walk = walk->getNextClass();
  1028. }
  1029. // No dice.
  1030. Con::warnf("GuiInspectorDatablockField::setClassName - no class '%s' found!", className);
  1031. return;
  1032. }
  1033. GuiControl* GuiInspectorDatablockField::constructEditControl()
  1034. {
  1035. GuiControl* retCtrl = new GuiDropDownCtrl();
  1036. // If we couldn't construct the control, bail!
  1037. if( retCtrl == NULL )
  1038. return retCtrl;
  1039. GuiDropDownCtrl *menu = dynamic_cast<GuiDropDownCtrl*>(retCtrl);
  1040. menu->setField("text", getData());
  1041. registerEditControl( retCtrl );
  1042. // Configure it to update our value when the dropdown is closed
  1043. char szBuffer[512];
  1044. dSprintf( szBuffer, 512, "%d.%s = %d.getText();%d.inspect(%d);",mTarget->getId(), mField->pFieldname, menu->getId(), mGroup->mInspector->getId(), mTarget->getId() );
  1045. menu->setField("Command", szBuffer );
  1046. Vector<StringTableEntry> entries;
  1047. SimDataBlockGroup * grp = Sim::getDataBlockGroup();
  1048. for(SimDataBlockGroup::iterator i = grp->begin(); i != grp->end(); i++)
  1049. {
  1050. SimDataBlock * datablock = dynamic_cast<SimDataBlock*>(*i);
  1051. // Skip non-datablocks if we somehow encounter them.
  1052. if(!datablock)
  1053. continue;
  1054. // Ok, now we have to figure inheritance info.
  1055. if( datablock && datablock->getClassRep()->isClass(mDesiredClass) )
  1056. entries.push_back(datablock->getName());
  1057. }
  1058. // sort the entries
  1059. dQsort(entries.address(), entries.size(), sizeof(StringTableEntry), stringCompare);
  1060. // add them to our enum
  1061. for(U32 j = 0; j < (U32)entries.size(); j++)
  1062. menu->getList()->addItem(entries[j]);
  1063. return retCtrl;
  1064. }
  1065. #pragma endregion