guiInspector.cc 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  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. Point2I origin = Point2I(0,0);
  461. RectI innerRect = getInnerRect(origin, mGroup->mInspector->mFieldCellSize, NormalState, mProfile);
  462. mEdit = constructEditControl(innerRect.extent.x);
  463. if( mEdit == NULL )
  464. return false;
  465. innerRect.extent.y = mGroup->mInspector->mControlOffset.y + mEdit->getExtent().y;
  466. Point2I outerExt = getOuterExtent(innerRect.extent, NormalState, mProfile);
  467. mBounds.extent.y = outerExt.y;
  468. //Set the tool tip if possible
  469. if (mField != NULL && mField->pFieldDocs != NULL)
  470. {
  471. mEdit->setField("tooltip", mField->pFieldDocs);
  472. if (mGroup->mInspector->mTooltipProfile != NULL)
  473. {
  474. char buffer[256];
  475. dSprintf(buffer, sizeof(buffer), "%d", mGroup->mInspector->mTooltipProfile->getId());
  476. mEdit->setField("tooltipProfile", buffer);
  477. }
  478. }
  479. addObject( mEdit );
  480. // Force our editField to set it's value
  481. updateValue( getData() );
  482. return true;
  483. }
  484. void GuiInspectorField::updateValue( const char* newValue )
  485. {
  486. GuiTextEditCtrl *ctrl = dynamic_cast<GuiTextEditCtrl*>( mEdit );
  487. if( ctrl != NULL )
  488. ctrl->setText( newValue );
  489. }
  490. ConsoleMethod( GuiInspectorField, apply, void, 3,3, "(newValue) Applies the given value to the field\n"
  491. "@return No return value." )
  492. {
  493. object->setData( argv[2] );
  494. }
  495. #pragma endregion
  496. #pragma region GuiInspectorGroup
  497. //////////////////////////////////////////////////////////////////////////
  498. // GuiInspectorGroup
  499. //////////////////////////////////////////////////////////////////////////
  500. //
  501. // The GuiInspectorGroup control is a helper control that the inspector
  502. // makes use of which houses a collapsible panel type control for separating
  503. // inspected objects fields into groups. The content of the inspector is
  504. // made up of zero or more GuiInspectorGroup controls inside of a GuiChainControl
  505. //
  506. //
  507. //
  508. IMPLEMENT_CONOBJECT(GuiInspectorGroup);
  509. GuiInspectorGroup::GuiInspectorGroup()
  510. {
  511. mChildren.clear();
  512. mTarget = NULL;
  513. mInspector = NULL;
  514. mCanSave = false;
  515. mHorizSizing = horizSizingOptions::horizResizeWidth;
  516. mVertSizing = vertSizingOptions::vertResizeTop;
  517. mBounds.set(10, 0, (mInspector->getExtent().x - 20), 24);
  518. }
  519. GuiInspectorGroup::GuiInspectorGroup( SimObjectPtr<SimObject> target, StringTableEntry groupName, SimObjectPtr<GuiInspector> inspector )
  520. {
  521. mChildren.clear();
  522. mText = StringTable->insert(groupName);
  523. mTarget = target;
  524. mInspector = inspector;
  525. mCanSave = false;
  526. mHorizSizing = horizSizingOptions::horizResizeWidth;
  527. mVertSizing = vertSizingOptions::vertResizeTop;
  528. mBounds.set(10, 0, (mInspector->getExtent().x - 20), 24);
  529. }
  530. bool GuiInspectorGroup::onAdd()
  531. {
  532. if( !Parent::onAdd() )
  533. return false;
  534. setControlProfile(mInspector->mGroupPanelProfile);
  535. // Create our inner controls. Allow subclasses to provide other content.
  536. if(!createContent())
  537. return false;
  538. inspectGroup();
  539. return true;
  540. }
  541. bool GuiInspectorGroup::createContent()
  542. {
  543. // Create our field stack control
  544. mGrid = new GuiGridCtrl();
  545. if( !mGrid)
  546. return false;
  547. mGrid->setControlProfile(mInspector->mGroupGridProfile);
  548. mGrid->setCellSize(mInspector->mFieldCellSize.x, mInspector->mFieldCellSize.y);
  549. mGrid->setCellSpacing(0,0);
  550. mGrid->setCellModeX(GuiGridCtrl::CellMode::Variable);
  551. mGrid->setCellModeY(GuiGridCtrl::CellMode::Variable);
  552. mGrid->setMaxColCount(0);
  553. mGrid->mIsExtentDynamic = true;
  554. mGrid->mOrderMode = GuiGridCtrl::OrderMode::LRTB;
  555. mGrid->setWidth(getExtent().x - 20);
  556. mGrid->setPosition(Point2I(10, getExtent().y));
  557. mGrid->setField("horizSizing", "width");
  558. mGrid->setField("vertSizing", "bottom");
  559. mGrid->registerObject();
  560. addObject( mGrid );
  561. return true;
  562. }
  563. GuiInspectorField* GuiInspectorGroup::constructField( S32 fieldType )
  564. {
  565. ConsoleBaseType *cbt = ConsoleBaseType::getType(fieldType);
  566. AssertFatal(cbt, "GuiInspectorGroup::constructField - could not resolve field type!");
  567. // Alright, is it a datablock?
  568. if(cbt->isDatablock())
  569. {
  570. // This is fairly straightforward to deal with.
  571. GuiInspectorDatablockField *dbFieldClass = new GuiInspectorDatablockField( cbt->getTypeClassName() );
  572. if( dbFieldClass != NULL )
  573. {
  574. // return our new datablock field with correct datablock type enumeration info
  575. return dbFieldClass;
  576. }
  577. }
  578. // Nope, not a datablock. So maybe it has a valid inspector field override we can use?
  579. if(!cbt->getInspectorFieldType())
  580. // Nothing, so bail.
  581. return NULL;
  582. // Otherwise try to make it!
  583. ConsoleObject *co = create(cbt->getInspectorFieldType());
  584. GuiInspectorField *gif = dynamic_cast<GuiInspectorField*>(co);
  585. if(!gif)
  586. {
  587. // Wasn't appropriate type, bail.
  588. delete co;
  589. return NULL;
  590. }
  591. return gif;
  592. }
  593. GuiInspectorField *GuiInspectorGroup::findField( StringTableEntry fieldName )
  594. {
  595. // If we don't have any field children we can't very well find one then can we?
  596. if( mChildren.empty() )
  597. return NULL;
  598. Vector<GuiInspectorField*>::iterator i = mChildren.begin();
  599. for( ; i != mChildren.end(); i++ )
  600. {
  601. if( (*i)->getFieldName() != NULL && dStricmp( (*i)->getFieldName(), fieldName ) == 0 )
  602. return (*i);
  603. }
  604. return NULL;
  605. }
  606. bool GuiInspectorGroup::inspectGroup()
  607. {
  608. // We can't inspect a group without a target!
  609. if( !mTarget )
  610. return false;
  611. // to prevent crazy resizing, we'll just freeze our stack for a sec..
  612. //mStack->freeze(true);
  613. bool bNoGroup = false;
  614. // Un-grouped fields are all sorted into the 'general' group
  615. if ( dStricmp( mText, "General" ) == 0 )
  616. bNoGroup = true;
  617. AbstractClassRep::FieldList &fieldList = mTarget->getModifiableFieldList();
  618. AbstractClassRep::FieldList::iterator itr;
  619. bool bGrabItems = false;
  620. bool bNewItems = false;
  621. for(itr = fieldList.begin(); itr != fieldList.end(); itr++)
  622. {
  623. if( itr->type == AbstractClassRep::StartGroupFieldType )
  624. {
  625. // If we're dealing with general fields, always set grabItems to true (to skip them)
  626. if( bNoGroup == true || ( itr->pGroupname != NULL && dStricmp( itr->pGroupname, mText ) == 0 ))
  627. bGrabItems = true;
  628. continue;
  629. }
  630. else if ( itr->type == AbstractClassRep::EndGroupFieldType )
  631. {
  632. // If we're dealing with general fields, always set grabItems to false (to grab them)
  633. if( bNoGroup == true || ( itr->pGroupname != NULL && dStricmp( itr->pGroupname, mText ) == 0 ))
  634. bGrabItems = false;
  635. continue;
  636. }
  637. if((bGrabItems == true || (bNoGroup == true && bGrabItems == false)) && itr->type != AbstractClassRep::DepricatedFieldType )
  638. {
  639. //We are inside a group and looking for items that don't have a group. Move on.
  640. if( bNoGroup == true && bGrabItems == true )
  641. continue;
  642. // We are going to check to see if this item is an array
  643. // if so, we're going to construct a field for each array element
  644. if( itr->elementCount > 1 )
  645. {
  646. for(S32 nI = 0; nI < itr->elementCount; nI++)
  647. {
  648. FrameTemp<char> intToStr( 64 );
  649. dSprintf( intToStr, 64, "%d", nI );
  650. const char *val = mTarget->getDataField( itr->pFieldname, intToStr );
  651. if (!val)
  652. val = StringTable->EmptyString;
  653. // Copy Val and construct proper ValueName[nI] format
  654. // which is "ValueName0" for index 0, etc.
  655. S32 frameTempSize = dStrlen( val ) + 32;
  656. FrameTemp<char> valCopy( frameTempSize );
  657. dSprintf( (char *)valCopy, frameTempSize, "%s%d", itr->pFieldname, nI );
  658. // If the field already exists, just update it
  659. GuiInspectorField *field = findField( valCopy );
  660. if( field != NULL )
  661. {
  662. field->updateValue( field->getData() );
  663. continue;
  664. }
  665. bNewItems = true;
  666. field = constructField( itr->type );
  667. if( field == NULL )
  668. {
  669. field = new GuiInspectorField( this, mTarget, itr );
  670. field->setExtent(Point2I(this->getExtent().x,30));
  671. field->setInspectorField( itr, intToStr );
  672. }
  673. else
  674. {
  675. field->setExtent(Point2I(this->getExtent().x, 30));
  676. field->setTarget( mTarget );
  677. field->setInspectorGroup( this );
  678. field->setInspectorField( itr, intToStr );
  679. }
  680. field->registerObject();
  681. mChildren.push_back( field );
  682. mGrid->addObject( field );
  683. }
  684. }
  685. else
  686. {
  687. // If the field already exists, just update it
  688. GuiInspectorField *field = findField( itr->pFieldname );
  689. if( field != NULL )
  690. {
  691. field->updateValue( field->getData() );
  692. continue;
  693. }
  694. bNewItems = true;
  695. //check the hidden field list
  696. if (mInspector->hideField(itr->pFieldname))
  697. {
  698. continue;
  699. }
  700. //Time to create a new field
  701. field = constructField( itr->type );
  702. if( field == NULL )
  703. field = new GuiInspectorField( this, mTarget, itr );
  704. else
  705. {
  706. field->setTarget( mTarget );
  707. field->setInspectorGroup( this );
  708. field->setInspectorField( itr );
  709. }
  710. field->setExtent(Point2I(this->getExtent().x, 30));
  711. field->registerObject();
  712. mChildren.push_back( field );
  713. mGrid->addObject( field );
  714. }
  715. }
  716. }
  717. // If we've no new items, there's no need to resize anything!
  718. if( bNewItems == false && !mChildren.empty() )
  719. return true;
  720. //sizeToContents();
  721. setUpdate();
  722. return true;
  723. }
  724. #pragma endregion
  725. #pragma region GuiInspectorDynamicGroup
  726. IMPLEMENT_CONOBJECT(GuiInspectorDynamicGroup);
  727. //////////////////////////////////////////////////////////////////////////
  728. // GuiInspectorDynamicGroup - add custom controls
  729. //////////////////////////////////////////////////////////////////////////
  730. bool GuiInspectorDynamicGroup::createContent()
  731. {
  732. if(!Parent::createContent())
  733. return false;
  734. // add a button that lets us add new dynamic fields.
  735. GuiButtonCtrl* addFieldBtn = new GuiButtonCtrl();
  736. {
  737. SimObject* profilePtr = Sim::findObject("EditorButton");
  738. if( profilePtr != NULL )
  739. addFieldBtn->setControlProfile( dynamic_cast<GuiControlProfile*>(profilePtr) );
  740. char commandBuf[64];
  741. dSprintf(commandBuf, 64, "%d.addDynamicField();", this->getId());
  742. addFieldBtn->setField("profile", "GuiButtonDynProfile");
  743. addFieldBtn->setField("command", commandBuf);
  744. addFieldBtn->setField("text", "+");
  745. addFieldBtn->setExtent(Point2I(30, 30));
  746. addFieldBtn->registerObject("zAddButton");
  747. }
  748. // encapsulate the button in a dummy control.
  749. GuiControl* shell = new GuiControl();
  750. shell->setField( "profile", "GuiTextProfile" );
  751. shell->registerObject();
  752. shell->setField("text", "Add Field");
  753. shell->setExtent(Point2I(getExtent().x - 30,30 + 10));
  754. addFieldBtn->setPosition(Point2I((shell->getExtent().x) - 30, 0));
  755. shell->addObject(addFieldBtn);
  756. // save off the shell control, so we can push it to the bottom of the stack in inspectGroup()
  757. mAddCtrl = shell;
  758. mGrid->addObject(shell);
  759. return true;
  760. }
  761. static S32 QSORT_CALLBACK compareEntries(const void* a,const void* b)
  762. {
  763. SimFieldDictionary::Entry *fa = *((SimFieldDictionary::Entry **)a);
  764. SimFieldDictionary::Entry *fb = *((SimFieldDictionary::Entry **)b);
  765. return dStricmp(fa->slotName, fb->slotName);
  766. }
  767. //////////////////////////////////////////////////////////////////////////
  768. // GuiInspectorDynamicGroup - inspectGroup override
  769. //////////////////////////////////////////////////////////////////////////
  770. bool GuiInspectorDynamicGroup::inspectGroup()
  771. {
  772. // We can't inspect a group without a target!
  773. if( !mTarget )
  774. return false;
  775. // Clearing the fields and recreating them will more than likely be more
  776. // efficient than looking up existent fields, updating them, and then iterating
  777. // over existent fields and making sure they still exist, if not, deleting them.
  778. clearFields();
  779. // Create a vector of the fields
  780. Vector<SimFieldDictionary::Entry *> flist;
  781. // Then populate with fields
  782. SimFieldDictionary * fieldDictionary = mTarget->getFieldDictionary();
  783. for(SimFieldDictionaryIterator ditr(fieldDictionary); *ditr; ++ditr)
  784. {
  785. flist.push_back(*ditr);
  786. }
  787. dQsort(flist.address(),flist.size(),sizeof(SimFieldDictionary::Entry *),compareEntries);
  788. for(U32 i = 0; i < (U32)flist.size(); i++)
  789. {
  790. SimFieldDictionary::Entry * entry = flist[i];
  791. GuiInspectorField *field = new GuiInspectorDynamicField( this, mTarget, entry );
  792. if( field != NULL )
  793. {
  794. field->setExtent(Point2I(this->getExtent().x, 30));
  795. field->registerObject();
  796. mChildren.push_back( field );
  797. mGrid->addObject( field );
  798. }
  799. }
  800. mGrid->pushObjectToBack(mAddCtrl);
  801. setUpdate();
  802. return true;
  803. }
  804. ConsoleMethod(GuiInspectorDynamicGroup, inspectGroup, bool, 2, 2, "() Refreshes the dynamic fields in the inspector.\n"
  805. "@return Returns true on success.")
  806. {
  807. return object->inspectGroup();
  808. }
  809. void GuiInspectorDynamicGroup::clearFields()
  810. {
  811. // save mAddCtrl
  812. Sim::getGuiGroup()->addObject(mAddCtrl);
  813. // delete everything else
  814. mGrid->clear();
  815. // clear the mChildren list.
  816. mChildren.clear();
  817. // and restore.
  818. mGrid->addObject(mAddCtrl);
  819. }
  820. SimFieldDictionary::Entry* GuiInspectorDynamicGroup::findDynamicFieldInDictionary( StringTableEntry fieldName )
  821. {
  822. if( !mTarget )
  823. return NULL;
  824. SimFieldDictionary * fieldDictionary = mTarget->getFieldDictionary();
  825. for(SimFieldDictionaryIterator ditr(fieldDictionary); *ditr; ++ditr)
  826. {
  827. SimFieldDictionary::Entry * entry = (*ditr);
  828. if( dStricmp( entry->slotName, fieldName ) == 0 )
  829. return entry;
  830. }
  831. return NULL;
  832. }
  833. void GuiInspectorDynamicGroup::addDynamicField()
  834. {
  835. // We can't add a field without a target
  836. if( !mTarget || !mGrid)
  837. {
  838. Con::warnf("GuiInspectorDynamicGroup::addDynamicField - no target SimObject to add a dynamic field to.");
  839. return;
  840. }
  841. // find a field name that is not in use.
  842. // But we wont try more than 100 times to find an available field.
  843. U32 uid = 1;
  844. char buf[64] = "dynamicField";
  845. SimFieldDictionary::Entry* entry = findDynamicFieldInDictionary(buf);
  846. while(entry != NULL && uid < 100)
  847. {
  848. dSprintf(buf, sizeof(buf), "dynamicField%03d", uid++);
  849. entry = findDynamicFieldInDictionary(buf);
  850. }
  851. //Con::evaluatef( "%d.%s = \"defaultValue\";", mTarget->getId(), buf );
  852. mTarget->setDataField(StringTable->insert(buf), NULL, "defaultValue");
  853. // now we simply re-inspect the object, to see the new field.
  854. this->inspectGroup();
  855. //animateToContents();
  856. }
  857. ConsoleMethod( GuiInspectorDynamicGroup, addDynamicField, void, 2, 2, "obj.addDynamicField();" )
  858. {
  859. object->addDynamicField();
  860. }
  861. #pragma endregion
  862. #pragma region GuiInspectorDynamicField
  863. //////////////////////////////////////////////////////////////////////////
  864. // GuiInspectorDynamicField - Child class of GuiInspectorField
  865. //////////////////////////////////////////////////////////////////////////
  866. IMPLEMENT_CONOBJECT(GuiInspectorDynamicField);
  867. GuiInspectorDynamicField::GuiInspectorDynamicField( GuiInspectorGroup* parent, SimObjectPtr<SimObject> target, SimFieldDictionary::Entry* field )
  868. {
  869. mGroup = parent;
  870. mTarget = target;
  871. mDynField = field;
  872. mRenameCtrl = NULL;
  873. }
  874. void GuiInspectorDynamicField::setData( const char* data )
  875. {
  876. if( mTarget == NULL || mDynField == NULL )
  877. return;
  878. char buf[1024];
  879. const char * newValue = mEdit->getScriptValue();
  880. dStrcpy( buf, newValue ? newValue : "" );
  881. collapseEscape(buf);
  882. mTarget->getFieldDictionary()->setFieldValue(mDynField->slotName, buf);
  883. // Force our edit to update
  884. updateValue( data );
  885. }
  886. const char* GuiInspectorDynamicField::getData()
  887. {
  888. if( mTarget == NULL || mDynField == NULL )
  889. return "";
  890. return mTarget->getFieldDictionary()->getFieldValue( mDynField->slotName );
  891. }
  892. void GuiInspectorDynamicField::renameField( StringTableEntry newFieldName )
  893. {
  894. if( mTarget == NULL || mDynField == NULL || mGroup == NULL || mEdit == NULL )
  895. {
  896. Con::warnf("GuiInspectorDynamicField::renameField - No target object or dynamic field data found!" );
  897. return;
  898. }
  899. if( !newFieldName )
  900. {
  901. Con::warnf("GuiInspectorDynamicField::renameField - Invalid field name specified!" );
  902. return;
  903. }
  904. // Only proceed if the name has changed
  905. if( dStricmp( newFieldName, getFieldName() ) == 0 )
  906. return;
  907. // Grab a pointer to our parent and cast it to GuiInspectorDynamicGroup
  908. GuiInspectorDynamicGroup *group = dynamic_cast<GuiInspectorDynamicGroup*>(mGroup);
  909. if( group == NULL )
  910. {
  911. Con::warnf("GuiInspectorDynamicField::renameField - Unable to locate GuiInspectorDynamicGroup parent!" );
  912. return;
  913. }
  914. // Grab our current dynamic field value
  915. const char* currentValue = getData();
  916. // Create our new field with the value of our old field and the new fields name!
  917. mTarget->setDataField( newFieldName, NULL, currentValue );
  918. // Configure our field to grab data from the new dynamic field
  919. SimFieldDictionary::Entry *newEntry = group->findDynamicFieldInDictionary( newFieldName );
  920. if( newEntry == NULL )
  921. {
  922. Con::warnf("GuiInspectorDynamicField::renameField - Unable to find new field!" );
  923. return;
  924. }
  925. // Set our old fields data to "" (which will effectively erase the field)
  926. mTarget->setDataField( getFieldName(), NULL, "" );
  927. // Assign our dynamic field pointer (where we retrieve field information from) to our new field pointer
  928. mDynField = newEntry;
  929. // Lastly we need to reassign our AltCommand fields for our value edit control
  930. char szBuffer[512];
  931. dSprintf( szBuffer, 512, "%d.%s = %d.getText();",mTarget->getId(), getFieldName(), mEdit->getId() );
  932. mEdit->setExtent(Point2I((getExtent().x / 2) - 20, 30));
  933. mEdit->setField("AltCommand", szBuffer );
  934. }
  935. ConsoleMethod( GuiInspectorDynamicField, renameField, void, 3,3, "field.renameField(newDynamicFieldName);" )
  936. {
  937. object->renameField( StringTable->insert(argv[2]) );
  938. }
  939. bool GuiInspectorDynamicField::onAdd()
  940. {
  941. if( !Parent::onAdd() )
  942. return false;
  943. mRenameCtrl = constructRenameControl();
  944. pushObjectToBack(mEdit);
  945. return true;
  946. }
  947. GuiControl* GuiInspectorDynamicField::constructRenameControl()
  948. {
  949. // Create our renaming field
  950. GuiControl* retCtrl = new GuiTextEditCtrl();
  951. // If we couldn't construct the control, bail!
  952. if( retCtrl == NULL )
  953. return retCtrl;
  954. // Let's make it look pretty.
  955. retCtrl->setField( "profile", "GuiTextEditProfile" );
  956. // Don't forget to register ourselves
  957. char szName[512];
  958. dSprintf( szName, 512, "IE_%s_%d_%s_Rename", retCtrl->getClassName(), mTarget->getId(), getFieldName() );
  959. retCtrl->registerObject( szName );
  960. // Our command will evaluate to :
  961. //
  962. // if( (editCtrl).getText() !$= "" )
  963. // (field).renameField((editCtrl).getText());
  964. //
  965. char szBuffer[512];
  966. dSprintf( szBuffer, 512, "if( %d.getText() !$= \"\" ) %d.renameField(%d.getText());",retCtrl->getId(), getId(), retCtrl->getId() );
  967. dynamic_cast<GuiTextEditCtrl*>(retCtrl)->setText( getFieldName() );
  968. retCtrl->setExtent(Point2I((getExtent().x / 2) - 20, 30));
  969. retCtrl->setField("AltCommand", szBuffer );
  970. addObject( retCtrl );
  971. // Finally, add a delete button for this field
  972. GuiButtonCtrl * delButt = new GuiButtonCtrl();
  973. if( delButt != NULL )
  974. {
  975. dSprintf(szBuffer, 512, "%d.%s = \"\";%d.inspectGroup();", mTarget->getId(), getFieldName(), mGroup->getId());
  976. delButt->setField("profile", "GuiButtonDynProfile");
  977. delButt->setField("Text", "X");
  978. delButt->setPosition(Point2I((getExtent().x - 40), 0));
  979. delButt->setField("extent", "30 30");
  980. delButt->setField("Command", szBuffer);
  981. delButt->registerObject();
  982. addObject(delButt);
  983. }
  984. return retCtrl;
  985. }
  986. void GuiInspectorDynamicField::resize( const Point2I &newPosition, const Point2I &newExtent )
  987. {
  988. Parent::resize( newPosition, newExtent );
  989. }
  990. #pragma endregion
  991. #pragma region GuiInspectorDatablockField
  992. //////////////////////////////////////////////////////////////////////////
  993. // GuiInspectorDatablockField
  994. // Field construction for datablock types
  995. //////////////////////////////////////////////////////////////////////////
  996. IMPLEMENT_CONOBJECT(GuiInspectorDatablockField);
  997. static S32 QSORT_CALLBACK stringCompare(const void *a,const void *b)
  998. {
  999. StringTableEntry sa = *(StringTableEntry*)a;
  1000. StringTableEntry sb = *(StringTableEntry*)b;
  1001. return(dStricmp(sb, sa));
  1002. }
  1003. GuiInspectorDatablockField::GuiInspectorDatablockField( StringTableEntry className )
  1004. {
  1005. setClassName(className);
  1006. };
  1007. void GuiInspectorDatablockField::setClassName( StringTableEntry className )
  1008. {
  1009. // Walk the ACR list and find a matching class if any.
  1010. AbstractClassRep *walk = AbstractClassRep::getClassList();
  1011. while(walk)
  1012. {
  1013. if(!dStricmp(walk->getClassName(), className))
  1014. {
  1015. // Match!
  1016. mDesiredClass = walk;
  1017. return;
  1018. }
  1019. walk = walk->getNextClass();
  1020. }
  1021. // No dice.
  1022. Con::warnf("GuiInspectorDatablockField::setClassName - no class '%s' found!", className);
  1023. return;
  1024. }
  1025. GuiControl* GuiInspectorDatablockField::constructEditControl()
  1026. {
  1027. GuiControl* retCtrl = new GuiDropDownCtrl();
  1028. // If we couldn't construct the control, bail!
  1029. if( retCtrl == NULL )
  1030. return retCtrl;
  1031. GuiDropDownCtrl *menu = dynamic_cast<GuiDropDownCtrl*>(retCtrl);
  1032. menu->setField("text", getData());
  1033. registerEditControl( retCtrl );
  1034. // Configure it to update our value when the dropdown is closed
  1035. char szBuffer[512];
  1036. dSprintf( szBuffer, 512, "%d.%s = %d.getText();%d.inspect(%d);",mTarget->getId(), mField->pFieldname, menu->getId(), mGroup->mInspector->getId(), mTarget->getId() );
  1037. menu->setField("Command", szBuffer );
  1038. Vector<StringTableEntry> entries;
  1039. SimDataBlockGroup * grp = Sim::getDataBlockGroup();
  1040. for(SimDataBlockGroup::iterator i = grp->begin(); i != grp->end(); i++)
  1041. {
  1042. SimDataBlock * datablock = dynamic_cast<SimDataBlock*>(*i);
  1043. // Skip non-datablocks if we somehow encounter them.
  1044. if(!datablock)
  1045. continue;
  1046. // Ok, now we have to figure inheritance info.
  1047. if( datablock && datablock->getClassRep()->isClass(mDesiredClass) )
  1048. entries.push_back(datablock->getName());
  1049. }
  1050. // sort the entries
  1051. dQsort(entries.address(), entries.size(), sizeof(StringTableEntry), stringCompare);
  1052. // add them to our enum
  1053. for(U32 j = 0; j < (U32)entries.size(); j++)
  1054. menu->getList()->addItem(entries[j]);
  1055. return retCtrl;
  1056. }
  1057. #pragma endregion