guiInspector.cpp 26 KB

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