| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- // Main code for the Datablock Editor plugin.
- $DATABLOCK_EDITOR_DEFAULT_FILENAME = "art/datablocks/managedDatablocks." @ $TorqueScriptFileExtension;
- //=============================================================================================
- // Initialization.
- //=============================================================================================
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::init( %this )
- {
- if( !DatablockEditorTree.getItemCount() )
- %this.populateTrees();
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::onWorldEditorStartup( %this )
- {
- // Add ourselves to the window menu.
- %accel = EditorGui.addToEditorsMenu( "Datablock Editor", "", DatablockEditorPlugin );
-
- // Add ourselves to the ToolsToolbar
- %tooltip = "Datablock Editor (" @ %accel @ ")";
- EditorGui.addToToolsToolbar( "DatablockEditorPlugin", "DatablockEditorPalette", "ToolsModule:datablock_editor_n_image", %tooltip );
- //connect editor windows
- GuiWindowCtrl::Attach( DatablockEditorInspectorWindow, DatablockEditorTreeWindow);
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::onActivated( %this )
- {
- EditorGui-->WorldEditorToolbar.setVisible(false);
- EditorGui.bringToFront( DatablockEditorPlugin );
-
- DatablockEditorTreeWindow.setVisible( true );
- DatablockEditorInspectorWindow.setVisible( true );
- DatablockEditorInspectorWindow.makeFirstResponder( true );
-
- // Maximize the windows when set
- DatablockEditorGui.onWake();
-
- %this.map.push();
- // Set the status bar here until all tool have been hooked up
- EditorGuiStatusBar.setInfo( "Datablock editor." );
-
- %numSelected = %this.getNumSelectedDatablocks();
- if( !%numSelected )
- EditorGuiStatusBar.setSelection( "" );
- else
- EditorGuiStatusBar.setSelection( %numSelected @ " datablocks selected" );
-
- %this.init();
- DatablockEditorPlugin.readSettings();
-
- if( EWorldEditor.getSelectionSize() == 1 )
- %this.onObjectSelected( EWorldEditor.getSelectedObject( 0 ) );
- Parent::onActivated( %this );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::onDeactivated( %this )
- {
- DatablockEditorPlugin.writeSettings();
-
- DatablockEditorInspectorWindow.setVisible( false );
- DatablockEditorTreeWindow.setVisible( false );
- %this.map.pop();
-
- Parent::onDeactivated(%this);
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::onExitMission( %this )
- {
- DatablockEditorTree.clear();
- DatablockEditorInspector.inspect( "" );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::openDatablock( %this, %datablock )
- {
- EditorGui.setEditor( DatablockEditorPlugin );
- %this.selectDatablock( %datablock );
- DatablockEditorTreeTabBook.selectedPage = 0;
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::setEditorFunction( %this )
- {
- return true;
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::onObjectSelected( %this, %object )
- {
- // Select datablock of object if this is a GameBase object.
-
- if( %object.isMemberOfClass( "GameBase" ) )
- %this.selectDatablock( %object.getDatablock() );
- else if( %object.isMemberOfClass( "SFXEmitter" ) && isObject( %object.track ) )
- %this.selectDatablock( %object.track );
- else if( %object.isMemberOfClass( "LightBase" ) && isObject( %object.animationType ) )
- %this.selectDatablock( %object.animationType );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::populateTrees(%this)
- {
- // Populate datablock tree.
-
- if( %this.excludeClientOnlyDatablocks )
- %set = DataBlockGroup;
- else
- %set = DataBlockSet;
- DatablockEditorTree.clear();
-
- foreach( %datablock in %set )
- {
- %unlistedFound = false;
- %id = %datablock.getId();
-
- foreach( %obj in UnlistedDatablocks )
- if( %obj.getId() == %id )
- {
- %unlistedFound = true;
- break;
- }
-
- if( %unlistedFound )
- continue;
-
- %this.addExistingItem( %datablock, true );
- }
-
- DatablockEditorTree.sort( 0, true, false, false );
-
- // Populate datablock type tree.
-
- %classList = enumerateConsoleClasses( "SimDatablock" );
- DatablockEditorTypeTree.clear();
-
- foreach$( %datablockClass in %classList )
- {
- if( !%this.isExcludedDatablockType( %datablockClass )
- && DatablockEditorTypeTree.findItemByName( %datablockClass ) == 0 )
- DatablockEditorTypeTree.insertItem( 0, %datablockClass );
- }
-
- DatablockEditorTypeTree.sort( 0, false, false, false );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::addExistingItem( %this, %datablock, %dontSort )
- {
- %tree = DatablockEditorTree;
-
- // Look up class at root level. Create if needed.
-
- %class = %datablock.getClassName();
- %parentID = %tree.findItemByName( %class );
- if( %parentID == 0 )
- %parentID = %tree.insertItem( 0, %class );
- // If the datablock is already there, don't
- // do anything.
-
- if( %tree.findItemByValue( %datablock.getId() ) )
- return;
-
- // It doesn't exist so add it.
- %name = %datablock.getName();
- if( %this.PM.isDirty( %datablock ) )
- %name = %name @ " *";
-
- %id = DatablockEditorTree.insertItem( %parentID, %name, %datablock.getId() );
- if( !%dontSort )
- DatablockEditorTree.sort( %parentID, false, false, false );
-
- return %id;
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::isExcludedDatablockType( %this, %className )
- {
- switch$( %className )
- {
- case "SimDatablock":
- return true;
- case "SFXTrack": // Abstract.
- return true;
- }
- return false;
- }
- //=============================================================================================
- // Settings.
- //=============================================================================================
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::initSettings( %this )
- {
- EditorSettings.beginGroup("DatablockEditor", true);
-
- EditorSettings.setDefaultValue("libraryTab", "0");
-
- EditorSettings.endGroup();
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::readSettings( %this )
- {
- EditorSettings.beginGroup("DatablockEditor", true);
-
- DatablockEditorTreeTabBook.selectPage( EditorSettings.value( "libraryTab" ) );
- %db = EditorSettings.value( "selectedDatablock" );
- if( isObject( %db ) && %db.isMemberOfClass( "SimDatablock" ) )
- %this.selectDatablock( %db );
-
- EditorSettings.endGroup();
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::writeSettings( %this )
- {
- EditorSettings.beginGroup( "DatablockEditor", true );
-
- EditorSettings.setValue( "libraryTab", DatablockEditorTreeTabBook.getSelectedPage() );
- if( %this.getNumSelectedDatablocks() > 0 )
- EditorSettings.setValue( "selectedDatablock", %this.getSelectedDatablock().getName() );
- EditorSettings.endGroup();
- }
- //=============================================================================================
- // Persistence.
- //=============================================================================================
- //---------------------------------------------------------------------------------------------
- /// Return true if there is any datablock with unsaved changes.
- function DatablockEditorPlugin::isDirty( %this )
- {
- return %this.PM.hasDirty();
- }
- //---------------------------------------------------------------------------------------------
- /// Return true if any of the currently selected datablocks has unsaved changes.
- function DatablockEditorPlugin::selectedDatablockIsDirty( %this )
- {
- %tree = DatablockEditorTree;
-
- %count = %tree.getSelectedItemsCount();
- %selected = %tree.getSelectedItemList();
-
- foreach$( %id in %selected )
- {
- %db = %tree.getItemValue( %id );
- if( %this.PM.isDirty( %db ) )
- return true;
- }
-
- return false;
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::syncDirtyState( %this )
- {
- %tree = DatablockEditorTree;
- %count = %tree.getSelectedItemsCount();
- %selected = %tree.getSelectedItemList();
- %haveDirty = false;
- foreach$( %id in %selected )
- {
- %db = %tree.getItemValue( %id );
- if( %this.PM.isDirty( %db ) )
- {
- %this.flagDatablockAsDirty( %db, true );
- %haveDirty = true;
- }
- else
- %this.flagInspectorAsDirty( %db, false );
- }
- %this.flagInspectorAsDirty( %haveDirty );
- }
- //---------------------------------------------------------------------------------------------
- ///
- function DatablockEditorPlugin::flagInspectorAsDirty( %this, %dirty )
- {
- if( %dirty )
- DatablockEditorInspectorWindow.text = "Datablock *";
- else
- DatablockEditorInspectorWindow.text = "Datablock";
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::flagDatablockAsDirty(%this, %datablock, %dirty )
- {
- %tree = DatablockEditorTree;
-
- %id = %tree.findItemByValue( %datablock.getId() );
- if( %id == 0 )
- return;
- // Tag the item caption and sync the persistence manager.
-
- if( %dirty )
- {
- DatablockEditorTree.editItem( %id, %datablock.getName() @ " *", %datablock.getId() );
- %this.PM.setDirty( %datablock );
- }
- else
- {
- DatablockEditorTree.editItem( %id, %datablock.getName(), %datablock.getId() );
- %this.PM.removeDirty( %datablock );
- }
-
- // Sync the inspector dirty state.
-
- %this.flagInspectorAsDirty( %this.PM.hasDirty() );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::showSaveNewFileDialog(%this)
- {
- %currentFile = %this.getSelectedDatablock().getFilename();
- getSaveFilename( "TorqueScript Files|*." @ $TorqueScriptFileExtension @ "|All Files|*.*", %this @ ".saveNewFileFinish", %currentFile, false );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::saveNewFileFinish( %this, %newFileName )
- {
- // Clear the first responder to capture any inspector changes
- %ctrl = canvas.getFirstResponder();
- if( isObject(%ctrl) )
- %ctrl.clearFirstResponder();
- %tree = DatablockEditorTree;
- %count = %tree.getSelectedItemsCount();
- %selected = %tree.getSelectedItemList();
- foreach$( %id in %selected )
- {
- %db = %tree.getItemValue( %id );
- %db = %this.getSelectedDatablock();
-
- // Remove from current file.
-
- %oldFileName = %db.getFileName();
- if( %oldFileName !$= "" )
- %this.PM.removeObjectFromFile( %db, %oldFileName );
-
- // Save to new file.
- %this.PM.setDirty( %db, %newFileName );
- if( %this.PM.saveDirtyObject( %db ) )
- {
- // Clear dirty state.
-
- %this.flagDatablockAsDirty( %db, false );
- }
- }
-
- DatablockEditorInspectorWindow-->DatablockFile.setText( %newFileName );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::save( %this )
- {
- // Clear the first responder to capture any inspector changes
- %ctrl = canvas.getFirstResponder();
- if( isObject(%ctrl) )
- %ctrl.clearFirstResponder();
- %tree = DatablockEditorTree;
- %count = %tree.getSelectedItemsCount();
- %selected = %tree.getSelectedItemList();
-
- for( %i = 0; %i < %count; %i ++ )
- {
- %id = getWord( %selected, %i );
- %db = %tree.getItemValue( %id );
-
- if( %this.PM.isDirty( %db ) )
- {
- %this.PM.saveDirtyObject( %db );
- %this.flagDatablockAsDirty( %db, false );
- }
- }
- }
- //=============================================================================================
- // Selection.
- //=============================================================================================
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::getNumSelectedDatablocks( %this )
- {
- return DatablockEditorTree.getSelectedItemsCount();
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::getSelectedDatablock( %this, %index )
- {
- %tree = DatablockEditorTree;
- if( !%tree.getSelectedItemsCount() )
- return 0;
-
- if( !%index )
- %id = %tree.getSelectedItem();
- else
- %id = getWord( %tree.getSelectedItemList(), %index );
-
- return %tree.getItemValue( %id );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::resetSelectedDatablock( %this )
- {
- DatablockEditorTree.clearSelection();
- DatablockEditorInspector.inspect(0);
- DatablockEditorInspectorWindow-->DatablockFile.setText("");
- EditorGuiStatusBar.setSelection( "" );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::selectDatablockCheck( %this, %datablock )
- {
- if( %this.selectedDatablockIsDirty() )
- %this.showSaveDialog( %datablock );
- else
- %this.selectDatablock( %datablock );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::selectDatablock( %this, %datablock, %add, %dontSyncTree )
- {
- if( %add )
- DatablockEditorInspector.addInspect( %datablock );
- else
- DatablockEditorInspector.inspect( %datablock );
-
- if( !%dontSyncTree )
- {
- %id = DatablockEditorTree.findItemByValue( %datablock.getId() );
-
- if( !%add )
- DatablockEditorTree.clearSelection();
-
- DatablockEditorTree.selectItem( %id, true );
- DatablockEditorTree.scrollVisible( %id );
- }
-
- %this.syncDirtyState();
-
- // Update the filename text field.
-
- %numSelected = %this.getNumSelectedDatablocks();
- %fileNameField = DatablockEditorInspectorWindow-->DatablockFile;
-
- if( %numSelected == 1 )
- {
- %fileName = %datablock.getFilename();
- if( %fileName !$= "" )
- %fileNameField.setText( %fileName );
- else
- %fileNameField.setText( $DATABLOCK_EDITOR_DEFAULT_FILENAME );
- }
- else
- {
- %fileNameField.setText( "" );
- }
- EditorGuiStatusBar.setSelection( %this.getNumSelectedDatablocks() @ " Datablocks Selected" );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::unselectDatablock( %this, %datablock, %dontSyncTree )
- {
- DatablockEditorInspector.removeInspect( %datablock );
-
- if( !%dontSyncTree )
- {
- %id = DatablockEditorTree.findItemByValue( %datablock.getId() );
- DatablockEditorTree.selectItem( %id, false );
- }
-
- %this.syncDirtyState();
- // If we have exactly one selected datablock remaining, re-enable
- // the save-as button.
-
- %numSelected = %this.getNumSelectedDatablocks();
- if( %numSelected == 1 )
- {
- DatablockEditorInspectorWindow-->saveAsButton.setActive( true );
- %fileNameField = DatablockEditorInspectorWindow-->DatablockFile;
- %fileNameField.setText( %this.getSelectedDatablock().getFilename() );
- %fileNameField.setActive( true );
- }
- EditorGuiStatusBar.setSelection( %this.getNumSelectedDatablocks() @ " Datablocks Selected" );
- }
- //=============================================================================================
- // Creation and Deletion.
- //=============================================================================================
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::deleteDatablock( %this )
- {
- %tree = DatablockEditorTree;
-
- // If we have more than single datablock selected,
- // turn our undos into a compound undo.
-
- %numSelected = %tree.getSelectedItemsCount();
- if( %numSelected > 1 )
- Editor.getUndoManager().pushCompound( "Delete Multiple Datablocks" );
-
- for( %i = 0; %i < %numSelected; %i ++ )
- {
- %id = %tree.getSelectedItem( %i );
- %db = %tree.getItemValue( %id );
-
- %fileName = %db.getFileName();
-
- // Remove the datablock from the tree.
-
- DatablockEditorTree.removeItem( %id );
-
- // Create undo.
- %action = %this.createUndo( ActionDeleteDatablock, "Delete Datablock" );
- %action.db = %db;
- %action.dbName = %db.getName();
- %action.fname = %fileName;
-
- %this.submitUndo( %action );
-
- // Kill the datablock in the file.
- if( %fileName !$= "" )
- %this.PM.removeObjectFromFile( %db );
- UnlistedDatablocks.add( %db );
- // Show some confirmation.
- if( %numSelected == 1 )
- toolsMessageBoxOk( "Datablock Deleted", "The datablock (" @ %db.getName() @ ") has been removed from " @
- "it's file (" @ %db.getFilename() @ ") and upon restart will cease to exist" );
- }
-
- // Close compound, if we were deleting multiple datablocks.
-
- if( %numSelected > 1 )
- Editor.getUndoManager().popCompound();
-
- // Show confirmation for multiple datablocks.
-
- if( %numSelected > 1 )
- toolsMessageBoxOk( "Datablocks Deleted", "The datablocks have been deleted and upon restart will cease to exist." );
- // Clear selection.
-
- DatablockEditorPlugin.resetSelectedDatablock();
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::createNewDatablockOfType(%this, %class, %inheritFrom)
- {
- $DATABLOCK_EDITOR_NEWDB_CLASS = %class;
- $DATABLOCK_EDITOR_NEWDB_INHERITFROM = %inheritFrom;
- %this.pickDatablockPath();
- }
- function DatablockEditorPlugin::createDatablock(%this)
- {
- if($DATABLOCK_EDITOR_NEWDB_CLASS $= "")
- %class = DatablockEditorTypeTree.getItemText(DatablockEditorTypeTree.getSelectedItem());
- else
- %class = $DATABLOCK_EDITOR_NEWDB_CLASS;
-
- if( %class !$= "" )
- {
- // Need to prompt for a name.
-
- DatablockEditorCreatePrompt-->CreateDatablockName.setText("Name");
- DatablockEditorCreatePrompt-->CreateDatablockName.selectAllText();
-
- // Populate the copy source dropdown.
-
- %list = DatablockEditorCreatePrompt-->CopySourceDropdown;
- %list.clear();
- %list.add( "", 0 );
-
- %set = DataBlockSet;
- %count = %set.getCount();
- for( %i = 0; %i < %count; %i ++ )
- {
- %datablock = %set.getObject( %i );
- %datablockClass = %datablock.getClassName();
-
- if( !isMemberOfClass( %datablockClass, %class ) )
- continue;
-
- %list.add( %datablock.getName(), %i + 1 );
- }
-
- if($DATABLOCK_EDITOR_NEWDB_INHERITFROM !$= "")
- {
- %inheritFromListId = %list.findText($DATABLOCK_EDITOR_NEWDB_INHERITFROM);
- %list.setSelected(%inheritFromListId);
- }
-
- // Set up state of client-side checkbox.
-
- %clientSideCheckBox = DatablockEditorCreatePrompt-->ClientSideCheckBox;
- %canBeClientSide = DatablockEditorPlugin::canBeClientSideDatablock( %class );
- %clientSideCheckBox.setStateOn( %canBeClientSide );
- %clientSideCheckBox.setActive( %canBeClientSide );
-
- // Show the dialog.
-
- canvas.pushDialog( DatablockEditorCreatePrompt, 0, true );
- DatablockEditorCreatePrompt-->promptWindow.text = "Create New Datablock in module: " @ DatablockEditorPlugin.targetCreationModule;
- }
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::pickDatablockPath(%this)
- {
- AssetBrowser_SelectModule.showDialog("DatablockEditorPlugin.pickedNewDBTargetModule");
- //SelectAssetPath.showDialog(AssetBrowser.dirHandler.currentAddress, "DatablockEditorPlugin.pickedNewDBPath", "Select New Datablock Path");
- AssetBrowser_SelectModuleWindow.selectWindow();
- }
- function DatablockEditorPlugin::pickedNewDBTargetModule(%this, %module)
- {
- DatablockEditorPlugin.targetCreationModule = %module;
- %moduleDef = ModuleDatabase.findModule(%module);
-
- $DATABLOCK_EDITOR_DEFAULT_FILENAME = %moduleDef.ModulePath @ "/scripts/managedData/managedDatablocks." @ $TorqueScriptFileExtension;
-
- if(!isDirectory(filePath($DATABLOCK_EDITOR_DEFAULT_FILENAME)))
- {
- AssetBrowser.dirHandler.createFolder(filePath($DATABLOCK_EDITOR_DEFAULT_FILENAME));
- }
-
- DatablockEditorPlugin.createDatablock();
- }
- function DatablockEditorPlugin::createPromptNameCheck(%this, %path)
- {
- %name = DatablockEditorCreatePrompt-->CreateDatablockName.getText();
- if( !Editor::validateObjectName( %name, true ) )
- return;
-
- // Fetch the copy source and clear the list.
-
- %copySource = DatablockEditorCreatePrompt-->copySourceDropdown.getText();
- DatablockEditorCreatePrompt-->copySourceDropdown.clear();
-
- // Remove the dialog and create the datablock.
-
- canvas.popDialog( DatablockEditorCreatePrompt );
- %this.createDatablockFinish( %name, %copySource );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::createDatablockFinish( %this, %name, %copySource )
- {
- if($DATABLOCK_EDITOR_NEWDB_CLASS $= "")
- %class = DatablockEditorTypeTree.getItemText(DatablockEditorTypeTree.getSelectedItem());
- else
- %class = $DATABLOCK_EDITOR_NEWDB_CLASS;
- if( %class !$= "" )
- {
- %action = %this.createUndo( ActionCreateDatablock, "Create New Datablock" );
-
- if( DatablockEditorCreatePrompt-->ClientSideCheckBox.isStateOn() )
- %dbType = "singleton ";
- else
- %dbType = "datablock ";
-
- if( %copySource !$= "" )
- %eval = %dbType @ %class @ "(" @ %name @ " : " @ %copySource @ ") { canSaveDynamicFields = \"1\"; };";
- else
- %eval = %dbType @ %class @ "(" @ %name @ ") { canSaveDynamicFields = \"1\"; };";
-
- %res = eval( %eval );
-
- %action.db = %name.getId();
- %action.dbName = %name;
- %action.fname = $DATABLOCK_EDITOR_DEFAULT_FILENAME;
-
- %this.submitUndo( %action );
-
- %action.redo();
- }
-
- $DATABLOCK_EDITOR_NEWDB_CLASS = "";
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorPlugin::canBeClientSideDatablock( %className )
- {
- switch$( %className )
- {
- case "SFXProfile" or
- "SFXPlayList" or
- "SFXAmbience" or
- "SFXEnvironment" or
- "SFXState" or
- "SFXDescription":
- return true;
-
- default:
- return false;
- }
- }
- //------------------------------------------------------------------------------
- // GUI
- //------------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- function DatablockEditorGui::onWake(%this)
- {
- %fixedWindow = MeshRoadEditorTreeWindow;
- %fluidWindow = MeshRoadEditorOptionsWindow;
-
- if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1)
- {
- // Let's dock the side panel to the right side
- %this.docked = false;
- %this.resizing = true;
- %this.dockSidePanel();
- }
- else
- {
- // Let's release the side panel so it can be moved
- %this.docked = true;
- %this.resizing = false;
- %this.releaseSidePanel();
- }
- }
- function DatablockEditorGui::maxSize(%this, %window)
- {
- // Resize the windows to the max height
- // and force these to the right side if set
- if(EditorSettings.value( "WorldEditor/forceSidebarToSide" ) == 1 && %this.resizing == true)
- {
- // prevent onResize after a resize
- %this.resizing = false;
-
- %fixedWindow = DatablockEditorTreeWindow;
- %fluidWindow = DatablockEditorInspectorWindow;
- %top = EditorGuiToolbar.extent.y + 6;
- %bottom = %top + 65 - 6;
- %maxHeight = Canvas.extent.y - %top - %bottom;
-
- // --- Fixed window (top) ------------------------------------------------
- // put it back if it moved
- %fixedWindow.position.x = Canvas.extent.x - %fixedWindow.extent.x;
- %fixedWindow.position.y = %top;
-
- // don't go beyond the canvas
- if(%fixedWindow.extent.y > %maxHeight)
- %fixedWindow.extent.y = %maxHeight - %fluidWindow.extent.y;
- %position = %fixedWindow.position.x SPC %fixedWindow.position.y;
- %extent = %window.extent.x SPC %fixedWindow.extent.y;
- %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
-
- // --- Fluid window (bottom) ---------------------------------------------
- // position is relative to the top window
- %position = %fixedWindow.position.x SPC %fixedWindow.extent.y + %top;
- %extent = %window.extent.x SPC Canvas.extent.y - %fixedWindow.extent.y - %bottom;
- %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
-
- // --- AssetBrowser window ----------------------------------------------
- if(isObject(AssetBrowserWindow))
- {
- // Only resize the AssetBrowser if it's docked
- if(AssetBrowserWindow.docked == true)
- {
- // The width is relative to the sidepanel
- %browserWidth = Canvas.extent.x - %extent.x;
- %browserHeight = AssetBrowserWindow.extent.y;
- %browserPosY = Canvas.extent.y - AssetBrowserWindow.extent.y - 33;
- AssetBrowserWindow.resize(0, %browserPosY, %browserWidth, %browserHeight);
- }
- }
- // --- Windowed Console --------------------------------------------------
- if(isObject(windowConsoleControl))
- {
- // Only resize the AssetBrowser if it's docked
- if(windowConsoleControl.docked == true)
- {
- // The width is relative to the sidepanel
- %consoleWidth = Canvas.extent.x - %extent.x;
- %consoleHeight = windowConsoleControl.extent.y;
- %consolePosY = Canvas.extent.y - windowConsoleControl.extent.y - 33;
- windowConsoleControl.resize(0, %consolePosY, %consoleWidth, %consoleHeight);
- }
- }
- }
- }
- function DatablockEditorTreeWindow::onMouseDragged(%this)
- {
- %parent = DatablockEditorGui;
-
- if(%parent.panelHidden == true)
- {
- %parent.showSidePanel();
- }
-
- if(%parent.resizing == false && %parent.docked == true)
- {
- %parent.resizing = true;
- %parent.maxSize(%this);
- }
- }
- function DatablockEditorInspectorWindow::onMouseDragged(%this)
- {
- %parent = DatablockEditorGui;
-
- if(%parent.panelHidden == true)
- {
- %parent.showSidePanel();
- }
-
- if(%parent.resizing == false && %parent.docked == true)
- {
- %parent.resizing = true;
- %parent.maxSize(%this);
- }
- }
- function DatablockEditorGui::onResize(%this, %newPosition, %newExtent)
- {
- // Window to focus on (mostly the fluid window)
- %window = DatablockEditorInspectorWindow;
-
- if(%window.panelHidden == true)
- {
- %window.showSidePanel();
- }
-
- if(%this.resizing == false && %this.docked == true)
- {
- // Only resize once
- %this.resizing = true;
- %this.maxSize(%window);
- }
- }
- function DatablockEditorGui::dockSidePanel()
- {
- %parent = DatablockEditorGui;
- %fixedWindow = DatablockEditorTreeWindow;
- %fluidWindow = DatablockEditorInspectorWindow;
-
- if(%parent.docked == true)
- return;
-
- // Move and resize the window(s)
- %parent.resizing = true;
- %parent.maxSize(%fluidWindow);
-
- %parent.docked = true;
- %fluidWindow.onMouseDragged();
- // Lock the windows in place
- %fixedWindow.canCollapse = "0";
- %fixedWindow.canMove = "0";
-
- %fluidWindow.canCollapse = "0";
- %fluidWindow.canMove = "0";
-
- DatablockEditorGui_UnDockBtn.Visible = "1";
- DatablockEditorGui_DockBtn.Visible = "0";
-
- DatablockEditorGui_showBtn.Visible = "0";
- DatablockEditorGui_hideBtn.Visible = "1";
- }
- function DatablockEditorGui::releaseSidePanel()
- {
- %parent = DatablockEditorGui;
- %fixedWindow = DatablockEditorTreeWindow;
- %fluidWindow = DatablockEditorInspectorWindow;
-
- if(%parent.docked == false)
- return;
-
- // Unlock the windows so that be moved
- %fixedWindow.canCollapse = "1";
- %fixedWindow.canMove = "1";
-
- %fluidWindow.canCollapse = "1";
- %fluidWindow.canMove = "1";
-
- DatablockEditorGui_UnDockBtn.Visible = "0";
- DatablockEditorGui_DockBtn.Visible = "1";
-
- DatablockEditorGui_showBtn.Visible = "0";
- DatablockEditorGui_hideBtn.Visible = "0";
-
- // Let's do a small resize so it's visually clear we're undocking
- %position = %fixedWindow.position.x - 6 SPC %fixedWindow.position.y + 6;
- %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y;
- %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
- %position = %fluidWindow.position.x - 6 SPC %fluidWindow.position.y + 6;
- %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y - 12;
- %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
-
- %parent.docked = false;
- %parent.resizing = false;
- }
- function DatablockEditorGui::hideSidePanel()
- {
- %parent = DatablockEditorGui;
- %fixedWindow = DatablockEditorTreeWindow;
- %fluidWindow = DatablockEditorInspectorWindow;
-
- DatablockEditorGui_showBtn.Visible = "1";
- DatablockEditorGui_hideBtn.Visible = "0";
-
- // hide the content of the panels
- %fixedWindow.titleText = %fixedWindow.text;
- %fluidWindow.titleText = %fluidWindow.text;
-
- %fixedWindow.text = "";
- DatablockEditorTreeTabBook.Visible = "0";
-
- %fluidWindow.text = "";
- DatablockEditorInspectorPanel.Visible = "0";
- DatablockFieldInfoControl.Visible = "0";
- DatablockFileField.Visible = "0";
-
- // Let's do a resize so that the panel is collapsed to the side
- %position = Canvas.extent.x - 24 SPC %fixedWindow.position.y;
- %extent = %fixedWindow.extent.x SPC %fixedWindow.extent.y;
- %fixedWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
- %position = Canvas.extent.x - 24 SPC %fluidWindow.position.y;
- %extent = %fluidWindow.extent.x SPC %fluidWindow.extent.y;
- %fluidWindow.resize(%position.x, %position.y, %extent.x, %extent.y);
-
- %parent.panelHidden = true;
- }
- function DatablockEditorGui::showSidePanel()
- {
- %parent = DatablockEditorGui;
- %fixedWindow = DatablockEditorTreeWindow;
- %fluidWindow = DatablockEditorInspectorWindow;
-
- DatablockEditorGui_showBtn.Visible = "0";
- DatablockEditorGui_hideBtn.Visible = "1";
-
- // show the content of the panels
- // hide the content of the panels
- %fixedWindow.text = %fixedWindow.titleText;
- DatablockEditorTreeTabBook.Visible = "1";
-
- %fluidWindow.text = %fluidWindow.titleText;
- DatablockEditorInspectorPanel.Visible = "1";
- DatablockFieldInfoControl.Visible = "1";
- DatablockFileField.Visible = "1";
-
- %parent.resizing = true;
- %parent.maxSize(%fluidWindow);
-
- %parent.panelHidden = false;
- }
- //------------------------------------------------------------------------------
- //=============================================================================================
- // Events.
- //=============================================================================================
- //---------------------------------------------------------------------------------------------
- function DatablockEditorInspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue )
- {
- // Same work to do as for the regular WorldEditor Inspector.
- Inspector::onInspectorFieldModified( %this, %object, %fieldName, %arrayIndex, %oldValue, %newValue );
-
- DatablockEditorPlugin.flagDatablockAsDirty( %object, true );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorInspector::onFieldSelected( %this, %fieldName, %fieldTypeStr, %fieldDoc )
- {
- DatablockFieldInfoControl.setText( "<font:" @ $Gui::fontTypeBold @ ":16>" @ %fieldName @ "<font:Arial Italic:14> (" @ %fieldTypeStr @ ") " @ " : " @ "<font:Arial:14>" @ %fieldDoc );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorInspector::onBeginCompoundEdit( %this )
- {
- Editor.getUndoManager().pushCompound( "Multiple Field Edit" );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorInspector::onEndCompoundEdit( %this, %discard )
- {
- Editor.getUndoManager().popCompound( %discard );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorInspector::onClear( %this )
- {
- DatablockFieldInfoControl.setText( "" );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorTree::onDeleteSelection( %this )
- {
- %this.undoDeleteList = "";
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorTree::onDeleteObject( %this, %object )
- {
- // Append it to our list.
- %this.undoDeleteList = %this.undoDeleteList TAB %object;
-
- // We're gonna delete this ourselves in the
- // completion callback.
- return true;
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorTree::onObjectDeleteCompleted( %this )
- {
- //MEDeleteUndoAction::submit( %this.undoDeleteList );
-
- // Let the world editor know to
- // clear its selection.
- //EWorldEditor.clearSelection();
- //EWorldEditor.isDirty = true;
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorTree::onClearSelected(%this)
- {
- DatablockEditorInspector.inspect( 0 );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorTree::onAddSelection( %this, %id )
- {
- %obj = %this.getItemValue( %id );
-
- if( !isObject( %obj ) )
- %this.selectItem( %id, false );
- else
- DatablockEditorPlugin.selectDatablock( %obj, true, true );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorTree::onRemoveSelection( %this, %id )
- {
- %obj = %this.getItemValue( %id );
- if( isObject( %obj ) )
- DatablockEditorPlugin.unselectDatablock( %obj, true );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorTree::onRightMouseUp( %this, %id, %mousePos )
- {
- %datablock = %this.getItemValue( %id );
- if( !isObject( %datablock ) )
- return;
-
- if( !isObject( DatablockEditorTreePopup ) )
- new PopupMenu( DatablockEditorTreePopup )
- {
- superClass = "MenuBuilder";
- isPopup = true;
-
- item[ 0 ] = "Delete" TAB "" TAB "DatablockEditorPlugin.selectDatablock( DatablockEditorTreePopup.datablockObject ); DatablockEditorPlugin.deleteDatablock( DatablockEditorTreePopup.datablockObject );";
- item[ 1 ] = "Jump to Definition in Torsion" TAB "" TAB "EditorOpenDeclarationInTorsion( DatablockEditorTreePopup.datablockObject );";
-
- datablockObject = "";
- };
-
- DatablockEditorTreePopup.datablockObject = %datablock;
- DatablockEditorTreePopup.showPopup( Canvas );
- }
- //---------------------------------------------------------------------------------------------
- function DatablockEditorTreeTabBook::onTabSelected(%this, %text, %id)
- {
- switch(%id)
- {
- case 0:
- DatablockEditorTreeWindow-->DeleteSelection.visible = true;
- DatablockEditorTreeWindow-->CreateSelection.visible = false;
-
- case 1:
- DatablockEditorTreeWindow-->DeleteSelection.visible = false;
- DatablockEditorTreeWindow-->CreateSelection.visible = true;
- }
- }
|