| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193 |
- //-----------------------------------------------------------------------------
- // 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;
- %offset = -1; // tweak the vertical offset so that it aligns neatly
- %top = EditorGuiToolbar.extent.y + %offset;
- %bottom = %top + 59;
- %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;
- }
- }
|