datablockEditor.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  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. // Main code for the Datablock Editor plugin.
  23. $DATABLOCK_EDITOR_DEFAULT_FILENAME = "art/datablocks/managedDatablocks.cs";
  24. //=============================================================================================
  25. // Initialization.
  26. //=============================================================================================
  27. //---------------------------------------------------------------------------------------------
  28. function DatablockEditorPlugin::init( %this )
  29. {
  30. if( !DatablockEditorTree.getItemCount() )
  31. %this.populateTrees();
  32. }
  33. //---------------------------------------------------------------------------------------------
  34. function DatablockEditorPlugin::onWorldEditorStartup( %this )
  35. {
  36. // Add ourselves to the window menu.
  37. %accel = EditorGui.addToEditorsMenu( "Datablock Editor", "", DatablockEditorPlugin );
  38. // Add ourselves to the ToolsToolbar
  39. %tooltip = "Datablock Editor (" @ %accel @ ")";
  40. EditorGui.addToToolsToolbar( "DatablockEditorPlugin", "DatablockEditorPalette", expandFilename("tools/worldEditor/images/toolbar/datablock-editor"), %tooltip );
  41. //connect editor windows
  42. GuiWindowCtrl::Attach( DatablockEditorInspectorWindow, DatablockEditorTreeWindow);
  43. }
  44. //---------------------------------------------------------------------------------------------
  45. function DatablockEditorPlugin::onActivated( %this )
  46. {
  47. EditorGui-->WorldEditorToolbar.setVisible(false);
  48. EditorGui.bringToFront( DatablockEditorPlugin );
  49. DatablockEditorTreeWindow.setVisible( true );
  50. DatablockEditorInspectorWindow.setVisible( true );
  51. DatablockEditorInspectorWindow.makeFirstResponder( true );
  52. %this.map.push();
  53. // Set the status bar here until all tool have been hooked up
  54. EditorGuiStatusBar.setInfo( "Datablock editor." );
  55. %numSelected = %this.getNumSelectedDatablocks();
  56. if( !%numSelected )
  57. EditorGuiStatusBar.setSelection( "" );
  58. else
  59. EditorGuiStatusBar.setSelection( %numSelected @ " datablocks selected" );
  60. %this.init();
  61. DatablockEditorPlugin.readSettings();
  62. if( EWorldEditor.getSelectionSize() == 1 )
  63. %this.onObjectSelected( EWorldEditor.getSelectedObject( 0 ) );
  64. Parent::onActivated( %this );
  65. }
  66. //---------------------------------------------------------------------------------------------
  67. function DatablockEditorPlugin::onDeactivated( %this )
  68. {
  69. DatablockEditorPlugin.writeSettings();
  70. DatablockEditorInspectorWindow.setVisible( false );
  71. DatablockEditorTreeWindow.setVisible( false );
  72. %this.map.pop();
  73. Parent::onDeactivated(%this);
  74. }
  75. //---------------------------------------------------------------------------------------------
  76. function DatablockEditorPlugin::onExitMission( %this )
  77. {
  78. DatablockEditorTree.clear();
  79. DatablockEditorInspector.inspect( "" );
  80. }
  81. //---------------------------------------------------------------------------------------------
  82. function DatablockEditorPlugin::openDatablock( %this, %datablock )
  83. {
  84. EditorGui.setEditor( DatablockEditorPlugin );
  85. %this.selectDatablock( %datablock );
  86. DatablockEditorTreeTabBook.selectedPage = 0;
  87. }
  88. //---------------------------------------------------------------------------------------------
  89. function DatablockEditorPlugin::setEditorFunction( %this )
  90. {
  91. return true;
  92. }
  93. //---------------------------------------------------------------------------------------------
  94. function DatablockEditorPlugin::onObjectSelected( %this, %object )
  95. {
  96. // Select datablock of object if this is a GameBase object.
  97. if( %object.isMemberOfClass( "GameBase" ) )
  98. %this.selectDatablock( %object.getDatablock() );
  99. else if( %object.isMemberOfClass( "SFXEmitter" ) && isObject( %object.track ) )
  100. %this.selectDatablock( %object.track );
  101. else if( %object.isMemberOfClass( "LightBase" ) && isObject( %object.animationType ) )
  102. %this.selectDatablock( %object.animationType );
  103. }
  104. //---------------------------------------------------------------------------------------------
  105. function DatablockEditorPlugin::populateTrees(%this)
  106. {
  107. // Populate datablock tree.
  108. if( %this.excludeClientOnlyDatablocks )
  109. %set = DataBlockGroup;
  110. else
  111. %set = DataBlockSet;
  112. DatablockEditorTree.clear();
  113. foreach( %datablock in %set )
  114. {
  115. %unlistedFound = false;
  116. %id = %datablock.getId();
  117. foreach( %obj in UnlistedDatablocks )
  118. if( %obj.getId() == %id )
  119. {
  120. %unlistedFound = true;
  121. break;
  122. }
  123. if( %unlistedFound )
  124. continue;
  125. %this.addExistingItem( %datablock, true );
  126. }
  127. DatablockEditorTree.sort( 0, true, false, false );
  128. // Populate datablock type tree.
  129. %classList = enumerateConsoleClasses( "SimDatablock" );
  130. DatablockEditorTypeTree.clear();
  131. foreach$( %datablockClass in %classList )
  132. {
  133. if( !%this.isExcludedDatablockType( %datablockClass )
  134. && DatablockEditorTypeTree.findItemByName( %datablockClass ) == 0 )
  135. DatablockEditorTypeTree.insertItem( 0, %datablockClass );
  136. }
  137. DatablockEditorTypeTree.sort( 0, false, false, false );
  138. }
  139. //---------------------------------------------------------------------------------------------
  140. function DatablockEditorPlugin::addExistingItem( %this, %datablock, %dontSort )
  141. {
  142. %tree = DatablockEditorTree;
  143. // Look up class at root level. Create if needed.
  144. %class = %datablock.getClassName();
  145. %parentID = %tree.findItemByName( %class );
  146. if( %parentID == 0 )
  147. %parentID = %tree.insertItem( 0, %class );
  148. // If the datablock is already there, don't
  149. // do anything.
  150. if( %tree.findItemByValue( %datablock.getId() ) )
  151. return;
  152. // It doesn't exist so add it.
  153. %name = %datablock.getName();
  154. if( %this.PM.isDirty( %datablock ) )
  155. %name = %name @ " *";
  156. %id = DatablockEditorTree.insertItem( %parentID, %name, %datablock.getId() );
  157. if( !%dontSort )
  158. DatablockEditorTree.sort( %parentID, false, false, false );
  159. return %id;
  160. }
  161. //---------------------------------------------------------------------------------------------
  162. function DatablockEditorPlugin::isExcludedDatablockType( %this, %className )
  163. {
  164. switch$( %className )
  165. {
  166. case "SimDatablock":
  167. return true;
  168. case "SFXTrack": // Abstract.
  169. return true;
  170. case "SFXFMODEvent": // Internally created.
  171. return true;
  172. case "SFXFMODEventGroup": // Internally created.
  173. return true;
  174. }
  175. return false;
  176. }
  177. //=============================================================================================
  178. // Settings.
  179. //=============================================================================================
  180. //---------------------------------------------------------------------------------------------
  181. function DatablockEditorPlugin::initSettings( %this )
  182. {
  183. EditorSettings.beginGroup("DatablockEditor", true);
  184. EditorSettings.setDefaultValue("libraryTab", "0");
  185. EditorSettings.endGroup();
  186. }
  187. //---------------------------------------------------------------------------------------------
  188. function DatablockEditorPlugin::readSettings( %this )
  189. {
  190. EditorSettings.beginGroup("DatablockEditor", true);
  191. DatablockEditorTreeTabBook.selectPage( EditorSettings.value( "libraryTab" ) );
  192. %db = EditorSettings.value( "selectedDatablock" );
  193. if( isObject( %db ) && %db.isMemberOfClass( "SimDatablock" ) )
  194. %this.selectDatablock( %db );
  195. EditorSettings.endGroup();
  196. }
  197. //---------------------------------------------------------------------------------------------
  198. function DatablockEditorPlugin::writeSettings( %this )
  199. {
  200. EditorSettings.beginGroup( "DatablockEditor", true );
  201. EditorSettings.setValue( "libraryTab", DatablockEditorTreeTabBook.getSelectedPage() );
  202. if( %this.getNumSelectedDatablocks() > 0 )
  203. EditorSettings.setValue( "selectedDatablock", %this.getSelectedDatablock().getName() );
  204. EditorSettings.endGroup();
  205. }
  206. //=============================================================================================
  207. // Persistence.
  208. //=============================================================================================
  209. //---------------------------------------------------------------------------------------------
  210. /// Return true if there is any datablock with unsaved changes.
  211. function DatablockEditorPlugin::isDirty( %this )
  212. {
  213. return %this.PM.hasDirty();
  214. }
  215. //---------------------------------------------------------------------------------------------
  216. /// Return true if any of the currently selected datablocks has unsaved changes.
  217. function DatablockEditorPlugin::selectedDatablockIsDirty( %this )
  218. {
  219. %tree = DatablockEditorTree;
  220. %count = %tree.getSelectedItemsCount();
  221. %selected = %tree.getSelectedItemList();
  222. foreach$( %id in %selected )
  223. {
  224. %db = %tree.getItemValue( %id );
  225. if( %this.PM.isDirty( %db ) )
  226. return true;
  227. }
  228. return false;
  229. }
  230. //---------------------------------------------------------------------------------------------
  231. function DatablockEditorPlugin::syncDirtyState( %this )
  232. {
  233. %tree = DatablockEditorTree;
  234. %count = %tree.getSelectedItemsCount();
  235. %selected = %tree.getSelectedItemList();
  236. %haveDirty = false;
  237. foreach$( %id in %selected )
  238. {
  239. %db = %tree.getItemValue( %id );
  240. if( %this.PM.isDirty( %db ) )
  241. {
  242. %this.flagDatablockAsDirty( %db, true );
  243. %haveDirty = true;
  244. }
  245. else
  246. %this.flagInspectorAsDirty( %db, false );
  247. }
  248. %this.flagInspectorAsDirty( %haveDirty );
  249. }
  250. //---------------------------------------------------------------------------------------------
  251. ///
  252. function DatablockEditorPlugin::flagInspectorAsDirty( %this, %dirty )
  253. {
  254. if( %dirty )
  255. DatablockEditorInspectorWindow.text = "Datablock *";
  256. else
  257. DatablockEditorInspectorWindow.text = "Datablock";
  258. }
  259. //---------------------------------------------------------------------------------------------
  260. function DatablockEditorPlugin::flagDatablockAsDirty(%this, %datablock, %dirty )
  261. {
  262. %tree = DatablockEditorTree;
  263. %id = %tree.findItemByValue( %datablock.getId() );
  264. if( %id == 0 )
  265. return;
  266. // Tag the item caption and sync the persistence manager.
  267. if( %dirty )
  268. {
  269. DatablockEditorTree.editItem( %id, %datablock.getName() @ " *", %datablock.getId() );
  270. %this.PM.setDirty( %datablock );
  271. }
  272. else
  273. {
  274. DatablockEditorTree.editItem( %id, %datablock.getName(), %datablock.getId() );
  275. %this.PM.removeDirty( %datablock );
  276. }
  277. // Sync the inspector dirty state.
  278. %this.flagInspectorAsDirty( %this.PM.hasDirty() );
  279. }
  280. //---------------------------------------------------------------------------------------------
  281. function DatablockEditorPlugin::showSaveNewFileDialog(%this)
  282. {
  283. %currentFile = %this.getSelectedDatablock().getFilename();
  284. getSaveFilename( "TorqueScript Files|*.cs|All Files|*.*", %this @ ".saveNewFileFinish", %currentFile, false );
  285. }
  286. //---------------------------------------------------------------------------------------------
  287. function DatablockEditorPlugin::saveNewFileFinish( %this, %newFileName )
  288. {
  289. // Clear the first responder to capture any inspector changes
  290. %ctrl = canvas.getFirstResponder();
  291. if( isObject(%ctrl) )
  292. %ctrl.clearFirstResponder();
  293. %tree = DatablockEditorTree;
  294. %count = %tree.getSelectedItemsCount();
  295. %selected = %tree.getSelectedItemList();
  296. foreach$( %id in %selected )
  297. {
  298. %db = %tree.getItemValue( %id );
  299. %db = %this.getSelectedDatablock();
  300. // Remove from current file.
  301. %oldFileName = %db.getFileName();
  302. if( %oldFileName !$= "" )
  303. %this.PM.removeObjectFromFile( %db, %oldFileName );
  304. // Save to new file.
  305. %this.PM.setDirty( %db, %newFileName );
  306. if( %this.PM.saveDirtyObject( %db ) )
  307. {
  308. // Clear dirty state.
  309. %this.flagDatablockAsDirty( %db, false );
  310. }
  311. }
  312. DatablockEditorInspectorWindow-->DatablockFile.setText( %newFileName );
  313. }
  314. //---------------------------------------------------------------------------------------------
  315. function DatablockEditorPlugin::save( %this )
  316. {
  317. // Clear the first responder to capture any inspector changes
  318. %ctrl = canvas.getFirstResponder();
  319. if( isObject(%ctrl) )
  320. %ctrl.clearFirstResponder();
  321. %tree = DatablockEditorTree;
  322. %count = %tree.getSelectedItemsCount();
  323. %selected = %tree.getSelectedItemList();
  324. for( %i = 0; %i < %count; %i ++ )
  325. {
  326. %id = getWord( %selected, %i );
  327. %db = %tree.getItemValue( %id );
  328. if( %this.PM.isDirty( %db ) )
  329. {
  330. %this.PM.saveDirtyObject( %db );
  331. %this.flagDatablockAsDirty( %db, false );
  332. }
  333. }
  334. }
  335. //=============================================================================================
  336. // Selection.
  337. //=============================================================================================
  338. //---------------------------------------------------------------------------------------------
  339. function DatablockEditorPlugin::getNumSelectedDatablocks( %this )
  340. {
  341. return DatablockEditorTree.getSelectedItemsCount();
  342. }
  343. //---------------------------------------------------------------------------------------------
  344. function DatablockEditorPlugin::getSelectedDatablock( %this, %index )
  345. {
  346. %tree = DatablockEditorTree;
  347. if( !%tree.getSelectedItemsCount() )
  348. return 0;
  349. if( !%index )
  350. %id = %tree.getSelectedItem();
  351. else
  352. %id = getWord( %tree.getSelectedItemList(), %index );
  353. return %tree.getItemValue( %id );
  354. }
  355. //---------------------------------------------------------------------------------------------
  356. function DatablockEditorPlugin::resetSelectedDatablock( %this )
  357. {
  358. DatablockEditorTree.clearSelection();
  359. DatablockEditorInspector.inspect(0);
  360. DatablockEditorInspectorWindow-->DatablockFile.setText("");
  361. EditorGuiStatusBar.setSelection( "" );
  362. }
  363. //---------------------------------------------------------------------------------------------
  364. function DatablockEditorPlugin::selectDatablockCheck( %this, %datablock )
  365. {
  366. if( %this.selectedDatablockIsDirty() )
  367. %this.showSaveDialog( %datablock );
  368. else
  369. %this.selectDatablock( %datablock );
  370. }
  371. //---------------------------------------------------------------------------------------------
  372. function DatablockEditorPlugin::selectDatablock( %this, %datablock, %add, %dontSyncTree )
  373. {
  374. if( %add )
  375. DatablockEditorInspector.addInspect( %datablock );
  376. else
  377. DatablockEditorInspector.inspect( %datablock );
  378. if( !%dontSyncTree )
  379. {
  380. %id = DatablockEditorTree.findItemByValue( %datablock.getId() );
  381. if( !%add )
  382. DatablockEditorTree.clearSelection();
  383. DatablockEditorTree.selectItem( %id, true );
  384. DatablockEditorTree.scrollVisible( %id );
  385. }
  386. %this.syncDirtyState();
  387. // Update the filename text field.
  388. %numSelected = %this.getNumSelectedDatablocks();
  389. %fileNameField = DatablockEditorInspectorWindow-->DatablockFile;
  390. if( %numSelected == 1 )
  391. {
  392. %fileName = %datablock.getFilename();
  393. if( %fileName !$= "" )
  394. %fileNameField.setText( %fileName );
  395. else
  396. %fileNameField.setText( $DATABLOCK_EDITOR_DEFAULT_FILENAME );
  397. }
  398. else
  399. {
  400. %fileNameField.setText( "" );
  401. }
  402. EditorGuiStatusBar.setSelection( %this.getNumSelectedDatablocks() @ " Datablocks Selected" );
  403. }
  404. //---------------------------------------------------------------------------------------------
  405. function DatablockEditorPlugin::unselectDatablock( %this, %datablock, %dontSyncTree )
  406. {
  407. DatablockEditorInspector.removeInspect( %datablock );
  408. if( !%dontSyncTree )
  409. {
  410. %id = DatablockEditorTree.findItemByValue( %datablock.getId() );
  411. DatablockEditorTree.selectItem( %id, false );
  412. }
  413. %this.syncDirtyState();
  414. // If we have exactly one selected datablock remaining, re-enable
  415. // the save-as button.
  416. %numSelected = %this.getNumSelectedDatablocks();
  417. if( %numSelected == 1 )
  418. {
  419. DatablockEditorInspectorWindow-->saveAsButton.setActive( true );
  420. %fileNameField = DatablockEditorInspectorWindow-->DatablockFile;
  421. %fileNameField.setText( %this.getSelectedDatablock().getFilename() );
  422. %fileNameField.setActive( true );
  423. }
  424. EditorGuiStatusBar.setSelection( %this.getNumSelectedDatablocks() @ " Datablocks Selected" );
  425. }
  426. //=============================================================================================
  427. // Creation and Deletion.
  428. //=============================================================================================
  429. //---------------------------------------------------------------------------------------------
  430. function DatablockEditorPlugin::deleteDatablock( %this )
  431. {
  432. %tree = DatablockEditorTree;
  433. // If we have more than single datablock selected,
  434. // turn our undos into a compound undo.
  435. %numSelected = %tree.getSelectedItemsCount();
  436. if( %numSelected > 1 )
  437. Editor.getUndoManager().pushCompound( "Delete Multiple Datablocks" );
  438. for( %i = 0; %i < %numSelected; %i ++ )
  439. {
  440. %id = %tree.getSelectedItem( %i );
  441. %db = %tree.getItemValue( %id );
  442. %fileName = %db.getFileName();
  443. // Remove the datablock from the tree.
  444. DatablockEditorTree.removeItem( %id );
  445. // Create undo.
  446. %action = %this.createUndo( ActionDeleteDatablock, "Delete Datablock" );
  447. %action.db = %db;
  448. %action.dbName = %db.getName();
  449. %action.fname = %fileName;
  450. %this.submitUndo( %action );
  451. // Kill the datablock in the file.
  452. if( %fileName !$= "" )
  453. %this.PM.removeObjectFromFile( %db );
  454. UnlistedDatablocks.add( %db );
  455. // Show some confirmation.
  456. if( %numSelected == 1 )
  457. MessageBoxOk( "Datablock Deleted", "The datablock (" @ %db.getName() @ ") has been removed from " @
  458. "it's file (" @ %db.getFilename() @ ") and upon restart will cease to exist" );
  459. }
  460. // Close compound, if we were deleting multiple datablocks.
  461. if( %numSelected > 1 )
  462. Editor.getUndoManager().popCompound();
  463. // Show confirmation for multiple datablocks.
  464. if( %numSelected > 1 )
  465. MessageBoxOk( "Datablocks Deleted", "The datablocks have been deleted and upon restart will cease to exist." );
  466. // Clear selection.
  467. DatablockEditorPlugin.resetSelectedDatablock();
  468. }
  469. //---------------------------------------------------------------------------------------------
  470. function DatablockEditorPlugin::createDatablock(%this)
  471. {
  472. %class = DatablockEditorTypeTree.getItemText(DatablockEditorTypeTree.getSelectedItem());
  473. if( %class !$= "" )
  474. {
  475. // Need to prompt for a name.
  476. DatablockEditorCreatePrompt-->CreateDatablockName.setText("Name");
  477. DatablockEditorCreatePrompt-->CreateDatablockName.selectAllText();
  478. // Populate the copy source dropdown.
  479. %list = DatablockEditorCreatePrompt-->CopySourceDropdown;
  480. %list.clear();
  481. %list.add( "", 0 );
  482. %set = DataBlockSet;
  483. %count = %set.getCount();
  484. for( %i = 0; %i < %count; %i ++ )
  485. {
  486. %datablock = %set.getObject( %i );
  487. %datablockClass = %datablock.getClassName();
  488. if( !isMemberOfClass( %datablockClass, %class ) )
  489. continue;
  490. %list.add( %datablock.getName(), %i + 1 );
  491. }
  492. // Set up state of client-side checkbox.
  493. %clientSideCheckBox = DatablockEditorCreatePrompt-->ClientSideCheckBox;
  494. %canBeClientSide = DatablockEditorPlugin::canBeClientSideDatablock( %class );
  495. %clientSideCheckBox.setStateOn( %canBeClientSide );
  496. %clientSideCheckBox.setActive( %canBeClientSide );
  497. // Show the dialog.
  498. canvas.pushDialog( DatablockEditorCreatePrompt, 0, true );
  499. }
  500. }
  501. //---------------------------------------------------------------------------------------------
  502. function DatablockEditorPlugin::createPromptNameCheck(%this)
  503. {
  504. %name = DatablockEditorCreatePrompt-->CreateDatablockName.getText();
  505. if( !Editor::validateObjectName( %name, true ) )
  506. return;
  507. // Fetch the copy source and clear the list.
  508. %copySource = DatablockEditorCreatePrompt-->copySourceDropdown.getText();
  509. DatablockEditorCreatePrompt-->copySourceDropdown.clear();
  510. // Remove the dialog and create the datablock.
  511. canvas.popDialog( DatablockEditorCreatePrompt );
  512. %this.createDatablockFinish( %name, %copySource );
  513. }
  514. //---------------------------------------------------------------------------------------------
  515. function DatablockEditorPlugin::createDatablockFinish( %this, %name, %copySource )
  516. {
  517. %class = DatablockEditorTypeTree.getItemText(DatablockEditorTypeTree.getSelectedItem());
  518. if( %class !$= "" )
  519. {
  520. %action = %this.createUndo( ActionCreateDatablock, "Create New Datablock" );
  521. if( DatablockEditorCreatePrompt-->ClientSideCheckBox.isStateOn() )
  522. %dbType = "singleton ";
  523. else
  524. %dbType = "datablock ";
  525. if( %copySource !$= "" )
  526. %eval = %dbType @ %class @ "(" @ %name @ " : " @ %copySource @ ") { canSaveDynamicFields = \"1\"; };";
  527. else
  528. %eval = %dbType @ %class @ "(" @ %name @ ") { canSaveDynamicFields = \"1\"; };";
  529. %res = eval( %eval );
  530. %action.db = %name.getId();
  531. %action.dbName = %name;
  532. %action.fname = $DATABLOCK_EDITOR_DEFAULT_FILENAME;
  533. %this.submitUndo( %action );
  534. %action.redo();
  535. }
  536. }
  537. //---------------------------------------------------------------------------------------------
  538. function DatablockEditorPlugin::canBeClientSideDatablock( %className )
  539. {
  540. switch$( %className )
  541. {
  542. case "SFXProfile" or
  543. "SFXPlayList" or
  544. "SFXAmbience" or
  545. "SFXEnvironment" or
  546. "SFXState" or
  547. "SFXDescription" or
  548. "SFXFMODProject":
  549. return true;
  550. default:
  551. return false;
  552. }
  553. }
  554. //=============================================================================================
  555. // Events.
  556. //=============================================================================================
  557. //---------------------------------------------------------------------------------------------
  558. function DatablockEditorInspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue )
  559. {
  560. // Same work to do as for the regular WorldEditor Inspector.
  561. Inspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue );
  562. DatablockEditorPlugin.flagDatablockAsDirty( %object, true );
  563. }
  564. //---------------------------------------------------------------------------------------------
  565. function DatablockEditorInspector::onFieldSelected( %this, %fieldName, %fieldTypeStr, %fieldDoc )
  566. {
  567. DatablockFieldInfoControl.setText( "<font:ArialBold:14>" @ %fieldName @ "<font:ArialItalic:14> (" @ %fieldTypeStr @ ") " NL "<font:Arial:14>" @ %fieldDoc );
  568. }
  569. //---------------------------------------------------------------------------------------------
  570. function DatablockEditorInspector::onBeginCompoundEdit( %this )
  571. {
  572. Editor.getUndoManager().pushCompound( "Multiple Field Edit" );
  573. }
  574. //---------------------------------------------------------------------------------------------
  575. function DatablockEditorInspector::onEndCompoundEdit( %this, %discard )
  576. {
  577. Editor.getUndoManager().popCompound( %discard );
  578. }
  579. //---------------------------------------------------------------------------------------------
  580. function DatablockEditorInspector::onClear( %this )
  581. {
  582. DatablockFieldInfoControl.setText( "" );
  583. }
  584. //---------------------------------------------------------------------------------------------
  585. function DatablockEditorTree::onDeleteSelection( %this )
  586. {
  587. %this.undoDeleteList = "";
  588. }
  589. //---------------------------------------------------------------------------------------------
  590. function DatablockEditorTree::onDeleteObject( %this, %object )
  591. {
  592. // Append it to our list.
  593. %this.undoDeleteList = %this.undoDeleteList TAB %object;
  594. // We're gonna delete this ourselves in the
  595. // completion callback.
  596. return true;
  597. }
  598. //---------------------------------------------------------------------------------------------
  599. function DatablockEditorTree::onObjectDeleteCompleted( %this )
  600. {
  601. //MEDeleteUndoAction::submit( %this.undoDeleteList );
  602. // Let the world editor know to
  603. // clear its selection.
  604. //EWorldEditor.clearSelection();
  605. //EWorldEditor.isDirty = true;
  606. }
  607. //---------------------------------------------------------------------------------------------
  608. function DatablockEditorTree::onClearSelected(%this)
  609. {
  610. DatablockEditorInspector.inspect( 0 );
  611. }
  612. //---------------------------------------------------------------------------------------------
  613. function DatablockEditorTree::onAddSelection( %this, %id )
  614. {
  615. %obj = %this.getItemValue( %id );
  616. if( !isObject( %obj ) )
  617. %this.selectItem( %id, false );
  618. else
  619. DatablockEditorPlugin.selectDatablock( %obj, true, true );
  620. }
  621. //---------------------------------------------------------------------------------------------
  622. function DatablockEditorTree::onRemoveSelection( %this, %id )
  623. {
  624. %obj = %this.getItemValue( %id );
  625. if( isObject( %obj ) )
  626. DatablockEditorPlugin.unselectDatablock( %obj, true );
  627. }
  628. //---------------------------------------------------------------------------------------------
  629. function DatablockEditorTree::onRightMouseUp( %this, %id, %mousePos )
  630. {
  631. %datablock = %this.getItemValue( %id );
  632. if( !isObject( %datablock ) )
  633. return;
  634. if( !isObject( DatablockEditorTreePopup ) )
  635. new PopupMenu( DatablockEditorTreePopup )
  636. {
  637. superClass = "MenuBuilder";
  638. isPopup = true;
  639. item[ 0 ] = "Delete" TAB "" TAB "DatablockEditorPlugin.selectDatablock( %this.datablockObject ); DatablockEditorPlugin.deleteDatablock( %this.datablockObject );";
  640. item[ 1 ] = "Jump to Definition in Torsion" TAB "" TAB "EditorOpenDeclarationInTorsion( %this.datablockObject );";
  641. datablockObject = "";
  642. };
  643. DatablockEditorTreePopup.datablockObject = %datablock;
  644. DatablockEditorTreePopup.showPopup( Canvas );
  645. }
  646. //---------------------------------------------------------------------------------------------
  647. function DatablockEditorTreeTabBook::onTabSelected(%this, %text, %id)
  648. {
  649. switch(%id)
  650. {
  651. case 0:
  652. DatablockEditorTreeWindow-->DeleteSelection.visible = true;
  653. DatablockEditorTreeWindow-->CreateSelection.visible = false;
  654. case 1:
  655. DatablockEditorTreeWindow-->DeleteSelection.visible = false;
  656. DatablockEditorTreeWindow-->CreateSelection.visible = true;
  657. }
  658. }