guiInspector.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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. {
  47. mPadding = 1;
  48. }
  49. //-----------------------------------------------------------------------------
  50. GuiInspector::~GuiInspector()
  51. {
  52. clearGroups();
  53. }
  54. //-----------------------------------------------------------------------------
  55. void GuiInspector::initPersistFields()
  56. {
  57. docsURL;
  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. S32 GuiInspector::findExistentGroupIndex(StringTableEntry groupName)
  179. {
  180. // If we have no groups, it couldn't possibly exist
  181. if (mGroups.empty())
  182. return -1;
  183. // Attempt to find it in the group list
  184. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  185. S32 index = 0;
  186. for (; i != mGroups.end(); i++)
  187. {
  188. if (dStricmp((*i)->getGroupName(), groupName) == 0)
  189. return index;
  190. index++;
  191. }
  192. return -1;
  193. }
  194. //-----------------------------------------------------------------------------
  195. void GuiInspector::updateFieldValue( StringTableEntry fieldName, StringTableEntry arrayIdx )
  196. {
  197. // We don't know which group contains the field of this name,
  198. // so ask each group in turn, and break when a group returns true
  199. // signifying it contained and updated that field.
  200. Vector<GuiInspectorGroup*>::iterator groupIter = mGroups.begin();
  201. for( ; groupIter != mGroups.end(); groupIter++ )
  202. {
  203. if ( (*groupIter)->updateFieldValue( fieldName, arrayIdx ) )
  204. break;
  205. }
  206. }
  207. //-----------------------------------------------------------------------------
  208. void GuiInspector::clearGroups()
  209. {
  210. #ifdef DEBUG_SPEW
  211. Platform::outputDebugString( "[GuiInspector] Clearing %i (%s)", getId(), getName() );
  212. #endif
  213. // If we have no groups, there's nothing to clear!
  214. if( mGroups.empty() )
  215. return;
  216. mHLField = NULL;
  217. if( isMethod( "onClear" ) )
  218. Con::executef( this, "onClear" );
  219. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  220. freeze(true);
  221. // Delete Groups
  222. for( ; i != mGroups.end(); i++ )
  223. {
  224. if((*i) && (*i)->isProperlyAdded())
  225. (*i)->deleteObject();
  226. }
  227. mGroups.clear();
  228. freeze(false);
  229. updatePanes();
  230. }
  231. //-----------------------------------------------------------------------------
  232. bool GuiInspector::isInspectingObject( SimObject* object )
  233. {
  234. const U32 numTargets = mTargets.size();
  235. for( U32 i = 0; i < numTargets; ++ i )
  236. if( mTargets[ i ] == object )
  237. return true;
  238. return false;
  239. }
  240. //-----------------------------------------------------------------------------
  241. void GuiInspector::inspectObject( SimObject *object )
  242. {
  243. if( mTargets.size() > 1 || !isInspectingObject( object ) )
  244. clearInspectObjects();
  245. addInspectObject( object );
  246. }
  247. //-----------------------------------------------------------------------------
  248. void GuiInspector::clearInspectObjects()
  249. {
  250. const U32 numTargets = mTargets.size();
  251. for( U32 i = 0; i < numTargets; ++ i )
  252. clearNotify( mTargets[ i ] );
  253. clearGroups();
  254. mTargets.clear();
  255. }
  256. //-----------------------------------------------------------------------------
  257. void GuiInspector::addInspectObject( SimObject* object, bool autoSync )
  258. {
  259. // If we are already inspecting the object, just update the groups.
  260. if( isInspectingObject( object ) )
  261. {
  262. #ifdef DEBUG_SPEW
  263. Platform::outputDebugString( "[GuiInspector] Refreshing view of %i:%s (%s)",
  264. object->getId(), object->getClassName(), object->getName() );
  265. #endif
  266. Vector<GuiInspectorGroup*>::iterator i = mGroups.begin();
  267. for ( ; i != mGroups.end(); i++ )
  268. (*i)->updateAllFields();
  269. return;
  270. }
  271. #ifdef DEBUG_SPEW
  272. Platform::outputDebugString( "[GuiInspector] Adding %i:%s (%s) to inspect set",
  273. object->getId(), object->getClassName(), object->getName() );
  274. #endif
  275. // Give users a chance to customize fields on this object
  276. if( object->isMethod("onDefineFieldTypes") )
  277. Con::executef( object, "onDefineFieldTypes" );
  278. // Set Target
  279. mTargets.push_back( object );
  280. deleteNotify( object );
  281. if( autoSync )
  282. refresh();
  283. }
  284. //-----------------------------------------------------------------------------
  285. void GuiInspector::removeInspectObject( SimObject* object )
  286. {
  287. const U32 numTargets = mTargets.size();
  288. for( U32 i = 0; i < numTargets; ++ i )
  289. if( mTargets[ i ] == object )
  290. {
  291. // Delete all inspector data *before* removing the target so that apply calls
  292. // triggered by edit controls losing focus will not find the inspect object
  293. // gone.
  294. clearGroups();
  295. #ifdef DEBUG_SPEW
  296. Platform::outputDebugString( "[GuiInspector] Removing %i:%s (%s) from inspect set",
  297. object->getId(), object->getClassName(), object->getName() );
  298. #endif
  299. mTargets.erase( i );
  300. clearNotify( object );
  301. // Refresh the inspector except if the system is going down.
  302. if( !Sim::isShuttingDown() )
  303. refresh();
  304. return;
  305. }
  306. }
  307. //-----------------------------------------------------------------------------
  308. void GuiInspector::setName( StringTableEntry newName )
  309. {
  310. if( mTargets.size() != 1 )
  311. return;
  312. StringTableEntry name = StringTable->insert(newName);
  313. // Only assign a new name if we provide one
  314. mTargets[ 0 ]->assignName(name);
  315. }
  316. //-----------------------------------------------------------------------------
  317. bool GuiInspector::collideDivider( const Point2I &localPnt )
  318. {
  319. RectI divisorRect( getWidth() - getWidth() * mDividerPos - mDividerMargin, 0, mDividerMargin * 2, getHeight() );
  320. if ( divisorRect.pointInRect( localPnt ) )
  321. return true;
  322. return false;
  323. }
  324. //-----------------------------------------------------------------------------
  325. void GuiInspector::updateDivider()
  326. {
  327. for ( U32 i = 0; i < mGroups.size(); i++ )
  328. for ( U32 j = 0; j < mGroups[i]->mChildren.size(); j++ )
  329. mGroups[i]->mChildren[j]->updateRects();
  330. //setUpdate();
  331. }
  332. //-----------------------------------------------------------------------------
  333. void GuiInspector::getDivider( S32 &pos, S32 &margin )
  334. {
  335. pos = (F32)getWidth() * mDividerPos;
  336. margin = mDividerMargin;
  337. }
  338. //-----------------------------------------------------------------------------
  339. void GuiInspector::setHighlightField( GuiInspectorField *field )
  340. {
  341. if ( mHLField == field )
  342. return;
  343. if ( mHLField.isValid() )
  344. mHLField->setHLEnabled( false );
  345. mHLField = field;
  346. // We could have been passed a null field, meaning, set no field highlighted.
  347. if ( mHLField.isNull() )
  348. return;
  349. mHLField->setHLEnabled( true );
  350. }
  351. //-----------------------------------------------------------------------------
  352. bool GuiInspector::isGroupFiltered( const char *groupName ) const
  353. {
  354. // Internal and Ungrouped always filtered, we never show them.
  355. if ( dStricmp( groupName, "Internal" ) == 0 ||
  356. dStricmp( groupName, "Ungrouped" ) == 0 ||
  357. dStricmp( groupName, "AdvCoordManipulation" ) == 0)
  358. return true;
  359. // Normal case, determine if filtered by looking at the mGroupFilters string.
  360. String searchStr;
  361. // Is this group explicitly show? Does it immediately follow a + char.
  362. searchStr = String::ToString( "+%s", groupName );
  363. if ( mGroupFilters.find( searchStr ) != String::NPos )
  364. return false;
  365. // Were there any other + characters, if so, we are implicitly hidden.
  366. if ( mGroupFilters.find( "+" ) != String::NPos )
  367. return true;
  368. // Is this group explicitly hidden? Does it immediately follow a - char.
  369. searchStr = String::ToString( "-%s", groupName );
  370. if ( mGroupFilters.find( searchStr ) != String::NPos )
  371. return true;
  372. return false;
  373. }
  374. //-----------------------------------------------------------------------------
  375. bool GuiInspector::isGroupExplicitlyFiltered( const char *groupName ) const
  376. {
  377. String searchStr;
  378. searchStr = String::ToString( "-%s", groupName );
  379. if ( mGroupFilters.find( searchStr ) != String::NPos )
  380. return true;
  381. return false;
  382. }
  383. //-----------------------------------------------------------------------------
  384. void GuiInspector::setObjectField( const char *fieldName, const char *data )
  385. {
  386. GuiInspectorField *field;
  387. for ( S32 i = 0; i < mGroups.size(); i++ )
  388. {
  389. field = mGroups[i]->findField( fieldName );
  390. if( field )
  391. {
  392. field->setData( data );
  393. return;
  394. }
  395. }
  396. }
  397. //-----------------------------------------------------------------------------
  398. static SimObject *sgKeyObj = NULL;
  399. bool findInspectors( GuiInspector *obj )
  400. {
  401. if ( obj->isAwake() && obj->isInspectingObject( sgKeyObj ) )
  402. return true;
  403. return false;
  404. }
  405. //-----------------------------------------------------------------------------
  406. GuiInspector* GuiInspector::findByObject( SimObject *obj )
  407. {
  408. sgKeyObj = obj;
  409. Vector< GuiInspector* > found;
  410. Sim::getGuiGroup()->findObjectByCallback( findInspectors, found );
  411. if ( found.empty() )
  412. return NULL;
  413. return found.first();
  414. }
  415. //-----------------------------------------------------------------------------
  416. void GuiInspector::refresh()
  417. {
  418. clearGroups();
  419. // Remove any inspect object that happened to have
  420. // already been killed.
  421. for( U32 i = 0; i < mTargets.size(); ++ i )
  422. if( !mTargets[ i ] )
  423. {
  424. mTargets.erase( i );
  425. -- i;
  426. }
  427. if( !mTargets.size() )
  428. return;
  429. // Special group for fields which should appear at the top of the
  430. // list outside of a rollout control.
  431. GuiInspectorGroup *ungroup = NULL;
  432. if( mTargets.size() == 1 )
  433. {
  434. ungroup = new GuiInspectorGroup( "Ungrouped", this );
  435. ungroup->setHeaderHidden( true );
  436. ungroup->setCanCollapse( false );
  437. ungroup->registerObject();
  438. mGroups.push_back( ungroup );
  439. addObject( ungroup );
  440. }
  441. // Put the 'transform' group first
  442. GuiInspectorGroup *transform = new GuiInspectorGroup( "Transform", this );
  443. transform->registerObject();
  444. mGroups.push_back(transform);
  445. addObject(transform);
  446. // Always create the 'general' group (for fields without a group)
  447. GuiInspectorGroup *general = new GuiInspectorGroup( "General", this );
  448. general->registerObject();
  449. mGroups.push_back(general);
  450. addObject(general);
  451. // Create the inspector groups for static fields.
  452. for( TargetVector::iterator iter = mTargets.begin(); iter != mTargets.end(); ++ iter )
  453. {
  454. AbstractClassRep::FieldList &fieldList = ( *iter )->getModifiableFieldList();
  455. // Iterate through, identifying the groups and create necessary GuiInspectorGroups
  456. for( AbstractClassRep::FieldList::iterator itr = fieldList.begin(); itr != fieldList.end(); itr++ )
  457. {
  458. if ( itr->type == AbstractClassRep::StartGroupFieldType )
  459. {
  460. GuiInspectorGroup* group = findExistentGroup( itr->pGroupname );
  461. if( !group && !isGroupFiltered( itr->pGroupname ) )
  462. {
  463. GuiInspectorGroup *newGroup = new GuiInspectorGroup( itr->pGroupname, this );
  464. newGroup->registerObject();
  465. if( !newGroup->getNumFields() )
  466. {
  467. #ifdef DEBUG_SPEW
  468. Platform::outputDebugString( "[GuiInspector] Removing empty group '%s'",
  469. newGroup->getCaption().c_str() );
  470. #endif
  471. // The group ended up having no fields. Remove it.
  472. newGroup->deleteObject();
  473. }
  474. else
  475. {
  476. mGroups.push_back(newGroup);
  477. addObject(newGroup);
  478. }
  479. }
  480. }
  481. }
  482. }
  483. mTargets.first()->onInspect(this);
  484. // Deal with dynamic fields
  485. if ( !isGroupFiltered( "Dynamic Fields" ) )
  486. {
  487. GuiInspectorGroup *dynGroup = new GuiInspectorDynamicGroup( "Dynamic Fields", this);
  488. dynGroup->registerObject();
  489. mGroups.push_back( dynGroup );
  490. addObject( dynGroup );
  491. }
  492. if( mShowCustomFields && mTargets.size() == 1 )
  493. {
  494. SimObject* object = mTargets.first();
  495. // Add the SimObjectID field to the ungrouped group.
  496. GuiInspectorCustomField* field = new GuiInspectorCustomField();
  497. field->init( this, ungroup );
  498. if( field->registerObject() )
  499. {
  500. ungroup->mChildren.push_back( field );
  501. ungroup->mStack->addObject( field );
  502. static StringTableEntry sId = StringTable->insert( "id" );
  503. field->setCaption( sId );
  504. field->setData( object->getIdString() );
  505. field->setDoc( "SimObjectId of this object. [Read Only]" );
  506. }
  507. else
  508. delete field;
  509. // Add the Source Class field to the ungrouped group.
  510. field = new GuiInspectorCustomField();
  511. field->init( this, ungroup );
  512. if( field->registerObject() )
  513. {
  514. ungroup->mChildren.push_back( field );
  515. ungroup->mStack->addObject( field );
  516. StringTableEntry sSourceClass = StringTable->insert( "Source Class", true );
  517. field->setCaption( sSourceClass );
  518. field->setData( object->getClassName() );
  519. Namespace* ns = object->getClassRep()->getNameSpace();
  520. field->setToolTip( Con::getNamespaceList( ns ) );
  521. field->setDoc( "Native class of this object. [Read Only]" );
  522. }
  523. else
  524. delete field;
  525. }
  526. // If the general group is still empty at this point ( or filtered ), kill it.
  527. if ( isGroupFiltered( "General" ) || general->mStack->size() == 0 )
  528. {
  529. for(S32 i=0; i<mGroups.size(); i++)
  530. {
  531. if ( mGroups[i] == general )
  532. {
  533. mGroups.erase(i);
  534. general->deleteObject();
  535. updatePanes();
  536. break;
  537. }
  538. }
  539. }
  540. // If transform turns out to be empty or filtered, remove it
  541. if( isGroupFiltered( "Transform" ) || transform->mStack->size() == 0 )
  542. {
  543. for(S32 i=0; i<mGroups.size(); i++)
  544. {
  545. if ( mGroups[i] == transform )
  546. {
  547. mGroups.erase(i);
  548. transform->deleteObject();
  549. updatePanes();
  550. break;
  551. }
  552. }
  553. }
  554. // If ungrouped is empty or explicitly filtered, remove it.
  555. if( ungroup && ( isGroupExplicitlyFiltered( "Ungrouped" ) || ungroup->getNumFields() == 0 ) )
  556. {
  557. for(S32 i=0; i<mGroups.size(); i++)
  558. {
  559. if ( mGroups[i] == ungroup )
  560. {
  561. mGroups.erase(i);
  562. ungroup->deleteObject();
  563. updatePanes();
  564. break;
  565. }
  566. }
  567. }
  568. // If the object cannot be renamed, deactivate the name field if we have it.
  569. if( ungroup && getNumInspectObjects() == 1 && !getInspectObject()->isNameChangeAllowed() )
  570. {
  571. GuiInspectorField* nameField = ungroup->findField( "name" );
  572. if( nameField )
  573. nameField->setActive( false );
  574. }
  575. }
  576. //-----------------------------------------------------------------------------
  577. void GuiInspector::sendInspectPreApply()
  578. {
  579. const U32 numObjects = getNumInspectObjects();
  580. for( U32 i = 0; i < numObjects; ++ i )
  581. getInspectObject( i )->inspectPreApply();
  582. }
  583. //-----------------------------------------------------------------------------
  584. void GuiInspector::sendInspectPostApply()
  585. {
  586. const U32 numObjects = getNumInspectObjects();
  587. for( U32 i = 0; i < numObjects; ++ i )
  588. getInspectObject( i )->inspectPostApply();
  589. }
  590. //=============================================================================
  591. // Console Methods.
  592. //=============================================================================
  593. // MARK: ---- Console Methods ----
  594. //-----------------------------------------------------------------------------
  595. DefineEngineMethod( GuiInspector, inspect, void, (const char* simObject), (""),
  596. "Inspect the given object.\n"
  597. "@param simObject Object to inspect.")
  598. {
  599. SimObject * target = Sim::findObject(simObject);
  600. if(!target)
  601. {
  602. if(dAtoi(simObject) > 0)
  603. Con::warnf("%s::inspect(): invalid object: %s", object->getClassName(), simObject);
  604. object->clearInspectObjects();
  605. return;
  606. }
  607. object->inspectObject(target);
  608. }
  609. //-----------------------------------------------------------------------------
  610. DefineEngineMethod( GuiInspector, addInspect, void, (const char* simObject, bool autoSync), (true),
  611. "Add the object to the list of objects being inspected.\n"
  612. "@param simObject Object to add to the inspection."
  613. "@param autoSync Auto sync the values when they change.")
  614. {
  615. SimObject* obj;
  616. if( !Sim::findObject( simObject, obj ) )
  617. {
  618. Con::errorf( "%s::addInspect(): invalid object: %s", object->getClassName(), simObject );
  619. return;
  620. }
  621. object->addInspectObject( obj, autoSync );
  622. }
  623. //-----------------------------------------------------------------------------
  624. DefineEngineMethod( GuiInspector, removeInspect, void, (const char* simObject), ,
  625. "Remove the object from the list of objects being inspected.\n"
  626. "@param simObject Object to remove from the inspection.")
  627. {
  628. SimObject* obj;
  629. if( !Sim::findObject( simObject, obj ) )
  630. {
  631. Con::errorf( "%s::removeInspect(): invalid object: %s", object->getClassName(), simObject );
  632. return;
  633. }
  634. object->removeInspectObject( obj );
  635. }
  636. //-----------------------------------------------------------------------------
  637. DefineEngineMethod( GuiInspector, refresh, void, (), ,
  638. "Re-inspect the currently selected object.\n")
  639. {
  640. if ( object->getNumInspectObjects() == 0 )
  641. return;
  642. SimObject *target = object->getInspectObject();
  643. if ( target )
  644. object->inspectObject( target );
  645. }
  646. //-----------------------------------------------------------------------------
  647. DefineEngineMethod( GuiInspector, getInspectObject, const char*, (S32 index), (0),
  648. "Returns currently inspected object.\n"
  649. "@param index Index of object in inspection list you want to get."
  650. "@return object being inspected.")
  651. {
  652. if( index < 0 || index >= object->getNumInspectObjects() )
  653. {
  654. Con::errorf( "GuiInspector::getInspectObject() - index out of range: %i", index );
  655. return "";
  656. }
  657. return object->getInspectObject( index )->getIdString();
  658. }
  659. //-----------------------------------------------------------------------------
  660. DefineEngineMethod( GuiInspector, getNumInspectObjects, S32, (), ,
  661. "Return the number of objects currently being inspected.\n"
  662. "@return number of objects currently being inspected.")
  663. {
  664. return object->getNumInspectObjects();
  665. }
  666. //-----------------------------------------------------------------------------
  667. DefineEngineMethod( GuiInspector, setName, void, (const char* newObjectName), ,
  668. "Rename the object being inspected (first object in inspect list).\n"
  669. "@param newObjectName new name for object being inspected.")
  670. {
  671. object->setName(newObjectName);
  672. }
  673. //-----------------------------------------------------------------------------
  674. DefineEngineMethod( GuiInspector, apply, void, (), ,
  675. "Force application of inspected object's attributes.\n")
  676. {
  677. object->sendInspectPostApply();
  678. }
  679. //-----------------------------------------------------------------------------
  680. DefineEngineMethod( GuiInspector, setObjectField, void, (const char* fieldname, const char* data ), ,
  681. "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"
  682. "@param fieldname Field name on object we are inspecting we want to change."
  683. "@param data New Value for the given field.")
  684. {
  685. object->setObjectField( fieldname, data );
  686. }
  687. //-----------------------------------------------------------------------------
  688. DefineEngineMethod( GuiInspector, findByObject, S32, (SimObject* obj), ,
  689. "Returns the id of an awake inspector that is inspecting the passed object if one exists\n"
  690. "@param object Object to find away inspector for."
  691. "@return id of an awake inspector that is inspecting the passed object if one exists, else NULL or 0.")
  692. {
  693. if ( !obj)
  694. return 0;
  695. SimObject *inspector = GuiInspector::findByObject(obj);
  696. if ( !inspector )
  697. return 0;
  698. return inspector->getId();
  699. }