| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- //-----------------------------------------------------------------------------
- // 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.
- //-----------------------------------------------------------------------------
- function initializeForestEditor()
- {
- echo(" % - Initializing Forest Editor");
-
- exec( "./forestEditor.cs" );
- exec( "./forestEditorGui.gui" );
- exec( "./forestEditToolbar.ed.gui" );
- exec( "./forestEditorGui.cs" );
- exec( "./tools.cs" );
-
- ForestEditorGui.setVisible( false );
- ForestEditorPalleteWindow.setVisible( false );
- ForestEditorPropertiesWindow.setVisible( false );
- ForestEditToolbar.setVisible( false );
-
- EditorGui.add( ForestEditorGui );
- EditorGui.add( ForestEditorPalleteWindow );
- EditorGui.add( ForestEditorPropertiesWindow );
- EditorGui.add( ForestEditToolbar );
-
- new ScriptObject( ForestEditorPlugin )
- {
- superClass = "EditorPlugin";
- editorGui = ForestEditorGui;
- };
-
- new SimSet(ForestTools)
- {
- new ForestBrushTool()
- {
- internalName = "BrushTool";
- toolTip = "Paint Tool";
- buttonImage = "tools/forest/images/brushTool";
- };
- new ForestSelectionTool()
- {
- internalName = "SelectionTool";
- toolTip = "Selection Tool";
- buttonImage = "tools/forest/images/selectionTool";
- };
- };
-
- %map = new ActionMap();
- %map.bindCmd( keyboard, "1", "ForestEditorSelectModeBtn.performClick();", "" ); // Select
- %map.bindCmd( keyboard, "2", "ForestEditorMoveModeBtn.performClick();", "" ); // Move
- %map.bindCmd( keyboard, "3", "ForestEditorRotateModeBtn.performClick();", "" ); // Rotate
- %map.bindCmd( keyboard, "4", "ForestEditorScaleModeBtn.performClick();", "" ); // Scale
- %map.bindCmd( keyboard, "5", "ForestEditorPaintModeBtn.performClick();", "" ); // Paint
- %map.bindCmd( keyboard, "6", "ForestEditorEraseModeBtn.performClick();", "" ); // Erase
- %map.bindCmd( keyboard, "7", "ForestEditorEraseSelectedModeBtn.performClick();", "" ); // EraseSelected
- //%map.bindCmd( keyboard, "backspace", "ForestEditorGui.onDeleteKey();", "" );
- //%map.bindCmd( keyboard, "delete", "ForestEditorGui.onDeleteKey();", "" );
- ForestEditorPlugin.map = %map;
- }
- function destroyForestEditor()
- {
- }
- // NOTE: debugging helper.
- function reinitForest()
- {
- exec( "./main.cs" );
- exec( "./forestEditorGui.cs" );
- exec( "./tools.cs" );
- }
- function ForestEditorPlugin::onWorldEditorStartup( %this )
- {
- new PersistenceManager( ForestDataManager );
-
- %brushPath = "art/forest/brushes.cs";
- if ( !isFile( %brushPath ) )
- createPath( %brushPath );
-
- // This creates the ForestBrushGroup, all brushes, and elements.
- exec( %brushpath );
-
- if ( !isObject( ForestBrushGroup ) )
- {
- new SimGroup( ForestBrushGroup );
- %this.showError = true;
- }
-
- ForestEditBrushTree.open( ForestBrushGroup );
-
- if ( !isObject( ForestItemDataSet ) )
- new SimSet( ForestItemDataSet );
-
- ForestEditMeshTree.open( ForestItemDataSet );
- // Add ourselves to the window menu.
- %accel = EditorGui.addToEditorsMenu( "Forest Editor", "", ForestEditorPlugin );
-
- // Add ourselves to the tools menu.
- %tooltip = "Forest Editor (" @ %accel @ ")";
- EditorGui.addToToolsToolbar( "ForestEditorPlugin", "ForestEditorPalette", expandFilename("tools/forestEditor/images/forest-editor-btn"), %tooltip );
-
- //connect editor windows
- GuiWindowCtrl::attach( ForestEditorPropertiesWindow, ForestEditorPalleteWindow );
- ForestEditTabBook.selectPage(0);
- }
- function ForestEditorPlugin::onWorldEditorShutdown( %this )
- {
- if ( isObject( ForestBrushGroup ) )
- ForestBrushGroup.delete();
- if ( isObject( ForestDataManager ) )
- ForestDataManager.delete();
- }
- function ForestEditorPlugin::onActivated( %this )
- {
- EditorGui.bringToFront( ForestEditorGui );
- ForestEditorGui.setVisible( true );
- ForestEditorPalleteWindow.setVisible( true );
- ForestEditorPropertiesWindow.setVisible( true );
- ForestEditorGui.makeFirstResponder( true );
- //ForestEditToolbar.setVisible( true );
- //Get our existing forest object in our current mission if we have one
- %forestObject = trim(parseMissionGroupForIds("Forest", ""));
- if(isObject(%forestObject))
- {
- ForestEditorGui.setActiveForest(%forestObject.getName());
- }
-
- %this.map.push();
- Parent::onActivated(%this);
-
- ForestEditBrushTree.open( ForestBrushGroup );
- ForestEditMeshTree.open( ForestItemDataSet );
-
- // Open the Brush tab.
- ForestEditTabBook.selectPage(0);
-
- // Sync the pallete button state
-
- // And toolbar.
- %tool = ForestEditorGui.getActiveTool();
- if ( isObject( %tool ) )
- %tool.onActivated();
-
- if ( !isObject( %tool ) )
- {
- ForestEditorPaintModeBtn.performClick();
-
- if ( ForestEditBrushTree.getItemCount() > 0 )
- {
- ForestEditBrushTree.selectItem( 0, true );
- }
- }
- else if ( %tool == ForestTools->SelectionTool )
- {
- %mode = GlobalGizmoProfile.mode;
- switch$ (%mode)
- {
- case "None":
- ForestEditorSelectModeBtn.performClick();
- case "Move":
- ForestEditorMoveModeBtn.performClick();
- case "Rotate":
- ForestEditorRotateModeBtn.performClick();
- case "Scale":
- ForestEditorScaleModeBtn.performClick();
- }
- }
- else if ( %tool == ForestTools->BrushTool )
- {
- %mode = ForestTools->BrushTool.mode;
- switch$ (%mode)
- {
- case "Paint":
- ForestEditorPaintModeBtn.performClick();
- case "Erase":
- ForestEditorEraseModeBtn.performClick();
- case "EraseSelected":
- ForestEditorEraseSelectedModeBtn.performClick();
- }
- }
-
- if ( %this.showError )
- MessageBoxOK( "Error", "Your art/forest folder does not contain a valid brushes.cs. Brushes you create will not be saved!" );
- }
- function ForestEditorPlugin::onDeactivated( %this )
- {
- ForestEditorGui.setVisible( false );
- ForestEditorPalleteWindow.setVisible( false );
- ForestEditorPropertiesWindow.setVisible( false );
-
- %tool = ForestEditorGui.getActiveTool();
- if ( isObject( %tool ) )
- %tool.onDeactivated();
-
- // Also take this opportunity to save.
- ForestDataManager.saveDirty();
-
- %this.map.pop();
-
- Parent::onDeactivated(%this);
- }
- function ForestEditorPlugin::isDirty( %this )
- {
- %dirty = %this.dirty || ForestEditorGui.isDirty();
- return %dirty;
- }
- function ForestEditorPlugin::clearDirty( %this )
- {
- %this.dirty = false;
- }
- function ForestEditorPlugin::onSaveMission( %this, %missionFile )
- {
- ForestDataManager.saveDirty();
- //First, find out if we have an existing forest object
- %forestObject = trim(parseMissionGroupForIds("Forest", ""));
-
- if ( isObject( %forestObject ) )
- {
- //We do. Next, see if we have a file already by polling the datafield.
- if(%forestObject.dataFile !$= "")
- {
- //If we do, just save to the provided file.
- %forestObject.saveDataFile(%forestObject.dataFile);
- }
- else
- {
- //We don't, so we'll save in the same place as the mission file and give it the missionpath\missionName.forest
- //naming convention.
- %path = filePath(%missionFile);
- %missionName = fileBase(%missionFile);
- %forestObject.saveDataFile(%path @ "/" @ %missionName @ ".forest");
- }
- }
-
- ForestBrushGroup.save( "art/forest/brushes.cs" );
- }
- function ForestEditorPlugin::onEditorSleep( %this )
- {
- }
- function ForestEditorPlugin::onEditMenuSelect( %this, %editMenu )
- {
- %hasSelection = false;
-
- %selTool = ForestTools->SelectionTool;
- if ( ForestEditorGui.getActiveTool() == %selTool )
- if ( %selTool.getSelectionCount() > 0 )
- %hasSelection = true;
-
- %editMenu.enableItem( 3, %hasSelection ); // Cut
- %editMenu.enableItem( 4, %hasSelection ); // Copy
- %editMenu.enableItem( 5, %hasSelection ); // Paste
- %editMenu.enableItem( 6, %hasSelection ); // Delete
- %editMenu.enableItem( 8, %hasSelection ); // Deselect
- }
- function ForestEditorPlugin::handleDelete( %this )
- {
- ForestTools->SelectionTool.deleteSelection();
- }
- function ForestEditorPlugin::handleDeselect( %this )
- {
- ForestTools->SelectionTool.clearSelection();
- }
- function ForestEditorPlugin::handleCut( %this )
- {
- ForestTools->SelectionTool.cutSelection();
- }
- function ForestEditorPlugin::handleCopy( %this )
- {
- ForestTools->SelectionTool.copySelection();
- }
- function ForestEditorPlugin::handlePaste( %this )
- {
- ForestTools->SelectionTool.pasteSelection();
- }
|