guiInspector.cpp 27 KB

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