From 8af6513aead2ea916d5152b4b7215a08c1a516eb Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 21 Feb 2021 02:04:13 -0600 Subject: [PATCH] Adjusts Forest object creation and forest item data creation/management to work with asset/module workflows --- .../assetBrowser/scripts/selectPath.tscript | 7 ++- .../forestEditor/forestEditorGui.tscript | 44 ++++++++++++++----- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/selectPath.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/selectPath.tscript index 42c3440f6..691a546e0 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/selectPath.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/selectPath.tscript @@ -3,7 +3,7 @@ function SelectAssetPath::onWake(%this) } //SelectAssetPath.showDialog(); -function SelectAssetPath::showDialog(%this, %startingPath, %callback) +function SelectAssetPath::showDialog(%this, %startingPath, %callback, %promptText) { if(!isObject(%this.dirHandler)) %this.dirHandler = makedirectoryHandler(SelectAssetPath-->folderTree, "Core,Tools,cache,shaderCache", ""); @@ -12,6 +12,11 @@ function SelectAssetPath::showDialog(%this, %startingPath, %callback) SelectAssetPath-->folderTree.buildIconTable( ":tools/classIcons/Prefab:tools/classIcons/Prefab" @ ":tools/classIcons/SimSet:tools/classIcons/SimSet"); + + if(%promptText $= "") + %promptText = "Select Path"; + + SelectAssetPathWindow.text = %promptText; %this.dirHandler.currentPath = %startingPath; %this.callback = %callback; diff --git a/Templates/BaseGame/game/tools/forestEditor/forestEditorGui.tscript b/Templates/BaseGame/game/tools/forestEditor/forestEditorGui.tscript index 820689b6a..b6a3d61d4 100644 --- a/Templates/BaseGame/game/tools/forestEditor/forestEditorGui.tscript +++ b/Templates/BaseGame/game/tools/forestEditor/forestEditorGui.tscript @@ -62,9 +62,11 @@ function ForestEditorGui::createForest( %this ) new Forest( theForest ) { dataFile = ""; - parentGroup = "MissionGroup"; + //parentGroup = "MissionGroup"; }; + getRootScene().add(theForest); + MECreateUndoAction::submit( theForest ); ForestEditorGui.setActiveForest( theForest ); @@ -169,7 +171,19 @@ function ForestEditorGui::deleteBrushOrElement( %this ) function ForestEditorGui::newMesh( %this ) { - %spec = "All Mesh Files|*.dts;*.dae|DTS|*.dts|DAE|*.dae"; + SelectAssetPath.showDialog(AssetBrowser.dirHandler.currentAddress, "createNewForestMesh", "Select Forest Mesh Datablock Path"); + SelectAssetPathWindow.selectWindow(); +} + +function createNewForestMesh(%newPath) +{ + ForestEditorGui.newMeshPath = %newPath; + AssetBrowser.showDialog("ShapeAsset", "selectNewForestMesh", "", "", ""); +} + +function selectNewForestMesh(%selectedShapeAssetId) +{ + /*%spec = "All Mesh Files|*.dts;*.dae|DTS|*.dts|DAE|*.dae"; %dlg = new OpenFileDialog() { @@ -188,15 +202,23 @@ function ForestEditorGui::newMesh( %this ) %file = fileBase( %fullPath ); } - %dlg.delete(); + %dlg.delete();*/ - if ( !%ret ) + if ( %selectedShapeAssetId $= "") return; - %name = getUniqueName( %file ); + %name = getUniqueName( AssetDatabase.getAssetName(%selectedShapeAssetId) ); - %str = "datablock TSForestItemData( " @ %name @ " ) { shapeFile = \"" @ %fullPath @ "\"; };"; - eval( %str ); + //%str = "datablock TSForestItemData( " @ %name @ " ) { shapeFile = \"" @ %fullPath @ "\"; };"; + //eval( %str ); + + %fullPath = AssetDatabase.acquireAsset(%selectedShapeAssetId).getShapeFile(); + + new TSForestItemData(%name) { + shapeFile = %fullPath; + }; + + %isrl = isObject( %name ); if ( isObject( %name ) ) { @@ -206,7 +228,7 @@ function ForestEditorGui::newMesh( %this ) ForestEditMeshTree.scrollVisible( %item ); ForestEditMeshTree.addSelection( %item ); - ForestDataManager.setDirty( %name, "art/forest/managedItemData." @ $TorqueScriptFileExtension ); + ForestDataManager.setDirty( %name, ForestEditorGui.newMeshPath @ "/managedForestItemData." @ $TorqueScriptFileExtension ); %element = new ForestBrushElement() { @@ -233,7 +255,7 @@ function ForestEditorGui::newMesh( %this ) %action.addToManager( Editor.getUndoManager() ); ForestEditorPlugin.dirty = true; - } + } } function ForestEditorGui::deleteMesh( %this ) @@ -254,8 +276,10 @@ function ForestEditorGui::deleteMesh( %this ) function ForestEditorGui::okDeleteMesh( %this, %mesh ) { + %originatingFile = %mesh.getFileName(); + // Remove mesh from file - ForestDataManager.removeObjectFromFile( %mesh, "art/forest/managedItemData." @ $TorqueScriptFileExtension ); + ForestDataManager.removeObjectFromFile( %mesh, %originatingFile ); // Submitting undo actions is handled in code. %this.deleteMeshSafe( %mesh );