guiInspector.cpp 27 KB

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