Jelajahi Sumber

Merge pull request #760 from Areloch/ForestBrushGroupToolingFixes

Fixes tooling of Forest Editor to be module-friendly
Brian Roberts 3 tahun lalu
induk
melakukan
be3be2eb7d

+ 2 - 0
Engine/source/console/sim.cpp

@@ -68,6 +68,8 @@ namespace Sim
    ImplementNamedSet(SFXAmbienceSet)
    ImplementNamedSet(TerrainMaterialSet)
    ImplementNamedSet(DataBlockSet);
+   ImplementNamedSet(ForestBrushSet);
+   ImplementNamedSet(ForestItemDataSet);
    ImplementNamedGroup(ActionMapGroup)
    ImplementNamedGroup(ClientGroup)
    ImplementNamedGroup(GuiGroup)

+ 2 - 0
Engine/source/console/sim.h

@@ -107,6 +107,8 @@ namespace Sim
    DeclareNamedSet(SFXAmbienceSet);
    DeclareNamedSet(TerrainMaterialSet);
    DeclareNamedSet(DataBlockSet);
+   DeclareNamedSet(ForestBrushSet);
+   DeclareNamedSet(ForestItemDataSet);
    DeclareNamedGroup(ActionMapGroup)
    DeclareNamedGroup(ClientGroup)
    DeclareNamedGroup(GuiGroup)

+ 2 - 0
Engine/source/console/simManager.cpp

@@ -565,6 +565,8 @@ void init()
    InstantiateNamedSet(SFXAmbienceSet);
    InstantiateNamedSet(TerrainMaterialSet);
    InstantiateNamedSet(DataBlockSet);
+   InstantiateNamedSet(ForestBrushSet); 
+   InstantiateNamedSet(ForestItemDataSet);
    InstantiateNamedGroup(ActionMapGroup);
    InstantiateNamedGroup(ClientGroup);
    InstantiateNamedGroup(GuiGroup);

+ 75 - 1
Engine/source/forest/editor/forestBrushElement.cpp

@@ -197,4 +197,78 @@ DefineEngineMethod( ForestBrush, containsItemData, bool, ( const char * obj ), ,
    }
 
    return object->containsItemData( data );
-}
+}
+
+//-------------------------------------------------------------------------
+// ForestBrushGroupSet
+//-------------------------------------------------------------------------
+
+IMPLEMENT_CONOBJECT(ForestBrushGroup);
+
+ConsoleDocClass(ForestBrushGroup,
+   "@brief Container class for ForestBrushes\n\n"
+   "Editor use only.\n\n"
+   "@internal"
+);
+
+ForestBrushGroup::ForestBrushGroup()
+{
+
+}
+
+bool ForestBrushGroup::onAdd()
+{
+   if (!Parent::onAdd())
+      return false;
+
+   SimSet* forestBrushSet;
+   if (!Sim::findObject("ForestBrushSet", forestBrushSet))
+   {
+      Con::errorf("ForestBrushGroup::onAdd() - failed to find ForestBrushSet to add new ForestBrushGroup to!");
+   }
+
+   forestBrushSet->addObject(this);
+
+   return true;
+}
+
+void ForestBrushGroup::addObject(SimObject* inObj)
+{
+   ForestBrush* ele = dynamic_cast<ForestBrush*>(inObj);
+   if (!ele)
+      return;
+
+   //if ( containsItemData( ele->mData ) )
+   //   return;
+
+   Parent::addObject(inObj);
+}
+
+bool ForestBrushGroup::containsBrushData(const ForestBrush* inData)
+{
+   SimObjectList::iterator iter = mObjectList.begin();
+   for (; iter != mObjectList.end(); iter++)
+   {
+      ForestBrush* pElement = dynamic_cast<ForestBrush*>(*iter);
+
+      if (!pElement)
+         continue;
+
+      if (pElement == inData)
+         return true;
+   }
+
+   return false;
+}
+
+DefineEngineMethod(ForestBrushGroup, containsBrushData, bool, (const char* obj), , "( ForestBrush obj )")
+{
+   ForestBrush* data = NULL;
+   if (!Sim::findObject(obj, data))
+   {
+      Con::warnf("ForestBrush::containsBrushData - invalid object passed");
+      return false;
+   }
+
+   return object->containsBrushData(data);
+}

