guiInspector.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/engineAPI.h"
  23. #include "gui/editor/guiInspector.h"
  24. #include "gui/editor/inspector/field.h"
  25. #include "gui/editor/inspector/group.h"
  26. #include "gui/buttons/guiIconButtonCtrl.h"
  27. #include "gui/editor/inspector/dynamicGroup.h"
  28. #include "gui/containers/guiScrollCtrl.h"
  29. #include "gui/editor/inspector/customField.h"
  30. #include "gui/editor/inspector/entityGroup.h"
  31. #include "gui/editor/inspector/mountingGroup.h"
  32. #include "gui/editor/inspector/componentGroup.h"
  33. #include "T3D/components/component.h"
  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. //Entity inspector group
  438. if (mTargets.first()->getClassRep()->isSubclassOf("Entity"))
  439. {
  440. //Put the GameObject group before everything that'd be gameobject-effecting, for orginazational purposes
  441. GuiInspectorGroup *gameObject = new GuiInspectorGroup("GameObject", this);
  442. gameObject->registerObject();
  443. mGroups.push_back(gameObject);
  444. addObject(gameObject);
  445. GuiInspectorEntityGroup *components = new GuiInspectorEntityGroup("Components", this);
  446. if (components != NULL)
  447. {
  448. components->registerObject();
  449. mGroups.push_back(components);
  450. addObject(components);
  451. }
  452. Entity* selectedEntity = dynamic_cast<Entity*>(mTargets.first().getObject());
  453. U32 compCount = selectedEntity->getComponentCount();
  454. //Now, add the component groups
  455. for (U32 c = 0; c < compCount; ++c)
  456. {
  457. Component* comp = selectedEntity->getComponent(c);
  458. String compName;
  459. if (comp->getFriendlyName() != StringTable->EmptyString())
  460. compName = comp->getFriendlyName();
  461. else
  462. compName = comp->getComponentName();
  463. GuiInspectorGroup *compGroup = new GuiInspectorComponentGroup(compName, this, comp);
  464. if (compGroup != NULL)
  465. {
  466. compGroup->registerObject();
  467. mGroups.push_back(compGroup);
  468. addObject(compGroup);
  469. }
  470. }
  471. //Mounting group override
  472. GuiInspectorGroup *mounting = new GuiInspectorMountingGroup("Mounting", this);
  473. if (mounting != NULL)
  474. {
  475. mounting->registerObject();
  476. mGroups.push_back(mounting);
  477. addObject(mounting);
  478. }
  479. }
  480. // Create the inspector groups for static fields.
  481. for( TargetVector::iterator iter = mTargets.begin(); iter != mTargets.end(); ++ iter )
  482. {
  483. AbstractClassRep::FieldList &fieldList = ( *iter )->getModifiableFieldList();
  484. // Iterate through, identifying the groups and create necessary GuiInspectorGroups
  485. for( AbstractClassRep::FieldList::iterator itr = fieldList.begin(); itr != fieldList.end(); itr++ )
  486. {
  487. if ( itr->type == AbstractClassRep::StartGroupFieldType )
  488. {
  489. GuiInspectorGroup* group = findExistentGroup( itr->pGroupname );
  490. if( !group && !isGroupFiltered( itr->pGroupname ) )
  491. {
  492. GuiInspectorGroup *group = new GuiInspectorGroup( itr->pGroupname, this );
  493. group->registerObject();
  494. if( !group->getNumFields() )
  495. {
  496. #ifdef DEBUG_SPEW
  497. Platform::outputDebugString( "[GuiInspector] Removing empty group '%s'",
  498. group->getCaption().c_str() );
  499. #endif
  500. // The group ended up having no fields. Remove it.
  501. group->deleteObject();
  502. }
  503. else
  504. {
  505. mGroups.push_back( group );
  506. addObject( group );
  507. }
  508. }
  509. }
  510. }
  511. }
  512. // Deal with dynamic fields
  513. if ( !isGroupFiltered( "Dynamic Fields" ) )
  514. {
  515. GuiInspectorGroup *dynGroup = new GuiInspectorDynamicGroup( "Dynamic Fields", this);
  516. dynGroup->registerObject();
  517. mGroups.push_back( dynGroup );
  518. addObject( dynGroup );
  519. }
  520. if( mShowCustomFields && mTargets.size() == 1 )
  521. {
  522. SimObject* object = mTargets.first();
  523. // Add the SimObjectID field to the ungrouped group.
  524. GuiInspectorCustomField* field = new GuiInspectorCustomField();
  525. field->init( this, ungroup );
  526. if( field->registerObject() )
  527. {
  528. ungroup->mChildren.push_back( field );
  529. ungroup->mStack->addObject( field );
  530. static StringTableEntry sId = StringTable->insert( "id" );
  531. field->setCaption( sId );
  532. field->setData( object->getIdString() );
  533. field->setDoc( "SimObjectId of this object. [Read Only]" );
  534. }
  535. else
  536. delete field;
  537. // Add the Source Class field to the ungrouped group.
  538. field = new GuiInspectorCustomField();
  539. field->init( this, ungroup );
  540. if( field->registerObject() )
  541. {
  542. ungroup->mChildren.push_back( field );
  543. ungroup->mStack->addObject( field );
  544. StringTableEntry sSourceClass = StringTable->insert( "Source Class", true );
  545. field->setCaption( sSourceClass );
  546. field->setData( object->getClassName() );
  547. Namespace* ns = object->getClassRep()->getNameSpace();
  548. field->setToolTip( Con::getNamespaceList( ns ) );
  549. field->setDoc( "Native class of this object. [Read Only]" );
  550. }
  551. else
  552. delete field;
  553. }
  554. // If the general group is still empty at this point ( or filtered ), kill it.
  555. if ( isGroupFiltered( "General" ) || general->mStack->size() == 0 )
  556. {
  557. for(S32 i=0; i<mGroups.size(); i++)
  558. {
  559. if ( mGroups[i] == general )
  560. {
  561. mGroups.erase(i);
  562. general->deleteObject();
  563. updatePanes();
  564. break;
  565. }
  566. }
  567. }
  568. // If transform turns out to be empty or filtered, remove it
  569. if( isGroupFiltered( "Transform" ) || transform->mStack->size() == 0 )
  570. {
  571. for(S32 i=0; i<mGroups.size(); i++)
  572. {
  573. if ( mGroups[i] == transform )
  574. {
  575. mGroups.erase(i);
  576. transform->deleteObject();
  577. updatePanes();
  578. break;
  579. }
  580. }
  581. }
  582. // If ungrouped is empty or explicitly filtered, remove it.
  583. if( ungroup && ( isGroupExplicitlyFiltered( "Ungrouped" ) || ungroup->getNumFields() == 0 ) )
  584. {
  585. for(S32 i=0; i<mGroups.size(); i++)
  586. {
  587. if ( mGroups[i] == ungroup )
  588. {
  589. mGroups.erase(i);
  590. ungroup->deleteObject();
  591. updatePanes();
  592. break;
  593. }
  594. }
  595. }
  596. // If the object cannot be renamed, deactivate the name field if we have it.
  597. if( ungroup && getNumInspectObjects() == 1 && !getInspectObject()->isNameChangeAllowed() )
  598. {
  599. GuiInspectorField* nameField = ungroup->findField( "name" );
  600. if( nameField )
  601. nameField->setActive( false );
  602. }
  603. }
  604. //-----------------------------------------------------------------------------
  605. void GuiInspector::sendInspectPreApply()
  606. {
  607. const U32 numObjects = getNumInspectObjects();
  608. for( U32 i = 0; i < numObjects; ++ i )
  609. getInspectObject( i )->inspectPreApply();
  610. }
  611. //-----------------------------------------------------------------------------
  612. void GuiInspector::sendInspectPostApply()
  613. {
  614. const U32 numObjects = getNumInspectObjects();
  615. for( U32 i = 0; i < numObjects; ++ i )
  616. getInspectObject( i )->inspectPostApply();
  617. }
  618. //=============================================================================
  619. // Console Methods.
  620. //=============================================================================
  621. // MARK: ---- Console Methods ----
  622. //-----------------------------------------------------------------------------
  623. DefineEngineMethod( GuiInspector, inspect, void, (const char* simObject), (""),
  624. "Inspect the given object.\n"
  625. "@param simObject Object to inspect.")
  626. {
  627. SimObject * target = Sim::findObject(simObject);
  628. if(!target)
  629. {
  630. if(dAtoi(simObject) > 0)
  631. Con::warnf("%s::inspect(): invalid object: %s", object->getClassName(), simObject);
  632. object->clearInspectObjects();
  633. return;
  634. }
  635. object->inspectObject(target);
  636. }
  637. //-----------------------------------------------------------------------------
  638. DefineEngineMethod( GuiInspector, addInspect, void, (const char* simObject, bool autoSync), (true),
  639. "Add the object to the list of objects being inspected.\n"
  640. "@param simObject Object to add to the inspection."
  641. "@param autoSync Auto sync the values when they change.")
  642. {
  643. SimObject* obj;
  644. if( !Sim::findObject( simObject, obj ) )
  645. {
  646. Con::errorf( "%s::addInspect(): invalid object: %s", object->getClassName(), simObject );
  647. return;
  648. }
  649. object->addInspectObject( obj, autoSync );
  650. }
  651. //-----------------------------------------------------------------------------
  652. DefineEngineMethod( GuiInspector, removeInspect, void, (const char* simObject), ,
  653. "Remove the object from the list of objects being inspected.\n"
  654. "@param simObject Object to remove from the inspection.")
  655. {
  656. SimObject* obj;
  657. if( !Sim::findObject( simObject, obj ) )
  658. {
  659. Con::errorf( "%s::removeInspect(): invalid object: %s", object->getClassName(), simObject );
  660. return;
  661. }
  662. object->removeInspectObject( obj );
  663. }
  664. //-----------------------------------------------------------------------------
  665. DefineEngineMethod( GuiInspector, refresh, void, (), ,
  666. "Re-inspect the currently selected object.\n")
  667. {
  668. if ( object->getNumInspectObjects() == 0 )
  669. return;
  670. SimObject *target = object->getInspectObject();
  671. if ( target )
  672. object->inspectObject( target );
  673. }
  674. //-----------------------------------------------------------------------------
  675. DefineEngineMethod( GuiInspector, getInspectObject, const char*, (S32 index), (0),
  676. "Returns currently inspected object.\n"
  677. "@param index Index of object in inspection list you want to get."
  678. "@return object being inspected.")
  679. {
  680. if( index < 0 || index >= object->getNumInspectObjects() )
  681. {
  682. Con::errorf( "GuiInspector::getInspectObject() - index out of range: %i", index );
  683. return "";
  684. }
  685. return object->getInspectObject( index )->getIdString();
  686. }
  687. //-----------------------------------------------------------------------------
  688. DefineEngineMethod( GuiInspector, getNumInspectObjects, S32, (), ,
  689. "Return the number of objects currently being inspected.\n"
  690. "@return number of objects currently being inspected.")
  691. {
  692. return object->getNumInspectObjects();
  693. }
  694. //-----------------------------------------------------------------------------
  695. DefineEngineMethod( GuiInspector, setName, void, (const char* newObjectName), ,
  696. "Rename the object being inspected (first object in inspect list).\n"
  697. "@param newObjectName new name for object being inspected.")
  698. {
  699. object->setName(newObjectName);
  700. }
  701. //-----------------------------------------------------------------------------
  702. DefineEngineMethod( GuiInspector, apply, void, (), ,
  703. "Force application of inspected object's attributes.\n")
  704. {
  705. object->sendInspectPostApply();
  706. }
  707. //-----------------------------------------------------------------------------
  708. DefineEngineMethod( GuiInspector, setObjectField, void, (const char* fieldname, const char* data ), ,
  709. "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"
  710. "@param fieldname Field name on object we are inspecting we want to change."
  711. "@param data New Value for the given field.")
  712. {
  713. object->setObjectField( fieldname, data );
  714. }
  715. //-----------------------------------------------------------------------------
  716. DefineEngineMethod( GuiInspector, findByObject, S32, (SimObject* obj), ,
  717. "Returns the id of an awake inspector that is inspecting the passed object if one exists\n"
  718. "@param object Object to find away inspector for."
  719. "@return id of an awake inspector that is inspecting the passed object if one exists, else NULL or 0.")
  720. {
  721. if ( !obj)
  722. return NULL;
  723. SimObject *inspector = GuiInspector::findByObject(obj);
  724. if ( !inspector )
  725. return NULL;
  726. return inspector->getId();
  727. }