guiInspector.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 "console/engineAPI.h"
  23. #include "gui/editor/guiInspector.h"
  24. #include "gui/editor/inspector/field.h"
  25. #include "gui/editor/inspector/group.h"
  26. #include "gui/buttons/guiIconButtonCtrl.h"
  27. #include "gui/editor/inspector/dynamicGroup.h"
  28. #include "gui/containers/guiScrollCtrl.h"
  29. #include "gui/editor/inspector/customField.h"
  30. IMPLEMENT_CONOBJECT(GuiInspector);
  31. ConsoleDocClass( GuiInspector,
  32. "@brief A control that allows to edit the properties of one or more SimObjects.\n\n"
  33. "Editor use only.\n\n"
  34. "@internal"
  35. );
  36. //#define DEBUG_SPEW
  37. //-----------------------------------------------------------------------------
  38. GuiInspector::GuiInspector()
  39. : mDividerPos( 0.35f ),
  40. mDividerMargin( 5 ),
  41. mOverDivider( false ),
  42. mMovingDivider( false ),
  43. mHLField( NULL ),
  44. mShowCustomFields( true ),
  45. mComponentGroupTargetId(-1),
  46. mForcedArrayIndex(-1)
  47. {
  48. mPadding = 1;
  49. }
  50. //-----------------------------------------------------------------------------
  51. GuiInspector::~GuiInspector()
  52. {
  53. clearGroups();
  54. }
  55. //-----------------------------------------------------------------------------
  56. void GuiInspector::initPersistFields()
  57. {
  58. docsURL;
  59. addGroup( "Inspector" );
  60. addField( "dividerMargin", TypeS32, Offset( mDividerMargin, GuiInspector ) );
  61. addField( "groupFilters", TypeRealString, Offset( mGroupFilters, GuiInspector ),
  62. "Specify groups that should be shown or not. Specifying 'shown' implicitly does 'not show' all other groups. Example string: +name -otherName" );
  63. addField( "showCustomFields", TypeBool, Offset( mShowCustomFields, GuiInspector ),
  64. "If false the custom fields Name, Id, and Source Class will not be shown." );
  65. addField("forcedArrayIndex", TypeS32, Offset(mForcedArrayIndex, GuiInspector));
  66. endGroup( "Inspector" );
  67. Parent::initPersistFields();
  68. }
  69. //-----------------------------------------------------------------------------
  70. void GuiInspector::onRemove()
  71. {
  72. clearGroups();
  73. Parent::onRemove();
  74. }
  75. //-----------------------------------------------------------------------------
  76. void GuiInspector::onDeleteNotify( SimObject *object )
  77. {
  78. Parent::onDeleteNotify( object );
  79. if( isInspectingObject( object ) )
  80. removeInspectObject( object );
  81. }
  82. //-----------------------------------------------------------------------------
  83. void GuiInspector::parentResized(const RectI &oldParentRect, const RectI &newParentRect)
  84. {
  85. GuiControl *parent = getParent();
  86. if ( parent && dynamic_cast<GuiScrollCtrl*>(parent) != NULL )
  87. {
  88. GuiScrollCtrl *scroll = dynamic_cast<GuiScrollCtrl*>(parent);
  89. setWidth( ( newParentRect.extent.x - ( scroll->scrollBarThickness() + 4 ) ) );
  90. }
  91. else
  92. Parent::parentResized(oldParentRect,newParentRect);
  93. }
  94. //-----------------------------------------------------------------------------
  95. bool GuiInspector::resize( const Point2I &newPosition, const Point2I &newExtent )
  96. {
  97. //F32 dividerPerc = (F32)getWidth() / (F32)mDividerPos;
  98. bool result = Parent::resize( newPosition, newExtent );
  99. //mDividerPos = (F32)getWidth() * dividerPerc;
  100. updateDivider();
  101. return result;
  102. }
  103. //-----------------------------------------------------------------------------
  104. GuiControl* GuiInspector::findHitControl( const Point2I &pt, S32 initialLayer )
  105. {
  106. if ( mOverDivider || mMovingDivider )
  107. return this;
  108. return Parent::findHitControl( pt, initialLayer );
  109. }
  110. //-----------------------------------------------------------------------------
  111. void GuiInspector::getCursor( GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent )
  112. {
  113. GuiCanvas *pRoot = getRoot();
  114. if( !pRoot )
  115. return;
  116. S32 desiredCursor = mOverDivider ? PlatformCursorController::curResizeVert : PlatformCursorController::curArrow;
  117. // Bail if we're already at the desired cursor
  118. if ( pRoot->mCursorChanged == desiredCursor )
  119. return;
  120. PlatformWindow *pWindow = static_cast<GuiCanvas*>(getRoot())->getPlatformWindow();
  121. AssertFatal(pWindow != NULL,"GuiControl without owning platform window! This should not be possible.");
  122. PlatformCursorController *pController = pWindow->getCursorController();
  123. AssertFatal(pController != NULL,"PlatformWindow without an owned CursorController!");
  124. // Now change the cursor shape
  125. pController->popCursor();
  126. pController->pushCursor(desiredCursor);
  127. pRoot->mCursorChanged = desiredCursor;
  128. }
  129. //-----------------------------------------------------------------------------
  130. void GuiInspector::onMouseMove(const GuiEvent &event)
  131. {
  132. if ( collideDivider( globalToLocalCoord( event.mousePoint ) ) )
  133. mOverDivider = true;
  134. else
  135. mOverDivider = false;
  136. }
  137. //-----------------------------------------------------------------------------
  138. void GuiInspector::onMouseDown(const GuiEvent &event)
  139. {
  140. if ( mOverDivider )
  141. {
  142. mMovingDivider = true;
  143. }
  144. }
  145. //-----------------------------------------------------------------------------
  146. void GuiInspector::onMouseUp(const GuiEvent &event)
  147. {
  148. mMovingDivider = false;
  149. }
  150. //-----------------------------------------------------------------------------
  151. void GuiInspector::onMouseDragged(const GuiEvent &event)
  152. {
  153. if ( !mMovingDivider )
  154. return;
  155. Point2I localPnt = globalToLocalCoord( event.mousePoint );
  156. S32 inspectorWidth = getWidth();
  157. // Distance from mouse/divider position in local space
  158. // to the right edge of the inspector
  159. mDividerPos = inspectorWidth - localPnt.x;
  160. mDividerPos = mClamp( mDividerPos, 0, inspectorWidth );
  161. // Divide that by the inspectorWidth to get a percentage
  162. mDividerPos /= inspectorWidth;
  163. updateDivider();
  164. }
  165. //-----------------------------------------------------------------------------
  166. GuiInspectorGroup* GuiInspector::findExistentGroup( StringTableEntry groupName )
  167. {
  168. // If we have no groups, it couldn't possibly exist
  169. if( mGroups.empty() )
  170. return NULL;
  171. // Attempt to find it in the group list
  172. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  173. for( ; i != mGroups.end(); i++ )
  174. {
  175. if( dStricmp( (*i)->getGroupName(), groupName ) == 0 )
  176. return *i;
  177. }
  178. return NULL;
  179. }
  180. S32 GuiInspector::findExistentGroupIndex(StringTableEntry groupName)
  181. {
  182. // If we have no groups, it couldn't possibly exist
  183. if (mGroups.empty())
  184. return -1;
  185. // Attempt to find it in the group list
  186. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  187. S32 index = 0;
  188. for (; i != mGroups.end(); i++)
  189. {
  190. if (dStricmp((*i)->getGroupName(), groupName) == 0)
  191. return index;
  192. index++;
  193. }
  194. return -1;
  195. }
  196. //-----------------------------------------------------------------------------
  197. void GuiInspector::updateFieldValue( StringTableEntry fieldName, StringTableEntry arrayIdx )
  198. {
  199. // We don't know which group contains the field of this name,
  200. // so ask each group in turn, and break when a group returns true
  201. // signifying it contained and updated that field.
  202. Vector<GuiInspectorGroup*>::iterator groupIter = mGroups.begin();
  203. for( ; groupIter != mGroups.end(); groupIter++ )
  204. {
  205. if ( (*groupIter)->updateFieldValue( fieldName, arrayIdx ) )
  206. break;
  207. }
  208. }
  209. //-----------------------------------------------------------------------------
  210. void GuiInspector::clearGroups()
  211. {
  212. #ifdef DEBUG_SPEW
  213. Platform::outputDebugString( "[GuiInspector] Clearing %i (%s)", getId(), getName() );
  214. #endif
  215. // If we have no groups, there's nothing to clear!
  216. if( mGroups.empty() )
  217. return;
  218. mHLField = NULL;
  219. if( isMethod( "onClear" ) )
  220. Con::executef( this, "onClear" );
  221. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  222. freeze(true);
  223. // Delete Groups
  224. for( ; i != mGroups.end(); i++ )
  225. {
  226. if((*i) && (*i)->isProperlyAdded())
  227. (*i)->deleteObject();
  228. }
  229. mGroups.clear();
  230. freeze(false);
  231. updatePanes();
  232. }
  233. //-----------------------------------------------------------------------------
  234. bool GuiInspector::isInspectingObject( SimObject* object )
  235. {
  236. const U32 numTargets = mTargets.size();
  237. for( U32 i = 0; i < numTargets; ++ i )
  238. if( mTargets[ i ] == object )
  239. return true;
  240. return false;
  241. }
  242. //-----------------------------------------------------------------------------
  243. void GuiInspector::inspectObject( SimObject *object )
  244. {
  245. if( mTargets.size() > 1 || !isInspectingObject( object ) )
  246. clearInspectObjects();
  247. addInspectObject( object );
  248. }
  249. //-----------------------------------------------------------------------------
  250. void GuiInspector::clearInspectObjects()
  251. {
  252. const U32 numTargets = mTargets.size();
  253. for( U32 i = 0; i < numTargets; ++ i )
  254. clearNotify( mTargets[ i ] );
  255. clearGroups();
  256. mTargets.clear();
  257. }
  258. //-----------------------------------------------------------------------------
  259. void GuiInspector::addInspectObject( SimObject* object, bool autoSync )
  260. {
  261. // If we are already inspecting the object, just update the groups.
  262. if( isInspectingObject( object ) )
  263. {
  264. #ifdef DEBUG_SPEW
  265. Platform::outputDebugString( "[GuiInspector] Refreshing view of %i:%s (%s)",
  266. object->getId(), object->getClassName(), object->getName() );
  267. #endif
  268. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  269. for ( ; i != mGroups.end(); i++ )
  270. (*i)->updateAllFields();
  271. return;
  272. }
  273. #ifdef DEBUG_SPEW
  274. Platform::outputDebugString( "[GuiInspector] Adding %i:%s (%s) to inspect set",
  275. object->getId(), object->getClassName(), object->getName() );
  276. #endif
  277. // Give users a chance to customize fields on this object
  278. if( object->isMethod("onDefineFieldTypes") )
  279. Con::executef( object, "onDefineFieldTypes" );
  280. // Set Target
  281. mTargets.push_back( object );
  282. deleteNotify( object );
  283. if( autoSync )
  284. refresh();
  285. }
  286. //-----------------------------------------------------------------------------
  287. void GuiInspector::removeInspectObject( SimObject* object )
  288. {
  289. const U32 numTargets = mTargets.size();
  290. for( U32 i = 0; i < numTargets; ++ i )
  291. if( mTargets[ i ] == object )
  292. {
  293. // Delete all inspector data *before* removing the target so that apply calls
  294. // triggered by edit controls losing focus will not find the inspect object
  295. // gone.
  296. clearGroups();
  297. #ifdef DEBUG_SPEW
  298. Platform::outputDebugString( "[GuiInspector] Removing %i:%s (%s) from inspect set",
  299. object->getId(), object->getClassName(), object->getName() );
  300. #endif
  301. mTargets.erase( i );
  302. clearNotify( object );
  303. // Refresh the inspector except if the system is going down.
  304. if( !Sim::isShuttingDown() )
  305. refresh();
  306. return;
  307. }
  308. }
  309. //-----------------------------------------------------------------------------
  310. void GuiInspector::setName( StringTableEntry newName )
  311. {
  312. if( mTargets.size() != 1 )
  313. return;
  314. StringTableEntry name = StringTable->insert(newName);
  315. // Only assign a new name if we provide one
  316. mTargets[ 0 ]->assignName(name);
  317. }
  318. //-----------------------------------------------------------------------------
  319. bool GuiInspector::collideDivider( const Point2I &localPnt )
  320. {
  321. RectI divisorRect( getWidth() - getWidth() * mDividerPos - mDividerMargin, 0, mDividerMargin * 2, getHeight() );
  322. if ( divisorRect.pointInRect( localPnt ) )
  323. return true;
  324. return false;
  325. }
  326. //-----------------------------------------------------------------------------
  327. void GuiInspector::updateDivider()
  328. {
  329. for ( U32 i = 0; i < mGroups.size(); i++ )
  330. for ( U32 j = 0; j < mGroups[i]->mChildren.size(); j++ )
  331. mGroups[i]->mChildren[j]->updateRects();
  332. //setUpdate();
  333. }
  334. //-----------------------------------------------------------------------------
  335. void GuiInspector::getDivider( S32 &pos, S32 &margin )
  336. {
  337. pos = (F32)getWidth() * mDividerPos;
  338. margin = mDividerMargin;
  339. }
  340. //-----------------------------------------------------------------------------
  341. void GuiInspector::setHighlightField( GuiInspectorField *field )
  342. {
  343. if ( mHLField == field )
  344. return;
  345. if ( mHLField.isValid() )
  346. mHLField->setHLEnabled( false );
  347. mHLField = field;
  348. // We could have been passed a null field, meaning, set no field highlighted.
  349. if ( mHLField.isNull() )
  350. return;
  351. mHLField->setHLEnabled( true );
  352. }
  353. //-----------------------------------------------------------------------------
  354. bool GuiInspector::isGroupFiltered( const char *groupName ) const
  355. {
  356. // Internal and Ungrouped always filtered, we never show them.
  357. if ( dStricmp( groupName, "Internal" ) == 0 ||
  358. dStricmp( groupName, "Ungrouped" ) == 0 ||
  359. dStricmp( groupName, "AdvCoordManipulation" ) == 0)
  360. return true;
  361. // Normal case, determine if filtered by looking at the mGroupFilters string.
  362. String searchStr;
  363. // Is this group explicitly show? Does it immediately follow a + char.
  364. searchStr = String::ToString( "+%s", groupName );
  365. if ( mGroupFilters.find( searchStr ) != String::NPos )
  366. return false;
  367. // Were there any other + characters, if so, we are implicitly hidden.
  368. if ( mGroupFilters.find( "+" ) != String::NPos )
  369. return true;
  370. // Is this group explicitly hidden? Does it immediately follow a - char.
  371. searchStr = String::ToString( "-%s", groupName );
  372. if ( mGroupFilters.find( searchStr ) != String::NPos )
  373. return true;
  374. return false;
  375. }
  376. //-----------------------------------------------------------------------------
  377. bool GuiInspector::isGroupExplicitlyFiltered( const char *groupName ) const
  378. {
  379. String searchStr;
  380. searchStr = String::ToString( "-%s", groupName );
  381. if ( mGroupFilters.find( searchStr ) != String::NPos )
  382. return true;
  383. return false;
  384. }
  385. //-----------------------------------------------------------------------------
  386. void GuiInspector::setObjectField( const char *fieldName, const char *data )
  387. {
  388. GuiInspectorField *field;
  389. for ( S32 i = 0; i < mGroups.size(); i++ )
  390. {
  391. field = mGroups[i]->findField( fieldName );
  392. if( field )
  393. {
  394. field->setData( data );
  395. return;
  396. }
  397. }
  398. }
  399. //-----------------------------------------------------------------------------
  400. static SimObject *sgKeyObj = NULL;
  401. bool findInspectors( GuiInspector *obj )
  402. {
  403. if ( obj->isAwake() && obj->isInspectingObject( sgKeyObj ) )
  404. return true;
  405. return false;
  406. }
  407. //-----------------------------------------------------------------------------
  408. GuiInspector* GuiInspector::findByObject( SimObject *obj )
  409. {
  410. sgKeyObj = obj;
  411. Vector< GuiInspector* > found;
  412. Sim::getGuiGroup()->findObjectByCallback( findInspectors, found );
  413. if ( found.empty() )
  414. return NULL;
  415. return found.first();
  416. }
  417. //-----------------------------------------------------------------------------
  418. void GuiInspector::refresh()
  419. {
  420. clearGroups();
  421. // Remove any inspect object that happened to have
  422. // already been killed.
  423. for( U32 i = 0; i < mTargets.size(); ++ i )
  424. if( !mTargets[ i ] )
  425. {
  426. mTargets.erase( i );
  427. -- i;
  428. }
  429. if( !mTargets.size() )
  430. return;
  431. // Special group for fields which should appear at the top of the
  432. // list outside of a rollout control.
  433. GuiInspectorGroup *ungroup = NULL;
  434. if( mTargets.size() == 1 )
  435. {
  436. ungroup = new GuiInspectorGroup( "Ungrouped", this );
  437. ungroup->setHeaderHidden( true );
  438. ungroup->setCanCollapse( false );
  439. ungroup->registerObject();
  440. mGroups.push_back( ungroup );
  441. addObject( ungroup );
  442. }
  443. // Put the 'transform' group first
  444. GuiInspectorGroup *transform = new GuiInspectorGroup( "Transform", this );
  445. transform->registerObject();
  446. mGroups.push_back(transform);
  447. addObject(transform);
  448. // Always create the 'general' group (for fields without a group)
  449. GuiInspectorGroup *general = new GuiInspectorGroup( "General", this );
  450. general->registerObject();
  451. mGroups.push_back(general);
  452. addObject(general);
  453. // Create the inspector groups for static fields.
  454. for( TargetVector::iterator iter = mTargets.begin(); iter != mTargets.end(); ++ iter )
  455. {
  456. AbstractClassRep::FieldList &fieldList = ( *iter )->getModifiableFieldList();
  457. // Iterate through, identifying the groups and create necessary GuiInspectorGroups
  458. for( AbstractClassRep::FieldList::iterator itr = fieldList.begin(); itr != fieldList.end(); itr++ )
  459. {
  460. if ( itr->type == AbstractClassRep::StartGroupFieldType )
  461. {
  462. GuiInspectorGroup* group = findExistentGroup( itr->pGroupname );
  463. if( !group && !isGroupFiltered( itr->pGroupname ) )
  464. {
  465. GuiInspectorGroup *newGroup = new GuiInspectorGroup( itr->pGroupname, this );
  466. newGroup->setForcedArrayIndex(mForcedArrayIndex);
  467. newGroup->registerObject();
  468. if( !newGroup->getNumFields() )
  469. {
  470. #ifdef DEBUG_SPEW
  471. Platform::outputDebugString( "[GuiInspector] Removing empty group '%s'",
  472. newGroup->getCaption().c_str() );
  473. #endif
  474. // The group ended up having no fields. Remove it.
  475. newGroup->deleteObject();
  476. }
  477. else
  478. {
  479. mGroups.push_back(newGroup);
  480. addObject(newGroup);
  481. }
  482. }
  483. else if(group)
  484. {
  485. group->setForcedArrayIndex(mForcedArrayIndex);
  486. }
  487. }
  488. }
  489. }
  490. mTargets.first()->onInspect(this);
  491. // Deal with dynamic fields
  492. if ( !isGroupFiltered( "Dynamic Fields" ) )
  493. {
  494. GuiInspectorGroup *dynGroup = new GuiInspectorDynamicGroup( "Dynamic Fields", this);
  495. dynGroup->registerObject();
  496. mGroups.push_back( dynGroup );
  497. addObject( dynGroup );
  498. }
  499. if( mShowCustomFields && mTargets.size() == 1 )
  500. {
  501. SimObject* object = mTargets.first();
  502. // Add the SimObjectID field to the ungrouped group.
  503. GuiInspectorCustomField* field = new GuiInspectorCustomField();
  504. field->init( this, ungroup );
  505. if( field->registerObject() )
  506. {
  507. ungroup->mChildren.push_back( field );
  508. ungroup->mStack->addObject( field );
  509. static StringTableEntry sId = StringTable->insert( "id" );
  510. field->setCaption( sId );
  511. field->setData( object->getIdString() );
  512. field->setDoc( "SimObjectId of this object. [Read Only]" );
  513. }
  514. else
  515. delete field;
  516. // Add the Source Class field to the ungrouped group.
  517. field = new GuiInspectorCustomField();
  518. field->init( this, ungroup );
  519. if( field->registerObject() )
  520. {
  521. ungroup->mChildren.push_back( field );
  522. ungroup->mStack->addObject( field );
  523. StringTableEntry sSourceClass = StringTable->insert( "Source Class", true );
  524. field->setCaption( sSourceClass );
  525. field->setData( object->getClassName() );
  526. Namespace* ns = object->getClassRep()->getNameSpace();
  527. field->setToolTip( Con::getNamespaceList( ns ) );
  528. field->setDoc( "Native class of this object. [Read Only]" );
  529. }
  530. else
  531. delete field;
  532. }
  533. // If the general group is still empty at this point ( or filtered ), kill it.
  534. if ( isGroupFiltered( "General" ) || general->mStack->size() == 0 )
  535. {
  536. for(S32 i=0; i<mGroups.size(); i++)
  537. {
  538. if ( mGroups[i] == general )
  539. {
  540. mGroups.erase(i);
  541. general->deleteObject();
  542. updatePanes();
  543. break;
  544. }
  545. }
  546. }
  547. // If transform turns out to be empty or filtered, remove it
  548. if( isGroupFiltered( "Transform" ) || transform->mStack->size() == 0 )
  549. {
  550. for(S32 i=0; i<mGroups.size(); i++)
  551. {
  552. if ( mGroups[i] == transform )
  553. {
  554. mGroups.erase(i);
  555. transform->deleteObject();
  556. updatePanes();
  557. break;
  558. }
  559. }
  560. }
  561. // If ungrouped is empty or explicitly filtered, remove it.
  562. if( ungroup && ( isGroupExplicitlyFiltered( "Ungrouped" ) || ungroup->getNumFields() == 0 ) )
  563. {
  564. for(S32 i=0; i<mGroups.size(); i++)
  565. {
  566. if ( mGroups[i] == ungroup )
  567. {
  568. mGroups.erase(i);
  569. ungroup->deleteObject();
  570. updatePanes();
  571. break;
  572. }
  573. }
  574. }
  575. // If the object cannot be renamed, deactivate the name field if we have it.
  576. if( ungroup && getNumInspectObjects() == 1 && !getInspectObject()->isNameChangeAllowed() )
  577. {
  578. GuiInspectorField* nameField = ungroup->findField( "name" );
  579. if( nameField )
  580. nameField->setActive( false );
  581. }
  582. }
  583. //-----------------------------------------------------------------------------
  584. void GuiInspector::sendInspectPreApply()
  585. {
  586. const U32 numObjects = getNumInspectObjects();
  587. for( U32 i = 0; i < numObjects; ++ i )
  588. getInspectObject( i )->inspectPreApply();
  589. }
  590. //-----------------------------------------------------------------------------
  591. void GuiInspector::sendInspectPostApply()
  592. {
  593. const U32 numObjects = getNumInspectObjects();
  594. for( U32 i = 0; i < numObjects; ++ i )
  595. getInspectObject( i )->inspectPostApply();
  596. }
  597. S32 GuiInspector::createInspectorGroup(StringTableEntry groupName, S32 index)
  598. {
  599. GuiInspectorGroup* newGroup = nullptr;
  600. newGroup = findExistentGroup(groupName);
  601. if (newGroup)
  602. return newGroup->getId(); //if we already have a group under this name, just return it
  603. newGroup = new GuiInspectorGroup(groupName, this);
  604. newGroup->registerObject();
  605. if (index == -1)
  606. {
  607. //if index is -1, we just throw the group onto the stack at the end
  608. mGroups.push_back(newGroup);
  609. }
  610. else
  611. {
  612. //if we have an explicit index, insert it specifically
  613. mGroups.insert(index, newGroup);
  614. }
  615. addObject(newGroup);
  616. return newGroup->getId();
  617. }
  618. void GuiInspector::removeInspectorGroup(StringTableEntry groupName)
  619. {
  620. GuiInspectorGroup* group = findExistentGroup(groupName);
  621. if (group == nullptr)
  622. return;
  623. mGroups.remove(group);
  624. removeObject(group);
  625. }
  626. void GuiInspector::setForcedArrayIndex(S32 arrayIndex)
  627. {
  628. mForcedArrayIndex = arrayIndex;
  629. refresh();
  630. }
  631. //=============================================================================
  632. // Console Methods.
  633. //=============================================================================
  634. // MARK: ---- Console Methods ----
  635. //-----------------------------------------------------------------------------
  636. DefineEngineMethod( GuiInspector, inspect, void, (const char* simObject), (""),
  637. "Inspect the given object.\n"
  638. "@param simObject Object to inspect.")
  639. {
  640. SimObject * target = Sim::findObject(simObject);
  641. if(!target)
  642. {
  643. if(dAtoi(simObject) > 0)
  644. Con::warnf("%s::inspect(): invalid object: %s", object->getClassName(), simObject);
  645. object->clearInspectObjects();
  646. return;
  647. }
  648. object->inspectObject(target);
  649. }
  650. //-----------------------------------------------------------------------------
  651. DefineEngineMethod( GuiInspector, addInspect, void, (const char* simObject, bool autoSync), (true),
  652. "Add the object to the list of objects being inspected.\n"
  653. "@param simObject Object to add to the inspection."
  654. "@param autoSync Auto sync the values when they change.")
  655. {
  656. SimObject* obj;
  657. if( !Sim::findObject( simObject, obj ) )
  658. {
  659. Con::errorf( "%s::addInspect(): invalid object: %s", object->getClassName(), simObject );
  660. return;
  661. }
  662. object->addInspectObject( obj, autoSync );
  663. }
  664. //-----------------------------------------------------------------------------
  665. DefineEngineMethod( GuiInspector, removeInspect, void, (const char* simObject), ,
  666. "Remove the object from the list of objects being inspected.\n"
  667. "@param simObject Object to remove from the inspection.")
  668. {
  669. SimObject* obj;
  670. if( !Sim::findObject( simObject, obj ) )
  671. {
  672. Con::errorf( "%s::removeInspect(): invalid object: %s", object->getClassName(), simObject );
  673. return;
  674. }
  675. object->removeInspectObject( obj );
  676. }
  677. //-----------------------------------------------------------------------------
  678. DefineEngineMethod( GuiInspector, refresh, void, (), ,
  679. "Re-inspect the currently selected object.\n")
  680. {
  681. if ( object->getNumInspectObjects() == 0 )
  682. return;
  683. SimObject *target = object->getInspectObject();
  684. if ( target )
  685. object->inspectObject( target );
  686. }
  687. //-----------------------------------------------------------------------------
  688. DefineEngineMethod( GuiInspector, getInspectObject, const char*, (S32 index), (0),
  689. "Returns currently inspected object.\n"
  690. "@param index Index of object in inspection list you want to get."
  691. "@return object being inspected.")
  692. {
  693. if( index < 0 || index >= object->getNumInspectObjects() )
  694. {
  695. Con::errorf( "GuiInspector::getInspectObject() - index out of range: %i", index );
  696. return "";
  697. }
  698. return object->getInspectObject( index )->getIdString();
  699. }
  700. //-----------------------------------------------------------------------------
  701. DefineEngineMethod( GuiInspector, getNumInspectObjects, S32, (), ,
  702. "Return the number of objects currently being inspected.\n"
  703. "@return number of objects currently being inspected.")
  704. {
  705. return object->getNumInspectObjects();
  706. }
  707. //-----------------------------------------------------------------------------
  708. DefineEngineMethod( GuiInspector, setName, void, (const char* newObjectName), ,
  709. "Rename the object being inspected (first object in inspect list).\n"
  710. "@param newObjectName new name for object being inspected.")
  711. {
  712. object->setName(newObjectName);
  713. }
  714. //-----------------------------------------------------------------------------
  715. DefineEngineMethod( GuiInspector, apply, void, (), ,
  716. "Force application of inspected object's attributes.\n")
  717. {
  718. object->sendInspectPostApply();
  719. }
  720. //-----------------------------------------------------------------------------
  721. DefineEngineMethod( GuiInspector, setObjectField, void, (const char* fieldname, const char* data ), ,
  722. "Set a named fields value on the inspected object if it exists. This triggers all the usual callbacks that would occur if the field had been changed through the gui..\n"
  723. "@param fieldname Field name on object we are inspecting we want to change."
  724. "@param data New Value for the given field.")
  725. {
  726. object->setObjectField( fieldname, data );
  727. }
  728. //-----------------------------------------------------------------------------
  729. DefineEngineMethod( GuiInspector, findByObject, S32, (SimObject* obj), ,
  730. "Returns the id of an awake inspector that is inspecting the passed object if one exists\n"
  731. "@param object Object to find away inspector for."
  732. "@return id of an awake inspector that is inspecting the passed object if one exists, else NULL or 0.")
  733. {
  734. if ( !obj)
  735. return 0;
  736. SimObject *inspector = GuiInspector::findByObject(obj);
  737. if ( !inspector )
  738. return 0;
  739. return inspector->getId();
  740. }
  741. DefineEngineMethod(GuiInspector, createGroup, S32, (const char* groupName, S32 index), (-1),
  742. "Creates a new GuiInspectorGroup for this inspector and returns it's Id. If one already exists, then the Id of the existing one is returned.\n"
  743. "@param groupName Name of the new GuiInspectorGroup to add to this Inspector."
  744. "@param index(Optional) The index where to add the new group to in this Inspector's group stack."
  745. "@return id of the named GuiInspectorGroup")
  746. {
  747. return object->createInspectorGroup(StringTable->insert(groupName), index);
  748. }
  749. DefineEngineMethod(GuiInspector, findExistentGroup, S32, (const char* groupName), ,
  750. "Finds an existing GuiInspectorGroup if it exists and returns it's Id.\n"
  751. "@param groupName Name of the new GuiInspectorGroup to find in this Inspector."
  752. "@return id of the named GuiInspectorGroup")
  753. {
  754. GuiInspectorGroup* group = object->findExistentGroup(StringTable->insert(groupName));
  755. return group ? group->getId() : 0;
  756. }
  757. DefineEngineMethod(GuiInspector, removeGroup, void, (const char* groupName), ,
  758. "Finds an existing GuiInspectorGroup if it exists removes it.\n"
  759. "@param groupName Name of the new GuiInspectorGroup to find in this Inspector.")
  760. {
  761. object->removeInspectorGroup(StringTable->insert(groupName));
  762. }
  763. DefineEngineMethod(GuiInspector, setForcedArrayIndex, void, (S32 arrayIndex), (-1),
  764. "Sets the ForcedArrayIndex for the inspector. Used to force presentation of arrayed fields to only show a specific field index inside groups."
  765. "@param arrayIndex The specific field index for arrayed fields to show. Use -1 or blank arg to go back to normal behavior.")
  766. {
  767. object->setForcedArrayIndex(arrayIndex);
  768. }