From 32d8acd1b385efc8dc1445b038979a2042077231 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 5 Apr 2020 01:28:34 -0500 Subject: [PATCH] Adds functionality to duplicate an existing asset, currently works with image and level. Other types to follow. Adds editor setting for default target module, as well as if duplication of an asset should prompt for a new name, or proceed automatically with a default naming behavior. Shifts collada loader logic back to collada from assimp until the oddities with the assimp DAE import configs is ironed out. --- Engine/source/ts/tsShape.cpp | 4 +- .../tools/assetBrowser/guis/assetNameEdit.gui | 118 ++++++++++++++++++ .../BaseGame/game/tools/assetBrowser/main.cs | 1 + .../assetBrowser/scripts/assetTypes/image.cs | 18 +++ .../assetBrowser/scripts/assetTypes/level.cs | 18 +++ .../tools/assetBrowser/scripts/editAsset.cs | 91 +++++++++++--- .../game/tools/gui/editorSettingsWindow.ed.cs | 6 + 7 files changed, 240 insertions(+), 16 deletions(-) create mode 100644 Templates/BaseGame/game/tools/assetBrowser/guis/assetNameEdit.gui diff --git a/Engine/source/ts/tsShape.cpp b/Engine/source/ts/tsShape.cpp index bd0da7fc4..9ffef7b56 100644 --- a/Engine/source/ts/tsShape.cpp +++ b/Engine/source/ts/tsShape.cpp @@ -2143,7 +2143,7 @@ template<> void *Resource::create(const Torque::Path &path) ret = new TSShape; readSuccess = ret->read(&stream); } - /*else if ( extension.equal( "dae", String::NoCase ) || extension.equal( "kmz", String::NoCase ) ) + else if ( extension.equal( "dae", String::NoCase ) || extension.equal( "kmz", String::NoCase ) ) { #ifdef TORQUE_COLLADA // Attempt to load the DAE file @@ -2164,7 +2164,7 @@ template<> void *Resource::create(const Torque::Path &path) ret = new TSShape; readSuccess = ret->read(&stream); #endif - }*/ + } else { //Con::errorf( "Resource::create - '%s' has an unknown file format", path.getFullPath().c_str() ); diff --git a/Templates/BaseGame/game/tools/assetBrowser/guis/assetNameEdit.gui b/Templates/BaseGame/game/tools/assetBrowser/guis/assetNameEdit.gui new file mode 100644 index 000000000..e99e12118 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/guis/assetNameEdit.gui @@ -0,0 +1,118 @@ +//--- OBJECT WRITE BEGIN --- +%guiContent = new GuiControl(AssetBrowser_assetNameEdit) { + position = "0 0"; + extent = "1024 768"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultNonModalProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "1"; + Enabled = "1"; + + new GuiWindowCtrl() { + text = "Set Asset Name"; + resizeWidth = "1"; + resizeHeight = "0"; + canMove = "1"; + canClose = "1"; + canMinimize = "0"; + canMaximize = "0"; + canCollapse = "0"; + edgeSnap = "1"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "362 334"; + extent = "355 99"; + minExtent = "48 92"; + horizSizing = "center"; + vertSizing = "center"; + profile = "ToolsGuiWindowProfile"; + visible = "1"; + active = "1"; + command = "Canvas.popDialog(AssetBrowser_assetNameEdit);"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiButtonCtrl() { + text = "Select"; + groupNum = "-1"; + buttonType = "PushButton"; + useMouseEvents = "0"; + position = "207 68"; + extent = "71 22"; + minExtent = "8 2"; + horizSizing = "left"; + vertSizing = "top"; + profile = "ToolsGuiButtonProfile"; + visible = "1"; + active = "1"; + command = "Canvas.popDialog(AssetBrowser_assetNameEdit); eval(AssetBrowser_assetNameEdit.callback);"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiButtonCtrl() { + text = "Cancel"; + groupNum = "-1"; + buttonType = "PushButton"; + useMouseEvents = "0"; + position = "284 68"; + extent = "64 22"; + minExtent = "8 2"; + horizSizing = "left"; + vertSizing = "top"; + profile = "ToolsGuiButtonProfile"; + visible = "1"; + active = "1"; + command = "Canvas.popDialog(AssetBrowser_assetNameEdit);"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(AssetBrowser_assetNameEditTxt) { + historySize = "0"; + tabComplete = "0"; + sinkAllKeyEvents = "0"; + password = "0"; + passwordMask = "*"; + maxLength = "1024"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "8 38"; + extent = "341 18"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "height"; + profile = "ToolsGuiTextEditProfile"; + visible = "1"; + active = "1"; + tooltipProfile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + }; +}; +//--- OBJECT WRITE END --- diff --git a/Templates/BaseGame/game/tools/assetBrowser/main.cs b/Templates/BaseGame/game/tools/assetBrowser/main.cs index a01ae0012..f8f575842 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/main.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/main.cs @@ -66,6 +66,7 @@ function initializeAssetBrowser() exec("./guis/newFolder.gui"); exec("./guis/assetImportLog.gui"); exec("./guis/looseFileAudit.gui"); + exec("./guis/assetNameEdit.gui"); exec("./scripts/assetBrowser.cs"); exec("./scripts/popupMenus.cs"); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.cs index c2fc147cf..72dae5226 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.cs @@ -212,6 +212,24 @@ function AssetBrowser::renameImageAsset(%this, %assetDef, %newAssetName) renameAssetFile(%assetDef, %newAssetName); } +//Duplicates the asset +function AssetBrowser::duplicateImageAsset(%this, %assetDef, %newAssetName) +{ + %duplicatedAsset = duplicateAssetFile(%assetDef, %newAssetName); + + %newFilename = duplicateAssetLooseFile(%assetDef.imageFile, %newAssetName); + + if(!%newFilename $= "") + return; + + %module = AssetBrowser.dirHandler.getModuleFromAddress(%duplicatedAsset); + + %dupAssetDef = AssetDatabase.acquireAsset(%module.ModuleId @ ":" @ %newAssetName); + + %dupAssetDef.imageFile = fileName(%newFilename); + %dupAssetDef.saveAsset(); +} + //Deletes the asset function AssetBrowser::deleteImageAsset(%this, %assetDef) { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/level.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/level.cs index 0afbef7ef..8d117e65e 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/level.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/level.cs @@ -86,6 +86,24 @@ function AssetBrowser::renameLevelAsset(%this, %assetDef, %newAssetName) renameAssetFile(%assetDef, %newAssetName); } +//Duplicates the asset +function AssetBrowser::duplicateLevelAsset(%this, %assetDef, %newAssetName) +{ + %duplicatedAsset = duplicateAssetFile(%assetDef, %newAssetName); + + %newFilename = duplicateAssetLooseFile(%assetDef.LevelFile, %newAssetName); + + if(!%newFilename $= "") + return; + + %module = AssetBrowser.dirHandler.getModuleFromAddress(%duplicatedAsset); + + %dupAssetDef = AssetDatabase.acquireAsset(%module.ModuleId @ ":" @ %newAssetName); + + %dupAssetDef.LevelFile = fileName(%newFilename); + %dupAssetDef.saveAsset(); +} + //Deletes the asset function AssetBrowser::deleteLevelAsset(%this, %assetDef) { diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/editAsset.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/editAsset.cs index a7393c771..b78722fcc 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/editAsset.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/editAsset.cs @@ -260,26 +260,89 @@ function moveAssetLooseFile(%file, %destinationPath) //------------------------------------------------------------ -function AssetBrowser::duplicateAsset(%this, %targetModule) +function AssetBrowser::duplicateAsset(%this) { - if(%targetModule $= "") - { - //we need a module to duplicate to first - Canvas.pushDialog(AssetBrowser_selectModule); - AssetBrowser_selectModule.callback = "AssetBrowser.duplicateAsset"; - return; - } - %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); %assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId); - //this acts as a redirect based on asset type and will enact the appropriate function - //so for a GameObjectAsset, it'll become %this.duplicateGameObjectAsset(%assetDef, %targetModule); - //and call to the tools/assetBrowser/scripts/assetTypes/gameObject.cs file for implementation - if(%this.isMethod("duplicate"@%assetType)) - eval(%this @ ".duplicate"@%assetType@"("@%assetDef@","@%targetModule@");"); + %trailingNum = getTrailingNumber(%assetDef.assetName); + if(%trailingNum != -1) + { + %trailingNum++; + %newName = stripTrailingNumber(%assetDef.assetName) @ (%trailingNum); + } + else + { + %newName = stripTrailingNumber(%assetDef.assetName) @ "1"; + } + + AssetBrowser_assetNameEditTxt.text = %newName; + + AssetBrowser_assetNameEdit.callback = "AssetBrowser.doDuplicateAsset();"; + + if(EditorSettings.value("AssetManagement/Assets/promptOnRename", "1") == 1) + Canvas.pushDialog(AssetBrowser_assetNameEdit); + else + eval(AssetBrowser_assetNameEdit.callback); } +function AssetBrowser::doDuplicateAsset(%this) +{ + %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); + %assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId); + + if(AssetBrowser_assetNameEditTxt.text !$= "" && AssetBrowser_assetNameEditTxt.text !$= %assetDef.assetName) + { + //this acts as a redirect based on asset type and will enact the appropriate function + //so for a GameObjectAsset, it'll become %this.duplicateGameObjectAsset(%assetDef, %targetModule); + //and call to the tools/assetBrowser/scripts/assetTypes/gameObject.cs file for implementation + if(%this.isMethod("duplicate"@%assetType)) + eval(%this @ ".duplicate"@%assetType@"("@%assetDef@","@AssetBrowser_assetNameEditTxt.text@");"); + + AssetBrowser.refresh(); + } +} + +function duplicateAssetFile(%assetDef, %newAssetName) +{ + %assetPath = makeFullPath(AssetDatabase.getAssetFilePath(%assetDef.getAssetId())); + %assetFilepath = filePath(%assetPath); + %assetFileExt = fileExt(%assetPath); + + %newAssetPath = %assetFilepath @ "/" @ %newAssetName @ ".asset.taml"; + + %copiedSuccess = pathCopy(%assetPath, %newAssetPath); + + if(!%copiedSuccess) + return ""; + + replaceInFile(%newAssetPath, %assetDef.assetName, %newAssetName); + + %module = AssetBrowser.dirHandler.getModuleFromAddress(%newAssetPath); + + //Add with the new file + AssetDatabase.addDeclaredAsset(%module, %newAssetPath); + + return %newAssetPath; +} + +function duplicateAssetLooseFile(%file, %newFilename) +{ + %filePath = filePath(%file); + %fileExt = fileExt(%file); + + %newPath = %filePath @ "/" @ %newFilename @ %fileExt; + %copiedSuccess = pathCopy(%file, %newPath); + + if(!%copiedSuccess) + return ""; + + return %newPath; +} + + +//------------------------------------------------------------ + function AssetBrowser::deleteAsset(%this) { //Find out what type it is diff --git a/Templates/BaseGame/game/tools/gui/editorSettingsWindow.ed.cs b/Templates/BaseGame/game/tools/gui/editorSettingsWindow.ed.cs index ea13d0c88..0dd8727f4 100644 --- a/Templates/BaseGame/game/tools/gui/editorSettingsWindow.ed.cs +++ b/Templates/BaseGame/game/tools/gui/editorSettingsWindow.ed.cs @@ -444,6 +444,11 @@ function ESettingsWindow::getAssetManagementSettings(%this) SettingsInspector.addSettingsField("AssetManagement/Modules/coreModulePath", "Core Module Path", "string", ""); SettingsInspector.addSettingsField("AssetManagement/Modules/gameDataModulePath", "Game Data Module Path", "string", ""); SettingsInspector.addSettingsField("AssetManagement/Modules/moduleExtension", "Module Extension", "string", ""); + + %moduleList = ModuleDatabase.findModules(true); + %moduleList = strreplace(%moduleList, " ", ","); + + SettingsInspector.addSettingsField("AssetManagement/Modules/DefaultModule", "Default Module", "list", %moduleList); SettingsInspector.endGroup(); SettingsInspector.startGroup("Assets"); @@ -480,6 +485,7 @@ function ESettingsWindow::getAssetEditingSettings(%this) SettingsInspector.addSettingsField("Assets/Browser/showFolders", "Show Folders in Tiles view in Asset Browser", "bool", ""); SettingsInspector.addSettingsField("Assets/Browser/showEmptyFolders", "Show Empty Folders in Tiles view in Asset Browser", "bool", ""); SettingsInspector.addSettingsField("Assets/Browser/previewTileSize", "Asset Preview Tile Size", "bool", ""); + SettingsInspector.addSettingsField("AssetManagement/Assets/promptOnRename", "Prompt on Rename", "bool", ""); SettingsInspector.endGroup(); }