+ 24 - 1
Engine/source/forest/editor/forestBrushElement.h

@@ -121,5 +121,28 @@ protected:
    static SimObjectPtr<SimGroup> smGroup;
 };
 
+//-------------------------------------------------------------------------
+// ForestBrushGroup
+//-------------------------------------------------------------------------
+
+class ForestBrushGroup : public SimGroup
+{
+   typedef SimGroup Parent;
+
+public:
+
+   ForestBrushGroup();
+
+   DECLARE_CONOBJECT(ForestBrushGroup);
+
+   virtual bool onAdd();
+
+   virtual void addObject(SimObject*);
+
+   bool containsBrushData(const ForestBrush* inData);
+protected:
+
+   static SimObjectPtr<SimGroup> smGroup;
+};
 
-#endif // _FOREST_EDITOR_BRUSHELEMENT_H_
+#endif // _FOREST_EDITOR_BRUSHELEMENT_H_

+ 7 - 2
Engine/source/forest/editor/forestBrushTool.cpp

@@ -610,9 +610,14 @@ void ForestBrushTool::_collectElements()
    }
 
    // Find all ForestBrushElements that are directly or indirectly selected.
+   SimSet* brushSet;
+   if (!Sim::findObject("ForestBrushSet", brushSet))
+   {
+      Con::errorf("ForestBrushTool::_collectElements() - could not find ForestBrushSet!");
+      return;
+   }
 
-   SimGroup *brushGroup = ForestBrush::getGroup();
-   brushGroup->findObjectByCallback( findSelectedElements, mElements );
+   brushSet->findObjectByCallback( findSelectedElements, mElements );
 
    // We just needed to flag these objects as selected for the benefit of our
    // findSelectedElements callback, we can now mark them un-selected again.

+ 9 - 3
Engine/source/forest/editor/forestEditorCtrl.cpp

@@ -328,10 +328,16 @@ void ForestEditorCtrl::deleteMeshSafe( ForestItemData *mesh )
    }
 
    // Find ForestBrushElement(s) referencing this datablock.
-   SimGroup *brushGroup = ForestBrush::getGroup();
+   SimSet* brushSet;
+   if (!Sim::findObject("ForestBrushSet", brushSet))
+   {
+      Con::errorf("ForestBrushTool::_collectElements() - could not find ForestBrushSet!");
+      return;
+   }
+
    sKey = mesh;
    Vector<SimObject*> foundElements;   
-   brushGroup->findObjectByCallback( &findMeshReferences, foundElements );   
+   brushSet->findObjectByCallback( &findMeshReferences, foundElements );
 
    // Add UndoAction to delete the ForestBrushElement(s) and the ForestItemData.
    MEDeleteUndoAction *elementAction = new MEDeleteUndoAction();
@@ -408,4 +414,4 @@ DefineEngineMethod(ForestEditorCtrl, setActiveForest, void, (const char * obj),
       return;
 
    object->setActiveForest(forestObject);
-}
+}

+ 2 - 0
Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/module.tscript.template

@@ -21,6 +21,8 @@ function @@::onCreateGameServer(%this)
         %this.registerDatablock("./scripts/managedData/managedDatablocks");
     if(isFile("./scripts/managedData/managedForestItemData." @ $TorqueScriptFileExtension))
         %this.registerDatablock("./scripts/managedData/managedForestItemData");
+    if(isFile("./scripts/managedData/managedForestBrushData." @ $TorqueScriptFileExtension))
+        %this.registerDatablock("./scripts/managedData/managedForestBrushData");
     if(isFile("./scripts/managedData/managedParticleEmitterData." @ $TorqueScriptFileExtension))
         %this.registerDatablock("./scripts/managedData/managedParticleEmitterData");
     if(isFile("./scripts/managedData/managedParticleData." @ $TorqueScriptFileExtension))

