From 2f69ffd2d43bfc7b80201348ca7557f48da2d448 Mon Sep 17 00:00:00 2001 From: Areloch Date: Tue, 21 Apr 2015 00:36:19 -0500 Subject: [PATCH] Fixes issue #1277 Adds the file path to the saveDataFile call (missionpath\missionname.forest as the format) This correctly utilizes the forest object's datafile field if it's set. If not, it will create a new forest item with the missionPath\missionName.forest convention. This also removes the checks for the hardcoded "theForest" forest object name, so that if it is renamed for some reason, it doesn't break. Lastly, this corrects a minor semi-related bug, where if you are in the forest editor and have a brush selected, and then click to paint, but no forest object currently exists, it prompts to create one. Once the forest object is created, it would trigger the editor to inspect the newly made forest object. If you attempted to paint the currently selected brush, there was a mis-match in the inspector information, and it would trigger a crash. This has been corrected by re-initializing the forest editor's selected tool mode so it can be utilized immediately after the forest object is created. --- .../source/forest/editor/forestEditorCtrl.cpp | 10 ++++- .../source/forest/editor/forestEditorCtrl.h | 3 ++ .../game/core/scripts/client/helperfuncs.cs | 2 +- .../tools/forestEditor/forestEditorGui.cs | 42 +++++++++++++++++-- .../Empty/game/tools/forestEditor/main.cs | 31 ++++++++++++-- .../game/core/scripts/client/helperfuncs.cs | 2 +- .../tools/forestEditor/forestEditorGui.cs | 42 +++++++++++++++++-- .../Full/game/tools/forestEditor/main.cs | 31 ++++++++++++-- 8 files changed, 148 insertions(+), 15 deletions(-) diff --git a/Engine/source/forest/editor/forestEditorCtrl.cpp b/Engine/source/forest/editor/forestEditorCtrl.cpp index 651fb4780..d8b54ba9c 100644 --- a/Engine/source/forest/editor/forestEditorCtrl.cpp +++ b/Engine/source/forest/editor/forestEditorCtrl.cpp @@ -97,7 +97,6 @@ void ForestEditorCtrl::onSleep() bool ForestEditorCtrl::updateActiveForest( bool createNew ) { - mForest = dynamic_cast( Sim::findObject( "theForest" ) ); Con::executef( this, "onActiveForestUpdated", mForest ? mForest->getIdString() : "", createNew ? "1" : "0" ); if ( mTool ) @@ -400,4 +399,13 @@ DefineConsoleMethod( ForestEditorCtrl, deleteMeshSafe, void, ( const char * obj DefineConsoleMethod( ForestEditorCtrl, isDirty, bool, (), , "" ) { return object->isDirty(); +} + +DefineConsoleMethod(ForestEditorCtrl, setActiveForest, void, (const char * obj), , "( Forest obj )") +{ + Forest *forestObject; + if (!Sim::findObject(obj, forestObject)) + return; + + object->setActiveForest(forestObject); } \ No newline at end of file diff --git a/Engine/source/forest/editor/forestEditorCtrl.h b/Engine/source/forest/editor/forestEditorCtrl.h index d210040e9..b91310a58 100644 --- a/Engine/source/forest/editor/forestEditorCtrl.h +++ b/Engine/source/forest/editor/forestEditorCtrl.h @@ -86,6 +86,9 @@ class ForestEditorCtrl : public EditTSCtrl /// Causes the editor to reselect the active forest. bool updateActiveForest( bool createNew ); + /// Sets the active Forest + void setActiveForest(Forest* forestObject) { mForest = forestObject; } + /// Returns the active Forest. Forest *getActiveForest() const { return mForest; } diff --git a/Templates/Empty/game/core/scripts/client/helperfuncs.cs b/Templates/Empty/game/core/scripts/client/helperfuncs.cs index 785ab2577..f8988a270 100644 --- a/Templates/Empty/game/core/scripts/client/helperfuncs.cs +++ b/Templates/Empty/game/core/scripts/client/helperfuncs.cs @@ -252,7 +252,7 @@ function parseMissionGroupForIds( %className, %childGroup ) if( (%currentGroup).getObject(%i).getClassName() $= "SimGroup" ) %classIds = %classIds @ parseMissionGroupForIds( %className, (%currentGroup).getObject(%i).getId()); } - return %classIds; + return trim( %classIds ); } //------------------------------------------------------------------------------ diff --git a/Templates/Empty/game/tools/forestEditor/forestEditorGui.cs b/Templates/Empty/game/tools/forestEditor/forestEditorGui.cs index d2c5b9737..e0e9f1ce4 100644 --- a/Templates/Empty/game/tools/forestEditor/forestEditorGui.cs +++ b/Templates/Empty/game/tools/forestEditor/forestEditorGui.cs @@ -50,7 +50,9 @@ function ForestEditorGui::onActiveForestUpdated( %this, %forest, %createNew ) /// Called from a message box when a forest is not found. function ForestEditorGui::createForest( %this ) { - if ( isObject( theForest ) ) + %forestObject = parseMissionGroupForIds("Forest", ""); + + if ( isObject( %forestObject ) ) { error( "Cannot create a second 'theForest' Forest!" ); return; @@ -64,8 +66,42 @@ function ForestEditorGui::createForest( %this ) }; MECreateUndoAction::submit( theForest ); - - ForestEditorInspector.inspect( theForest ); + + ForestEditorGui.setActiveForest( theForest ); + + //Re-initialize the editor settings so we can start using it immediately. + %tool = ForestEditorGui.getActiveTool(); + if ( isObject( %tool ) ) + %tool.onActivated(); + + 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(); + } + } EWorldEditor.isDirty = true; } diff --git a/Templates/Empty/game/tools/forestEditor/main.cs b/Templates/Empty/game/tools/forestEditor/main.cs index a5fc84f38..6a7dbf994 100644 --- a/Templates/Empty/game/tools/forestEditor/main.cs +++ b/Templates/Empty/game/tools/forestEditor/main.cs @@ -141,6 +141,13 @@ function ForestEditorPlugin::onActivated( %this ) ForestEditorPropertiesWindow.setVisible( true ); ForestEditorGui.makeFirstResponder( true ); //ForestEditToolbar.setVisible( true ); + + //Get our existing forest object in our current mission if we have one + %forestObject = parseMissionGroupForIds("Forest", ""); + if(isObject(%forestObject)) + { + ForestEditorGui.setActiveForest(%forestObject.getName()); + } %this.map.push(); Parent::onActivated(%this); @@ -232,9 +239,27 @@ function ForestEditorPlugin::clearDirty( %this ) function ForestEditorPlugin::onSaveMission( %this, %missionFile ) { ForestDataManager.saveDirty(); - - if ( isObject( theForest ) ) - theForest.saveDataFile(); + + //First, find out if we have an existing forest object + %forestObject = 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" ); } diff --git a/Templates/Full/game/core/scripts/client/helperfuncs.cs b/Templates/Full/game/core/scripts/client/helperfuncs.cs index 785ab2577..f8988a270 100644 --- a/Templates/Full/game/core/scripts/client/helperfuncs.cs +++ b/Templates/Full/game/core/scripts/client/helperfuncs.cs @@ -252,7 +252,7 @@ function parseMissionGroupForIds( %className, %childGroup ) if( (%currentGroup).getObject(%i).getClassName() $= "SimGroup" ) %classIds = %classIds @ parseMissionGroupForIds( %className, (%currentGroup).getObject(%i).getId()); } - return %classIds; + return trim( %classIds ); } //------------------------------------------------------------------------------ diff --git a/Templates/Full/game/tools/forestEditor/forestEditorGui.cs b/Templates/Full/game/tools/forestEditor/forestEditorGui.cs index d2c5b9737..e0e9f1ce4 100644 --- a/Templates/Full/game/tools/forestEditor/forestEditorGui.cs +++ b/Templates/Full/game/tools/forestEditor/forestEditorGui.cs @@ -50,7 +50,9 @@ function ForestEditorGui::onActiveForestUpdated( %this, %forest, %createNew ) /// Called from a message box when a forest is not found. function ForestEditorGui::createForest( %this ) { - if ( isObject( theForest ) ) + %forestObject = parseMissionGroupForIds("Forest", ""); + + if ( isObject( %forestObject ) ) { error( "Cannot create a second 'theForest' Forest!" ); return; @@ -64,8 +66,42 @@ function ForestEditorGui::createForest( %this ) }; MECreateUndoAction::submit( theForest ); - - ForestEditorInspector.inspect( theForest ); + + ForestEditorGui.setActiveForest( theForest ); + + //Re-initialize the editor settings so we can start using it immediately. + %tool = ForestEditorGui.getActiveTool(); + if ( isObject( %tool ) ) + %tool.onActivated(); + + 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(); + } + } EWorldEditor.isDirty = true; } diff --git a/Templates/Full/game/tools/forestEditor/main.cs b/Templates/Full/game/tools/forestEditor/main.cs index a5fc84f38..6a7dbf994 100644 --- a/Templates/Full/game/tools/forestEditor/main.cs +++ b/Templates/Full/game/tools/forestEditor/main.cs @@ -141,6 +141,13 @@ function ForestEditorPlugin::onActivated( %this ) ForestEditorPropertiesWindow.setVisible( true ); ForestEditorGui.makeFirstResponder( true ); //ForestEditToolbar.setVisible( true ); + + //Get our existing forest object in our current mission if we have one + %forestObject = parseMissionGroupForIds("Forest", ""); + if(isObject(%forestObject)) + { + ForestEditorGui.setActiveForest(%forestObject.getName()); + } %this.map.push(); Parent::onActivated(%this); @@ -232,9 +239,27 @@ function ForestEditorPlugin::clearDirty( %this ) function ForestEditorPlugin::onSaveMission( %this, %missionFile ) { ForestDataManager.saveDirty(); - - if ( isObject( theForest ) ) - theForest.saveDataFile(); + + //First, find out if we have an existing forest object + %forestObject = 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" ); }