2018-01-28 21:30:17 +00:00
//-----------------------------------------------------------------------------
// 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 CreateAssetButton::onClick(%this)
{
AddNewAssetPopup.showPopup(Canvas);
}
function AssetBrowser_newAsset::onWake(%this)
{
Misc Quality of Life and Bug fixes
Added handling for if preview images on image assets fails to generate, will fallback to using the full image
Added handling for double clicking or drag-n-dropping terrain assets to create them
Improved handling of field labels in variable inspector by making the stringtable be case sensitive.
Added editor settings for handling of asset double click behavior. Can now select between Edit Asset and Spawn Asset. Support is asset type dependent.
Added editor setting for auto-importing loose files when navigating to a folder. If on and the user has flagged to also enable auto-import generally, will auto import all unaffiliated loose files in as assets.
Added editor setting for default module to use when creating new assets. Updated various tooling logic so when creating a new material, if this and the 'Always Prompt Module Target' setting is off, it will fill in the target module and target asset path info based on the default module.
Fixed issue with editors that use managedData scripts where if the path didn't exist, the script file wouldn't be made.
Fixed display issue in terrain editor where if you clear the detail map, the normal/macro/orm maps would disable, but not also clear.
Fixed handling of cleared maps in terrain editor so it no longer fills empty maps in with the no image image.
Fixed handling of creating new material where it would fill in the diffuse with a no texture image as the default.
Fixed issue where canceling out of creating a module would still prompt to create the common default folders.
Fixed issue where the Select Module window couldn't be closed via the cancel or x buttons.
Based on feedback, reduced default size of the Text Pad window.
Fixed issue where the Drop At menu list wouldn't correctly display which item was marked after it was changed.
Fixed spawning shape asset handling so it uses whatever the editor's Drop At setting is.
Improved themeing of regular bitmap buttons in the editor.
Based on feedback, flipped layout of Target Module and Target Path in the Create New Asset window.
Improved handling of setting up the Target Path for when creating new assets. If a path is not set, and the user has a Default Module, it will default the path to that module.
2021-08-28 23:51:27 +00:00
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(AssetBrowser.dirHandler.currentAddress).ModuleId;
2019-12-23 18:37:55 +00:00
Misc Quality of Life and Bug fixes
Added handling for if preview images on image assets fails to generate, will fallback to using the full image
Added handling for double clicking or drag-n-dropping terrain assets to create them
Improved handling of field labels in variable inspector by making the stringtable be case sensitive.
Added editor settings for handling of asset double click behavior. Can now select between Edit Asset and Spawn Asset. Support is asset type dependent.
Added editor setting for auto-importing loose files when navigating to a folder. If on and the user has flagged to also enable auto-import generally, will auto import all unaffiliated loose files in as assets.
Added editor setting for default module to use when creating new assets. Updated various tooling logic so when creating a new material, if this and the 'Always Prompt Module Target' setting is off, it will fill in the target module and target asset path info based on the default module.
Fixed issue with editors that use managedData scripts where if the path didn't exist, the script file wouldn't be made.
Fixed display issue in terrain editor where if you clear the detail map, the normal/macro/orm maps would disable, but not also clear.
Fixed handling of cleared maps in terrain editor so it no longer fills empty maps in with the no image image.
Fixed handling of creating new material where it would fill in the diffuse with a no texture image as the default.
Fixed issue where canceling out of creating a module would still prompt to create the common default folders.
Fixed issue where the Select Module window couldn't be closed via the cancel or x buttons.
Based on feedback, reduced default size of the Text Pad window.
Fixed issue where the Drop At menu list wouldn't correctly display which item was marked after it was changed.
Fixed spawning shape asset handling so it uses whatever the editor's Drop At setting is.
Improved themeing of regular bitmap buttons in the editor.
Based on feedback, flipped layout of Target Module and Target Path in the Create New Asset window.
Improved handling of setting up the Target Path for when creating new assets. If a path is not set, and the user has a Default Module, it will default the path to that module.
2021-08-28 23:51:27 +00:00
if(%targetModule $= "")
%targetModule = EditorSettings.value("Assets/New/defaultModule", "");
NewAssetTargetModule.setText(%targetModule);
%moduleDef = ModuleDatabase.findModule(%targetModule);
%targetPath = AssetBrowser.dirHandler.currentAddress;
if(!startsWith(%targetPath, %moduleDef.ModulePath))
{
%targetPath = %moduleDef.ModulePath;
}
NewAssetTargetAddress.text = %targetPath;
2018-01-28 21:30:17 +00:00
}
function AssetBrowser_newAssetWindow::onClose(%this)
{
NewAssetPropertiesInspector.clearFields();
Canvas.popDialog(AssetBrowser_newAsset);
}
function NewAssetTypeList::onWake(%this)
{
%this.refresh();
}
function NewAssetTypeList::refresh(%this)
{
%this.clear();
//TODO: make this more automated
//%this.add("GameObject", 0);
2020-01-10 00:28:53 +00:00
%this.add("ComponentAsset", 0);
%this.add("ImageAsset", 1);
%this.add("MaterialAsset", 2);
%this.add("ShapeAsset", 3);
%this.add("SoundAsset", 4);
%this.add("StateMachineAsset", 5);
2018-01-28 21:30:17 +00:00
}
function NewAssetTypeList::onSelected(%this)
{
%assetType = %this.getText();
2020-01-10 00:28:53 +00:00
if(%assetType $= "ComponentAsset")
2018-01-28 21:30:17 +00:00
{
NewComponentAssetSettings.hidden = false;
}
}
function NewAssetModuleBtn::onClick(%this)
{
Canvas.pushDialog(AssetBrowser_AddModule);
AssetBrowser_addModuleWindow.selectWindow();
}
2022-03-29 06:40:07 +00:00
function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName, %callback, %nameOverride)
2018-01-28 21:30:17 +00:00
{
Canvas.pushDialog(AssetBrowser_newAsset);
2019-12-23 18:37:55 +00:00
%shortAssetTypeName = strreplace(%assetType, "Asset", "");
AssetBrowser_newAssetWindow.text = "New" SPC %shortAssetTypeName SPC "Asset";
2018-01-28 21:30:17 +00:00
2019-05-04 16:49:42 +00:00
NewAssetPropertiesInspector.clearFields();
2018-01-28 21:30:17 +00:00
2019-05-04 16:49:42 +00:00
AssetBrowser_newAsset.callbackFunc = %callback;
2018-01-28 21:30:17 +00:00
//get rid of the old one if we had one.
if(isObject(%this.newAssetSettings))
%this.newAssetSettings.delete();
%this.newAssetSettings = new ScriptObject();
%this.newAssetSettings.assetType = %assetType;
%this.newAssetSettings.moduleName = %moduleName;
2022-03-29 06:40:07 +00:00
%newAssetName = "New" @ %shortAssetTypeName;
if(%nameOverride !$= "")
%newAssetName = %nameOverride;
2018-01-28 21:30:17 +00:00
NewAssetPropertiesInspector.startGroup("General");
2022-03-29 06:40:07 +00:00
NewAssetPropertiesInspector.addField("assetName", "New Asset Name", "String", "Name of the new asset", %newAssetName, "", %this.newAssetSettings);
2018-01-28 21:30:17 +00:00
//NewAssetPropertiesInspector.addField("AssetType", "New Asset Type", "List", "Type of the new asset", %assetType, "Component,Image,Material,Shape,Sound,State Machine", %newAssetSettings);
2019-05-04 16:49:42 +00:00
//NewAssetPropertiesInspector.addField("friendlyName", "Friendly Name", "String", "Human-readable name of new asset", "", "", %this.newAssetSettings);
2018-01-28 21:30:17 +00:00
2019-12-23 18:37:55 +00:00
NewAssetPropertiesInspector.addCallbackField("description", "Description", "Command", "Description of the new asset", "", "", "updateNewAssetField", %this.newAssetSettings);
2018-01-28 21:30:17 +00:00
NewAssetPropertiesInspector.endGroup();
2019-12-23 18:37:55 +00:00
if(%this.isMethod("setupCreateNew"@%assetType))
{
%command = %this @ ".setupCreateNew"@%assetType @"();";
eval(%command);
}
2025-02-06 04:51:43 +00:00
NewAssetPropertiesInspector.refresh();
2018-01-28 21:30:17 +00:00
}
2019-12-23 18:37:55 +00:00
function NewAssetPropertiesInspector::updateNewAssetField(%this)
{
%this.schedule(32, "update");
}
function newAssetUpdatePath(%newPath)
{
AssetBrowser.navigateTo(%newPath);
NewAssetTargetAddress.text = %newPath;
NewAssetTargetModule.text = AssetBrowser.dirHandler.getModuleFromAddress(AssetBrowser.dirHandler.currentAddress).ModuleId;
}
2022-04-23 21:07:36 +00:00
//
function AssetBrowser::importNewFile(%this)
{
%importingPath = "";
%dlg = new OpenFileDialog()
{
Filters = "(All Files (*.*)|*.*|";
DefaultFile = "";
ChangePath = false;
MustExist = true;
MultipleFiles = false;
forceRelativePath = false;
};
if ( %dlg.Execute() )
{
%importingPath = makeFullPath(%dlg.FileName);
}
%dlg.delete();
AssetBrowser.onBeginDropFiles();
AssetBrowser.onDropFile(%importingPath);
AssetBrowser.onEndDropFiles();
}
2022-04-04 01:00:30 +00:00
//
function NewAssetTargetModule::onSelect(%this, %idx, %idy)
{
%newModuleName = %this.getText();
%currentTargetPath = NewAssetTargetAddress.getText();
if(!startsWith(%currentTargetPath, "data/" @ %newModuleName @ "/"))
{
NewAssetTargetAddress.setText("data/" @ %newModuleName @ "/");
}
}
//
2018-01-28 21:30:17 +00:00
//We do a quick validation that mandatory fields are filled in before passing along to the asset-type specific function
function CreateNewAsset()
{
2020-08-12 18:11:13 +00:00
//To enusre that any in-progress-of-being-edited field applies it's changes
%lastEditField = AssetBrowser_newAsset.getFirstResponder();
2020-09-08 06:22:57 +00:00
if(isObject(%lastEditField) && %lastEditField.isMethod("forceValidateText"))
2020-08-12 18:11:13 +00:00
%lastEditField.forceValidateText();
2018-01-28 21:30:17 +00:00
%assetName = AssetBrowser.newAssetSettings.assetName;
if(%assetName $= "")
{
2020-07-24 05:40:03 +00:00
toolsMessageBoxOK( "Error", "Attempted to make a new asset with no name!");
2018-01-28 21:30:17 +00:00
return;
}
2020-10-25 17:26:42 +00:00
%firstChar = getSubStr(%assetName, 0, 1);
if(isInt(%firstChar))
{
toolsMessageBoxOK( "Error", "Names cannot start with a number!");
return;
}
2018-01-28 21:30:17 +00:00
//get the selected module data
2019-12-23 18:37:55 +00:00
%moduleName = NewAssetTargetModule.getText();
2018-01-28 21:30:17 +00:00
if(%moduleName $= "")
{
2020-07-24 05:40:03 +00:00
toolsMessageBoxOK( "Error", "Attempted to make a new asset with no module!");
2018-01-28 21:30:17 +00:00
return;
}
2022-04-04 01:00:30 +00:00
//First, we need to make sure we're not creating a conflicting asset
if(AssetDatabase.isDeclaredAsset(%moduleName @ ":" @ %assetName))
{
toolsMessageBoxOK( "Error", "An asset with the ID: " @ %moduleName @ ":" @ %assetName
@ " already exists! Please review and rename.");
return;
}
%assetType = AssetBrowser.newAssetSettings.assetType;
if(%assetType $= "MaterialAsset" || %assetType $= "TerrainMaterialAsset" ||
%assetType $= "GUIAsset")
{
if(isObject(%assetName))
{
toolsMessageBoxOK( "Error", "Attempted to create a new asset that requires " @
"a unique name, as the object definition must be unique. " @
"Please use a new name.");
return;
}
}
%currentTargetPath = NewAssetTargetAddress.getText();
%modulePath = makeRelativePath(ModuleDatabase.findModule(%moduleName).ModulePath);
if(!startsWith(%currentTargetPath, %modulePath))
{
toolsMessageBoxOK( "Error", "Attempting to create a new asset in an invalid path. " @
"Please set the target path to be within the target module folder.");
return;
}
2018-01-28 21:30:17 +00:00
AssetBrowser.newAssetSettings.moduleName = %moduleName;
if(%assetType $= "")
{
2020-07-24 05:40:03 +00:00
toolsMessageBoxOK( "Error", "Attempted to make a new asset with no type!");
2018-01-28 21:30:17 +00:00
return;
}
2019-05-04 16:49:42 +00:00
%assetFilePath = eval(AssetBrowser @ ".create"@%assetType@"();");
2018-01-28 21:30:17 +00:00
Canvas.popDialog(AssetBrowser_newAsset);
//Load it
2022-03-27 08:05:48 +00:00
if(!AssetDatabase.isDeclaredAsset(%moduleName @ ":" @ %assetName))
{
%moduleDef = ModuleDatabase.findModule(%moduleName,1);
AssetDatabase.addDeclaredAsset(%moduleDef, %assetFilePath);
//For utilities' sake, we'll acquire it immediately so it can be utilized
//without delay if it's got any script/dependencies stuff
AssetDatabase.acquireAsset("\"" @ %moduleName @ ":" @ %assetName @ "\"");
}
2018-01-28 21:30:17 +00:00
2019-05-04 16:49:42 +00:00
if(AssetBrowser_newAsset.callbackFunc !$= "")
2018-01-28 21:30:17 +00:00
{
2019-05-04 16:49:42 +00:00
%callbackCommand = "" @ AssetBrowser_newAsset.callbackFunc @ "(\"" @ %moduleName @ ":" @ %assetName @ "\");";
eval(%callbackCommand);
2018-01-28 21:30:17 +00:00
}
2019-10-20 07:47:15 +00:00
//Update the selection to immediately jump to the new asset
2019-12-03 06:09:18 +00:00
/*AssetBrowser-->filterTree.clearSelection();
2019-10-20 07:47:15 +00:00
%ModuleItem = AssetBrowser-->filterTree.findItemByName(%moduleName);
%assetTypeId = AssetBrowser-->filterTree.findChildItemByName(%ModuleItem, %assetType);
AssetBrowser-->filterTree.selectItem(%assetTypeId);
%selectedItem = AssetBrowser-->filterTree.getSelectedItem();
AssetBrowser-->filterTree.scrollVisibleByObjectId(%selectedItem);
2019-12-03 06:09:18 +00:00
AssetBrowser-->filterTree.buildVisibleTree(); */
AssetBrowser.refresh();
2018-01-28 21:30:17 +00:00
}
function ParentComponentList::onWake(%this)
{
%this.refresh();
}
function ParentComponentList::refresh(%this)
{
%this.clear();
%assetQuery = new AssetQuery();
if(!AssetDatabase.findAssetType(%assetQuery, "ComponentAsset"))
return; //if we didn't find ANY, just exit
// Find all the types.
%count = %assetQuery.getCount();
/*%categories = "";
for (%i = 0; %i < %count; %i++)
{
%assetId = %assetQuery.getAsset(%i);
%componentAsset = AssetDatabase.acquireAsset(%assetId);
%componentName = %componentAsset.componentName;
if(%componentName $= "")
%componentName = %componentAsset.componentClass;
%this.add(%componentName, %i);
}*/
%categories = "";
for (%i = 0; %i < %count; %i++)
{
%assetId = %assetQuery.getAsset(%i);
%componentAsset = AssetDatabase.acquireAsset(%assetId);
%componentClass = %componentAsset.componentClass;
if (!isInList(%componentClass, %categories))
%categories = %categories TAB %componentClass;
}
%categories = trim(%categories);
%index = 0;
%categoryCount = getFieldCount(%categories);
for (%i = 0; %i < %categoryCount; %i++)
{
%category = getField(%categories, %i);
%this.addCategory(%category);
for (%j = 0; %j < %count; %j++)
{
%assetId = %assetQuery.getAsset(%j);
%componentAsset = AssetDatabase.acquireAsset(%assetId);
%componentName = %componentAsset.componentName;
%componentClass = %componentAsset.componentClass;
if (%componentClass $= %category)
{
if(%componentName !$= "")
%this.add(" "@%componentName, %i);
}
}
}
}
//----------------------------------------------------------
// Game Object creation
//----------------------------------------------------------
function EWorldEditor::createGameObject( %this )
{
2019-05-04 16:49:42 +00:00
AssetBrowser.createGameObjectAsset();
2018-01-28 21:30:17 +00:00
}