+ 0 - 26
Templates/BaseGame/game/tools/forestEditor/brushes.tscript

@@ -1,26 +0,0 @@
-//-----------------------------------------------------------------------------
-// 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.
-//-----------------------------------------------------------------------------
-
-$forestBrushesGroup = new SimGroup( ForestBrushGroup )
-{
-};
-//--- OBJECT WRITE END ---

+ 34 - 32
Templates/BaseGame/game/tools/forestEditor/forestEditorGui.tscript

@@ -110,17 +110,45 @@ function ForestEditorGui::createForest( %this )
 
 function ForestEditorGui::newBrush( %this )
 {   
-   %internalName = getUniqueInternalName( "Brush", ForestBrushGroup, true );
+   AssetBrowser_SelectModule.showDialog("ForestEditorGui.pickedNewBrushTargetModule");
+   AssetBrowser_SelectModuleWindow.selectWindow();
+}
+
+function ForestEditorGui::pickedNewBrushTargetModule(%this, %module)
+{   
+   %moduleDef = ModuleDatabase.findModule(%module);
+   
+   ForestEditorGui.forestBrushPath = %moduleDef.ModulePath @ "/scripts/managedData/managedForestBrushData." @ $TorqueScriptFileExtension;
+   
+   if(!isDirectory(filePath(ForestEditorGui.forestItemDataPath)))
+   {
+      AssetBrowser.dirHandler.createFolder(filePath(ForestEditorGui.forestItemDataPath));
+   }
+   
+   %group = ForestBrushSet.findObjectByInternalName(%module @ "ForestBrushGroup");
+   if(!isObject(%group))
+   {
+      %group = new ForestBrushGroup() {
+         internalName = %module @ "ForestBrushGroup";
+      };
+      
+      %group.setFilename(ForestEditorGui.forestBrushPath);
+   }
+   
+   %internalName = getUniqueInternalName( "Brush", ForestBrushSet, true );
          
    %brush = new ForestBrush()
    {
+      class = "ForestBrushGroup";
       internalName = %internalName;
-      parentGroup = ForestBrushGroup; 
+      parentGroup = ForestBrushSet; 
    };   
    
+   %group.add(%brush);
+   
    MECreateUndoAction::submit( %brush );
    
-   ForestEditBrushTree.open( ForestBrushGroup );
+   ForestEditBrushTree.open( ForestBrushSet );
    ForestEditBrushTree.buildVisibleTree(true);
    %item = ForestEditBrushTree.findItemByObjectId( %brush );
    ForestEditBrushTree.clearSelection();
@@ -135,7 +163,7 @@ function ForestEditorGui::newElement( %this )
    %sel = ForestEditBrushTree.getSelectedObject();
    
    if ( !isObject( %sel ) )
-      %parentGroup = ForestBrushGroup;
+      %parentGroup = ForestBrushSet;
    else
    {
       if ( %sel.getClassName() $= "ForestBrushElement" )  
@@ -144,7 +172,7 @@ function ForestEditorGui::newElement( %this )
          %parentGroup = %sel;
    }
       
-   %internalName = getUniqueInternalName( "Element", ForestBrushGroup, true );   
+   %internalName = getUniqueInternalName( "Element", ForestBrushSet, true );   
    
    %element = new ForestBrushElement()
    {
@@ -191,37 +219,11 @@ function ForestEditorGui::pickedNewMeshTargetModule(%this, %module)
 
 function selectNewForestMesh(%selectedShapeAssetId)
 {
-   /*%spec = "All Mesh Files|*.dts;*.dae|DTS|*.dts|DAE|*.dae";
-   
-   %dlg = new OpenFileDialog()
-   {
-      Filters        = %spec;
-      DefaultPath    = $Pref::WorldEditor::LastPath;
-      DefaultFile    = "";
-      ChangePath     = true;
-   };
-         
-   %ret = %dlg.Execute();
-   
-   if ( %ret )
-   {
-      $Pref::WorldEditor::LastPath = filePath( %dlg.FileName );
-      %fullPath = makeRelativePath( %dlg.FileName, getMainDotCSDir() );
-      %file = fileBase( %fullPath );
-   }   
-   
-   %dlg.delete();*/
-   
    if ( %selectedShapeAssetId $= "")
       return;
          
    %name = getUniqueName( AssetDatabase.getAssetName(%selectedShapeAssetId) );
       
-   //%str = "datablock TSForestItemData( " @ %name @ " ) { shapeFile = \"" @ %fullPath @ "\"; };";            
-   //eval( %str );
-   
-   //%fullPath = AssetDatabase.acquireAsset(%selectedShapeAssetId).getShapePath();
-   
    new TSForestItemData(%name) {
       shapeAsset = %selectedShapeAssetId;
    };
@@ -418,7 +420,7 @@ function ForestEditBrushTree::handleRenameObject( %this, %name, %obj )
 {   
    if ( %name !$= "" )
    {       
-      %found = ForestBrushGroup.findObjectByInternalName( %name );
+      %found = ForestBrushSet.findObjectByInternalName( %name );
       if ( isObject( %found ) && %found.getId() != %obj.getId() )
       {
          toolsMessageBoxOK( "Error", "Brush or Element with that name already exists.", "" );   

+ 20 - 23
Templates/BaseGame/game/tools/forestEditor/main.tscript

@@ -91,25 +91,7 @@ function ForestEditorPlugin::onWorldEditorStartup( %this )
 {       
    new PersistenceManager( ForestDataManager );
    
-   %brushPath = "tools/forestEditor/brushes." @ $TorqueScriptFileExtension;
-   
-   if ( !isFile( %brushPath ) )   
-      %successfulFile = 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 );
-      
+   ForestEditBrushTree.open( ForestBrushSet );   
    ForestEditMeshTree.open( ForestItemDataSet );
 
    // Add ourselves to the window menu.
@@ -126,8 +108,8 @@ function ForestEditorPlugin::onWorldEditorStartup( %this )
 
 function ForestEditorPlugin::onWorldEditorShutdown( %this )
 {
-   if ( isObject( ForestBrushGroup ) )   
-      ForestBrushGroup.delete();
+   if ( isObject( ForestBrushSet ) )   
+      ForestBrushSet.delete();
    if ( isObject( ForestDataManager ) )
       ForestDataManager.delete();
 }
@@ -153,7 +135,7 @@ function ForestEditorPlugin::onActivated( %this )
    %this.map.push();
    Parent::onActivated(%this);   
    
-   ForestEditBrushTree.open( ForestBrushGroup );   
+   ForestEditBrushTree.open( ForestBrushSet );   
    ForestEditMeshTree.open( ForestItemDataSet );
    
    // Open the Brush tab.
@@ -224,12 +206,26 @@ function ForestEditorPlugin::onDeactivated( %this )
    
    // Also take this opportunity to save.
    ForestDataManager.saveDirty();
+   %this.saveBrushSet();
    
    %this.map.pop();
    
    Parent::onDeactivated(%this);
 }
 
+function ForestEditorPlugin::saveBrushSet(%this)
+{
+   for(%i=0; %i < ForestBrushSet.getCount(); %i++)
+   {
+      %group = ForestBrushSet.getObject(%i);
+      if(%group.isMemberOfClass("ForestBrushGroup"))
+      {
+         %fileName = %group.getFileName();
+         %group.save(%group.getFileName());  
+      }
+   }
+}
+
 function ForestEditorPlugin::isDirty( %this )
 {
    %dirty = %this.dirty || ForestEditorGui.isDirty();
@@ -266,7 +262,8 @@ function ForestEditorPlugin::onSaveMission( %this, %missionFile )
       }
    }
       
-   ForestBrushGroup.save( "tools/forestEditor/brushes." @ $TorqueScriptFileExtension );
+   //Make sure our data is up to date too
+   %this.saveBrushSet();
 }
 
 function ForestEditorPlugin::onEditorSleep( %this )