Expands/Cleans up a lot of the asset functionality, including management, file association, and creation/importing

This commit is contained in:
Areloch 2019-05-04 11:49:42 -05:00
parent ba2e9f1547
commit ddfc416418
73 changed files with 4468 additions and 1876 deletions

View file

@ -124,7 +124,8 @@ void ComponentAsset::initPersistFields()
addField("componentType", TypeString, Offset(mComponentType, ComponentAsset), "The category of the component for organizing in the editor.");
addField("description", TypeString, Offset(mDescription, ComponentAsset), "Simple description of the component.");
addField("scriptFile", TypeString, Offset(mScriptFile, ComponentAsset), "A script file with additional scripted functionality for this component.");
addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, ComponentAsset),
&setScriptFile, &getScriptFile, "A script file with additional scripted functionality for this component.");
}
//------------------------------------------------------------------------------
@ -137,12 +138,35 @@ void ComponentAsset::copyTo(SimObject* object)
void ComponentAsset::initializeAsset()
{
mScriptFile = expandAssetFilePath(mScriptFile);
if(Platform::isFile(mScriptFile))
Con::executeFile(mScriptFile, false, false);
}
void ComponentAsset::onAssetRefresh()
{
mScriptFile = expandAssetFilePath(mScriptFile);
if (Platform::isFile(mScriptFile))
Con::executeFile(mScriptFile, false, false);
}
}
void ComponentAsset::setScriptFile(const char* pScriptFile)
{
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
// Fetch image file.
pScriptFile = StringTable->insert(pScriptFile);
// Ignore no change,
if (pScriptFile == mScriptFile)
return;
// Update.
mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile);
// Refresh the asset.
refreshAsset();
}

View file

@ -77,9 +77,15 @@ public:
AssetDefinition* getAssetDefinition() { return mpAssetDefinition; }
void setScriptFile(const char* pScriptFile);
inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
protected:
virtual void initializeAsset(void);
virtual void onAssetRefresh(void);
static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<ComponentAsset*>(obj)->setScriptFile(data); return false; }
static const char* getScriptFile(void* obj, const char* data) { return static_cast<ComponentAsset*>(obj)->getScriptFile(); }
};
DefineConsoleType(TypeComponentAssetPtr, ComponentAsset)

View file

@ -0,0 +1,167 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2013 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.
//-----------------------------------------------------------------------------
#ifndef CPP_ASSET_H
#include "CppAsset.h"
#endif
#ifndef _ASSET_MANAGER_H_
#include "assets/assetManager.h"
#endif
#ifndef _CONSOLETYPES_H_
#include "console/consoleTypes.h"
#endif
#ifndef _TAML_
#include "persistence/taml/taml.h"
#endif
#ifndef _ASSET_PTR_H_
#include "assets/assetPtr.h"
#endif
// Debug Profiling.
#include "platform/profiler.h"
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(CppAsset);
ConsoleType(CppAssetPtr, TypeCppAssetPtr, CppAsset, ASSET_ID_FIELD_PREFIX)
//-----------------------------------------------------------------------------
ConsoleGetType(TypeCppAssetPtr)
{
// Fetch asset Id.
return (*((AssetPtr<CppAsset>*)dptr)).getAssetId();
}
//-----------------------------------------------------------------------------
ConsoleSetType(TypeCppAssetPtr)
{
// Was a single argument specified?
if (argc == 1)
{
// Yes, so fetch field value.
const char* pFieldValue = argv[0];
// Fetch asset pointer.
AssetPtr<CppAsset>* pAssetPtr = dynamic_cast<AssetPtr<CppAsset>*>((AssetPtrBase*)(dptr));
// Is the asset pointer the correct type?
if (pAssetPtr == NULL)
{
// No, so fail.
//Con::warnf("(TypeCppAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
return;
}
// Set asset.
pAssetPtr->setAssetId(pFieldValue);
return;
}
// Warn.
Con::warnf("(TypeCppAssetPtr) - Cannot set multiple args to a single asset.");
}
//-----------------------------------------------------------------------------
CppAsset::CppAsset() : AssetBase()
{
mCodeFile = StringTable->EmptyString();
mHeaderFile = StringTable->EmptyString();
}
//-----------------------------------------------------------------------------
CppAsset::~CppAsset()
{
// If the asset manager does not own the asset then we own the
// asset definition so delete it.
if (!getOwned())
delete mpAssetDefinition;
}
//-----------------------------------------------------------------------------
void CppAsset::initPersistFields()
{
// Call parent.
Parent::initPersistFields();
addProtectedField("codeFile", TypeAssetLooseFilePath, Offset(mCodeFile, CppAsset),
&setCppFile, &getCppFile, "Path to the cpp file.");
addProtectedField("headerFile", TypeAssetLooseFilePath, Offset(mHeaderFile, CppAsset),
&setHeaderFile, &getHeaderFile, "Path to the h file.");
}
//------------------------------------------------------------------------------
void CppAsset::copyTo(SimObject* object)
{
// Call to parent.
Parent::copyTo(object);
}
void CppAsset::setCppFile(const char* pCppFile)
{
// Sanity!
AssertFatal(pCppFile != NULL, "Cannot use a NULL code file.");
// Fetch image file.
pCppFile = StringTable->insert(pCppFile);
// Ignore no change,
if (pCppFile == mCodeFile)
return;
// Update.
mCodeFile = getOwned() ? expandAssetFilePath(pCppFile) : StringTable->insert(pCppFile);
// Refresh the asset.
refreshAsset();
}
void CppAsset::setHeaderFile(const char* pHeaderFile)
{
// Sanity!
AssertFatal(pHeaderFile != NULL, "Cannot use a NULL header file.");
// Fetch image file.
pHeaderFile = StringTable->insert(pHeaderFile);
// Ignore no change,
if (pHeaderFile == mHeaderFile)
return;
// Update.
mHeaderFile = getOwned() ? expandAssetFilePath(pHeaderFile) : StringTable->insert(pHeaderFile);
// Refresh the asset.
refreshAsset();
}

View file

@ -0,0 +1,81 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2013 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.
//-----------------------------------------------------------------------------
#ifndef CPP_ASSET_H
#define CPP_ASSET_H
#pragma once
#ifndef _ASSET_BASE_H_
#include "assets/assetBase.h"
#endif
#ifndef _ASSET_DEFINITION_H_
#include "assets/assetDefinition.h"
#endif
#ifndef _STRINGUNIT_H_
#include "string/stringUnit.h"
#endif
#ifndef _ASSET_FIELD_TYPES_H_
#include "assets/assetFieldTypes.h"
#endif
//-----------------------------------------------------------------------------
class CppAsset : public AssetBase
{
typedef AssetBase Parent;
StringTableEntry mCodeFile;
StringTableEntry mHeaderFile;
public:
CppAsset();
virtual ~CppAsset();
/// Engine.
static void initPersistFields();
virtual void copyTo(SimObject* object);
/// Declare Console Object.
DECLARE_CONOBJECT(CppAsset);
void setCppFile(const char* pCppFile);
inline StringTableEntry getCppFile(void) const { return mCodeFile; };
void setHeaderFile(const char* pHeaderFile);
inline StringTableEntry getHeaderFile(void) const { return mHeaderFile; };
protected:
virtual void initializeAsset(void) {};
virtual void onAssetRefresh(void) {};
static bool setCppFile(void *obj, const char *index, const char *data) { static_cast<CppAsset*>(obj)->setCppFile(data); return false; }
static const char* getCppFile(void* obj, const char* data) { return static_cast<CppAsset*>(obj)->getCppFile(); }
static bool setHeaderFile(void *obj, const char *index, const char *data) { static_cast<CppAsset*>(obj)->setHeaderFile(data); return false; }
static const char* getHeaderFile(void* obj, const char* data) { return static_cast<CppAsset*>(obj)->getHeaderFile(); }
};
DefineConsoleType(TypeCppAssetPtr, CppAsset)
#endif // _ASSET_BASE_H_

View file

@ -92,8 +92,8 @@ ConsoleSetType(TypeGUIAssetPtr)
GUIAsset::GUIAsset()
{
mScriptFilePath = StringTable->EmptyString();
mGUIFilePath = StringTable->EmptyString();
mScriptFile = StringTable->EmptyString();
mGUIFile = StringTable->EmptyString();
}
//-----------------------------------------------------------------------------
@ -113,8 +113,11 @@ void GUIAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addField("scriptFilePath", TypeString, Offset(mScriptFilePath, GUIAsset), "Path to the script file for the gui");
addField("GUIFilePath", TypeString, Offset(mGUIFilePath, GUIAsset), "Path to the gui file");
addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, GUIAsset),
&setScriptFile, &getScriptFile, "Path to the script file for the gui");
addProtectedField("GUIFile", TypeAssetLooseFilePath, Offset(mGUIFile, GUIAsset),
&setScriptFile, &getScriptFile, "Path to the gui file");
}
//------------------------------------------------------------------------------
@ -127,20 +130,66 @@ void GUIAsset::copyTo(SimObject* object)
void GUIAsset::initializeAsset()
{
if (Platform::isFile(mGUIFilePath))
Con::executeFile(mGUIFilePath, false, false);
mGUIFile = expandAssetFilePath(mGUIFile);
if (Platform::isFile(mScriptFilePath))
Con::executeFile(mScriptFilePath, false, false);
if (Platform::isFile(mGUIFile))
Con::executeFile(mGUIFile, false, false);
mScriptFile = expandAssetFilePath(mScriptFile);
if (Platform::isFile(mScriptFile))
Con::executeFile(mScriptFile, false, false);
}
void GUIAsset::onAssetRefresh()
{
if (Platform::isFile(mGUIFilePath))
Con::executeFile(mGUIFilePath, false, false);
mGUIFile = expandAssetFilePath(mGUIFile);
if (Platform::isFile(mScriptFilePath))
Con::executeFile(mScriptFilePath, false, false);
if (Platform::isFile(mGUIFile))
Con::executeFile(mGUIFile, false, false);
mScriptFile = expandAssetFilePath(mScriptFile);
if (Platform::isFile(mScriptFile))
Con::executeFile(mScriptFile, false, false);
}
void GUIAsset::setGUIFile(const char* pScriptFile)
{
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL gui file.");
// Fetch image file.
pScriptFile = StringTable->insert(pScriptFile);
// Ignore no change,
if (pScriptFile == mGUIFile)
return;
// Update.
mGUIFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile);
// Refresh the asset.
refreshAsset();
}
void GUIAsset::setScriptFile(const char* pScriptFile)
{
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
// Fetch image file.
pScriptFile = StringTable->insert(pScriptFile);
// Ignore no change,
if (pScriptFile == mScriptFile)
return;
// Update.
mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile);
// Refresh the asset.
refreshAsset();
}
//-----------------------------------------------------------------------------

View file

@ -46,8 +46,8 @@ class GUIAsset : public AssetBase
{
typedef AssetBase Parent;
StringTableEntry mScriptFilePath;
StringTableEntry mGUIFilePath;
StringTableEntry mScriptFile;
StringTableEntry mGUIFile;
public:
GUIAsset();
@ -60,9 +60,19 @@ public:
/// Declare Console Object.
DECLARE_CONOBJECT(GUIAsset);
void setGUIFile(const char* pScriptFile);
inline StringTableEntry getGUIFile(void) const { return mGUIFile; };
void setScriptFile(const char* pScriptFile);
inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
protected:
virtual void initializeAsset(void);
virtual void onAssetRefresh(void);
static bool setGUIFile(void *obj, const char *index, const char *data) { static_cast<GUIAsset*>(obj)->setGUIFile(data); return false; }
static const char* getGUIFile(void* obj, const char* data) { return static_cast<GUIAsset*>(obj)->getGUIFile(); }
static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<GUIAsset*>(obj)->setScriptFile(data); return false; }
static const char* getScriptFile(void* obj, const char* data) { return static_cast<GUIAsset*>(obj)->getScriptFile(); }
};
DefineConsoleType(TypeGUIAssetPtr, GUIAsset)

View file

@ -92,9 +92,9 @@ ConsoleSetType(TypeGameObjectAssetPtr)
GameObjectAsset::GameObjectAsset()
{
mGameObjectName = StringTable->lookup("");
mScriptFilePath = StringTable->lookup("");
mTAMLFilePath = StringTable->lookup("");
mGameObjectName = StringTable->EmptyString();
mScriptFile = StringTable->EmptyString();
mTAMLFile = StringTable->EmptyString();
}
//-----------------------------------------------------------------------------
@ -115,8 +115,11 @@ void GameObjectAsset::initPersistFields()
Parent::initPersistFields();
addField("gameObjectName", TypeString, Offset(mGameObjectName, GameObjectAsset), "Name of the game object. Defines the created object's class.");
addField("scriptFilePath", TypeString, Offset(mScriptFilePath, GameObjectAsset), "Path to the script file for the GameObject's script code.");
addField("TAMLFilePath", TypeString, Offset(mTAMLFilePath, GameObjectAsset), "Path to the taml file for the GameObject's heirarchy.");
addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, GameObjectAsset),
&setScriptFile, &getScriptFile, "Path to the script file for the GameObject's script code.");
addProtectedField("TAMLFile", TypeAssetLooseFilePath, Offset(mTAMLFile, GameObjectAsset),
&setTAMLFile, &getTAMLFile, "Path to the taml file for the GameObject's heirarchy.");
}
//------------------------------------------------------------------------------
@ -129,14 +132,98 @@ void GameObjectAsset::copyTo(SimObject* object)
void GameObjectAsset::initializeAsset()
{
if (Platform::isFile(mScriptFilePath))
Con::executeFile(mScriptFilePath, false, false);
//Ensure we have an expanded filepath
mScriptFile = expandAssetFilePath(mScriptFile);
if (Platform::isFile(mScriptFile))
Con::executeFile(mScriptFile, false, false);
}
void GameObjectAsset::onAssetRefresh()
{
if (Platform::isFile(mScriptFilePath))
Con::executeFile(mScriptFilePath, false, false);
//Ensure we have an expanded filepath
mScriptFile = expandAssetFilePath(mScriptFile);
if (Platform::isFile(mScriptFile))
Con::executeFile(mScriptFile, false, false);
}
void GameObjectAsset::setScriptFile(const char* pScriptFile)
{
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
// Fetch image file.
pScriptFile = StringTable->insert(pScriptFile);
// Ignore no change,
if (pScriptFile == mScriptFile)
return;
// Update.
mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile);
// Refresh the asset.
refreshAsset();
}
void GameObjectAsset::setTAMLFile(const char* pTAMLFile)
{
// Sanity!
AssertFatal(pTAMLFile != NULL, "Cannot use a NULL TAML file.");
// Fetch image file.
pTAMLFile = StringTable->insert(pTAMLFile);
// Ignore no change,
if (pTAMLFile == mScriptFile)
return;
// Update.
mTAMLFile = getOwned() ? expandAssetFilePath(pTAMLFile) : StringTable->insert(pTAMLFile);
// Refresh the asset.
refreshAsset();
}
const char* GameObjectAsset::create()
{
if (!Platform::isFile(mTAMLFile))
return "";
// Set the format mode.
Taml taml;
// Yes, so set it.
taml.setFormatMode(Taml::getFormatModeEnum("xml"));
// Turn-off auto-formatting.
taml.setAutoFormat(false);
// Read object.
SimObject* pSimObject = taml.read(mTAMLFile);
// Did we find the object?
if (pSimObject == NULL)
{
// No, so warn.
Con::warnf("GameObjectAsset::create() - Could not read object from file '%s'.", mTAMLFile);
return "";
}
//Flag it so we know where it came from
pSimObject->setDataField("GameObject", nullptr, getAssetId());
return pSimObject->getIdString();
}
DefineEngineMethod(GameObjectAsset, createObject, const char*, (),,
"Creates an instance of the given GameObject given the asset definition.\n"
"@return The GameObject entity created from the asset.")
{
return object->create();
}
//-----------------------------------------------------------------------------
@ -160,35 +247,50 @@ void GuiInspectorTypeGameObjectAssetPtr::consoleInit()
GuiControl* GuiInspectorTypeGameObjectAssetPtr::constructEditControl()
{
// Create base filename edit controls
GuiControl *retCtrl = Parent::constructEditControl();
if (retCtrl == NULL)
return retCtrl;
// Create "Open in ShapeEditor" button
mGameObjectEditButton = new GuiButtonCtrl();
// Change filespec
char szBuffer[512];
dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"GameObjectAsset\", \"AssetBrowser.changeAsset\", %d, %s);",
mInspector->getComponentGroupTargetId(), mCaption);
mBrowseButton->setField("Command", szBuffer);
dSprintf(szBuffer, sizeof(szBuffer), "%d.onClick(%s);", this->getId(), mCaption);
mGameObjectEditButton->setField("Command", szBuffer);
// Create "Open in ShapeEditor" button
mSMEdButton = new GuiBitmapButtonCtrl();
mGameObjectEditButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
mGameObjectEditButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
mGameObjectEditButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId());
mSMEdButton->setField("Command", szBuffer);
const char* assetId = getData();
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
mSMEdButton->setBitmap(bitmapName);
if (assetId == "")
{
mGameObjectEditButton->setText("Create Game Object");
mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor");
mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Convert this object into a reusable Game Object asset.");
}
else
{
GameObjectAsset* goAsset = AssetDatabase.acquireAsset< GameObjectAsset>(assetId);
mSMEdButton->registerObject();
addObject(mSMEdButton);
if (goAsset)
{
mGameObjectEditButton->setText("Edit Game Object");
return retCtrl;
mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Edit this object instance or Game Object asset.");
}
else
{
mGameObjectEditButton->setText("Create Game Object");
mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Convert this object into a reusable Game Object asset.");
}
}
//mGameObjectEditButton->registerObject();
_registerEditControl(mGameObjectEditButton);
addObject(mGameObjectEditButton);
return mGameObjectEditButton;
}
bool GuiInspectorTypeGameObjectAssetPtr::updateRects()
@ -199,20 +301,13 @@ bool GuiInspectorTypeGameObjectAssetPtr::updateRects()
Point2I fieldPos = getPosition();
mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y);
mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y);
mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin, fieldExtent.y);
bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
if (mBrowseButton != NULL)
if (mGameObjectEditButton != NULL)
{
mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4);
resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent);
}
if (mSMEdButton != NULL)
{
RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4);
resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent);
resized |= mGameObjectEditButton->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
}
return resized;
}
}

View file

@ -48,8 +48,8 @@ class GameObjectAsset : public AssetBase
typedef AssetBase Parent;
StringTableEntry mGameObjectName;
StringTableEntry mScriptFilePath;
StringTableEntry mTAMLFilePath;
StringTableEntry mScriptFile;
StringTableEntry mTAMLFile;
public:
GameObjectAsset();
@ -59,12 +59,24 @@ public:
static void initPersistFields();
virtual void copyTo(SimObject* object);
const char* create();
/// Declare Console Object.
DECLARE_CONOBJECT(GameObjectAsset);
void setScriptFile(const char* pScriptFile);
inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
void setTAMLFile(const char* pScriptFile);
inline StringTableEntry getTAMLFile(void) const { return mTAMLFile; };
protected:
virtual void initializeAsset(void);
virtual void onAssetRefresh(void);
static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<GameObjectAsset*>(obj)->setScriptFile(data); return false; }
static const char* getScriptFile(void* obj, const char* data) { return static_cast<GameObjectAsset*>(obj)->getScriptFile(); }
static bool setTAMLFile(void *obj, const char *index, const char *data) { static_cast<GameObjectAsset*>(obj)->setTAMLFile(data); return false; }
static const char* getTAMLFile(void* obj, const char* data) { return static_cast<GameObjectAsset*>(obj)->getTAMLFile(); }
};
DefineConsoleType(TypeGameObjectAssetPtr, GameObjectAsset)
@ -73,12 +85,12 @@ DefineConsoleType(TypeGameObjectAssetPtr, GameObjectAsset)
//-----------------------------------------------------------------------------
// TypeAssetId GuiInspectorField Class
//-----------------------------------------------------------------------------
class GuiInspectorTypeGameObjectAssetPtr : public GuiInspectorTypeFileName
class GuiInspectorTypeGameObjectAssetPtr : public GuiInspectorField
{
typedef GuiInspectorTypeFileName Parent;
typedef GuiInspectorField Parent;
public:
GuiBitmapButtonCtrl *mSMEdButton;
GuiButtonCtrl *mGameObjectEditButton;
DECLARE_CONOBJECT(GuiInspectorTypeGameObjectAssetPtr);
static void consoleInit();

View file

@ -108,7 +108,9 @@ void ImageAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addField("imageFile", TypeString, Offset(mImageFileName, ImageAsset), "Path to the image file.");
addProtectedField("imageFile", TypeAssetLooseFilePath, Offset(mImageFileName, ImageAsset),
&setImageFileName, &getImageFileName, "Path to the image file.");
addField("useMips", TypeBool, Offset(mUseMips, ImageAsset), "Should the image use mips? (Currently unused).");
addField("isHDRImage", TypeBool, Offset(mIsHDRImage, ImageAsset), "Is the image in an HDR format? (Currently unused)");
}
@ -153,4 +155,23 @@ void ImageAsset::initializeAsset()
void ImageAsset::onAssetRefresh()
{
loadImage();
}
}
void ImageAsset::setImageFileName(const char* pScriptFile)
{
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL image file.");
// Fetch image file.
pScriptFile = StringTable->insert(pScriptFile);
// Ignore no change,
if (pScriptFile == mImageFileName)
return;
// Update.
mImageFileName = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile);
// Refresh the asset.
refreshAsset();
}

View file

@ -66,7 +66,8 @@ public:
/// Declare Console Object.
DECLARE_CONOBJECT(ImageAsset);
StringTableEntry getImageFileName() { return mImageFileName; }
void setImageFileName(const char* pScriptFile);
inline StringTableEntry getImageFileName(void) const { return mImageFileName; };
bool isValid() { return mIsValidImage; }
@ -76,6 +77,9 @@ protected:
virtual void initializeAsset(void);
virtual void onAssetRefresh(void);
static bool setImageFileName(void *obj, const char *index, const char *data) { static_cast<ImageAsset*>(obj)->setImageFileName(data); return false; }
static const char* getImageFileName(void* obj, const char* data) { return static_cast<ImageAsset*>(obj)->getImageFileName(); }
void loadImage();
};

View file

@ -92,6 +92,7 @@ ConsoleSetType(TypeLevelAssetPtr)
LevelAsset::LevelAsset() : AssetBase(), mIsSubLevel(false)
{
mLevelName = StringTable->EmptyString();
mLevelFile = StringTable->EmptyString();
mPreviewImage = StringTable->EmptyString();
@ -115,8 +116,11 @@ void LevelAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addField("LevelFile", TypeString, Offset(mLevelFile, LevelAsset), "Path to the actual level file.");
addField("PreviewImage", TypeString, Offset(mPreviewImage, LevelAsset), "Path to the image used for selection preview.");
addProtectedField("LevelFile", TypeAssetLooseFilePath, Offset(mLevelFile, LevelAsset),
&setLevelFile, &getLevelFile, "Path to the actual level file.");
addField("LevelName", TypeString, Offset(mLevelName, LevelAsset), "Human-friendly name for the level.");
addProtectedField("PreviewImage", TypeAssetLooseFilePath, Offset(mPreviewImage, LevelAsset),
&setPreviewImageFile, &getPreviewImageFile, "Path to the image used for selection preview.");
}
//------------------------------------------------------------------------------
@ -125,4 +129,54 @@ void LevelAsset::copyTo(SimObject* object)
{
// Call to parent.
Parent::copyTo(object);
}
}
//
void LevelAsset::initializeAsset()
{
// Call parent.
Parent::initializeAsset();
// Ensure the image-file is expanded.
mPreviewImage = expandAssetFilePath(mPreviewImage);
mLevelFile = expandAssetFilePath(mLevelFile);
}
//
void LevelAsset::setLevelFile(const char* pLevelFile)
{
// Sanity!
AssertFatal(pLevelFile != NULL, "Cannot use a NULL level file.");
// Fetch image file.
pLevelFile = StringTable->insert(pLevelFile);
// Ignore no change,
if (pLevelFile == mLevelFile)
return;
// Update.
mLevelFile = getOwned() ? expandAssetFilePath(pLevelFile) : StringTable->insert(pLevelFile);
// Refresh the asset.
refreshAsset();
}
void LevelAsset::setImageFile(const char* pImageFile)
{
// Sanity!
AssertFatal(pImageFile != NULL, "Cannot use a NULL image file.");
// Fetch image file.
pImageFile = StringTable->insert(pImageFile);
// Ignore no change,
if (pImageFile == mPreviewImage)
return;
// Update.
mPreviewImage = getOwned() ? expandAssetFilePath(pImageFile) : StringTable->insert(pImageFile);
// Refresh the asset.
refreshAsset();
}

View file

@ -44,6 +44,7 @@ class LevelAsset : public AssetBase
{
typedef AssetBase Parent;
StringTableEntry mLevelName;
StringTableEntry mLevelFile;
StringTableEntry mPreviewImage;
@ -61,8 +62,20 @@ public:
/// Declare Console Object.
DECLARE_CONOBJECT(LevelAsset);
void setLevelFile(const char* pImageFile);
inline StringTableEntry getLevelFile(void) const { return mLevelFile; };
void setImageFile(const char* pImageFile);
inline StringTableEntry getImageFile(void) const { return mPreviewImage; };
SimObjectId load();
protected:
virtual void initializeAsset(void) {}
static bool setLevelFile(void *obj, const char *index, const char *data) { static_cast<LevelAsset*>(obj)->setLevelFile(data); return false; }
static const char* getLevelFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getLevelFile(); }
static bool setPreviewImageFile(void *obj, const char *index, const char *data) { static_cast<LevelAsset*>(obj)->setImageFile(data); return false; }
static const char* getPreviewImageFile(void* obj, const char* data) { return static_cast<LevelAsset*>(obj)->getImageFile(); }
virtual void initializeAsset(void);
virtual void onAssetRefresh(void) {}
};

View file

@ -98,10 +98,6 @@ MaterialAsset::MaterialAsset()
MaterialAsset::~MaterialAsset()
{
// If the asset manager does not own the asset then we own the
// asset definition so delete it.
if (!getOwned())
delete mpAssetDefinition;
}
//-----------------------------------------------------------------------------
@ -112,7 +108,9 @@ void MaterialAsset::initPersistFields()
Parent::initPersistFields();
//addField("shaderGraph", TypeRealString, Offset(mShaderGraphFile, MaterialAsset), "");
addField("scriptFile", TypeRealString, Offset(mScriptFile, MaterialAsset), "Path to the file containing the material definition.");
addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, MaterialAsset),
&setScriptFile, &getScriptFile, "Path to the file containing the material definition.");
addField("materialDefinitionName", TypeRealString, Offset(mMatDefinitionName, MaterialAsset), "Name of the material definition this asset is for.");
}
@ -132,12 +130,12 @@ void MaterialAsset::onAssetRefresh()
if (Platform::isFile(mScriptFile))
Con::executeFile(mScriptFile, false, false);
if (!mMatDefinitionName.isEmpty())
if (mMatDefinitionName != StringTable->EmptyString())
{
Material* matDef;
if (!Sim::findObject(mMatDefinitionName.c_str(), matDef))
if (!Sim::findObject(mMatDefinitionName, matDef))
{
Con::errorf("MaterialAsset: Unable to find the Material %s", mMatDefinitionName.c_str());
Con::errorf("MaterialAsset: Unable to find the Material %s", mMatDefinitionName);
return;
}
@ -145,6 +143,25 @@ void MaterialAsset::onAssetRefresh()
}
}
void MaterialAsset::setScriptFile(const char* pScriptFile)
{
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
// Fetch image file.
pScriptFile = StringTable->insert(pScriptFile);
// Ignore no change,
if (pScriptFile == mScriptFile)
return;
// Update.
mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile);
// Refresh the asset.
refreshAsset();
}
//------------------------------------------------------------------------------
void MaterialAsset::compileShader()
@ -184,34 +201,68 @@ void GuiInspectorTypeMaterialAssetPtr::consoleInit()
GuiControl* GuiInspectorTypeMaterialAssetPtr::constructEditControl()
{
// Create base filename edit controls
GuiControl *retCtrl = Parent::constructEditControl();
if (retCtrl == NULL)
return retCtrl;
mUseHeightOverride = true;
mHeightOverride = 100;
mMatEdContainer = new GuiControl();
mMatEdContainer->registerObject();
addObject(mMatEdContainer);
// Create "Open in ShapeEditor" button
mMatPreviewButton = new GuiBitmapButtonCtrl();
const char* matAssetId = getData();
MaterialAsset* matAsset = AssetDatabase.acquireAsset< MaterialAsset>(matAssetId);
Material* materialDef = nullptr;
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
if (!Sim::findObject(matAsset->getMaterialDefinitionName(), materialDef))
{
Con::errorf("GuiInspectorTypeMaterialAssetPtr::constructEditControl() - unable to find material in asset");
}
else
{
mMatPreviewButton->setBitmap(materialDef->mDiffuseMapFilename[0]);
}
mMatPreviewButton->setPosition(0, 0);
mMatPreviewButton->setExtent(100,100);
// Change filespec
char szBuffer[512];
dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"MaterialAsset\", \"AssetBrowser.changeAsset\", %d, %s);",
mInspector->getComponentGroupTargetId(), mCaption);
mBrowseButton->setField("Command", szBuffer);
mMatPreviewButton->setField("Command", szBuffer);
// Create "Open in ShapeEditor" button
mSMEdButton = new GuiBitmapButtonCtrl();
mMatPreviewButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
mMatPreviewButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
mMatPreviewButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId());
mSMEdButton->setField("Command", szBuffer);
StringBuilder strbld;
strbld.append(matAsset->getMaterialDefinitionName());
strbld.append("\n");
strbld.append("Open this file in the Material Editor");
char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
mSMEdButton->setBitmap(bitmapName);
mMatPreviewButton->setDataField(StringTable->insert("tooltip"), NULL, strbld.data());
mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the Material Editor");
_registerEditControl(mMatPreviewButton);
//mMatPreviewButton->registerObject();
mMatEdContainer->addObject(mMatPreviewButton);
mSMEdButton->registerObject();
addObject(mSMEdButton);
mMatAssetIdTxt = new GuiTextEditCtrl();
mMatAssetIdTxt->registerObject();
mMatAssetIdTxt->setActive(false);
return retCtrl;
mMatAssetIdTxt->setText(matAssetId);
mMatAssetIdTxt->setBounds(100, 0, 150, 18);
mMatEdContainer->addObject(mMatAssetIdTxt);
return mMatEdContainer;
}
bool GuiInspectorTypeMaterialAssetPtr::updateRects()
@ -225,17 +276,41 @@ bool GuiInspectorTypeMaterialAssetPtr::updateRects()
mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y);
bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
if (mBrowseButton != NULL)
if (mMatEdContainer != nullptr)
{
mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4);
resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent);
mMatPreviewButton->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
}
if (mSMEdButton != NULL)
if (mMatPreviewButton != nullptr)
{
RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4);
resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent);
mMatPreviewButton->resize(Point2I::Zero, Point2I(100, 100));
}
if (mMatAssetIdTxt != nullptr)
{
mMatAssetIdTxt->resize(Point2I(100, 0), Point2I(mEditCtrlRect.extent.x - 100, 18));
}
return resized;
}
}
void GuiInspectorTypeMaterialAssetPtr::setMaterialAsset(String assetId)
{
mTargetObject->setDataField(mCaption, "", assetId);
//force a refresh
SimObject* obj = mInspector->getInspectObject();
mInspector->inspectObject(obj);
}
DefineEngineMethod(GuiInspectorTypeMaterialAssetPtr, setMaterialAsset, void, (String assetId), (""),
"Gets a particular shape animation asset for this shape.\n"
"@param animation asset index.\n"
"@return Shape Animation Asset.\n")
{
if (assetId == String::EmptyString)
return;
return object->setMaterialAsset(assetId);
}

View file

@ -57,7 +57,7 @@ class MaterialAsset : public AssetBase
String mShaderGraphFile;
String mScriptFile;
String mMatDefinitionName;
StringTableEntry mMatDefinitionName;
public:
MaterialAsset();
@ -67,15 +67,22 @@ public:
static void initPersistFields();
virtual void copyTo(SimObject* object);
virtual void initializeAsset();
virtual void onAssetRefresh(void);
void compileShader();
String getMaterialDefinitionName() { return mMatDefinitionName; }
StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; }
void setScriptFile(const char* pScriptFile);
inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
/// Declare Console Object.
DECLARE_CONOBJECT(MaterialAsset);
protected:
virtual void initializeAsset();
virtual void onAssetRefresh(void);
static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<MaterialAsset*>(obj)->setScriptFile(data); return false; }
static const char* getScriptFile(void* obj, const char* data) { return static_cast<MaterialAsset*>(obj)->getScriptFile(); }
};
DefineConsoleType(TypeMaterialAssetPtr, MaterialAsset)
@ -83,18 +90,21 @@ DefineConsoleType(TypeMaterialAssetPtr, MaterialAsset)
//-----------------------------------------------------------------------------
// TypeAssetId GuiInspectorField Class
//-----------------------------------------------------------------------------
class GuiInspectorTypeMaterialAssetPtr : public GuiInspectorTypeFileName
class GuiInspectorTypeMaterialAssetPtr : public GuiInspectorField
{
typedef GuiInspectorTypeFileName Parent;
typedef GuiInspectorField Parent;
public:
GuiBitmapButtonCtrl *mSMEdButton;
GuiControl* mMatEdContainer;
GuiBitmapButtonCtrl *mMatPreviewButton;
GuiTextEditCtrl *mMatAssetIdTxt;
DECLARE_CONOBJECT(GuiInspectorTypeMaterialAssetPtr);
static void consoleInit();
virtual GuiControl* constructEditControl();
virtual bool updateRects();
void setMaterialAsset(String assetId);
};
#endif // _ASSET_BASE_H_

View file

@ -112,7 +112,8 @@ void PostEffectAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addField("scriptFile", TypeString, Offset(mScriptFile, PostEffectAsset), "Path to the script file.");
addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, PostEffectAsset),
&setScriptFile, &getScriptFile, "Path to the script file.");
}
//------------------------------------------------------------------------------
@ -125,5 +126,31 @@ void PostEffectAsset::copyTo(SimObject* object)
void PostEffectAsset::initializeAsset()
{
//mPostEffect = new PostEffect();
}
if (Platform::isFile(mScriptFile))
Con::executeFile(mScriptFile, false, false);
}
void PostEffectAsset::onAssetRefresh()
{
if (Platform::isFile(mScriptFile))
Con::executeFile(mScriptFile, false, false);
}
void PostEffectAsset::setScriptFile(const char* pScriptFile)
{
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
// Fetch image file.
pScriptFile = StringTable->insert(pScriptFile);
// Ignore no change,
if (pScriptFile == mScriptFile)
return;
// Update.
mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile);
// Refresh the asset.
refreshAsset();
}

View file

@ -56,13 +56,18 @@ public:
static void initPersistFields();
virtual void copyTo(SimObject* object);
virtual void initializeAsset();
void setScriptFile(const char* pScriptFile);
inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
/// Declare Console Object.
DECLARE_CONOBJECT(PostEffectAsset);
protected:
virtual void onAssetRefresh(void) {}
virtual void initializeAsset();
virtual void onAssetRefresh(void);
static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<PostEffectAsset*>(obj)->setScriptFile(data); return false; }
static const char* getScriptFile(void* obj, const char* data) { return static_cast<PostEffectAsset*>(obj)->getScriptFile(); }
};
DefineConsoleType(TypePostEffectAssetPtr, PostEffectAsset)

View file

@ -91,7 +91,7 @@ ConsoleSetType(TypeScriptAssetPtr)
ScriptAsset::ScriptAsset() : AssetBase(), mIsServerSide(true)
{
mScriptFilePath = StringTable->EmptyString();
mScriptFile = StringTable->EmptyString();
}
//-----------------------------------------------------------------------------
@ -111,9 +111,8 @@ void ScriptAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addField("scriptFilePath", TypeString, Offset(mScriptFilePath, ScriptAsset), "Path to the script file.");
addField("isServerSide", TypeBool, Offset(mIsServerSide, ScriptAsset), "Is this script file to be run on the server side?");
addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, ScriptAsset),
&setScriptFile, &getScriptFile, "Path to the script file.");
}
//------------------------------------------------------------------------------
@ -124,14 +123,41 @@ void ScriptAsset::copyTo(SimObject* object)
Parent::copyTo(object);
}
void ScriptAsset::initializeAsset()
void ScriptAsset::setScriptFile(const char* pScriptFile)
{
if (Platform::isFile(mScriptFilePath))
Con::executeFile(mScriptFilePath, false, false);
// Sanity!
AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
// Fetch image file.
pScriptFile = StringTable->insert(pScriptFile);
// Ignore no change,
if (pScriptFile == mScriptFile)
return;
// Update.
mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile);
// Refresh the asset.
refreshAsset();
}
void ScriptAsset::onAssetRefresh()
bool ScriptAsset::execScript()
{
if (Platform::isFile(mScriptFilePath))
Con::executeFile(mScriptFilePath, false, false);
}
if (Platform::isFile(mScriptFile))
{
return Con::executeFile(mScriptFile, false, false);
}
else
{
Con::errorf("ScriptAsset:execScript() - Script asset must have a valid file to exec");
return false;
}
}
DefineEngineMethod(ScriptAsset, execScript, bool, (), ,
"Executes the script file.\n"
"@return The bool result of calling exec")
{
return object->execScript();
}

View file

@ -44,7 +44,7 @@ class ScriptAsset : public AssetBase
{
typedef AssetBase Parent;
StringTableEntry mScriptFilePath;
StringTableEntry mScriptFile;
bool mIsServerSide;
public:
@ -58,9 +58,17 @@ public:
/// Declare Console Object.
DECLARE_CONOBJECT(ScriptAsset);
void setScriptFile(const char* pScriptFile);
inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
bool execScript();
protected:
virtual void initializeAsset(void);
virtual void onAssetRefresh(void);
virtual void initializeAsset(void) {}
virtual void onAssetRefresh(void) {}
static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast<ScriptAsset*>(obj)->setScriptFile(data); return false; }
static const char* getScriptFile(void* obj, const char* data) { return static_cast<ScriptAsset*>(obj)->getScriptFile(); }
};
DefineConsoleType(TypeScriptAssetPtr, ScriptAsset)

View file

@ -105,10 +105,6 @@ ShapeAnimationAsset::ShapeAnimationAsset() :
ShapeAnimationAsset::~ShapeAnimationAsset()
{
// If the asset manager does not own the asset then we own the
// asset definition so delete it.
if (!getOwned())
delete mpAssetDefinition;
}
//-----------------------------------------------------------------------------
@ -118,7 +114,9 @@ void ShapeAnimationAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addField("animationFile", TypeFilename, Offset(mFileName, ShapeAnimationAsset), "Path to the file name containing the animation");
addProtectedField("animationFile", TypeAssetLooseFilePath, Offset(mFileName, ShapeAnimationAsset),
&setAnimationFile, &getAnimationFile, "Path to the file name containing the animation");
addField("animationName", TypeString, Offset(mAnimationName, ShapeAnimationAsset), "Name of the animation");
addField("isEmbedded", TypeBool, Offset(mIsEmbedded, ShapeAnimationAsset), "If true, this animation asset just referrs to an embedded animation of a regular shape mesh. If false, it is a self-contained animation file");
@ -172,4 +170,38 @@ void ShapeAnimationAsset::initializeAsset(void)
void ShapeAnimationAsset::onAssetRefresh(void)
{
}
}
void ShapeAnimationAsset::setAnimationFile(const char* pAnimationFile)
{
// Sanity!
AssertFatal(pAnimationFile != NULL, "Cannot use a NULL animation file.");
// Fetch image file.
pAnimationFile = StringTable->insert(pAnimationFile);
// Ignore no change,
if (pAnimationFile == mFileName)
return;
// Update.
mFileName = getOwned() ? expandAssetFilePath(pAnimationFile) : StringTable->insert(pAnimationFile);
// Refresh the asset.
refreshAsset();
}
S32 ShapeAnimationAsset::getAnimationCount()
{
if (mSourceShape == nullptr)
return 0;
return mSourceShape->sequences.size();
}
DefineEngineMethod(ShapeAnimationAsset, getAnimationCount, S32, (), ,
"Gets the number of animations for this shape asset.\n"
"@return Animation count.\n")
{
return object->getAnimationCount();
}

View file

@ -78,6 +78,9 @@ public:
static void initPersistFields();
virtual void copyTo(SimObject* object);
void setAnimationFile(const char* pScriptFile);
inline StringTableEntry getAnimationFile(void) const { return mFileName; };
/// Declare Console Object.
DECLARE_CONOBJECT(ShapeAnimationAsset);
@ -85,6 +88,9 @@ protected:
virtual void initializeAsset(void);
virtual void onAssetRefresh(void);
static bool setAnimationFile(void *obj, const char *index, const char *data) { static_cast<ShapeAnimationAsset*>(obj)->setAnimationFile(data); return false; }
static const char* getAnimationFile(void* obj, const char* data) { return static_cast<ShapeAnimationAsset*>(obj)->getAnimationFile(); }
public:
StringTableEntry getAnimationFilename() { return mFileName; }
StringTableEntry getAnimationName() { return mAnimationName; }
@ -101,6 +107,8 @@ public:
bool isBlend() { return mIsBlend; }
S32 getBlendFrame() { return mBlendFrame; }
S32 getAnimationCount();
};
DefineConsoleType(TypeShapeAnimationAssetPtr, ShapeAnimationAsset)

View file

@ -92,10 +92,6 @@ ShapeAsset::ShapeAsset()
ShapeAsset::~ShapeAsset()
{
// If the asset manager does not own the asset then we own the
// asset definition so delete it.
if (!getOwned())
delete mpAssetDefinition;
}
//-----------------------------------------------------------------------------
@ -105,7 +101,8 @@ void ShapeAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addField("fileName", TypeFilename, Offset(mFileName, ShapeAsset), "Path to the shape file we want to render");
addProtectedField("fileName", TypeAssetLooseFilePath, Offset(mFileName, ShapeAsset),
&setShapeFile, &getShapeFile, "Path to the shape file we want to render");
}
void ShapeAsset::setDataField(StringTableEntry slotName, const char *array, const char *value)
@ -127,7 +124,36 @@ void ShapeAsset::initializeAsset()
// Call parent.
Parent::initializeAsset();
if (dStrcmp(mFileName, "") == 0)
if (mFileName == StringTable->EmptyString())
return;
ResourceManager::get().getChangedSignal().notify(this, &ShapeAsset::_onResourceChanged);
loadShape();
}
void ShapeAsset::setShapeFile(const char* pShapeFile)
{
// Sanity!
AssertFatal(pShapeFile != NULL, "Cannot use a NULL shape file.");
// Fetch image file.
pShapeFile = StringTable->insert(pShapeFile);
// Ignore no change,
if (pShapeFile == mFileName)
return;
// Update.
mFileName = getOwned() ? expandAssetFilePath(pShapeFile) : StringTable->insert(pShapeFile);
// Refresh the asset.
refreshAsset();
}
void ShapeAsset::_onResourceChanged(const Torque::Path &path)
{
if (path != Torque::Path(mFileName) )
return;
loadShape();
@ -152,12 +178,12 @@ bool ShapeAsset::loadShape()
if (assetType == StringTable->insert("MaterialAsset"))
{
mMaterialAssetIds.push_back(assetDependenciesItr->value);
mMaterialAssetIds.push_front(assetDependenciesItr->value);
//Force the asset to become initialized if it hasn't been already
AssetPtr<MaterialAsset> matAsset = assetDependenciesItr->value;
mMaterialAssets.push_back(matAsset);
mMaterialAssets.push_front(matAsset);
}
else if (assetType == StringTable->insert("ShapeAnimationAsset"))
{
@ -227,6 +253,8 @@ bool ShapeAsset::loadShape()
}
}
onShapeChanged.trigger(this);
return true;
}

View file

@ -95,16 +95,40 @@ public:
Resource<TSShape> getShapeResource() { return mShape; }
void SplitSequencePathAndName(String& srcPath, String& srcName);
String getShapeFilename() { return mFileName; }
StringTableEntry getShapeFilename() { return mFileName; }
U32 getShapeFilenameHash() { return _StringTable::hashString(mFileName); }
Vector<AssetPtr<MaterialAsset>> getMaterialAssets() { return mMaterialAssets; }
inline AssetPtr<MaterialAsset> getMaterialAsset(U32 matId)
{
if(matId >= mMaterialAssets.size())
return nullptr;
else
return mMaterialAssets[matId];
}
void clearMaterialAssets() { mMaterialAssets.clear(); }
void addMaterialAssets(AssetPtr<MaterialAsset> matPtr) { mMaterialAssets.push_back(matPtr); }
S32 getMaterialCount() { return mMaterialAssets.size(); }
S32 getAnimationCount() { return mAnimationAssets.size(); }
ShapeAnimationAsset* getAnimation(S32 index);
void _onResourceChanged(const Torque::Path &path);
Signal< void(ShapeAsset*) > onShapeChanged;
void setShapeFile(const char* pScriptFile);
inline StringTableEntry getShapeFile(void) const { return mFileName; };
protected:
virtual void onAssetRefresh(void);
static bool setShapeFile(void *obj, const char *index, const char *data) { static_cast<ShapeAsset*>(obj)->setShapeFile(data); return false; }
static const char* getShapeFile(void* obj, const char* data) { return static_cast<ShapeAsset*>(obj)->getShapeFile(); }
};
DefineConsoleType(TypeShapeAssetPtr, S32)

View file

@ -92,7 +92,7 @@ ConsoleSetType(TypeSoundAssetPtr)
SoundAsset::SoundAsset()
{
mSoundFilePath = StringTable->EmptyString();
mSoundFile = StringTable->EmptyString();
mPitchAdjust = 0;
mVolumeAdjust = 0;
@ -117,7 +117,8 @@ void SoundAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addField("soundFilePath", TypeFilename, Offset(mSoundFilePath, SoundAsset), "Path to the sound file.");
addProtectedField("soundFile", TypeAssetLooseFilePath, Offset(mSoundFile, SoundAsset),
&setSoundFile, &getSoundFile, "Path to the sound file.");
addField("pitchAdjust", TypeF32, Offset(mPitchAdjust, SoundAsset), "Adjustment of the pitch value");
addField("volumeAdjust", TypeF32, Offset(mVolumeAdjust, SoundAsset), "Adjustment to the volume.");
@ -138,4 +139,23 @@ void SoundAsset::initializeAsset(void)
void SoundAsset::onAssetRefresh(void)
{
}
}
void SoundAsset::setSoundFile(const char* pSoundFile)
{
// Sanity!
AssertFatal(pSoundFile != NULL, "Cannot use a NULL shape file.");
// Fetch image file.
pSoundFile = StringTable->insert(pSoundFile);
// Ignore no change,
if (pSoundFile == mSoundFile)
return;
// Update.
mSoundFile = getOwned() ? expandAssetFilePath(pSoundFile) : StringTable->insert(pSoundFile);
// Refresh the asset.
refreshAsset();
}

View file

@ -47,7 +47,7 @@ class SoundAsset : public AssetBase
typedef AssetBase Parent;
protected:
StringTableEntry mSoundFilePath;
StringTableEntry mSoundFile;
F32 mPitchAdjust;
F32 mVolumeAdjust;
@ -62,11 +62,15 @@ public:
/// Declare Console Object.
DECLARE_CONOBJECT(SoundAsset);
StringTableEntry getSoundFilePath() { return mSoundFilePath; }
void setSoundFile(const char* pScriptFile);
inline StringTableEntry getSoundFile(void) const { return mSoundFile; };
protected:
virtual void initializeAsset(void);
virtual void onAssetRefresh(void);
static bool setSoundFile(void *obj, const char *index, const char *data) { static_cast<SoundAsset*>(obj)->setSoundFile(data); return false; }
static const char* getSoundFile(void* obj, const char* data) { return static_cast<SoundAsset*>(obj)->getSoundFile(); }
};
DefineConsoleType(TypeSoundAssetPtr, SoundAsset)

View file

@ -92,7 +92,7 @@ ConsoleSetType(TypeStateMachineAssetPtr)
StateMachineAsset::StateMachineAsset()
{
mStateMachineFileName = StringTable->EmptyString();
mStateMachineFile = StringTable->EmptyString();
}
//-----------------------------------------------------------------------------
@ -112,7 +112,8 @@ void StateMachineAsset::initPersistFields()
// Call parent.
Parent::initPersistFields();
addField("stateMachineFile", TypeString, Offset(mStateMachineFileName, StateMachineAsset), "Path to the state machine file.");
addProtectedField("stateMachineFile", TypeAssetLooseFilePath, Offset(mStateMachineFile, StateMachineAsset),
&setStateMachineFile, &getStateMachineFile, "Path to the state machine file.");
}
//------------------------------------------------------------------------------
@ -123,9 +124,29 @@ void StateMachineAsset::copyTo(SimObject* object)
Parent::copyTo(object);
}
void StateMachineAsset::setStateMachineFile(const char* pStateMachineFile)
{
// Sanity!
AssertFatal(pStateMachineFile != NULL, "Cannot use a NULL state machine file.");
// Fetch image file.
pStateMachineFile = StringTable->insert(pStateMachineFile);
// Ignore no change,
if (pStateMachineFile == mStateMachineFile)
return;
// Update.
mStateMachineFile = getOwned() ? expandAssetFilePath(pStateMachineFile) : StringTable->insert(pStateMachineFile);
// Refresh the asset.
refreshAsset();
}
DefineEngineMethod(StateMachineAsset, notifyAssetChanged, void, (),,"")
{
ResourceManager::get().getChangedSignal().trigger(object->getStateMachineFileName());
ResourceManager::get().getChangedSignal().trigger(object->getStateMachineFile());
}
//-----------------------------------------------------------------------------

View file

@ -46,7 +46,7 @@ class StateMachineAsset : public AssetBase
{
typedef AssetBase Parent;
StringTableEntry mStateMachineFileName;
StringTableEntry mStateMachineFile;
public:
StateMachineAsset();
@ -59,11 +59,15 @@ public:
/// Declare Console Object.
DECLARE_CONOBJECT(StateMachineAsset);
StringTableEntry getStateMachineFileName() { return mStateMachineFileName; }
void setStateMachineFile(const char* pStateMachineFile);
inline StringTableEntry getStateMachineFile(void) const { return mStateMachineFile; };
protected:
virtual void initializeAsset(void) {}
virtual void onAssetRefresh(void) {}
static bool setStateMachineFile(void *obj, const char *index, const char *data) { static_cast<StateMachineAsset*>(obj)->setStateMachineFile(data); return false; }
static const char* getStateMachineFile(void* obj, const char* data) { return static_cast<StateMachineAsset*>(obj)->getStateMachineFile(); }
};
DefineConsoleType(TypeStateMachineAssetPtr, StateMachineAsset)

View file

@ -124,6 +124,7 @@ Entity::Entity()
mGameObjectAssetId = StringTable->insert("");
mDirtyGameObject = false;
}
Entity::~Entity()
@ -156,8 +157,11 @@ void Entity::initPersistFields()
endGroup("Misc");
addGroup("GameObject");
addProtectedField("gameObjectName", TypeGameObjectAssetPtr, Offset(mGameObjectAsset, Entity), &_setGameObject, &defaultProtectedGetFn,
addProtectedField("GameObject", TypeGameObjectAssetPtr, Offset(mGameObjectAsset, Entity), &_setGameObject, &defaultProtectedGetFn,
"The asset Id used for the game object this entity is based on.");
addField("dirtyGameObject", TypeBool, Offset(mDirtyGameObject, Entity), "If this entity is a GameObject, it flags if this instance delinates from the template.",
AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
endGroup("GameObject");
}

View file

@ -85,6 +85,9 @@ private:
StringTableEntry mGameObjectAssetId;
AssetPtr<GameObjectAsset> mGameObjectAsset;
//Marked if this entity is a GameObject and deliniates from the parent GO asset
bool mDirtyGameObject;
ContainerQueryInfo containerInfo;
bool mInitialized;

View file

@ -60,6 +60,10 @@ mAssetInitialized(false)
{
// Generate an asset definition.
mpAssetDefinition = new AssetDefinition();
mInternalName = StringTable->EmptyString();
mClassName = StringTable->EmptyString();
mSuperClassName = StringTable->EmptyString();
}
//-----------------------------------------------------------------------------

View file

@ -243,7 +243,7 @@ function ChooseLevelDlg::addLevelAsset( %this, %levelAsset )
%LevelInfoObject.delete();
}*/
%levelName = %levelAsset.friendlyName;
%levelName = %levelAsset.LevelName;
%levelDesc = %levelAsset.description;
%levelPreview = %levelAsset.levelPreviewImage;

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

@ -1,18 +1,34 @@
<AssetImportConfigs>
<Config Name="TestConfig">
<Mesh ImportMesh="1" DoUpAxisOverride="0" UpAxisOverride="Z_AXIS" DoScaleOverride="0" ScaleOverride="1" IgnoreNodeScale="0" AdjustCenter="0" AdjustFloor="1" CollapseSubmeshes="0" LODType="TrailingNumber" ImportedNodes="" IgnoreNodes="" ImportMeshes="" IgnoreMeshes="" />
<Materials ImportMaterials="1" CreateComposites="1" UseDiffuseSuffixOnOriginImg="1" UseExistingMaterials="1" />
<Materials ImportMaterials="1" IgnoreMaterials="" CreateComposites="1" UseDiffuseSuffixOnOriginImg="1" UseExistingMaterials="1" />
<Animations ImportAnimations="1" SeparateAnimations="1" SeparateAnimationPrefix="" />
<Collisions GenerateCollisions="1" GenCollisionType="CollisionMesh" CollisionMeshPrefix="Col" GenerateLOSCollisions="1" GenLOSCollisionType="CollisionMesh" LOSCollisionMeshPrefix="LOS" />
<Images ImageType="N/A" DiffuseTypeSuffixes="_ALBEDO,_DIFFUSE,_ALB,_DIF,_COLOR,_COL" NormalTypeSuffixes="_NORMAL,_NORM" SpecularTypeSuffixes="_SPECULAR,_SPEC" MetalnessTypeSuffixes="_METAL,_MET,_METALNESS,_METALLIC" RoughnessTypeSuffixes="_ROUGH,_ROUGHNESS" SmoothnessTypeSuffixes="_SMOOTH,_SMOOTHNESS" AOTypeSuffixes="_AO,_AMBIENT,_AMBIENTOCCLUSION" CompositeTypeSuffixes="_COMP,_COMPOSITE" TextureFilteringMode="Bilinear" UseMips="1" IsHDR="0" Scaling="1" Compressed="0" GenerateMaterialOnImport="1" PopulateMaterialMaps="1" />
<Images ImageType="GUI" DiffuseTypeSuffixes="_ALBEDO,_DIFFUSE,_ALB,_DIF,_Base_Color,_COLOR,_COL" NormalTypeSuffixes="_NORMAL,_NORM" SpecularTypeSuffixes="_SPECULAR,_SPEC" MetalnessTypeSuffixes="_METAL,_MET,_METALNESS,_METALLIC" RoughnessTypeSuffixes="_ROUGH,_ROUGHNESS" SmoothnessTypeSuffixes="_SMOOTH,_SMOOTHNESS" AOTypeSuffixes="_AO,_AMBIENT,_AMBIENTOCCLUSION,_Ambient_Occlusion" CompositeTypeSuffixes="_COMP,_COMPOSITE" TextureFilteringMode="Bilinear" UseMips="1" IsHDR="0" Scaling="1" Compressed="0" GenerateMaterialOnImport="1" PopulateMaterialMaps="1" />
<Sounds VolumeAdjust="1" PitchAdjust="1" Compressed="0" />
</Config>
<Config Name="SecondTest">
<Mesh ImportMesh="1" DoUpAxisOverride="0" UpAxisOverride="Z_AXIS" DoScaleOverride="0" ScaleOverride="1" IgnoreNodeScale="0" AdjustCenter="0" AdjustFloor="0" CollapseSubmeshes="0" LODType="TrailingNumber" ImportedNodes="" IgnoreNodes="" ImportMeshes="" IgnoreMeshes="" />
<Materials ImportMaterials="1" CreateComposites="1" UseDiffuseSuffixOnOriginImg="" UseExistingMaterials="" />
<Materials ImportMaterials="1" IgnoreMaterials="" CreateComposites="1" UseDiffuseSuffixOnOriginImg="" UseExistingMaterials="" />
<Animations ImportAnimations="1" SeparateAnimations="1" SeparateAnimationPrefix="" />
<Collisions GenerateCollisions="1" GenCollisionType="CollisionMesh" CollisionMeshPrefix="Col" GenerateLOSCollisions="1" GenLOSCollisionType="CollisionMesh" LOSCollisionMeshPrefix="LOS" />
<Images ImageType="N/A" DiffuseTypeSuffixes="_ALBEDO,_DIFFUSE,_ALB,_DIF,_COLOR,_COL" NormalTypeSuffixes="_NORMAL,_NORM" SpecularTypeSuffixes="_SPECULAR,_SPEC" MetalnessTypeSuffixes="_METAL,_MET,_METALNESS,_METALLIC" RoughnessTypeSuffixes="_ROUGH,_ROUGHNESS" SmoothnessTypeSuffixes="_SMOOTH,_SMOOTHNESS" AOTypeSuffixes="_AO,_AMBIENT,_AMBIENTOCCLUSION" CompositeTypeSuffixes="_COMP,_COMPOSITE" TextureFilteringMode="Bilinear" UseMips="1" IsHDR="0" Scaling="1" Compressed="0" GenerateMaterialOnImport="" PopulateMaterialMaps="" />
<Sounds VolumeAdjust="1" PitchAdjust="1" Compressed="0" />
</Config>
<Config Name="GUI_Image_Import">
<Mesh ImportMesh="0" DoUpAxisOverride="0" UpAxisOverride="Z_AXIS" DoScaleOverride="0" ScaleOverride="1" IgnoreNodeScale="0" AdjustCenter="0" AdjustFloor="0" CollapseSubmeshes="0" LODType="TrailingNumber" ImportedNodes="" IgnoreNodes="" ImportMeshes="" IgnoreMeshes="" />
<Materials ImportMaterials="0" IgnoreMaterials="" CreateComposites="1" UseDiffuseSuffixOnOriginImg="1" UseExistingMaterials="1" />
<Animations ImportAnimations="0" SeparateAnimations="1" SeparateAnimationPrefix="" />
<Collisions GenerateCollisions="0" GenCollisionType="CollisionMesh" CollisionMeshPrefix="Col" GenerateLOSCollisions="1" GenLOSCollisionType="CollisionMesh" LOSCollisionMeshPrefix="LOS" />
<Images ImageType="GUI" DiffuseTypeSuffixes="_ALBEDO;_DIFFUSE;_ALB;_DIF;_COLOR;_COL;_BASECOLOR;_BASE_COLOR" NormalTypeSuffixes="_NORMAL;_NORM" SpecularTypeSuffixes="_SPECULAR;_SPEC" MetalnessTypeSuffixes="_METAL;_MET;_METALNESS;_METALLIC" RoughnessTypeSuffixes="_ROUGH;_ROUGHNESS" SmoothnessTypeSuffixes="_SMOOTH;_SMOOTHNESS" AOTypeSuffixes="_AO;_AMBIENT;_AMBIENTOCCLUSION" CompositeTypeSuffixes="_COMP;_COMPOSITE" TextureFilteringMode="Bilinear" UseMips="1" IsHDR="0" Scaling="1" Compressed="0" GenerateMaterialOnImport="0" PopulateMaterialMaps="0" />
<Sounds VolumeAdjust="1" PitchAdjust="1" Compressed="0" />
</Config>
<Config Name="CogflictsMesh">
<Mesh ImportMesh="1" DoUpAxisOverride="0" UpAxisOverride="Z_AXIS" DoScaleOverride="0" ScaleOverride="1" IgnoreNodeScale="0" AdjustCenter="0" AdjustFloor="0" CollapseSubmeshes="0" LODType="TrailingNumber" ImportedNodes="" IgnoreNodes="" ImportMeshes="" IgnoreMeshes="" />
<Materials ImportMaterials="1" IgnoreMaterials="ColorEffect*;" CreateComposites="1" UseDiffuseSuffixOnOriginImg="1" UseExistingMaterials="1" />
<Animations ImportAnimations="1" SeparateAnimations="1" SeparateAnimationPrefix="" />
<Collisions GenerateCollisions="1" GenCollisionType="CollisionMesh" CollisionMeshPrefix="Col" GenerateLOSCollisions="1" GenLOSCollisionType="CollisionMesh" LOSCollisionMeshPrefix="LOS" />
<Images ImageType="N/A" DiffuseTypeSuffixes="_ALBEDO;_DIFFUSE;_ALB;_DIF;_COLOR;_COL;_BASECOLOR;_BASE_COLOR;_Al" NormalTypeSuffixes="_NORMAL;_NORM;_N" SpecularTypeSuffixes="_SPECULAR;_SPEC" MetalnessTypeSuffixes="_METAL;_MET;_METALNESS;_METALLIC" RoughnessTypeSuffixes="_ROUGH;_ROUGHNESS" SmoothnessTypeSuffixes="_SMOOTH;_SMOOTHNESS" AOTypeSuffixes="_AO;_AMBIENT;_AMBIENTOCCLUSION" CompositeTypeSuffixes="_COMP;_COMPOSITE;_C" TextureFilteringMode="Bilinear" UseMips="1" IsHDR="0" Scaling="1" Compressed="0" GenerateMaterialOnImport="1" PopulateMaterialMaps="1" />
<Sounds VolumeAdjust="1" PitchAdjust="1" Compressed="0" />
</Config>
</AssetImportConfigs>

View file

@ -13,15 +13,15 @@
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "1";
AddNewArtAssetPopup = "18801";
AddNewAssetPopup = "18802";
AddNewScriptAssetPopup = "18800";
AddNewArtAssetPopup = "18222";
AddNewAssetPopup = "18223";
AddNewScriptAssetPopup = "18221";
coreModulesFilter = "0";
currentPreviewPage = "0";
enabled = "1";
importAssetFinalListArray = "20465";
importAssetNewListArray = "20463";
importAssetUnprocessedListArray = "20464";
isReImportingAsset = "0";
totalPages = "1";
treeFilterMode = "list";
new GuiWindowCtrl(AssetBrowser_addFilterWindow) {
text = "Create New Tag";
@ -400,7 +400,7 @@
canSaveDynamicFields = "0";
};
new GuiBitmapButtonCtrl() {
bitmap = "tools/gui/images/iconNew.png";
bitmap = "tools/gui/images/visible";
bitmapMode = "Stretched";
autoFitExtents = "0";
useModifiers = "0";
@ -409,41 +409,15 @@
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "113 1";
extent = "15 15";
position = "128 -1";
extent = "18 19";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
command = "AssetBrowser.viewTagsFilter();";
tooltipProfile = "GuiToolTipProfile";
tooltip = "Show assets grouped and filtered via tags.";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiBitmapButtonCtrl() {
bitmap = "tools/gui/images/iconList.png";
bitmapMode = "Stretched";
autoFitExtents = "0";
useModifiers = "0";
useStates = "1";
masked = "0";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "130 1";
extent = "15 15";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
command = "AssetBrowser.viewListFilter();";
command = "AssetBrowser.showFilterPopup();";
tooltipProfile = "GuiToolTipProfile";
tooltip = "Views assets via module-oriented list tree.";
hovertime = "1000";
@ -526,7 +500,7 @@
canRenameObjects = "1";
renameInternal = "0";
position = "1 1";
extent = "145 294";
extent = "145 252";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
@ -897,13 +871,14 @@
horizSizing = "left";
vertSizing = "top";
profile = "ToolsGuiButtonProfile";
visible = "1";
visible = "0";
active = "1";
command = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
internalName = "SelectButton";
hidden = "1";
canSave = "1";
canSaveDynamicFields = "0";
};

View file

@ -30,7 +30,7 @@
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "633 358";
position = "339 179";
extent = "346 409";
minExtent = "48 92";
horizSizing = "center";
@ -138,7 +138,7 @@
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "562 251";
position = "324 132";
extent = "376 503";
minExtent = "48 92";
horizSizing = "center";
@ -296,8 +296,8 @@
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "536 205";
extent = "368 502";
position = "140 98";
extent = "733 502";
minExtent = "48 92";
horizSizing = "center";
vertSizing = "center";
@ -315,7 +315,7 @@
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "224 470";
position = "589 470";
extent = "64 22";
minExtent = "8 2";
horizSizing = "left";
@ -335,7 +335,7 @@
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "292 470";
position = "657 470";
extent = "64 22";
minExtent = "8 2";
horizSizing = "left";
@ -343,7 +343,7 @@
profile = "ToolsGuiButtonProfile";
visible = "1";
active = "1";
command = "Canvas.popDialog();";
command = "ImportAssetWindow.close();";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
@ -364,7 +364,7 @@
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiTextProfile";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
@ -387,7 +387,7 @@
anchorLeft = "1";
anchorRight = "0";
position = "134 27";
extent = "204 22";
extent = "569 22";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "bottom";
@ -410,7 +410,7 @@
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "342 27";
position = "707 27";
extent = "22 22";
minExtent = "8 2";
horizSizing = "left";
@ -463,7 +463,7 @@
anchorLeft = "1";
anchorRight = "0";
position = "126 53";
extent = "175 22";
extent = "540 22";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "bottom";
@ -486,7 +486,7 @@
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "305 53";
position = "670 53";
extent = "15 22";
minExtent = "8 2";
horizSizing = "left";
@ -512,7 +512,7 @@
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "325 53";
position = "690 53";
extent = "15 22";
minExtent = "8 2";
horizSizing = "left";
@ -538,7 +538,7 @@
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "346 53";
position = "711 53";
extent = "15 22";
minExtent = "8 2";
horizSizing = "left";
@ -570,7 +570,7 @@
anchorLeft = "1";
anchorRight = "0";
position = "9 82";
extent = "348 381";
extent = "713 381";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "height";
@ -594,7 +594,7 @@
changeChildSizeToFit = "0";
changeChildPosition = "1";
position = "1 1";
extent = "345 20";
extent = "710 20";
minExtent = "16 16";
horizSizing = "width";
vertSizing = "bottom";

View file

@ -112,7 +112,7 @@
profile = "ToolsGuiButtonProfile";
visible = "1";
active = "1";
command = "Canvas.popDialog(AssetBrowser_SelectModule);";
command = "AssetBrowser_SelectModule.moduleSelected();";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "0";

View file

@ -38,6 +38,7 @@ function initializeAssetBrowser()
exec("./guis/assetImport.gui");
exec("./guis/selectModule.gui");
exec("./guis/editModule.gui");
exec("./guis/importTemplateModules.gui");
exec("./scripts/assetBrowser.cs");
exec("./scripts/popupMenus.cs");
@ -48,7 +49,23 @@ function initializeAssetBrowser()
exec("./scripts/newAsset.cs");
exec("./scripts/editAsset.cs");
exec("./scripts/editModule.cs");
exec("./scripts/selectModule.cs");
//Processing for the different asset types
exec("./scripts/assetTypes/component.cs");
exec("./scripts/assetTypes/cpp.cs");
exec("./scripts/assetTypes/gameObject.cs");
exec("./scripts/assetTypes/gui.cs");
exec("./scripts/assetTypes/image.cs");
exec("./scripts/assetTypes/level.cs");
exec("./scripts/assetTypes/material.cs");
exec("./scripts/assetTypes/postFX.cs");
exec("./scripts/assetTypes/script.cs");
exec("./scripts/assetTypes/shape.cs");
exec("./scripts/assetTypes/shapeAnimation.cs");
exec("./scripts/assetTypes/sound.cs");
exec("./scripts/assetTypes/stateMachine.cs");
exec("./scripts/fieldTypes.cs");
new ScriptObject( AssetBrowserPlugin )

View file

@ -57,6 +57,18 @@ function AssetBrowser_addModuleWindow::CreateNewModule(%this)
Extension = "asset.taml";
Recurse = true;
};
//Autoload the usual suspects
new AutoloadAssets()
{
AssetType = "ComponentAsset";
Recurse = true;
};
new AutoloadAssets()
{
AssetType = "GUIAsset";
Recurse = true;
};
};
TAMLWrite(%newModule, %moduleDefinitionFilePath);

View file

@ -1,4 +1,3 @@
new SimGroup(AssetBrowserPreviewCache);
//AssetBrowser.addToolbarButton
@ -34,14 +33,84 @@ function AssetBrowser::addToolbarButton(%this)
//
function AssetBrowser::onAdd(%this)
{
%this.isReImportingAsset = false;
}
function AssetBrowser::onWake(%this)
{
%this.importAssetNewListArray = new ArrayObject();
// manage preview array
if(!isObject(AssetPreviewArray))
new ArrayObject(AssetPreviewArray);
if(!isObject(ImportAssetTree))
new GuiTreeViewCtrl(ImportAssetTree);
%this.importingFilesArray = new ArrayObject();
%this.importAssetUnprocessedListArray = new ArrayObject();
%this.importAssetFinalListArray = new ArrayObject();
%this.isReImportingAsset = false;
%this.coreModulesFilter = false;
%this.onlyShowModulesWithAssets = false;
%this.treeFilterMode = "list";
//First, build our our list of active modules
%modulesList = ModuleDatabase.findModules(true);
%nonDefaultModuleCount = 0;
for(%i=0; %i < getWordCount(%modulesList); %i++)
{
%moduleName = getWord(%modulesList, %i).ModuleId;
%moduleGroup = getWord(%modulesList, %i).Group;
if((%moduleGroup $= "Core" || %moduleGroup $= "Tools") && !%this.coreModulesFilter)
continue;
%nonDefaultModuleCount++;
}
if(%nonDefaultModuleCount == 0)
{
MessageBoxYesNo( "Import Template Content?",
"You have no modules or content. Do you want to import a module from the template content?",
"AssetBrowser.ImportTemplateModules();", "" );
}
}
//Filters
function AssetBrowser::showFilterPopup(%this)
{
BrowserVisibilityPopup.showPopup(Canvas);
}
function AssetBrowser::viewCoreModulesFilter(%this)
{
%this.coreModulesFilter = !%this.coreModulesFilter;
BrowserVisibilityPopup.checkItem(0,%this.coreModulesFilter);
AssetBrowser.loadFilters();
}
function AssetBrowser::viewPopulatedModulesFilter(%this)
{
%this.onlyShowModulesWithAssets = !%this.onlyShowModulesWithAssets;
BrowserVisibilityPopup.checkItem(1,%this.onlyShowModulesWithAssets);
AssetBrowser.loadFilters();
}
function AssetBrowser::viewListFilter(%this)
{
%this.treeFilterMode = "list";
AssetBrowser.loadFilters();
}
function AssetBrowser::viewTagsFilter(%this)
{
%this.treeFilterMode = "tags";
AssetBrowser.loadFilters();
}
//Drag-Drop functionality
@ -113,6 +182,11 @@ function AssetBrowser::hideDialog( %this )
function AssetBrowser::buildPreviewArray( %this, %asset, %moduleName )
{
if(!isObject(%this.previewData))
{
%this.previewData = new ScriptObject();
}
%assetDesc = AssetDatabase.acquireAsset(%asset);
%assetName = AssetDatabase.getAssetName(%asset);
%previewImage = "core/art/warnmat";
@ -142,8 +216,20 @@ function AssetBrowser::buildPreviewArray( %this, %asset, %moduleName )
%tooltip = %assetName;
%doubleClickCommand = "AssetBrowser.editAsset( "@%assetDesc@" );";
if(%assetType $= "ShapeAsset")
{
%this.previewData.assetName = %assetDesc.assetName;
%this.previewData.assetPath = %assetDesc.scriptFile;
%this.previewData.doubleClickCommand = %doubleClickCommand;
%this.previewData.previewImage = "tools/assetBrowser/art/componentIcon";
%this.previewData.assetFriendlyName = %assetDesc.friendlyName;
%this.previewData.assetDesc = %assetDesc.description;
%this.previewData.tooltip = %assetDesc.friendlyName @ "\n" @ %assetDesc;
%previewButton = new GuiObjectView()
{
className = "AssetPreviewControl";
@ -218,111 +304,21 @@ function AssetBrowser::buildPreviewArray( %this, %asset, %moduleName )
}
else
{
if(%assetType $= "ComponentAsset")
{
%assetPath = "data/" @ %moduleName @ "/components/" @ %assetName @ ".cs";
%doubleClickCommand = "EditorOpenFileInTorsion( "@%assetPath@", 0 );";
%previewImage = "tools/assetBrowser/art/componentIcon";
%assetFriendlyName = %assetDesc.friendlyName;
%assetDesc = %assetDesc.description;
%tooltip = %assetFriendlyName @ "\n" @ %assetDesc;
}
else if(%assetType $= "GameObjectAsset")
{
%assetPath = "data/" @ %moduleName @ "/gameObjects/" @ %assetName @ ".cs";
%doubleClickCommand = "EditorOpenFileInTorsion( "@%assetPath@", 0 );";
%previewImage = "tools/assetBrowser/art/gameObjectIcon";
%tooltip = %assetDesc.gameObjectName;
}
else if(%assetType $= "ImageAsset")
{
//nab the image and use it for the preview
%assetQuery = new AssetQuery();
%numAssetsFound = AssetDatabase.findAllAssets(%assetQuery);
for( %i=0; %i < %numAssetsFound; %i++)
{
%assetId = %assetQuery.getAsset(%i);
%name = AssetDatabase.getAssetName(%assetId);
if(%name $= %assetName)
{
%asset = AssetDatabase.acquireAsset(%assetId);
%previewImage = %asset.imageFile;
break;
}
}
}
else if(%assetType $= "StateMachineAsset")
{
%previewImage = "tools/assetBrowser/art/stateMachineIcon";
}
else if(%assetType $= "SoundAsset")
{
%previewImage = "tools/assetBrowser/art/soundIcon";
}
else if(%assetType $= "LevelAsset")
{
%previewImage = "tools/assetBrowser/art/levelIcon";
}
else if(%assetType $= "PostEffectAsset")
{
%previewImage = "tools/assetBrowser/art/postEffectIcon";
}
else if(%assetType $= "GUIAsset")
{
%previewImage = "tools/assetBrowser/art/guiIcon";
}
else if(%assetType $= "ScriptAsset")
{
if(%assetDesc.isServerSide)
%previewImage = "tools/assetBrowser/art/serverScriptIcon";
else
%previewImage = "tools/assetBrowser/art/clientScriptIcon";
}
else if(%assetType $= "MaterialAsset")
{
%previewImage = "";
//nab the image and use it for the preview
%assetQuery = new AssetQuery();
%numAssetsFound = AssetDatabase.findAllAssets(%assetQuery);
for( %i=0; %i < %numAssetsFound; %i++)
{
%assetId = %assetQuery.getAsset(%i);
%name = AssetDatabase.getAssetName(%assetId);
if(%name $= %assetName)
{
%asset = AssetDatabase.acquireAsset(%assetId);
%previewImage = %asset.materialDefinitionName.diffuseMap[0];
break;
}
}
if(%previewImage $= "")
%previewImage = "tools/assetBrowser/art/materialIcon";
}
if(%assetType $= "ShapeAnimationAsset")
{
%previewImage = "tools/assetBrowser/art/animationIcon";
}
//Build out the preview
%buildCommand = %this @ ".build" @ %assetType @ "Preview(" @ %assetDesc @ "," @ %this.previewData @ ");";
eval(%buildCommand);
%previewButton = new GuiBitmapButtonCtrl()
{
className = "AssetPreviewControl";
internalName = %assetName;
internalName = %this.previewData.assetName;
HorizSizing = "right";
VertSizing = "bottom";
profile = "ToolsGuiButtonProfile";
position = "10 4";
extent = %previewSize;
buttonType = "PushButton";
bitmap = %previewImage;
bitmap = %this.previewData.previewImage;
Command = "";
text = "";
useStates = false;
@ -345,7 +341,7 @@ function AssetBrowser::buildPreviewArray( %this, %asset, %moduleName )
%previewBorder = new GuiButtonCtrl(){
class = "AssetPreviewButton";
internalName = %assetName@"Border";
internalName = %this.previewData.assetName@"Border";
HorizSizing = "right";
VertSizing = "bottom";
profile = "ToolsGuiThumbHighlightButtonProfile";
@ -353,21 +349,21 @@ function AssetBrowser::buildPreviewArray( %this, %asset, %moduleName )
extent = %previewSize.x + %previewBounds SPC %previewSize.y + 24;
Variable = "";
buttonType = "radioButton";
tooltip = %tooltip;
tooltip = %this.previewData.tooltip;
Command = "AssetBrowser.updateSelection( $ThisControl.getParent().assetName, $ThisControl.getParent().moduleName );";
altCommand = %doubleClickCommand;
altCommand = %this.previewData.doubleClickCommand;
groupNum = "0";
useMouseEvents = true;
text = "";
icon = %previewImage;
icon = %this.previewData.previewImage;
};
%previewNameCtrl = new GuiTextEditCtrl(){
position = 0 SPC %previewSize.y + %previewBounds - 16;
profile = ToolsGuiTextEditCenterProfile;
extent = %previewSize.x + %previewBounds SPC 16;
text = %assetName;
originalAssetName = %assetName; //special internal field used in renaming assets
text = %this.previewData.assetName;
originalAssetName = %this.previewData.assetName; //special internal field used in renaming assets
internalName = "AssetNameLabel";
class = "AssetNameField";
active = false;
@ -381,32 +377,7 @@ function AssetBrowser::buildPreviewArray( %this, %asset, %moduleName )
AssetBrowser-->materialSelection.add(%container);
// add to the array object for reference later
AssetPreviewArray.add( %previewButton, %previewImage );
}
function AssetBrowser::loadImages( %this, %materialNum )
{
// this will save us from spinning our wheels in case we don't exist
/*if( !AssetBrowser.visible )
return;
// this schedule is here to dynamically load images
%previewButton = AssetPreviewArray.getKey(%materialNum);
%previewImage = AssetPreviewArray.getValue(%materialNum);
if(%previewButton.getClassName() !$= "GuiObjectView")
{
%previewButton.setBitmap(%previewImage);
%previewButton.setText("");
}
%materialNum++;
/*if( %materialNum < AssetPreviewArray.count() )
{
%tempSchedule = %this.schedule(64, "loadImages", %materialNum);
MatEdScheduleArray.add( %tempSchedule, %materialNum );
}*/
AssetPreviewArray.add( %previewButton, %this.previewData.previewImage );
}
function AssetBrowser::loadFilters( %this )
@ -417,62 +388,91 @@ function AssetBrowser::loadFilters( %this )
AssetBrowser-->filterTree.insertItem(0, "Assets");
//First, build our our list of active modules
%modulesList = ModuleDatabase.findModules(true);
AssetPreviewArray.empty();
for(%i=0; %i < getWordCount(%modulesList); %i++)
if(%this.treeFilterMode $= "list")
{
%moduleName = getWord(%modulesList, %i).ModuleId;
//First, build our our list of active modules
%modulesList = ModuleDatabase.findModules(true);
%moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName);
if(%moduleItemId == 0)
%moduleItemId = AssetBrowser-->filterTree.insertItem(1, %moduleName, "", "", 1, 1);
}
for(%i=0; %i < getWordCount(%modulesList); %i++)
{
%moduleName = getWord(%modulesList, %i).ModuleId;
%moduleGroup = getWord(%modulesList, %i).Group;
if((%moduleGroup $= "Core" || %moduleGroup $= "Tools") && !%this.coreModulesFilter)
continue;
%moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName);
if(%moduleItemId == 0)
%moduleItemId = AssetBrowser-->filterTree.insertItem(1, %moduleName, "", "", 1, 1);
}
//Next, go through and list the asset categories
%assetQuery = new AssetQuery();
%numAssetsFound = AssetDatabase.findAllAssets(%assetQuery);
for( %i=0; %i < %numAssetsFound; %i++)
//Next, go through and list the asset categories
%assetQuery = new AssetQuery();
%numAssetsFound = AssetDatabase.findAllAssets(%assetQuery);
for( %i=0; %i < %numAssetsFound; %i++)
{
%assetId = %assetQuery.getAsset(%i);
//first, get the asset's module, as our major categories
%module = AssetDatabase.getAssetModule(%assetId);
%moduleName = %module.moduleId;
%moduleGroup = %module.Group;
if((%moduleGroup $= "Core" || %moduleGroup $= "Tools") && !%this.coreModulesFilter)
continue;
//first, see if this module Module is listed already
%moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName);
if(%moduleItemId == 0)
%moduleItemId = AssetBrowser-->filterTree.insertItem(1, %moduleName, "", "", 1, 1);
%assetType = AssetDatabase.getAssetCategory(%assetId);
if(%assetType $= "")
{
%assetType = AssetDatabase.getAssetType(%assetId);
if(%assetType $= "")
%assetType = "Misc";
}
if(AssetBrowser.assetTypeFilter !$= "" && AssetBrowser.assetTypeFilter !$= %assetType)
continue;
%assetTypeId = AssetBrowser-->filterTree.findChildItemByName(%moduleItemId, %assetType);
if(%assetTypeId == 0)
%assetTypeId = AssetBrowser-->filterTree.insertItem(%moduleItemId, %assetType);
}
AssetBrowser-->filterTree.buildVisibleTree(true);
}
else if(%this.treeFilterMode $= "tags")
{
%assetId = %assetQuery.getAsset(%i);
//first, get the asset's module, as our major categories
%module = AssetDatabase.getAssetModule(%assetId);
%moduleName = %module.moduleId;
//These are core, native-level components, so we're not going to be messing with this module at all, skip it
if(%moduleName $= "CoreComponentsModule")
continue;
//first, see if this module Module is listed already
%moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName);
if(%moduleItemId == 0)
%moduleItemId = AssetBrowser-->filterTree.insertItem(1, %moduleName, "", "", 1, 1);
%assetType = AssetDatabase.getAssetCategory(%assetId);
if(%assetType $= "")
{
%assetType = AssetDatabase.getAssetType(%assetId);
if(%assetType $= "")
%assetType = "Misc";
}
if(AssetBrowser.assetTypeFilter !$= "" && AssetBrowser.assetTypeFilter !$= %assetType)
continue;
%assetTypeId = AssetBrowser-->filterTree.findChildItemByName(%moduleItemId, %assetType);
if(%assetTypeId == 0)
%assetTypeId = AssetBrowser-->filterTree.insertItem(%moduleItemId, %assetType);
}
AssetBrowser-->filterTree.buildVisibleTree(true);
%this.collapseTree();
//Remove any modules that have no assets if we have that filter on
if(%this.onlyShowModulesWithAssets)
{
for(%i=0; %i < getWordCount(%modulesList); %i++)
{
%moduleName = getWord(%modulesList, %i).ModuleId;
%moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName);
if(AssetBrowser-->filterTree.isParentItem(%moduleItemId) == false)
AssetBrowser-->filterTree.removeItem(%moduleItemId);
}
}
//special handling for selections
if(AssetBrowser.newModuleId !$= "")
{
@ -484,6 +484,8 @@ function AssetBrowser::loadFilters( %this )
%selectedItem = AssetBrowser-->filterTree.getSelectedItem();
AssetBrowser-->filterTree.scrollVisibleByObjectId(%selectedItem);
AssetBrowser-->filterTree.buildVisibleTree();
}
// create category and update current material if there is one
@ -563,6 +565,26 @@ function AssetBrowser::updateSelection( %this, %asset, %moduleName )
%this.prevSelectedMaterialHL = %asset;
}
function AssetBrowser::collapseTree(%this)
{
%modulesList = ModuleDatabase.findModules(true);
for(%i=0; %i < getWordCount(%modulesList); %i++)
{
%moduleName = getWord(%modulesList, %i).ModuleId;
%moduleGroup = getWord(%modulesList, %i).Group;
if((%moduleGroup $= "Core" || %moduleGroup $= "Tools") && !%this.coreModulesFilter)
continue;
%moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName);
AssetBrowser-->filterTree.expandItem(%moduleItemId, false);
}
AssetBrowser-->filterTree.expandItem(1, true);
}
//
//needs to be deleted with the persistence manager and needs to be blanked out of the matmanager
//also need to update instances... i guess which is the tricky part....
@ -709,6 +731,9 @@ function AssetBrowser::changeAsset(%this)
%cmd = %this.fieldTargetObject @ "." @ %this.fieldTargetName @ "=\"" @ %this.selectedAsset @ "\";";
echo("Changing asset via the " @ %cmd @ " command");
eval(%cmd);
//Flag us as dirty for editing purposes
EWorldEditor.setSceneAsDirty();
}
function AssetBrowser::reImportAsset(%this)
@ -722,8 +747,34 @@ function AssetBrowser::reImportAsset(%this)
AssetBrowser.isAssetReImport = true;
AssetBrowser.reImportingAssetId = EditAssetPopup.assetId;
%reimportingPath = %assetDef.originalFilePath;
//first, double-check we have an originating file. if we don't then we need to basically go out looking for it
if(!isFile(%assetDef.originalFilePath))
{
//if(%assetType $= "ImageAsset")
// %filters = "";
%dlg = new OpenFileDialog()
{
Filters = "(All Files (*.*)|*.*|";
DefaultFile = %currentFile;
ChangePath = false;
MustExist = true;
MultipleFiles = false;
forceRelativePath = false;
};
if ( %dlg.Execute() )
{
%reimportingPath = %dlg.FileName;
}
%dlg.delete();
}
AssetBrowser.onBeginDropFiles();
AssetBrowser.onDropFile(%assetDef.originalFilePath);
AssetBrowser.onDropFile(%reimportingPath);
AssetBrowser.onEndDropFiles();
%module = AssetDatabase.getAssetModule(EditAssetPopup.assetId);
@ -745,7 +796,7 @@ function AssetPreviewButton::onRightClick(%this)
EditAssetPopup.enableItem(7, true);
//Is it an editable type?
if(%assetType $= "ImageAsset" || %assetType $= "GameObjectAsset" || %assetType $= "SoundAsset")
if(%assetType $= "ImageAsset" /*|| %assetType $= "GameObjectAsset"*/ || %assetType $= "CppAsset" || %assetType $= "SoundAsset")
{
EditAssetPopup.enableItem(0, false);
}
@ -758,7 +809,10 @@ function AssetPreviewButton::onRightClick(%this)
EditAssetPopup.enableItem(7, false);
}
EditAssetPopup.showPopup(Canvas);
if(%assetType $= "LevelAsset")
EditLevelAssetPopup.showPopup(Canvas);
else
EditAssetPopup.showPopup(Canvas);
}
function AssetListPanel::onRightMouseDown(%this)
@ -802,10 +856,6 @@ function AssetBrowserFilterTree::onSelect(%this, %itemId)
// we have to empty out the list; so when we create new schedules, these dont linger
MatEdScheduleArray.empty();
// manage preview array
if(!isObject(AssetPreviewArray))
new ArrayObject(AssetPreviewArray);
// we have to empty out the list; so when we create new guicontrols, these dont linger
AssetPreviewArray.empty();
@ -876,8 +926,6 @@ function AssetBrowserFilterTree::onSelect(%this, %itemId)
for(%i=0; %i < %assetArray.count(); %i++)
AssetBrowser.buildPreviewArray( %assetArray.getValue(%i), %assetArray.getKey(%i) );
AssetBrowser.loadImages( 0 );
}
function AssetBrowserFilterTree::onRightMouseDown(%this, %itemId)
@ -909,9 +957,9 @@ function AssetBrowserFilterTree::onRightMouseDown(%this, %itemId)
//Canvas.popDialog(AssetBrowser_newComponentAsset);
//AssetBrowser_newComponentAsset-->AssetBrowserModuleList.setText(AssetBrowser.selectedModule);
}
else
else if(%this.getItemText(%itemId) $= "ScriptAsset")
{
EditAssetCategoryPopup.showPopup(Canvas);
}
}
}
@ -1131,45 +1179,35 @@ function EWorldEditor::onControlDropped( %this, %payload, %position )
if(%assetType $= "ImageAsset")
{
echo("DROPPED AN IMAGE ON THE EDITOR WINDOW!");
echo("WorldEditor::onControlDropped - dropped an ImageAsset onto the editor window. Todo: Implement dropping image/material into scene");
}
else if(%assetType $= "ShapeAsset")
{
echo("DROPPED A SHAPE ON THE EDITOR WINDOW!");
%newEntity = new Entity()
{
position = %pos;
new MeshComponent()
{
MeshAsset = %module @ ":" @ %asset;
};
//new CollisionComponent(){};
};
%staticShapeObjDef = AssetDatabase.acquireAsset("Core_GameObjects:StaticShapeObject");
MissionGroup.add(%newEntity);
%newEntity = %staticShapeObjDef.createObject();
%newEntity.position = %pos;
%newEntity-->MeshComponent.MeshAsset = %module @ ":" @ %asset;
getScene(0).add(%newEntity);
EWorldEditor.clearSelection();
EWorldEditor.selectObject(%newEntity);
}
else if(%assetType $= "MaterialAsset")
{
echo("DROPPED A MATERIAL ON THE EDITOR WINDOW!");
echo("WorldEditor::onControlDropped - dropped an MaterialAsset onto the editor window. Todo: Implement dropping image/material into scene");
}
else if(%assetType $= "GameObjectAsset")
{
echo("DROPPED A GAME OBJECT ON THE EDITOR WINDOW!");
echo("WorldEditor::onControlDropped - dropped an GameObjectAsset onto the editor window.");
%GO = spawnGameObject(%asset, true);
%goAssetDef = AssetDatabase.acquireAsset(%module @ ":" @%asset);
%pos = EWCreatorWindow.getCreateObjectPosition(); //LocalClientConnection.camera.position;
%GO.position = %pos;
EWorldEditor.clearSelection();
EWorldEditor.selectObject(%GO);
AssetBrowser.dragAndDropGameObjectAsset(%goAssetDef, EWorldEditor);
}
else if(%assetType $= "ComponentAsset")
{
@ -1185,7 +1223,7 @@ function EWorldEditor::onControlDropped( %this, %payload, %position )
else
eval("$tmpVar = new " @ %assetDef.componentClass @ "() {}; %newEntity.add($tmpVar);");
MissionGroup.add(%newEntity);
getScene(0).add(%newEntity);
EWorldEditor.clearSelection();
EWorldEditor.selectObject(%newEntity);
@ -1198,7 +1236,7 @@ function EWorldEditor::onControlDropped( %this, %payload, %position )
class = %asset;
};
MissionGroup.add(%newEntity);
getScene(0).add(%newEntity);
EWorldEditor.clearSelection();
EWorldEditor.selectObject(%newEntity);
@ -1207,68 +1245,6 @@ function EWorldEditor::onControlDropped( %this, %payload, %position )
EWorldEditor.isDirty = true;
}
function GuiInspectorTypeShapeAssetPtr::onControlDropped( %this, %payload, %position )
{
Canvas.popDialog(EditorDragAndDropLayer);
// Make sure this is a color swatch drag operation.
if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
return;
%assetType = %payload.dragSourceControl.parentGroup.assetType;
if(%assetType $= "ShapeAsset")
{
echo("DROPPED A SHAPE ON A SHAPE ASSET COMPONENT FIELD!");
%module = %payload.dragSourceControl.parentGroup.moduleName;
%asset = %payload.dragSourceControl.parentGroup.assetName;
%targetComponent = %this.ComponentOwner;
%targetComponent.MeshAsset = %module @ ":" @ %asset;
//Inspector.refresh();
}
EWorldEditor.isDirty= true;
}
function GuiInspectorTypeImageAssetPtr::onControlDropped( %this, %payload, %position )
{
Canvas.popDialog(EditorDragAndDropLayer);
// Make sure this is a color swatch drag operation.
if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
return;
%assetType = %payload.dragSourceControl.parentGroup.assetType;
if(%assetType $= "ImageAsset")
{
echo("DROPPED A IMAGE ON AN IMAGE ASSET COMPONENT FIELD!");
}
EWorldEditor.isDirty = true;
}
function GuiInspectorTypeMaterialAssetPtr::onControlDropped( %this, %payload, %position )
{
Canvas.popDialog(EditorDragAndDropLayer);
// Make sure this is a color swatch drag operation.
if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
return;
%assetType = %payload.dragSourceControl.parentGroup.assetType;
if(%assetType $= "MaterialAsset")
{
echo("DROPPED A MATERIAL ON A MATERIAL ASSET COMPONENT FIELD!");
}
EWorldEditor.isDirty = true;
}
function AssetBrowserFilterTree::onControlDropped( %this, %payload, %position )
{
Canvas.popDialog(EditorDragAndDropLayer);

View file

@ -8,7 +8,9 @@ function ImportAssetConfigList::onSelect( %this, %id, %text )
ImportAssetWindow.activeImportConfigIndex = %id;
ImportAssetWindow.activeImportConfig = ImportAssetWindow.importConfigsList.getKey(%id);
ImportAssetWindow.refresh();
//ImportAssetWindow.refresh();
AssetBrowser.reloadImportingFiles();
}
function ImportAssetOptionsWindow::findMissingFile(%this, %assetItem)
@ -26,6 +28,7 @@ function ImportAssetOptionsWindow::findMissingFile(%this, %assetItem)
ChangePath = true;
OverwritePrompt = true;
forceRelativePath = false;
fileName="";
//MultipleFiles = true;
};
@ -43,6 +46,23 @@ function ImportAssetOptionsWindow::findMissingFile(%this, %assetItem)
return;
%assetItem.filePath = %fullPath;
%assetItem.assetName = fileBase(%assetItem.filePath);
if(%assetItem.assetType $= "Image")
{
//See if we have anything important to update for our material parent(if we have one)
%treeItem = ImportAssetTree.findItemByObjectId(%assetItem);
%parentItem = ImportAssetTree.getParentItem(%treeItem);
if(%parentItem != 0)
{
%parentAssetItem = ImportAssetTree.getItemObject(%parentItem);
if(%parentAssetItem.assetType $= "Material")
{
AssetBrowser.prepareImportMaterialAsset(%parentAssetItem);
}
}
}
ImportAssetWindow.refresh();
}
@ -128,6 +148,7 @@ function ImportAssetOptionsWindow::editImportSettings(%this, %assetItem)
ImportOptionsList.addField("PopulateMaterialMaps", "Populate Material Maps", "bool", "", "1", "", %optionsObj);
ImportOptionsList.addField("UseDiffuseSuffixOnOriginImg", "Use Diffuse Suffix for Origin Image", "bool", "", "1", "", %optionsObj);
ImportOptionsList.addField("UseExistingMaterials", "Use Existing Materials", "bool", "", "1", "", %optionsObj);
ImportOptionsList.addField("IgnoreMaterials", "Ignore Importing Materials that fit these naming convention.", "command", "", "1", "", %optionsObj);
ImportOptionsList.endGroup();
}
else if(%assetType $= "Sound")
@ -145,35 +166,13 @@ function ImportAssetOptionsWindow::editImportSettings(%this, %assetItem)
function ImportAssetOptionsWindow::deleteImportingAsset(%this, %assetItem)
{
%assetIndex = AssetBrowser.importAssetNewListArray.getIndexFromKey(%assetItem);
AssetBrowser.importAssetNewListArray.erase(%assetIndex);
%item = ImportAssetTree.findItemByObjectId(%assetItem);
//check if we have any child assets and remove them as well
for(%i=0; %i < AssetBrowser.importAssetNewListArray.count(); %i++)
{
%asset = AssetBrowser.importAssetNewListArray.getKey(%i);
if(%asset.ParentAssetItem == %assetItem)
{
AssetBrowser.importAssetNewListArray.erase(%i);
%i--;
}
}
%assetIndex = AssetBrowser.importAssetFinalListArray.getIndexFromKey(%assetItem);
AssetBrowser.importAssetFinalListArray.erase(%assetIndex);
//check if we have any child assets and remove them as well
for(%i=0; %i < AssetBrowser.importAssetFinalListArray.count(); %i++)
{
%asset = AssetBrowser.importAssetFinalListArray.getKey(%i);
if(%asset.ParentAssetItem == %assetItem)
{
AssetBrowser.importAssetFinalListArray.erase(%i);
%i--;
}
}
ImportAssetWindow.refresh();
ImportAssetTree.removeAllChildren(%item);
ImportAssetTree.removeItem(%item);
schedule(10, 0, "refreshImportAssetWindow");
//ImportAssetWindow.refresh();
ImportAssetOptionsWindow.setVisible(0);
}
@ -302,6 +301,7 @@ function ImportAssetConfigEditorWindow::addNewConfig(%this)
//Materials
%optionsObj.ImportMaterials = true;
%optionsObj.IgnoreMaterials = "";
%optionsObj.CreateComposites = true;
%optionsObj.UseDiffuseSuffixOnOriginImg = true;
%optionsObj.UseExistingMaterials = true;
@ -398,6 +398,7 @@ function ImportAssetConfigEditorWindow::saveAssetOptionsConfig(%this)
%xmlDoc.pushNewElement("Materials");
%xmlDoc.setAttribute("ImportMaterials", %configObj.ImportMaterials);
%xmlDoc.setAttribute("IgnoreMaterials", %configObj.IgnoreMaterials);
%xmlDoc.setAttribute("CreateComposites", %configObj.CreateComposites);
%xmlDoc.setAttribute("UseDiffuseSuffixOnOriginImg", %configObj.UseDiffuseSuffixOnOriginImg);
%xmlDoc.setAttribute("UseExistingMaterials", %configObj.UseExistingMaterials);

View file

@ -0,0 +1,53 @@
function AssetBrowser::create_Asset(%this)
{
}
function AssetBrowser::edit_Asset(%this, %assetDef)
{
}
function AssetBrowser::duplicate_Asset(%this, %assetDef, %targetModule)
{
}
function AssetBrowser::import_Asset(%this, %assetDef)
{
}
function AssetBrowser::dragAndDrop_Asset(%this, %assetDef, %dropTarget)
{
if(!isObject(%dropTarget))
return;
}
function AssetBrowser::rename_Asset(%this, %assetDef, %newAssetId, %originalName, %newName)
{
}
function AssetBrowser::delete_Asset(%this, %assetDef)
{
}
function AssetBrowser::build_AssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = "";
%previewData.doubleClickCommand = "";
%previewData.previewImage = "tools/assetBrowser/art/gameObjectIcon";
%previewData.assetFriendlyName = %assetDef.gameObjectName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.gameObjectName;
}
function GuiInspectorType_AssetPtr::onClick( %this, %fieldName )
{
//Get our data
%obj = %this.getInspector().getInspectObject(0);
}
function GuiInspectorType_AssetPtr::onControlDropped( %this, %payload, %position )
{
}

View file

@ -0,0 +1,141 @@
function AssetBrowser::createComponentAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/components/" @ %assetName @ ".asset.taml";
%scriptPath = %modulePath @ "/components/" @ %assetName @ ".cs";
%asset = new ComponentAsset()
{
AssetName = %assetName;
versionId = 1;
componentName = %assetName;
componentClass = AssetBrowser.newAssetSettings.parentClass;
friendlyName = AssetBrowser.newAssetSettings.friendlyName;
componentType = AssetBrowser.newAssetSettings.componentGroup;
description = AssetBrowser.newAssetSettings.description;
scriptFile = %assetName @ ".cs";
};
TamlWrite(%asset, %tamlpath);
%file = new FileObject();
if(%file.openForWrite(%scriptPath))
{
//TODO: enable ability to auto-embed a header for copyright or whatnot
%file.writeline("//onAdd is called when the component is created and then added to it's owner entity.\n");
%file.writeline("//You would also add any script-defined component fields via addComponentField().\n");
%file.writeline("function " @ %assetName @ "::onAdd(%this)\n{\n\n}\n");
%file.writeline("//onAdd is called when the component is removed and deleted from it's owner entity.");
%file.writeline("function " @ %assetName @ "::onRemove(%this)\n{\n\n}\n");
%file.writeline("//onClientConnect is called any time a new client connects to the server.");
%file.writeline("function " @ %assetName @ "::onClientConnect(%this, %client)\n{\n\n}\n");
%file.writeline("//onClientDisconnect is called any time a client disconnects from the server.");
%file.writeline("function " @ %assetName @ "::onClientDisonnect(%this, %client)\n{\n\n}\n");
%file.writeline("//update is called when the component does an update tick.\n");
%file.writeline("function " @ %assetName @ "::Update(%this)\n{\n\n}\n");
%file.close();
}
Canvas.popDialog(AssetBrowser_newComponentAsset);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "ComponentAsset");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function AssetBrowser::editComponentAsset(%this, %assetDef)
{
%scriptFile = %assetDef.scriptFile;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
function AssetBrowser::duplicateComponentAsset(%this, %assetId)
{
}
function AssetBrowser::renameGameObjectAsset(%this, %assetDef, %newAssetId, %originalName, %newName)
{
%assetPath = AssetDatabase.getAssetFilePath(%newAssetId);
//rename the file to match
%path = filePath(%assetPath);
%oldScriptFilePath = %assetDef.scriptFile;
%scriptFilePath = filePath(%assetDef.scriptFile);
%scriptExt = fileExt(%assetDef.scriptFile);
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %newName @ ".asset.taml";
%assetDef.componentName = %newName;
%assetDef.scriptFile = %newScriptFileName;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
//Go through our scriptfile and replace the old namespace with the new
%editedFileContents = "";
%file = new FileObject();
if ( %file.openForRead( %newScriptFileName ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %originalAssetName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newScriptFileName);
%file.writeline(%editedFileContents);
%file.close();
}
exec(%newScriptFileName);
}
//not used
function AssetBrowser::importComponentAsset(%this, %assetId)
{
}
function AssetBrowser::buildComponentAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
%previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "tools/assetBrowser/art/componentIcon";
%previewData.assetFriendlyName = %assetDef.friendlyName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef;
}

View file

@ -0,0 +1,143 @@
function AssetBrowser::createCppAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/source/" @ %assetName @ ".asset.taml";
%codePath = %modulePath @ "/source/" @ %assetName @ ".cpp";
%headerPath = %modulePath @ "/source/" @ %assetName @ ".h";
//Do the work here
%assetType = AssetBrowser.newAssetSettings.assetType;
/*if(%assetType $= "CppStaticClassAsset"
|| %assetType $= "CppRegularClassAsset"
|| %assetType $= "CppGameObjectAsset"
|| %assetType $= "CppComponentAsset"
|| %assetType $= "CppScriptClass")
{
}*/
%asset = new CppAsset()
{
AssetName = %assetName;
versionId = 1;
codeFile = %codePath;
headerFile = %headerPath;
};
TamlWrite(%asset, %tamlpath);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "CppAsset");
AssetBrowserFilterTree.onSelect(%smItem);
%templateFilesPath = "tools/assetBrowser/scripts/templateFiles/";
%file = new FileObject();
%templateFile = new FileObject();
if(%assetType $= "CppStaticClassAsset")
{
%cppTemplateCodeFilePath = %templateFilesPath @ "CppStaticClassFile.cpp";
%cppTemplateHeaderFilePath = %templateFilesPath @ "CppStaticClassFile.h";
}
if(%file.openForWrite(%codePath) && %templateFile.openForRead(%cppTemplateCodeFilePath))
{
while( !%templateFile.isEOF() )
{
%line = %templateFile.readline();
%line = strreplace( %line, "@", %assetName );
%file.writeline(%line);
echo(%line);
}
%file.close();
%templateFile.close();
}
else
{
%file.close();
%templateFile.close();
warnf("CreateNewCppAsset - Something went wrong and we couldn't write the C++ code file!");
}
if(%file.openForWrite(%headerPath) && %templateFile.openForRead(%cppTemplateHeaderFilePath))
{
while( !%templateFile.isEOF() )
{
%line = %templateFile.readline();
%line = strreplace( %line, "@", %assetName );
%file.writeline(%line);
echo(%line);
}
%file.close();
%templateFile.close();
}
else
{
%file.close();
%templateFile.close();
warnf("CreateNewCppAsset - Something went wrong and we couldn't write the C++ header file!");
}
//Last, check that we have a C++ Module definition. If not, make one so anything important can be initialized on startup there
%cppModuleFilePath = %modulePath @ "/source/" @ %moduleName @ ".cpp";
if(!isFile(%cppModuleFilePath))
{
%file = new FileObject();
%templateFile = new FileObject();
if(%file.openForWrite(%cppModuleFilePath) && %templateFile.openForRead(%templateFilesPath @ "CppModuleFile.cpp"))
{
while( !%templateFile.isEOF() )
{
%line = %templateFile.readline();
%line = strreplace( %line, "@", %moduleName );
%file.writeline(%line);
echo(%line);
}
%file.close();
%templateFile.close();
}
else
{
%file.close();
%templateFile.close();
warnf("CreateNewCppAsset - Something went wrong and we couldn't write the C++ module file!");
}
}
return %tamlpath;
}
function AssetBrowser::buildCppAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.codeFilePath;
%previewData.doubleClickCommand = "echo(\"Not yet implemented to edit C++ files from the editor\");";//"EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "tools/assetBrowser/art/cppIcon";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.assetName;
}

View file

@ -0,0 +1,242 @@
function AssetBrowser::createGameObjectAsset(%this)
{
GameObjectCreatorObjectName.text = "";
%activeSelection = EWorldEditor.getActiveSelection();
if( %activeSelection.getCount() == 0 )
return;
GameObjectCreator.selectedEntity = %activeSelection.getObject( 0 );
Canvas.pushDialog(GameObjectCreator);
}
function AssetBrowser::editGameObjectAsset(%this, %assetDef)
{
//We have no dedicated GO editor for now, so just defer to the script editing aspect
%this.editGameObjectAssetScript(%assetDef);
}
function AssetBrowser::editGameObjectAssetScript(%this, %assetDef)
{
%scriptFile = %assetDef.scriptFile;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
function AssetBrowser::applyInstanceToGameObject(%this, %assetDef)
{
%obj = EditGameObjectAssetPopup.object;
//TODO add proper validation against the original GO asset
%obj.dirtyGameObject = true;
TamlWrite(%obj, %assetDef.TAMLFilePath);
}
function AssetBrowser::duplicateGameObjectAsset(%this, %assetDef, %targetModule)
{
//Check if we have a target module, if not we need to select one
if(%targetModule $= "")
{
error("AssetBrowser::duplicateGameObjectAsset - No target module selected!");
return;
}
%assetId = %assetDef.getAssetId();
%assetName = AssetDatabase.getAssetName(%assetId);
//First step, copy the files
%modulePath = "data/" @ %targetModule @ "/gameObjects/";
if(!isDirectory(%modulePath))
createPath(%modulePath);
%assetFile = AssetDatabase.getAssetFilePath(%assetId);
%scriptFile = %assetDef.scriptFile;
%gameObjectFile = %assetDef.TAMLFile;
echo("AssetBrowser::duplicateGameObjectAsset - duplicating! " @ %assetId @ " to " @ %targetModule);
%tamlPath = %modulePath @ fileName(%assetFile);
pathCopy(%assetFile, %tamlPath);
pathCopy(%scriptFile, %modulePath @ fileName(%scriptFile));
pathCopy(%gameObjectFile, %modulePath @ fileName(%gameObjectFile));
echo("AssetBrowser::duplicateGameObjectAsset - duplicated!");
//Register the asset
%moduleDef = ModuleDatabase.findModule(%targetModule, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlPath);
//Refresh the browser
AssetBrowser.loadFilters();
//Ensure our context is set
%treeItemId = AssetBrowserFilterTree.findItemByName(%targetModule);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "GameObjectAsset");
AssetBrowserFilterTree.selectItem(%smItem);
//Rename it for convenience
AssetBrowser.performRenameAsset(%assetName, "New" @ %assetName);
//Expand and refresh the target module
AssetBrowserFilterTree.expandItem(%treeItemId,true);
AssetBrowserFilterTree.buildVisibleTree();
}
//not used
function AssetBrowser::importGameObjectAsset(%this, %assetId)
{
}
function AssetBrowser::dragAndDropGameObjectAsset(%this, %assetDef, %dropTarget)
{
if(!isObject(%dropTarget))
return;
if(%dropTarget.getId() == EWorldEditor.getId())
{
if(isObject(%assetDef))
{
%gameObject = %assetDef.createObject();
getScene(0).add(%gameObject);
%pos = EWCreatorWindow.getCreateObjectPosition(); //LocalClientConnection.camera.position;
%gameObject.position = %pos;
EWorldEditor.clearSelection();
EWorldEditor.selectObject(%gameObject);
}
else
{
error("WorldEditor::onControlDropped - unable to create GameObject");
}
}
}
function AssetBrowser::renameGameObjectAsset(%this, %assetDef, %newAssetId, %originalName, %newName)
{
%oldScriptFilePath = %assetDef.scriptFile;
%scriptFilePath = filePath(%assetDef.scriptFile);
%scriptExt = fileExt(%assetDef.scriptFile);
%oldGOFilePath = %assetDef.TAMLFile;
%filepath = AssetDatabase.getAssetFilePath(%assetDef.getAssetId());
%path = makeRelativePath(filePath(%filepath));
%newScriptFileName = %path @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %newName @ ".asset.taml";
%newGOFile = %path @ "/" @ %newName @ ".taml";
%assetDef.gameObjectName = %newName;
%assetDef.scriptFile = %newScriptFileName;
%assetDef.TAMLFile = %newGOFile;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%filepath);
//Quick check, if we duplicated the asset to a new module, the old path may not line up so we'll want to update that to be relevent
if(filePath(%oldScriptFilePath) !$= %path)
{
%oldFileBase = fileName(%oldScriptFilePath);
%oldScriptFilePath = %path @ "/" @ %oldFileBase;
}
%scriptFileCopySuccess = pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
if(!%scriptFileCopySuccess)
error("AssetBrowser::renameGameObjectAsset - unable to copy scriptFile");
if(filePath(%oldGOFilePath) !$= %path)
{
%oldFileBase = fileName(%oldGOFilePath);
%oldGOFilePath = %path @ "/" @ %oldFileBase;
}
%goFileCopySuccess = pathCopy(%oldGOFilePath, %newGOFile);
fileDelete(%oldGOFilePath);
if(!%scriptFileCopySuccess)
error("AssetBrowser::renameGameObjectAsset - unable to copy gameObject");
//Go through our scriptfile and replace the old namespace with the new
%editedFileContents = "";
%file = new FileObject();
if ( %file.openForRead( %newScriptFileName ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %originalName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newScriptFileName);
%file.writeline(%editedFileContents);
%file.close();
}
exec(%newScriptFileName);
%gameObj = TAMLRead(%newGOFile);
%gameObj.className = %newName;
%gameObj.GameObject = %assetDef.getAssetId();
TAMLWrite(%gameObj, %newGOFile);
}
function AssetBrowser::buildGameObjectAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
%previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "tools/assetBrowser/art/gameObjectIcon";
%previewData.assetFriendlyName = %assetDef.gameObjectName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.gameObjectName;
}
function GuiInspectorTypeGameObjectAssetPtr::onClick( %this, %fieldName )
{
//Get our data
%obj = %this.getInspector().getInspectObject(0);
EditGameObjectAssetPopup.object = %obj;
%assetId = %obj.getFieldValue(%fieldName);
if(%assetId !$= "")
{
EditGameObjectAssetPopup.assetId = %assetId;
EditGameObjectAssetPopup.showPopup(Canvas);
}
else
{
//We've gotta be trying to create a GameObject, so kick that off
AssetBrowser.createGameObjectAsset();
}
}

View file

@ -0,0 +1,83 @@
function AssetBrowser::createGUIAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/GUIs/" @ %assetName @ ".asset.taml";
%guipath = %modulePath @ "/GUIs/" @ %assetName @ ".gui";
%scriptPath = %modulePath @ "/GUIs/" @ %assetName @ ".cs";
%asset = new GUIAsset()
{
AssetName = %assetName;
versionId = 1;
scriptFile = %assetName @ ".cs";
guiFile = %assetName @ ".gui";
};
TamlWrite(%asset, %tamlpath);
%file = new FileObject();
if(%file.openForWrite(%guipath))
{
%file.writeline("//--- OBJECT WRITE BEGIN ---");
%file.writeline("%guiContent = new GuiControl(" @ %assetName @ ") {");
%file.writeline(" position = \"0 0\";");
%file.writeline(" extent = \"100 100\";");
%file.writeline("};");
%file.writeline("//--- OBJECT WRITE END ---");
%file.close();
}
if(%file.openForWrite(%scriptPath))
{
%file.writeline("function " @ %assetName @ "::onWake(%this)\n{\n\n}\n");
%file.writeline("function " @ %assetName @ "::onSleep(%this)\n{\n\n}\n");
%file.close();
}
//load the gui
exec(%guipath);
exec(%scriptPath);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "GUIs");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function AssetBrowser::editGUIAsset(%this, %assetDef)
{
if(!isObject(%assetDef.assetName))
{
exec(%assetDef.GUIFilePath);
exec(%assetDef.mScriptFilePath);
}
GuiEditContent(%assetDef.assetName);
}
function AssetBrowser::buildGUIAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.GUIFilePath;
%previewData.doubleClickCommand = "";
%previewData.previewImage = "tools/assetBrowser/art/guiIcon";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.assetName;
}

View file

@ -0,0 +1,163 @@
function AssetBrowser::prepareImportImageAsset(%this, %assetItem)
{
if(ImportAssetWindow.activeImportConfig.GenerateMaterialOnImport == 1 && %assetItem.parentAssetItem $= "")
{
//First, see if this already has a suffix of some sort based on our import config logic. Many content pipeline tools like substance automatically appends them
%foundSuffixType = ImportAssetWindow.parseImageSuffixes(%assetItem);
if(%foundSuffixType $= "")
{
%noSuffixName = %assetItem.AssetName;
}
else
{
%suffixPos = strpos(strlwr(%assetItem.AssetName), strlwr(%assetItem.imageSuffixType), 0);
%noSuffixName = getSubStr(%assetItem.AssetName, 0, %suffixPos);
}
//Check if our material already exists
//First, lets double-check that we don't already have an
%materialAsset = AssetBrowser.doesAssetItemAlreadyExist(%noSuffixName);
if(%materialAsset == 0)
{
%filePath = %assetItem.filePath;
if(%filePath !$= "")
%materialAsset = AssetBrowser.addImportingAsset("Material", "", "", %noSuffixName);
}
if(isObject(%materialAsset))
{
//Establish parentage
%itemId = ImportAssetTree.findItemByObjectId(%assetItem);
%materialItemId = ImportAssetTree.findItemByObjectId(%materialAsset);
%assetItem.parentId = %materialItemId;
ImportAssetTree.reparentItem(%itemId, %materialItemId);
ImportAssetTree.buildVisibleTree(true);
}
//Lets do some cleverness here. If we're generating a material we can parse like assets being imported(similar file names) but different suffixes
//if we find these, we'll just populate into the original's material
//If we need to append the diffuse suffix and indeed didn't find a suffix on the name, do that here
if(ImportAssetWindow.activeImportConfig.UseDiffuseSuffixOnOriginImg == 1)
{
if(%foundSuffixType $= "")
{
%diffuseToken = getToken(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",", 0);
%assetItem.AssetName = %assetItem.AssetName @ %diffuseToken;
if(ImportAssetWindow.activeImportConfig.PopulateMaterialMaps == 1)
%materialAsset.diffuseImageAsset = %assetItem;
}
else if(%foundSuffixType !$= "")
{
//otherwise, if we have some sort of suffix, we'll want to figure out if we've already got an existing material, and should append to it
if(ImportAssetWindow.activeImportConfig.PopulateMaterialMaps == 1)
{
if(%foundSuffixType $= "diffuse")
%materialAsset.diffuseImageAsset = %assetItem;
else if(%foundSuffixType $= "normal")
%materialAsset.normalImageAsset = %assetItem;
else if(%foundSuffixType $= "metalness")
%materialAsset.metalnessImageAsset = %assetItem;
else if(%foundSuffixType $= "roughness")
%materialAsset.roughnessImageAsset = %assetItem;
else if(%foundSuffixType $= "specular")
%materialAsset.specularImageAsset = %assetItem;
else if(%foundSuffixType $= "AO")
%materialAsset.AOImageAsset = %assetItem;
else if(%foundSuffixType $= "composite")
%materialAsset.compositeImageAsset = %assetItem;
}
}
}
else
{
//We need to ensure that our image asset doesn't match the same name as the material asset, so if we're not trying to force the diffuse suffix
//we'll give it a generic one
if(%materialAsset.assetName $= %assetItem.assetName)
{
%assetItem.AssetName = %assetItem.AssetName @ "_image";
}
}
%assetItem.processed = true;
}
}
function AssetBrowser::importImageAsset(%this, %assetItem)
{
%moduleName = ImportAssetModuleList.getText();
%assetType = %assetItem.AssetType;
%filePath = %assetItem.filePath;
%assetName = %assetItem.assetName;
%assetImportSuccessful = false;
%assetId = %moduleName@":"@%assetName;
%assetPath = "data/" @ %moduleName @ "/Images";
%assetFullPath = %assetPath @ "/" @ fileName(%filePath);
%newAsset = new ImageAsset()
{
assetName = %assetName;
versionId = 1;
imageFile = fileName(%filePath);
originalFilePath = %filePath;
};
%assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ "/" @ %assetName @ ".asset.taml");
//and copy the file into the relevent directory
%doOverwrite = !AssetBrowser.isAssetReImport;
if(!pathCopy(%filePath, %assetFullPath, %doOverwrite))
{
error("Unable to import asset: " @ %filePath);
return;
}
%moduleDef = ModuleDatabase.findModule(%moduleName,1);
if(!AssetBrowser.isAssetReImport)
AssetDatabase.addDeclaredAsset(%moduleDef, %assetPath @ "/" @ %assetName @ ".asset.taml");
else
AssetDatabase.refreshAsset(%assetId);
}
function AssetBrowser::buildImageAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
//%previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
if(isFile(%assetDef.imageFile))
%previewData.previewImage = %assetDef.imageFile;
else
%previewData.previewImage = "core/rendering/images/unavailable";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef;
}
function GuiInspectorTypeImageAssetPtr::onControlDropped( %this, %payload, %position )
{
Canvas.popDialog(EditorDragAndDropLayer);
// Make sure this is a color swatch drag operation.
if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
return;
%assetType = %payload.dragSourceControl.parentGroup.assetType;
if(%assetType $= "ImageAsset")
{
echo("DROPPED A IMAGE ON AN IMAGE ASSET COMPONENT FIELD!");
}
EWorldEditor.isDirty = true;
}

View file

@ -0,0 +1,62 @@
function AssetBrowser::createLevelAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/levels/" @ %assetName @ ".asset.taml";
%levelPath = %modulePath @ "/levels/" @ %assetName @ ".mis";
%asset = new LevelAsset()
{
AssetName = %assetName;
versionId = 1;
LevelFile = %assetName @ ".mis";
LevelName = AssetBrowser.newAssetSettings.levelName;
AssetDescription = AssetBrowser.newAssetSettings.description;
PreviewImage = AssetBrowser.newAssetSettings.levelPreviewImage;
};
TamlWrite(%asset, %tamlpath);
if(!pathCopy("tools/levels/BlankRoom.mis", %levelPath, false))
{
echo("Unable to copy template level file!");
}
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Levels");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function AssetBrowser::editLevelAsset(%this, %assetDef)
{
schedule( 1, 0, "EditorOpenMission", %assetDef);
}
function AssetBrowser::buildLevelAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.levelFile;
%previewData.doubleClickCommand = "schedule( 1, 0, \"EditorOpenMission\", "@%assetDef@");";
%levelPreviewImage = %assetDesc.PreviewImage;
if(isFile(%levelPreviewImage))
%previewData.previewImage = %levelPreviewImage;
else
%previewData.previewImage = "tools/assetBrowser/art/levelIcon";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.assetName;
}

View file

@ -0,0 +1,468 @@
function AssetBrowser::createMaterialAsset(%this)
{
%assetName = AssetBrowser.newAssetSettings.assetName;
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%tamlpath = %modulePath @ "/materials/" @ %assetName @ ".asset.taml";
%sgfPath = %modulePath @ "/materials/" @ %assetName @ ".sgf";
%asset = new MaterialAsset()
{
AssetName = %assetName;
versionId = 1;
shaderData = "";
shaderGraph = %sgfPath;
};
TamlWrite(%asset, %tamlpath);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Materials");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function AssetBrowser::editMaterialAsset(%this, %assetDef)
{
//if(EditorSettings.materialEditMode $= "MaterialEditor")
//{
%assetDef.materialDefinitionName.reload();
EditorGui.setEditor(MaterialEditorPlugin);
MaterialEditorGui.currentMaterial = %assetDef.materialDefinitionName;
MaterialEditorGui.setActiveMaterial( %assetDef.materialDefinitionName );
AssetBrowser.hideDialog();
/*}
else
{
Canvas.pushDialog(ShaderEditor);
ShaderEditorGraph.loadGraph(%assetDef.shaderGraph);
$ShaderGen::targetShaderFile = filePath(%assetDef.shaderGraph) @"/"@fileBase(%assetDef.shaderGraph);
//} */
}
function AssetBrowser::prepareImportMaterialAsset(%this, %assetItem)
{
//Iterate over to find appropriate images for
//Fetch just the fileBase name
%fileDir = filePath(%assetItem.filePath);
%fileName = fileBase(%assetItem.filePath);
%fileExt = fileExt(%assetItem.filePath);
//Check if we need to filter this material out or not
if(ImportAssetWindow.activeImportConfig.IgnoreMaterials !$= "")
{
%ignoredMatNamesCount = getTokenCount(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ",;");
for(%i=0; %i < %ignoredMatNamesCount; %i++)
{
%ignoreName = getToken(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ".;", %i);
if(strIsMatchExpr(%ignoreName, %fileName))
{
//We fit the bill, ignore this material and skip it
%assetItem.skip = true;
return;
}
}
}
if(ImportAssetWindow.activeImportConfig.PopulateMaterialMaps == 1)
{
%materialItemId = ImportAssetTree.findItemByObjectId(%assetItem);
if(%assetItem.diffuseImageAsset $= "")
{
//First, load our diffuse map, as set to the material in the shape
//We're going to presume(for now) that the specifically-mentioned file for a given material is the diffuse/albedo
%diffuseImagePath = %fileDir @ "/" @ %filename @ %fileExt;
%diffuseImageSuffix = ImportAssetWindow.parseImagePathSuffixes(%diffuseImagePath);
if(ImportAssetWindow.activeImportConfig.UseDiffuseSuffixOnOriginImg == 1 && %diffuseImageSuffix $= "")
{
%diffuseToken = getToken(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",;", 0);
%diffuseAsset = AssetBrowser.addImportingAsset("Image", %diffuseImagePath, %materialItemId, %filename @ %diffuseToken);
}
else
{
%diffuseAsset = AssetBrowser.addImportingAsset("Image", %diffuseImagePath, %materialItemId);
}
%assetItem.diffuseImageAsset = %diffuseAsset;
}
//Now, iterate over our comma-delimited suffixes to see if we have any matches. We'll use the first match in each case, if any.
if(%assetItem.normalImageAsset $= "")
{
//First, normal map
%targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, ImportAssetWindow.activeImportConfig.NormalTypeSuffixes);
if(%targetFilePath $= "")
{
//Didn't find it for the presumed file path, so lets angle it from the diffuse map's texture name, if it has one
if(isObject(%assetItem.diffuseImageAsset))
{
if(isFile(%assetItem.diffuseImageAsset.filePath))
{
%diffFileDir = filePath(%assetItem.diffuseImageAsset.filePath);
%diffFileName = fileBase(%assetItem.diffuseImageAsset.filePath);
%diffFileExt = fileExt(%assetItem.diffuseImageAsset.filePath);
%suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %diffFileName))
{
%diffFileName = strreplace(%diffFileName, %suffixToken, "");
break;
}
}
%targetFilePath = %this.findMaterialMapFileWSuffix(%diffFileDir, %diffFileName, %diffFileExt, ImportAssetWindow.activeImportConfig.NormalTypeSuffixes);
}
}
}
if(%targetFilePath !$= "")
{
%normalAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId);
%assetItem.normalImageAsset = %normalAsset;
}
}
if(%assetItem.specularImageAsset $= "")
{
//Specular
%listCount = getTokenCount(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;");
%foundFile = 0;
for(%i=0; %i < %listCount; %i++)
{
%entryText = getToken(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;", %i);
%targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt;
%foundFile = isFile(%targetFilePath);
if(%foundFile)
{
%specularAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId);
%assetItem.specularImageAsset = %specularAsset;
break;
}
}
}
if(%assetItem.metalImageAsset $= "")
{
//Metal
%listCount = getTokenCount(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ",;");
%foundFile = 0;
for(%i=0; %i < %listCount; %i++)
{
%entryText = getToken(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ",;", %i);
%targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt;
%foundFile = isFile(%targetFilePath);
if(%foundFile)
{
%metalAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId);
%assetItem.metalImageAsset = %metalAsset;
break;
}
}
}
if(%assetItem.roughnessImageAsset $= "")
{
//Roughness
%listCount = getTokenCount(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ",;");
%foundFile = 0;
for(%i=0; %i < %listCount; %i++)
{
%entryText = getToken(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ",;", %i);
%targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt;
%foundFile = isFile(%targetFilePath);
if(%foundFile)
{
%roughnessAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId);
%assetItem.roughnessImageAsset = %roughnessAsset;
break;
}
}
}
if(%assetItem.smoothnessImageAsset $= "")
{
//Smoothness
%listCount = getTokenCount(ImportAssetWindow.activeImportConfig.SmoothnessTypeSuffixes, ",;");
%foundFile = 0;
for(%i=0; %i < %listCount; %i++)
{
%entryText = getToken(ImportAssetWindow.activeImportConfig.SmoothnessTypeSuffixes, ",;", %i);
%targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt;
%foundFile = isFile(%targetFilePath);
if(%foundFile)
{
%smoothnessAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId);
%assetItem.SmoothnessImageAsset = %smoothnessAsset;
break;
}
}
}
if(%assetItem.AOImageAsset $= "")
{
//AO
%listCount = getTokenCount(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ",;");
%foundFile = 0;
for(%i=0; %i < %listCount; %i++)
{
%entryText = getToken(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ",;", %i);
%targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt;
%foundFile = isFile(%targetFilePath);
if(%foundFile)
{
%AOAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId);
%assetItem.AOImageAsset = %AOAsset;
break;
}
}
}
if(%assetItem.compositeImageAsset $= "")
{
//Composite
%listCount = getTokenCount(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ",;");
%foundFile = 0;
for(%i=0; %i < %listCount; %i++)
{
%entryText = getToken(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ",;", %i);
%targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt;
%foundFile = isFile(%targetFilePath);
if(%foundFile)
{
%compositeAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId);
%assetItem.compositeImageAsset = %compositeAsset;
break;
}
}
}
}
}
function AssetBrowser::findMaterialMapFileWSuffix(%this, %fileDir, %filename, %fileExt, %suffixList)
{
//Now, iterate over our comma-delimited suffixes to see if we have any matches. We'll use the first match in each case, if any.
//First, normal map
%listCount = getTokenCount(%suffixList, ",;");
%foundFile = 0;
for(%i=0; %i < %listCount; %i++)
{
%entryText = getToken(%suffixList, ",;", %i);
%targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt;
%foundFile = isFile(%targetFilePath);
if(%foundFile)
{
return %targetFilePath;
break;
}
}
return "";
}
function AssetBrowser::importMaterialAsset(%this, %assetItem)
{
%moduleName = ImportAssetModuleList.getText();
%assetType = %assetItem.AssetType;
%filePath = %assetItem.filePath;
%assetName = %assetItem.assetName;
%assetImportSuccessful = false;
%assetId = %moduleName@":"@%assetName;
%assetPath = "data/" @ %moduleName @ "/materials";
%tamlpath = %assetPath @ "/" @ %assetName @ ".asset.taml";
%sgfPath = %assetPath @ "/" @ %assetName @ ".sgf";
%scriptPath = %assetPath @ "/" @ %assetName @ ".cs";
%newAsset = new MaterialAsset()
{
assetName = %assetName;
versionId = 1;
shaderGraph = %sgfPath;
scriptFile = %scriptPath;
originalFilePath = %filePath;
materialDefinitionName = %assetName;
};
//check dependencies
%importItem = ImportAssetTree.findItemByObjectId(%assetItem);
if(ImportAssetTree.isParentItem(%importItem))
{
%imageSlot = 0;
%childId = ImportAssetTree.getChild(%importItem);
while(%childId > 0)
{
%dependencyAssetItem = ImportAssetTree.getItemObject(%childId);
%depAssetType = %dependencyAssetItem.assetType;
if(%depAssetType $= "Image")
{
%matSet = "%newAsset.imageMap"@%imageSlot@"=\"@Asset="@%moduleName@":"@%dependencyAssetItem.assetName@"\";";
eval(%matSet);
}
%childId = ImportAssetTree.getNextSibling(%childId);
%imageSlot++;
}
}
%assetImportSuccessful = TamlWrite(%newAsset, %tamlpath);
%file = new FileObject();
if(%file.openForWrite(%scriptPath))
{
%file.writeline("//--- OBJECT WRITE BEGIN ---");
%file.writeline("singleton Material(" @ %assetName @ ") {");
//TODO: pass along the shape's target material for this just to be sure
%file.writeLine(" mapTo = \"" @ %assetName @ "\";");
if(%assetItem.diffuseImageAsset !$= "")
{
%diffuseAssetPath = "data/" @ %moduleName @ "/Images/" @ fileName(%assetItem.diffuseImageAsset.filePath);
%file.writeline(" DiffuseMap[0] = \"" @ %diffuseAssetPath @"\";");
%file.writeline(" DiffuseMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.diffuseImageAsset.assetName @"\";");
}
if(%assetItem.normalImageAsset)
{
%normalAssetPath = "data/" @ %moduleName @ "/Images/" @ fileName(%assetItem.normalImageAsset.filePath);
%file.writeline(" NormalMap[0] = \"" @ %normalAssetPath @"\";");
%file.writeline(" NormalMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.normalImageAsset.assetName @"\";");
}
/*if(%assetItem.specularImageAsset)
{
%file.writeline(" SpecularMap[0] = \"" @ %assetItem.specularImageAsset.filePath @"\";");
%file.writeline(" SpecularMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.specularImageAsset.assetName @"\";");
}*/
if(%assetItem.roughnessImageAsset)
{
%file.writeline(" RoughMap[0] = \"" @ %assetItem.roughnessImageAsset.filePath @"\";");
%file.writeline(" RoughMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.roughnessImageAsset.assetName @"\";");
}
if(%assetItem.smoothnessImageAsset)
{
%file.writeline(" SmoothnessMap[0] = \"" @ %assetItem.smoothnessImageAsset.filePath @"\";");
%file.writeline(" SmoothnessMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.smoothnessImageAsset.assetName @"\";");
}
if(%assetItem.metalnessImageAsset)
{
%file.writeline(" MetalMap[0] = \"" @ %assetItem.metalnessImageAsset.filePath @"\";");
%file.writeline(" MetalMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.metalnessImageAsset.assetName @"\";");
}
if(%assetItem.AOImageAsset)
{
%file.writeline(" AOMap[0] = \"" @ %assetItem.AOImageAsset.filePath @"\";");
%file.writeline(" AOMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.AOImageAsset.assetName @"\";");
}
if(%assetItem.compositeImageAsset)
{
%file.writeline(" CompositeMap[0] = \"" @ %assetItem.compositeImageAsset.filePath @"\";");
%file.writeline(" CompositeMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.compositeImageAsset.assetName @"\";");
}
%file.writeline("};");
%file.writeline("//--- OBJECT WRITE END ---");
%file.close();
}
%moduleDef = ModuleDatabase.findModule(%moduleName,1);
if(!AssetBrowser.isAssetReImport)
AssetDatabase.addDeclaredAsset(%moduleDef, %assetPath @ "/" @ %assetName @ ".asset.taml");
else
AssetDatabase.refreshAsset(%assetId);
}
function AssetBrowser::buildMaterialAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.materialDefinitionName;
%previewData.assetPath = %assetDef.scriptFile;
//Lotta prepwork
%previewData.doubleClickCommand = %assetDef@".materialDefinitionName.reload(); "
@ "$Tools::materialEditorList = \"\";"
@ "EWorldEditor.clearSelection();"
@ "MaterialEditorGui.currentObject = 0;"
@ "MaterialEditorGui.currentMode = \"asset\";"
@ "MaterialEditorGui.currentMaterial = "@%assetDef@".materialDefinitionName;"
@ "MaterialEditorGui.setActiveMaterial( "@%assetDef@".materialDefinitionName );"
@ "EditorGui.setEditor(MaterialEditorPlugin); "
@ "AssetBrowser.hideDialog();";
if(isFile(%assetDef.materialDefinitionName.diffuseMap[0]))
%previewData.previewImage = %assetDef.materialDefinitionName.diffuseMap[0];
else
%previewData.previewImage = "tools/assetBrowser/art/materialIcon";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef;
}
function GuiInspectorTypeMaterialAssetPtr::onControlDropped( %this, %payload, %position )
{
Canvas.popDialog(EditorDragAndDropLayer);
// Make sure this is a color swatch drag operation.
if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
return;
%assetType = %payload.dragSourceControl.parentGroup.assetType;
%module = %payload.dragSourceControl.parentGroup.moduleName;
%assetName = %payload.dragSourceControl.parentGroup.assetName;
if(%assetType $= "MaterialAsset")
{
echo("DROPPED A MATERIAL ON A MATERIAL ASSET COMPONENT FIELD!");
//%assetDef = AssetDatabase.acquireAsset(%module @ ":" @ %assetName);
%this.setMaterialAsset(%module @ ":" @ %assetName);
}
EWorldEditor.isDirty = true;
}

View file

@ -0,0 +1,51 @@
function AssetBrowser::createPostEffectAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/postFXs/" @ %assetName @ ".asset.taml";
%scriptPath = %modulePath @ "/postFXs/" @ %assetName @ ".cs";
%asset = new PostEffectAsset()
{
AssetName = %assetName;
versionId = 1;
scriptFile = %assetName @ ".cs";
};
TamlWrite(%asset, %tamlpath);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "PostEffectAsset");
AssetBrowserFilterTree.onSelect(%smItem);
%file = new FileObject();
if(%file.openForWrite(%scriptPath))
{
%file.close();
}
return %tamlpath;
}
function AssetBrowser::buildPostEffectAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFilePath;
%previewData.doubleClickCommand = "";
%previewData.previewImage = "tools/assetBrowser/art/postEffectIcon";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.assetName;
}

View file

@ -0,0 +1,89 @@
function AssetBrowser::createScriptAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/scripts/" @ %assetName @ ".asset.taml";
%scriptPath = %modulePath @ "/scripts/" @ %assetName @ ".cs";
%asset = new ScriptAsset()
{
AssetName = %assetName;
versionId = 1;
scriptFile = %assetName @ ".cs";
};
TamlWrite(%asset, %tamlpath);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "ScriptAsset");
AssetBrowserFilterTree.onSelect(%smItem);
%file = new FileObject();
if(%file.openForWrite(%scriptPath))
{
%file.close();
}
return %tamlpath;
}
function AssetBrowser::editScriptAsset(%this, %assetDef)
{
%scriptFile = %assetDef.scriptFile;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
function AssetBrowser::duplicateScriptAsset(%this, %assetDef, %targetModule)
{
}
function AssetBrowser::importScriptAsset(%this, %assetId)
{
}
function AssetBrowser::dragAndDropScriptAsset(%this, %assetDef, %dropTarget)
{
if(!isObject(%dropTarget))
return;
}
function AssetBrowser::renameScriptAsset(%this, %assetDef, %originalName, %newName)
{
}
function AssetBrowser::deleteScriptAsset(%this, %assetDef)
{
}
function AssetBrowser::buildScriptAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
%previewData.doubleClickCommand = "EditorOpenFileInTorsion( \""@%previewData.assetPath@"\", 0 );";
if(%assetDef.isServerSide)
%previewData.previewImage = "tools/assetBrowser/art/serverScriptIcon";
else
%previewData.previewImage = "tools/assetBrowser/art/clientScriptIcon";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.assetName;
}
function GuiInspectorTypeScriptAssetPtr::onClick( %this, %fieldName )
{
//Get our data
%obj = %this.getInspector().getInspectObject(0);
}

View file

@ -0,0 +1,266 @@
function AssetBrowser::createShapeAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/shapes/" @ %assetName @ ".asset.taml";
%shapeFilePath = %modulePath @ "/shapes/" @ %assetName @ ".dae";
%asset = new ShapeAsset()
{
AssetName = %assetName;
versionId = 1;
friendlyName = AssetBrowser.newAssetSettings.friendlyName;
description = AssetBrowser.newAssetSettings.description;
fileName = %assetName @ ".dae";
};
TamlWrite(%asset, %tamlpath);
Canvas.popDialog(AssetBrowser_newComponentAsset);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "ShapeAsset");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function AssetBrowser::editShapeAsset(%this, %assetDef)
{
%this.hideDialog();
ShapeEditorPlugin.openShapeAsset(%assetDef);
}
function AssetBrowser::prepareImportShapeAsset(%this, %assetItem)
{
%fileExt = fileExt(%assetItem.filePath);
if(%fileExt $= ".dae")
{
%shapeInfo = new GuiTreeViewCtrl();
enumColladaForImport(%assetItem.filePath, %shapeInfo, false);
}
else
{
%shapeInfo = GetShapeInfo(%assetItem.filePath);
}
%assetItem.shapeInfo = %shapeInfo;
%shapeItem = %assetItem.shapeInfo.findItemByName("Shape");
%shapeCount = %assetItem.shapeInfo.getItemValue(%shapeItem);
%shapeId = ImportAssetTree.findItemByObjectId(%assetItem);
if(ImportAssetWindow.activeImportConfig.ImportMesh == 1 && %shapeCount > 0)
{
}
%animItem = %assetItem.shapeInfo.findItemByName("Animations");
%animCount = %assetItem.shapeInfo.getItemValue(%animItem);
if(ImportAssetWindow.activeImportConfig.ImportAnimations == 1 && %animCount > 0)
{
/*%animationItem = %assetItem.shapeInfo.getChild(%animItem);
%animName = %assetItem.shapeInfo.getItemText(%animationItem);
AssetBrowser.addImportingAsset("Animation", %animName, %shapeId);
%animationItem = %assetItem.shapeInfo.getNextSibling(%animationItem);
while(%animationItem != 0)
{
%animName = %assetItem.shapeInfo.getItemText(%animationItem);
//%animName = %assetItem.shapeInfo.getItemValue(%animationItem);
AssetBrowser.addImportingAsset("Animation", %animName, %shapeId);
%animationItem = %shapeInfo.getNextSibling(%animationItem);
}*/
}
%matItem = %assetItem.shapeInfo.findItemByName("Materials");
%matCount = %assetItem.shapeInfo.getItemValue(%matItem);
if(ImportAssetWindow.activeImportConfig.importMaterials == 1 && %matCount > 0)
{
%materialItem = %assetItem.shapeInfo.getChild(%matItem);
%matName = %assetItem.shapeInfo.getItemText(%materialItem);
%filePath = %assetItem.shapeInfo.getItemValue(%materialItem);
if(%filePath !$= "")
{
AssetBrowser.addImportingAsset("Material", %filePath, %shapeId);
}
else
{
//we need to try and find our material, since the shapeInfo wasn't able to find it automatically
%filePath = findImageFile(filePath(%assetItem.filePath), %matName);
if(%filePath !$= "")
AssetBrowser.addImportingAsset("Material", %filePath, %shapeId);
else
AssetBrowser.addImportingAsset("Material", %matName, %shapeId);
}
%materialItem = %assetItem.shapeInfo.getNextSibling(%materialItem);
while(%materialItem != 0)
{
%matName = %assetItem.shapeInfo.getItemText(%materialItem);
%filePath = %assetItem.shapeInfo.getItemValue(%materialItem);
if(%filePath !$= "")
{
AssetBrowser.addImportingAsset("Material", %filePath, %shapeId);
}
else
{
//we need to try and find our material, since the shapeInfo wasn't able to find it automatically
%filePath = findImageFile(filePath(%assetItem.filePath), %matName);
if(%filePath !$= "")
AssetBrowser.addImportingAsset("Material", %filePath, %shapeId);
else
AssetBrowser.addImportingAsset("Material", %matName, %shapeId);
}
%materialItem = %shapeInfo.getNextSibling(%materialItem);
}
}
}
function AssetBrowser::importShapeAsset(%this, %assetItem)
{
%moduleName = ImportAssetModuleList.getText();
%assetType = %assetItem.AssetType;
%filePath = %assetItem.filePath;
%assetName = %assetItem.assetName;
%assetImportSuccessful = false;
%assetId = %moduleName@":"@%assetName;
%assetPath = "data/" @ %moduleName @ "/Shapes";
%assetFullPath = %assetPath @ "/" @ fileName(%filePath);
%newAsset = new ShapeAsset()
{
assetName = %assetName;
versionId = 1;
fileName = fileName(%filePath);
originalFilePath = %filePath;
isNewShape = true;
};
//check dependencies
%importItem = ImportAssetTree.findItemByObjectId(%assetItem);
if(ImportAssetTree.isParentItem(%importItem))
{
%matSlotId = 0;
%childId = ImportAssetTree.getChild(%importItem);
while(%childId > 0)
{
%dependencyAssetItem = ImportAssetTree.getItemObject(%childId);
%depAssetType = %dependencyAssetItem.assetType;
if(%depAssetType $= "Material")
{
%matSet = "%newAsset.materialSlot"@%matSlotId@"=\"@Asset="@%moduleName@":"@%dependencyAssetItem.assetName@"\";";
eval(%matSet);
}
if(%depAssetType $= "Animation")
{
%matSet = "%newAsset.animationSequence"@%matSlotId@"=\"@Asset="@%moduleName@":"@%dependencyAssetItem.assetName@"\";";
eval(%matSet);
}
%childId = ImportAssetTree.getNextSibling(%childId);
%matSlotId++;
}
}
%assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ "/" @ %assetName @ ".asset.taml");
//and copy the file into the relevent directory
%doOverwrite = !AssetBrowser.isAssetReImport;
if(!pathCopy(%filePath, %assetFullPath, %doOverwrite))
{
error("Unable to import asset: " @ %filePath);
}
%constructor = ShapeEditor.findConstructor( %assetFullPath );
if(!isObject(%constructor))
%constructor = ShapeEditor.createConstructor(%assetFullPath);
//We'll update any relevent bits to the ShapeConstructor here
$TSShapeConstructor::neverImportMat = "";
if(ImportAssetWindow.activeImportConfig.IgnoreMaterials !$= "")
{
%ignoredMatNamesCount = getTokenCount(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ",;");
for(%i=0; %i < %ignoredMatNamesCount; %i++)
{
if(%i==0)
$TSShapeConstructor::neverImportMat = getToken(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ",;", %i);
else
$TSShapeConstructor::neverImportMat = $TSShapeConstructor::neverImportMat TAB getToken(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ",;", %i);
}
}
%constructor.neverImportMat = $TSShapeConstructor::neverImportMat;
ShapeEditor.saveConstructor( %constructor );
//now, force-load the file if it's collada
%fileExt = fileExt(%assetFullPath);
if(isSupportedFormat(getSubStr(%fileExt,1)))
{
%tempShape = new TSStatic()
{
shapeName = %assetFullPath;
};
%tempShape.delete();
}
%moduleDef = ModuleDatabase.findModule(%moduleName,1);
if(!AssetBrowser.isAssetReImport)
AssetDatabase.addDeclaredAsset(%moduleDef, %assetPath @ "/" @ %assetName @ ".asset.taml");
else
AssetDatabase.refreshAsset(%assetId);
}
function GuiInspectorTypeShapeAssetPtr::onControlDropped( %this, %payload, %position )
{
Canvas.popDialog(EditorDragAndDropLayer);
// Make sure this is a color swatch drag operation.
if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
return;
%assetType = %payload.dragSourceControl.parentGroup.assetType;
if(%assetType $= "ShapeAsset")
{
echo("DROPPED A SHAPE ON A SHAPE ASSET COMPONENT FIELD!");
%module = %payload.dragSourceControl.parentGroup.moduleName;
%asset = %payload.dragSourceControl.parentGroup.assetName;
%targetComponent = %this.ComponentOwner;
%targetComponent.MeshAsset = %module @ ":" @ %asset;
//Inspector.refresh();
}
EWorldEditor.isDirty= true;
}

View file

@ -0,0 +1,55 @@
function AssetBrowser::createShapeAnimationAsset(%this)
{
%dlg = new OpenFileDialog()
{
Filters = "Animation Files(*.dae, *.cached.dts)|*.dae;*.cached.dts";
DefaultPath = $Pref::WorldEditor::LastPath;
DefaultFile = "";
ChangePath = false;
OverwritePrompt = true;
forceRelativePath = false;
//MultipleFiles = true;
};
%ret = %dlg.Execute();
if ( %ret )
{
$Pref::WorldEditor::LastPath = filePath( %dlg.FileName );
%fullPath = %dlg.FileName;
}
%dlg.delete();
if ( !%ret )
return;
}
function AssetBrowser::editShapeAnimationAsset(%this, %assetDef)
{
%this.hideDialog();
ShapeEditorPlugin.openShapeAsset(%assetDef);
}
function AssetBrowser::buildShapeAnimationAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.animationName;
%previewData.assetPath = %assetDef.scriptFile;
//Lotta prepwork
/*%previewData.doubleClickCommand = %assetDef@".materialDefinitionName.reload(); "
@ "$Tools::materialEditorList = \"\";"
@ "EWorldEditor.clearSelection();"
@ "MaterialEditorGui.currentObject = 0;"
@ "MaterialEditorGui.currentMode = \"asset\";"
@ "MaterialEditorGui.currentMaterial = "@%assetDef@".materialDefinitionName;"
@ "MaterialEditorGui.setActiveMaterial( "@%assetDef@".materialDefinitionName );"
@ "EditorGui.setEditor(MaterialEditorPlugin); "
@ "AssetBrowser.hideDialog();";*/
%previewData.previewImage = "tools/assetBrowser/art/animationIcon";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef;
}

View file

@ -0,0 +1,12 @@
function AssetBrowser::buildSoundAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.soundFilePath;
//%previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "tools/assetBrowser/art/soundIcon";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.assetName;
}

View file

@ -0,0 +1,173 @@
function AssetBrowser::createStateMachineAsset(%this)
{
%assetName = AssetBrowser.newAssetSettings.assetName;
%moduleName = AssetBrowser.selectedModule;
%assetQuery = new AssetQuery();
%matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %assetName);
%i=1;
while(%matchingAssetCount > 0)
{
%newAssetName = %assetName @ %i;
%i++;
%matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %newAssetName);
}
%assetName = %newAssetName;
%assetQuery.delete();
%tamlpath = "data/" @ %moduleName @ "/stateMachines/" @ %assetName @ ".asset.taml";
%smFilePath = "data/" @ %moduleName @ "/stateMachines/" @ %assetName @ ".xml";
%asset = new StateMachineAsset()
{
AssetName = %assetName;
versionId = 1;
stateMachineFile = %assetName @ ".xml";
};
%xmlDoc = new SimXMLDocument();
%xmlDoc.saveFile(%smFilePath);
%xmlDoc.delete();
TamlWrite(%asset, %tamlpath);
//Now write our XML file
%xmlFile = new FileObject();
%xmlFile.openForWrite(%smFilePath);
%xmlFile.writeLine("<StateMachine>");
%xmlFile.writeLine("</StateMachine>");
%xmlFile.close();
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "StateMachines");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function AssetBrowser::editStateMachineAsset(%this, %assetDef)
{
eval("AssetBrowser.tempAsset = new " @ %assetDef.getClassName() @ "();");
AssetBrowser.tempAsset.assignFieldsFrom(%assetDef);
SMAssetEditInspector.inspect(AssetBrowser.tempAsset);
AssetBrowser_editAsset.editedAssetId = EditAssetPopup.assetId;
AssetBrowser_editAsset.editedAsset = AssetBrowser.tempAsset;
//remove some of the groups we don't need:
for(%i=0; %i < SMAssetEditInspector.getCount(); %i++)
{
%caption = SMAssetEditInspector.getObject(%i).caption;
if(%caption $= "Ungrouped" || %caption $= "Object" || %caption $= "Editing"
|| %caption $= "Persistence" || %caption $= "Dynamic Fields")
{
SMAssetEditInspector.remove(SMAssetEditInspector.getObject(%i));
%i--;
}
}
Canvas.pushDialog(StateMachineEditor);
StateMachineEditor.loadStateMachineAsset(EditAssetPopup.assetId);
StateMachineEditor-->Window.text = "State Machine Editor ("@EditAssetPopup.assetId@")";
}
function AssetBrowser::duplicateStateMachineAsset(%this, %assetDef)
{
//Check if we have a target module, if not we need to select one
if(%targetModule $= "")
{
error("AssetBrowser::duplicateStateMachineAsset - No target module selected!");
return;
}
%assetId = %assetDef.getAssetId();
%assetName = AssetDatabase.getAssetName(%assetId);
//First step, copy the files
%modulePath = "data/" @ %targetModule @ "/stateMachines/";
if(!isDirectory(%modulePath))
createPath(%modulePath);
%assetFile = AssetDatabase.getAssetFilePath(%assetId);
%stateMachineFile = %assetDef.stateMachineFile;
echo("AssetBrowser::duplicateGameObjectAsset - duplicating! " @ %assetId @ " to " @ %targetModule);
%tamlPath = %modulePath @ fileName(%assetFile);
pathCopy(%assetFile, %tamlPath);
pathCopy(%stateMachineFile, %modulePath @ fileName(%stateMachineFile));
echo("AssetBrowser::duplicateStateMachineAsset - duplicated!");
//Register the asset
%moduleDef = ModuleDatabase.findModule(%targetModule, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlPath);
//Refresh the browser
AssetBrowser.loadFilters();
//Ensure our context is set
%treeItemId = AssetBrowserFilterTree.findItemByName(%targetModule);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "StateMachineAsset");
AssetBrowserFilterTree.selectItem(%smItem);
//Rename it for convenience
AssetBrowser.performRenameAsset(%assetName, "New" @ %assetName);
//Expand and refresh the target module
AssetBrowserFilterTree.expandItem(%treeItemId,true);
AssetBrowserFilterTree.buildVisibleTree();
}
function AssetBrowser::renameGameObjectAsset(%this, %assetDef, %newAssetId, %originalName, %newName)
{
%assetPath = AssetDatabase.getAssetFilePath(%newAssetId);
//rename the file to match
%path = filePath(%assetPath);
%oldScriptFilePath = %assetDef.stateMachineFile;
%scriptFilePath = filePath(%assetDef.stateMachineFile);
%scriptExt = fileExt(%assetDef.stateMachineFile);
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %newName @ ".asset.taml";
%assetDef.stateMachineFile = %newScriptFileName;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
}
function AssetBrowser::buildStateMachineAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
%previewData.doubleClickCommand = "AssetBrowser.editStateMachineAsset( "@%assetDef@" );";
%previewData.previewImage = "tools/assetBrowser/art/stateMachineIcon";
%previewData.assetFriendlyName = %assetDef.friendlyName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef;
}

View file

@ -8,103 +8,26 @@ function AssetBrowser_editAsset::saveAsset(%this)
Canvas.popDialog(AssetBrowser_editAsset);
}
function AssetBrowser::editAsset(%this)
function AssetBrowser::editAsset(%this, %assetDef)
{
//Find out what type it is
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
//If the passed-in definition param is blank, then we're likely called via a popup
if(%assetDef $= "")
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = %assetDef.getClassName();
if(%assetType $= "MaterialAsset")
{
//if(EditorSettings.materialEditMode $= "MaterialEditor")
//{
%assetDef.materialDefinitionName.reload();
EditorGui.setEditor(MaterialEditorPlugin);
MaterialEditorGui.currentMaterial = %assetDef.materialDefinitionName;
MaterialEditorGui.setActiveMaterial( %assetDef.materialDefinitionName );
AssetBrowser.hideDialog();
/*}
else
{
Canvas.pushDialog(ShaderEditor);
ShaderEditorGraph.loadGraph(%assetDef.shaderGraph);
$ShaderGen::targetShaderFile = filePath(%assetDef.shaderGraph) @"/"@fileBase(%assetDef.shaderGraph);
}*/
}
else if(%assetType $= "StateMachineAsset")
{
eval("AssetBrowser.tempAsset = new " @ %assetDef.getClassName() @ "();");
AssetBrowser.tempAsset.assignFieldsFrom(%assetDef);
//Build out the edit command
%buildCommand = %this @ ".edit" @ %assetType @ "(" @ %assetDef @ ");";
eval(%buildCommand);
}
function AssetBrowser::appendSubLevel(%this)
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = %assetDef.getClassName();
SMAssetEditInspector.inspect(AssetBrowser.tempAsset);
AssetBrowser_editAsset.editedAssetId = EditAssetPopup.assetId;
AssetBrowser_editAsset.editedAsset = AssetBrowser.tempAsset;
//remove some of the groups we don't need:
for(%i=0; %i < SMAssetEditInspector.getCount(); %i++)
{
%caption = SMAssetEditInspector.getObject(%i).caption;
if(%caption $= "Ungrouped" || %caption $= "Object" || %caption $= "Editing"
|| %caption $= "Persistence" || %caption $= "Dynamic Fields")
{
SMAssetEditInspector.remove(SMAssetEditInspector.getObject(%i));
%i--;
}
}
Canvas.pushDialog(StateMachineEditor);
StateMachineEditor.loadStateMachineAsset(EditAssetPopup.assetId);
StateMachineEditor-->Window.text = "State Machine Editor ("@EditAssetPopup.assetId@")";
}
else if(%assetType $= "ComponentAsset")
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%scriptFile = %assetDef.scriptFile;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
else if(%assetType $= "GameObjectAsset")
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%scriptFile = %assetDef.scriptFilePath;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
else if(%assetType $= "ScriptAsset")
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%scriptFile = %assetDef.scriptFilePath;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
else if(%assetType $= "ShapeAsset")
{
%this.hideDialog();
ShapeEditorPlugin.openShapeAsset(EditAssetPopup.assetId);
}
else if(%assetType $= "ShapeAnimationAsset")
{
%this.hideDialog();
ShapeEditorPlugin.openShapeAsset(EditAssetPopup.assetId);
}
else if(%assetType $= "LevelAsset")
{
schedule( 1, 0, "EditorOpenMission", %assetDef.LevelFile);
}
else if(%assetType $= "GUIAsset")
{
if(!isObject(%assetDef.assetName))
{
exec(%assetDef.GUIFilePath);
exec(%assetDef.mScriptFilePath);
}
GuiEditContent(%assetDef.assetName);
}
schedule( 1, 0, "EditorOpenSceneAppend", %assetDef);
}
function AssetBrowser::editAssetInfo(%this)
@ -164,20 +87,24 @@ function AssetBrowser::renameAsset(%this)
AssetBrowser.selectedAssetPreview-->AssetNameLabel.setFirstResponder();
}
function AssetNameField::onReturn(%this)
function AssetBrowser::performRenameAsset(%this, %originalAssetName, %newName)
{
//if the name is different to the asset's original name, rename it!
%newName = %this.getText();
if(%this.originalAssetName !$= %this.getText())
if(%originalAssetName !$= %newName)
{
%moduleName = AssetBrowser.selectedModule;
//do a rename!
%success = AssetDatabase.renameDeclaredAsset(%moduleName @ ":" @ %this.originalAssetName, %moduleName @ ":" @ %this.getText());
%success = AssetDatabase.renameDeclaredAsset(%moduleName @ ":" @ %originalAssetName, %moduleName @ ":" @ %newName);
if(%success)
echo("AssetBrowser - renaming of asset " @ %moduleName @ ":" @ %originalAssetName @ " to " @ %moduleName @ ":" @ %newName @ " was a success.");
else
echo("AssetBrowser - renaming of asset " @ %moduleName @ ":" @ %originalAssetName @ " to " @ %moduleName @ ":" @ %newName @ " was a failure.");
if(%success)
{
%newAssetId = %moduleName @ ":" @ %this.getText();
%newAssetId = %moduleName @ ":" @ %newName;
%assetPath = AssetDatabase.getAssetFilePath(%newAssetId);
//Rename any associated files as well
@ -187,160 +114,44 @@ function AssetNameField::onReturn(%this)
//rename the file to match
%path = filePath(%assetPath);
if(%assetType $= "ComponentAsset")
{
%oldScriptFilePath = %assetDef.scriptFile;
%scriptFilePath = filePath(%assetDef.scriptFile);
%scriptExt = fileExt(%assetDef.scriptFile);
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %this.getText() @ ".asset.taml";
%assetDef.componentName = %newName;
%assetDef.scriptFile = %newScriptFileName;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
//Go through our scriptfile and replace the old namespace with the new
%editedFileContents = "";
%file = new FileObject();
if ( %file.openForRead( %newScriptFileName ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %this.originalAssetName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newScriptFileName);
%file.writeline(%editedFileContents);
%file.close();
}
exec(%newScriptFileName);
}
else if(%assetType $= "StateMachineAsset")
{
%oldScriptFilePath = %assetDef.stateMachineFile;
%scriptFilePath = filePath(%assetDef.stateMachineFile);
%scriptExt = fileExt(%assetDef.stateMachineFile);
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %this.getText() @ ".asset.taml";
%assetDef.stateMachineFile = %newScriptFileName;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
}
else if(%assetType $= "GameObjectAsset")
{
%oldScriptFilePath = %assetDef.scriptFilePath;
%scriptFilePath = filePath(%assetDef.scriptFilePath);
%scriptExt = fileExt(%assetDef.scriptFilePath);
%oldGOFilePath = %assetDef.TAMLFilePath;
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %this.getText() @ ".asset.taml";
%newGOFile = %path @ "/" @ %this.getText() @ ".taml";
%assetDef.gameObjectName = %newName;
%assetDef.scriptFilePath = %newScriptFileName;
%assetDef.TAMLFilePath = %newGOFile;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
pathCopy(%oldGOFilePath, %newGOFile);
fileDelete(%oldGOFilePath);
//Go through our scriptfile and replace the old namespace with the new
%editedFileContents = "";
%file = new FileObject();
if ( %file.openForRead( %newScriptFileName ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %this.originalAssetName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newScriptFileName);
%file.writeline(%editedFileContents);
%file.close();
}
exec(%newScriptFileName);
//Rename in the TAML file as well
%file = new FileObject();
if ( %file.openForRead( %newGOFile ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %this.originalAssetName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newGOFile);
%file.writeline(%editedFileContents);
%file.close();
}
}
//Do the rename command
%buildCommand = %this @ ".rename" @ %assetType @ "(" @ %assetDef @ "," @ %newAssetId @ ");";
eval(%buildCommand);
}
}
//Make sure everything is refreshed
AssetBrowser.loadFilters();
}
function AssetNameField::onReturn(%this)
{
%this.clearFirstResponder();
%this.setActive(false);
AssetBrowser.performRenameAsset(%this.originalAssetName, %this.getText());
}
//------------------------------------------------------------
function AssetBrowser::duplicateAsset(%this)
function AssetBrowser::duplicateAsset(%this, %targetModule)
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
if(%targetModule $= "")
{
//we need a module to duplicate to first
Canvas.pushDialog(AssetBrowser_selectModule);
AssetBrowser_selectModule.callback = "AssetBrowser.duplicateAsset";
return;
}
%this.setupCreateNewAsset(%assetDef.getClassName(), AssetBrowser.selectedModule);
%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@");");
}
function AssetBrowser::deleteAsset(%this)
@ -358,8 +169,15 @@ function AssetBrowser::confirmDeleteAsset(%this)
%currentSelectedItem = AssetBrowserFilterTree.getSelectedItem();
%currentItemParent = AssetBrowserFilterTree.getParentItem(%currentSelectedItem);
AssetDatabase.deleteAsset(EditAssetPopup.assetId, false);
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId);
//Do any cleanup required given the type
if(%this.isMethod("delete"@%assetType))
eval(%this @ ".delete"@%assetType@"("@%assetDef@");");
AssetDatabase.deleteAsset(EditAssetPopup.assetId, false);
%this.loadFilters();
if(!AssetBrowserFilterTree.selectItem(%currentSelectedItem))

View file

@ -39,8 +39,7 @@ function GameObjectCreateBtn::onClick(%this)
//also, exec any components that may exist
//find all GameObjectAssets
%assetQuery = new AssetQuery();
if(!AssetDatabase.findAssetType(%assetQuery, "GameObjectAsset"))
return; //if we didn't find ANY, just exit
AssetDatabase.findAssetType(%assetQuery, "GameObjectAsset");
%count = %assetQuery.getCount();
@ -69,7 +68,7 @@ function GameObjectCreateBtn::onClick(%this)
//get the selected module data
%moduleName = GameObjectModuleList.getText();
%selectedEntity.gameObjectAsset = %moduleName @ ":" @ %className;
%selectedEntity.gameObject = %moduleName @ ":" @ %className;
%path = "data/" @ %moduleName @ "/gameObjects/";

View file

@ -71,16 +71,18 @@ function NewAssetModuleBtn::onClick(%this)
AssetBrowser_addModuleWindow.selectWindow();
}
function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName)
function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName, %callback)
{
Canvas.pushDialog(AssetBrowser_newAsset);
AssetBrowser_newAssetWindow.text = "New" SPC %assetType SPC "Asset";
NewAssetPropertiesInspector.clear();
NewAssetPropertiesInspector.clearFields();
NewAssetModuleList.setText(%moduleName);
AssetBrowser_newAsset.callbackFunc = %callback;
//get rid of the old one if we had one.
if(isObject(%this.newAssetSettings))
%this.newAssetSettings.delete();
@ -96,7 +98,7 @@ function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName)
NewAssetPropertiesInspector.addField("assetName", "New Asset Name", "String", "Name of the new asset", "New" @ %shortAssetTypeName, "", %this.newAssetSettings);
//NewAssetPropertiesInspector.addField("AssetType", "New Asset Type", "List", "Type of the new asset", %assetType, "Component,Image,Material,Shape,Sound,State Machine", %newAssetSettings);
NewAssetPropertiesInspector.addField("friendlyName", "Friendly Name", "String", "Human-readable name of new asset", "", "", %this.newAssetSettings);
//NewAssetPropertiesInspector.addField("friendlyName", "Friendly Name", "String", "Human-readable name of new asset", "", "", %this.newAssetSettings);
NewAssetPropertiesInspector.addField("description", "Description", "Command", "Description of the new asset", "", "", %this.newAssetSettings);
NewAssetPropertiesInspector.endGroup();
@ -112,7 +114,8 @@ function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName)
else if(%assetType $= "LevelAsset")
{
NewAssetPropertiesInspector.startGroup("Level");
NewAssetPropertiesInspector.addField("levelPreviewImage", "LevePreviewImage", "Image", "Preview Image for the level", "", "", %this.newAssetSettings);
NewAssetPropertiesInspector.addField("levelName", "Level Name", "String", "Human-readable name of new level", "", "", %this.newAssetSettings);
NewAssetPropertiesInspector.addField("levelPreviewImage", "Level Preview Image", "Image", "Preview Image for the level", "", "", %this.newAssetSettings);
NewAssetPropertiesInspector.endGroup();
}
else if(%assetType $= "ScriptAsset")
@ -121,6 +124,13 @@ function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName)
NewAssetPropertiesInspector.addField("isServerScript", "Is Server Script", "bool", "Is this script used on the server?", "1", "", %this.newAssetSettings);
NewAssetPropertiesInspector.endGroup();
}
//Special case, we only do this via internal means like baking
/*else if(%assetType $= "ShapeAsset")
{
NewAssetPropertiesInspector.startGroup("Shape");
NewAssetPropertiesInspector.addField("isServerScript", "Is Server Script", "bool", "Is this script used on the server?", "1", "", %this.newAssetSettings);
NewAssetPropertiesInspector.endGroup();
}*/
/*else if(%assetType $= "ShapeAnimationAsset")
{
NewAssetPropertiesInspector.startGroup("Animation");
@ -134,30 +144,6 @@ function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName)
NewAssetPropertiesInspector.addField("padTransforms", "Pad Transforms", "bool", "Source file this animation will pull from", "0", "", %this.newAssetSettings);
NewAssetPropertiesInspector.endGroup();
}*/
return;
if(%moduleName $= "")
{
Canvas.pushDialog(AssetBrowser_selectModule);
}
else
{
AssetBrowser.SelectedModule = %moduleName;
if(%assetType $= "MaterialAsset")
{
createNewMaterialAsset("NewMaterial", %moduleName);
}
else if(%assetType $= "StateMachineAsset")
{
createNewStateMachineAsset("NewStateMachine", %moduleName);
}
else if(%assetType $= "ScriptAsset")
{
createNewScriptAsset("NewScriptAsset", %moduleName);
}
}
}
//We do a quick validation that mandatory fields are filled in before passing along to the asset-type specific function
@ -189,36 +175,7 @@ function CreateNewAsset()
return;
}
if(%assetType $= "ComponentAsset")
{
//Canvas.popDialog(AssetBrowser_newComponentAsset);
//AssetBrowser_newComponentAsset-->AssetBrowserModuleList.setText(AssetBrowser.selectedModule);
%assetFilePath = createNewComponentAsset(%assetName, %path);
}
else if(%assetType $= "MaterialAsset")
{
%assetFilePath = createNewMaterialAsset();
}
else if(%assetType $= "StateMachineAsset")
{
%assetFilePath = createNewStateMachineAsset();
}
else if(%assetType $= "GUIAsset")
{
%assetFilePath = createNewGUIAsset();
}
else if(%assetType $= "LevelAsset")
{
%assetFilePath = createNewLevelAsset();
}
else if(%assetType $= "ScriptAsset")
{
%assetFilePath = createNewScriptAsset();
}
else if(%assetType $= "ShapeAnimationAsset")
{
%assetFilePath = createShapeAnimationAsset();
}
%assetFilePath = eval(AssetBrowser @ ".create"@%assetType@"();");
Canvas.popDialog(AssetBrowser_newAsset);
@ -227,356 +184,12 @@ function CreateNewAsset()
AssetDatabase.addDeclaredAsset(%moduleDef, %assetFilePath);
AssetBrowser.loadFilters();
}
function createNewComponentAsset()
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/components/" @ %assetName @ ".asset.taml";
%scriptPath = %modulePath @ "/components/" @ %assetName @ ".cs";
%asset = new ComponentAsset()
{
AssetName = %assetName;
versionId = 1;
componentName = %assetName;
componentClass = AssetBrowser.newAssetSettings.parentClass;
friendlyName = AssetBrowser.newAssetSettings.friendlyName;
componentType = AssetBrowser.newAssetSettings.componentGroup;
description = AssetBrowser.newAssetSettings.description;
scriptFile = %scriptPath;
};
TamlWrite(%asset, %tamlpath);
%file = new FileObject();
if(%file.openForWrite(%scriptPath))
if(AssetBrowser_newAsset.callbackFunc !$= "")
{
//TODO: enable ability to auto-embed a header for copyright or whatnot
%file.writeline("//onAdd is called when the component is created and then added to it's owner entity.\n");
%file.writeline("//You would also add any script-defined component fields via addComponentField().\n");
%file.writeline("function " @ %assetName @ "::onAdd(%this)\n{\n\n}\n");
%file.writeline("//onAdd is called when the component is removed and deleted from it's owner entity.");
%file.writeline("function " @ %assetName @ "::onRemove(%this)\n{\n\n}\n");
%file.writeline("//onClientConnect is called any time a new client connects to the server.");
%file.writeline("function " @ %assetName @ "::onClientConnect(%this, %client)\n{\n\n}\n");
%file.writeline("//onClientDisconnect is called any time a client disconnects from the server.");
%file.writeline("function " @ %assetName @ "::onClientDisonnect(%this, %client)\n{\n\n}\n");
%file.writeline("//update is called when the component does an update tick.\n");
%file.writeline("function " @ %assetName @ "::Update(%this)\n{\n\n}\n");
%file.close();
%callbackCommand = "" @ AssetBrowser_newAsset.callbackFunc @ "(\"" @ %moduleName @ ":" @ %assetName @ "\");";
eval(%callbackCommand);
}
Canvas.popDialog(AssetBrowser_newComponentAsset);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Components");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function createNewMaterialAsset()
{
%assetName = AssetBrowser.newAssetSettings.assetName;
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%tamlpath = %modulePath @ "/materials/" @ %assetName @ ".asset.taml";
%sgfPath = %modulePath @ "/materials/" @ %assetName @ ".sgf";
%asset = new MaterialAsset()
{
AssetName = %assetName;
versionId = 1;
shaderData = "";
shaderGraph = %sgfPath;
};
TamlWrite(%asset, %tamlpath);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Materials");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function createNewScriptAsset()
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/scripts/" @ %assetName @ ".asset.taml";
%scriptPath = %modulePath @ "/scripts/" @ %assetName @ ".cs";
%asset = new ScriptAsset()
{
AssetName = %assetName;
versionId = 1;
scriptFilePath = %scriptPath;
};
TamlWrite(%asset, %tamlpath);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Scripts");
AssetBrowserFilterTree.onSelect(%smItem);
%file = new FileObject();
if(%file.openForWrite(%scriptPath))
{
%file.close();
}
return %tamlpath;
}
function createNewStateMachineAsset()
{
%assetName = AssetBrowser.newAssetSettings.assetName;
%assetQuery = new AssetQuery();
%matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %assetName);
%i=1;
while(%matchingAssetCount > 0)
{
%newAssetName = %assetName @ %i;
%i++;
%matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %newAssetName);
}
%assetName = %newAssetName;
%assetQuery.delete();
%tamlpath = "data/" @ %moduleName @ "/stateMachines/" @ %assetName @ ".asset.taml";
%smFilePath = "data/" @ %moduleName @ "/stateMachines/" @ %assetName @ ".xml";
%asset = new StateMachineAsset()
{
AssetName = %assetName;
versionId = 1;
stateMachineFile = %smFilePath;
};
%xmlDoc = new SimXMLDocument();
%xmlDoc.saveFile(%smFilePath);
%xmlDoc.delete();
TamlWrite(%asset, %tamlpath);
//Now write our XML file
%xmlFile = new FileObject();
%xmlFile.openForWrite(%smFilePath);
%xmlFile.writeLine("<StateMachine>");
%xmlFile.writeLine("</StateMachine>");
%xmlFile.close();
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "StateMachines");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function createNewGUIAsset()
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/GUIs/" @ %assetName @ ".asset.taml";
%guipath = %modulePath @ "/GUIs/" @ %assetName @ ".gui";
%scriptPath = %modulePath @ "/GUIs/" @ %assetName @ ".cs";
%asset = new GUIAsset()
{
AssetName = %assetName;
versionId = 1;
scriptFilePath = %scriptPath;
guiFilePath = %guipath;
};
TamlWrite(%asset, %tamlpath);
%file = new FileObject();
if(%file.openForWrite(%guipath))
{
%file.writeline("//--- OBJECT WRITE BEGIN ---");
%file.writeline("%guiContent = new GuiControl(" @ %assetName @ ") {");
%file.writeline(" position = \"0 0\";");
%file.writeline(" extent = \"100 100\";");
%file.writeline("};");
%file.writeline("//--- OBJECT WRITE END ---");
%file.close();
}
if(%file.openForWrite(%scriptPath))
{
%file.writeline("function " @ %assetName @ "::onWake(%this)\n{\n\n}\n");
%file.writeline("function " @ %assetName @ "::onSleep(%this)\n{\n\n}\n");
%file.close();
}
//load the gui
exec(%guipath);
exec(%scriptPath);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "GUIs");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function createNewLevelAsset()
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/levels/" @ %assetName @ ".asset.taml";
%levelPath = %modulePath @ "/levels/" @ %assetName @ ".mis";
%asset = new LevelAsset()
{
AssetName = %assetName;
versionId = 1;
LevelFile = %levelPath;
LevelDescription = AssetBrowser.newAssetSettings.levelDescription;
PreviewImage = AssetBrowser.newAssetSettings.levelPreviewImage;
};
TamlWrite(%asset, %tamlpath);
if(!pathCopy("tools/levels/BlankRoom.mis", %levelPath, false))
{
echo("Unable to copy template level file!");
}
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Levels");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;
}
function createNewShapeAnimationAsset()
{
%dlg = new OpenFileDialog()
{
Filters = "Animation Files(*.dae, *.cached.dts)|*.dae;*.cached.dts";
DefaultPath = $Pref::WorldEditor::LastPath;
DefaultFile = "";
ChangePath = false;
OverwritePrompt = true;
forceRelativePath = false;
//MultipleFiles = true;
};
%ret = %dlg.Execute();
if ( %ret )
{
$Pref::WorldEditor::LastPath = filePath( %dlg.FileName );
%fullPath = %dlg.FileName;
}
%dlg.delete();
if ( !%ret )
return;
/*%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/levels/" @ %assetName @ ".asset.taml";
%levelPath = %modulePath @ "/levels/" @ %assetName @ ".mis";
%asset = new ShapeAnimationAsset()
{
AssetName = %assetName;
versionId = 1;
LevelFile = %levelPath;
LevelDescription = AssetBrowser.newAssetSettings.levelDescription;
PreviewImage = AssetBrowser.newAssetSettings.levelPreviewImage;
};
TamlWrite(%asset, %tamlpath);
if(!pathCopy("tools/levels/BlankRoom.mis", %levelPath, false))
{
echo("Unable to copy template level file!");
}
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.loadFilters();
%treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName);
%smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Levels");
AssetBrowserFilterTree.onSelect(%smItem);
return %tamlpath;*/
}
function ParentComponentList::onWake(%this)
@ -651,13 +264,5 @@ function ParentComponentList::refresh(%this)
//----------------------------------------------------------
function EWorldEditor::createGameObject( %this )
{
GameObjectCreatorObjectName.text = "";
%activeSelection = %this.getActiveSelection();
if( %activeSelection.getCount() == 0 )
return;
GameObjectCreator.selectedEntity = %activeSelection.getObject( 0 );
Canvas.pushDialog(GameObjectCreator);
AssetBrowser.createGameObjectAsset();
}

View file

@ -37,6 +37,31 @@ function AssetBrowser::buildPopupMenus(%this)
};
}
if( !isObject( EditLevelAssetPopup ) )
{
new PopupMenu( EditLevelAssetPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
//isPopup = true;
item[ 0 ] = "Edit Level" TAB "" TAB "AssetBrowser.editAsset();";
item[ 1 ] = "Append as Sublevel" TAB "" TAB "AssetBrowser.appendSublevel();";
item[ 2 ] = "Rename Asset" TAB "" TAB "AssetBrowser.renameAsset();";
item[ 3 ] = "Refresh Asset" TAB "" TAB "AssetBrowser.refreshAsset();";
item[ 4 ] = "Asset Properties" TAB "" TAB "AssetBrowser.editAssetInfo();";
item[ 5 ] = "-";
Item[ 6 ] = "Duplicate Asset" TAB "" TAB "AssetBrowser.duplicateAsset();";
item[ 7 ] = "-";
item[ 8 ] = "Re-Import Asset" TAB "" TAB "AssetBrowser.reImportAsset();";
item[ 9 ] = "-";
item[ 10 ] = "Delete Asset" TAB "" TAB "AssetBrowser.deleteAsset();";
jumpFileName = "";
jumpLineNumber = "";
};
}
if( !isObject( AddNewComponentAssetPopup ) )
{
new PopupMenu( AddNewComponentAssetPopup )
@ -92,6 +117,25 @@ function AssetBrowser::buildPopupMenus(%this)
item[ 12 ] = "Create Particle Effect" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"ParticleEffectAsset\", AssetBrowser.selectedModule);";//"AssetBrowser.createNewParticleEffectAsset(\"NewParticleEffect\", AssetBrowser.selectedModule);";
};
}
if( !isObject( AddNewCppAssetPopup ) )
{
%this.AddNewCppAssetPopup = new PopupMenu( AddNewCppAssetPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
//isPopup = true;
/*item[ 0 ] = "Create Static Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppStaticClassAsset\", AssetBrowser.selectedModule);";
item[ 1 ] = "Create Regular Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppRegularClassAsset\", AssetBrowser.selectedModule);";
item[ 2 ] = "Create GameObject Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppGameObjectAsset\", AssetBrowser.selectedModule);";
item[ 3 ] = "Create Component Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppComponentAsset\", AssetBrowser.selectedModule);";
item[ 4 ] = "Create Script Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppScriptClass\", AssetBrowser.selectedModule);";*/
item[ 0 ] = "Create C++ Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppAsset\", AssetBrowser.selectedModule);";
};
//%this.AddNewScriptAssetPopup.insertSubMenu(0, "Create Component", AddNewComponentAssetPopup);
}
if( !isObject( AddNewAssetPopup ) )
{
@ -105,6 +149,9 @@ function AssetBrowser::buildPopupMenus(%this)
item[2] = "Create Art Asset" TAB AddNewArtAssetPopup;
item[3] = "-";
item[4] = "Create Level" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"LevelAsset\", AssetBrowser.selectedModule);";//"AssetBrowser.createNewLevelAsset(\"NewLevel\", AssetBrowser.selectedModule);";
item[5] = "-";
item[6] = "Create C++ Asset" TAB AddNewCppAssetPopup;
};
}
@ -130,11 +177,89 @@ function AssetBrowser::buildPopupMenus(%this)
//Some assets are not yet ready/implemented, so disable their creation here
AddNewArtAssetPopup.enableItem(3, false); //shape
AddNewArtAssetPopup.enableItem(4, false); //shape animation
AddNewArtAssetPopup.enableItem(8, false); //post effect
AddNewArtAssetPopup.enableItem(10, false); //sound asset
AddNewArtAssetPopup.enableItem(12, false); //particle effect
AddNewScriptAssetPopup.enableItem(2, false); //state machine
if( !isObject( EditAssetCategoryPopup ) )
{
new PopupMenu( EditAssetCategoryPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
//isPopup = true;
item[ 0 ] = "Toggle Autoloading of Script Assets" TAB "" TAB "AssetBrowser.toggleAutoloadAsset(\"Script\");";
};
}
//Browser visibility menu
if( !isObject( BrowserVisibilityPopup ) )
{
new PopupMenu( BrowserVisibilityPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
//isPopup = true;
item[ 0 ] = "Toggle Show Core Modules" TAB "" TAB "AssetBrowser.viewCoreModulesFilter();";
item[ 1 ] = "Toggle Only Show Modules with Assets" TAB "" TAB "AssetBrowser.viewPopulatedModulesFilter();";
Item[ 2 ] = "-";
item[ 3 ] = "Show Assets as list" TAB "" TAB "AssetBrowser.viewListFilter();";
Item[ 4 ] = "Show Assets with tags" TAB "" TAB "AssetBrowser.viewTagsFilter();";
};
}
//Import Legacy menus
if( !isObject( ImportAssetsPopup ) )
{
new PopupMenu( ImportAssetsPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
item[ 0 ] = "Import Legacy Game" TAB "" TAB "AssetBrowser.importLegacyGame();";
Item[ 1 ] = "-";
item[ 2 ] = "Import new assets" TAB "" TAB "AssetBrowser.importNewAssetFile();";
};
}
if( !isObject( EditGameObjectAssetPopup ) )
{
new PopupMenu( EditGameObjectAssetPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
//isPopup = true;
item[ 0 ] = "Open GameObject Editor" TAB "" TAB "echo(\"Not yet implemented.\");";
item[ 1 ] = "Edit GameObject Script" TAB "" TAB "AssetBrowser.editGameObjectAssetScript(AssetDatabase.acquireAsset(EditGameObjectAssetPopup.assetId));";
item[ 2 ] = "-";
item[ 3 ] = "Apply Instance to GameObject" TAB "" TAB "AssetBrowser.applyInstanceToGameObject(AssetDatabase.acquireAsset(EditGameObjectAssetPopup.assetId));";
item[ 4 ] = "Reset Instance to GameObject" TAB "" TAB "echo(\"Not yet implemented.\");";
item[ 5 ] = "-";
item[ 6 ] = "Create Child GameObject" TAB "" TAB "echo(\"Not yet implemented.\");";
};
}
//Asset Import Resolution menus
if( !isObject( ImportAssetResolutionsPopup ) )
{
%this.ImportAssetResolutionsPopup = new PopupMenu( ImportAssetResolutionsPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
item[0] = "Use original Asset for duplicates" TAB "" TAB "";
item[1] = "Override duplicate with new Asset" TAB "" TAB "";
item[2] = "-";
item[3] = "Rename Asset" TAB "" TAB "";
item[4] = "-";
item[5] = "Find missing file" TAB "" TAB "ImportAssetWindow.findMissingFile(ImportAssetResolutionsPopup.assetItem);";
item[6] = "-";
item[7] = "Edit Asset properties" TAB "" TAB "";
};
}
}
function AddNewScriptAssetPopupMenu::onSelectItem(%this, %id, %text)

View file

@ -1,8 +1,21 @@
function AssetBrowser_selectModule::onWake(%this)
function AssetBrowser_SelectModule::onWake(%this)
{
AssetBrowser_SelectModuleWindow-->ModuleList.refresh();
}
function AssetBrowser_SelectModule::moduleSelected(%this)
{
Canvas.popDialog(AssetBrowser_SelectModule);
%module = AssetBrowser_SelectModuleWindow-->ModuleList.getText();
echo("Module Selected: " @ %module);
if(%this.callback !$= "")
eval(%this.callback @ "(" @ %module @ ");");
else
error("AssetBrowser_SelectModule - Invalid callback");
}
function SelectModule_NewAssetModuleBtn::onClick(%this)
{
Canvas.pushDialog(AssetBrowser_AddModule);

View file

@ -0,0 +1,18 @@
#include "core/module.h"
#include "console/engineAPI.h"
MODULE_BEGIN(@_Module)
MODULE_INIT_AFTER(Sim)
MODULE_SHUTDOWN_BEFORE(Sim)
MODULE_INIT
{
// Setup anything needed when the engine initializes here
}
MODULE_SHUTDOWN
{
// Cleanup anything that was initialized before here
}
MODULE_END;

View file

@ -0,0 +1,15 @@
#include "@.h"
IMPLEMENT_STATIC_CLASS(@, , "Functions for maintaing a list of banned users.");
@* @::smInstance;
@::@()
{
smInstance = this;
}
DefineEngineStaticMethod(@, doSomething, void, (), , "")
{
//@::instance()->doSomething();
}

View file

@ -0,0 +1,17 @@
#pragma once
#include "console/engineAPI.h"
class @
{
DECLARE_STATIC_CLASS(@);
private:
protected:
static @* smInstance;
public:
@();
static @* instance() { return smInstance; }
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 805 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 762 B

View file

@ -287,6 +287,30 @@ new GuiControlProfile( ToolsGuiTextEditProfile )
category = "Tools";
};
if( !isObject( ToolsGuiTextEditErrorProfile ) )
new GuiControlProfile( ToolsGuiTextEditErrorProfile )
{
opaque = true;
bitmap = "./images/textEditFrame";
hasBitmapArray = true;
border = -2; // fix to display textEdit img
//borderWidth = "1"; // fix to display textEdit img
//borderColor = "100 100 100";
fillColor = "242 241 240 0";
fillColorHL = "255 255 255";
fontColor = "0 0 0";
fontColorHL = "255 0 0";
fontColorSEL = "98 100 137";
fontColorNA = "200 200 200";
textOffset = "4 2";
autoSizeWidth = false;
autoSizeHeight = true;
justify = "left";
tab = true;
canKeyFocus = true;
category = "Tools";
};
if( !isObject( ToolsGuiTextEditCenterProfile ) )
new GuiControlProfile (ToolsGuiTextEditCenterProfile)
{

View file

@ -137,6 +137,8 @@ function MaterialEditorGui::open(%this)
if( MaterialEditorGui.currentMode $= "Mesh" )
MaterialEditorGui.prepareActiveObject( true );
else if( MaterialEditorGui.currentMode $= "asset" )
MaterialEditorGui.prepareActiveMaterial( MaterialEditorGui.currentMaterial, true );
else
MaterialEditorGui.prepareActiveMaterial( "", true );
@ -288,7 +290,9 @@ function MaterialEditorGui::setMode( %this )
}
else
{
MaterialEditorGui.currentMode = "Material";
if(MaterialEditorGui.currentMode !$= "asset")
MaterialEditorGui.currentMode = "Material";
MatEdMaterialMode.setVisible(1);
EWorldEditor.clearSelection();
}

View file

@ -145,10 +145,9 @@ function ShapeEditorPlugin::onWorldEditorStartup(%this)
}
}
function ShapeEditorPlugin::openShapeAsset(%this, %assetId)
function ShapeEditorPlugin::openShapeAsset(%this, %assetDef)
{
%this.selectedAssetId = %assetId;
%this.selectedAssetDef = AssetDatabase.acquireAsset(%assetId);
%this.selectedAssetDef = %assetDef;
%this.open(%this.selectedAssetDef.fileName);
}

View file

@ -613,7 +613,7 @@ function ShapeEdPropWindow::update_onShapeSelectionChanged( %this )
ShapeEdThreadWindow.onAddThread(); // add thread 0
//Now, fetch any animation assets if we're utilizing a shape asset
if(ShapeEditorPlugin.selectedAssetId !$= "")
if(ShapeEditorPlugin.selectedAssetDef !$= "")
{
%animationAssetCount = ShapeEditorPlugin.selectedAssetDef.getAnimationCount();

View file

@ -319,7 +319,7 @@ function ShapeEditor::doAddSequence( %this, %seqName, %from, %start, %end )
function ActionAddSequence::doit( %this )
{
if(ShapeEditorPlugin.selectedAssetId $= "")
if(ShapeEditorPlugin.selectedAssetDef $= "")
{
// If adding this sequence from an existing sequence, make a backup copy of
// the existing sequence first, so we can edit the start/end frames later
@ -346,8 +346,20 @@ function ActionAddSequence::doit( %this )
%assetDef = AssetDatabase.acquireAsset(%this.seqName);
%moduleName = getWord(getToken(%this.seqName, ":", 0),0);
//If we have <rootpose> or ambient, we'll want to ignore them for our idx values when embedding animation dependencies to our shape asset
%idxOffset = 0;
if(ShapeEdSequenceList.findTextIndex("<rootpose>\t\t\t\t") != -1)
%idxOffset++;
if(ShapeEdSequenceList.findTextIndex("ambient\t\t\t\t") != -1)
%idxOffset++;
//TODO, properly ignore <rootpose> and ambient entries for our idx values, but only if they're there!
%idx = ShapeEdSequenceList.rowCount() - 2;
%idx = ShapeEdSequenceList.rowCount() - %idxOffset;
//We adjust due to the list "header" row as well
%idx -= 1;
%animSet = "ShapeEditorPlugin.selectedAssetDef.animationSequence"@%idx@"=\"@Asset="@%moduleName@":"@%assetDef.assetName@"\";";
eval(%animSet);

View file

@ -1596,6 +1596,8 @@ function EditorTree::onRightMouseUp( %this, %itemId, %mouse, %obj )
{
%popup.item[ 0 ] = "Delete" TAB "" TAB "EditorMenuEditDelete();";
%popup.item[ 1 ] = "Group" TAB "" TAB "EWorldEditor.addSimGroup( true );";
%popup.item[ 2 ] = "-";
%popup.item[ 1 ] = "Make select a Sub-Level" TAB "" TAB "MakeSelectionASublevel();";
}
else
{
@ -1726,7 +1728,7 @@ function EditorTree::isValidDragTarget( %this, %id, %obj )
if( %obj.name $= "CameraBookmarks" )
return EWorldEditor.areAllSelectedObjectsOfType( "CameraBookmark" );
else
return ( %obj.getClassName() $= "SimGroup" );
return ( %obj.getClassName() $= "SimGroup" || %obj.isMemberOfClass("Scene"));
}
function EditorTree::onBeginReparenting( %this )

View file

@ -237,7 +237,7 @@ function EditorNewLevel( %file )
function EditorSaveMissionMenu()
{
if(EditorGui.saveAs)
EditorSaveMissionAs();
AssetBrowser.setupCreateNewAsset("LevelAsset", AssetBrowser.selectedModule, "EditorSaveMissionAs");
else
EditorSaveMission();
}
@ -299,123 +299,32 @@ function EditorSaveMission()
return true;
}
function EditorSaveMissionAs( %missionName )
function EditorSaveMissionAs( %levelAsset )
{
// If we didn't get passed a new mission name then
// prompt the user for one.
if ( %missionName $= "" )
if ( %levelAsset $= "" )
return;
%levelAssetDef = AssetDatabase.acquireAsset(%levelAsset);
%assetType = AssetDatabase.getAssetType(%levelAsset);
if(%assetType !$= "LevelAsset")
{
%dlg = new SaveFileDialog()
{
Filters = $Pref::WorldEditor::FileSpec;
DefaultPath = EditorSettings.value("LevelInformation/levelsDirectory");
ChangePath = false;
OverwritePrompt = true;
};
%ret = %dlg.Execute();
if(%ret)
{
// Immediately override/set the levelsDirectory
EditorSettings.setValue( "LevelInformation/levelsDirectory", collapseFilename(filePath( %dlg.FileName )) );
%missionName = %dlg.FileName;
}
%dlg.delete();
if(! %ret)
return;
error("Somehow tried to save a non-level asset as a level? " @ %levelAsset);
return;
}
%missionName = %levelAssetDef.LevelFile;
if( fileExt( %missionName ) !$= ".mis" )
%missionName = %missionName @ ".mis";
EWorldEditor.isDirty = true;
%saveMissionFile = $Server::MissionFile;
$Server::MissionFile = %missionName;
%copyTerrainsFailed = false;
// Rename all the terrain files. Save all previous names so we can
// reset them if saving fails.
%newMissionName = fileBase(%missionName);
%oldMissionName = fileBase(%saveMissionFile);
initContainerTypeSearch( $TypeMasks::TerrainObjectType );
%savedTerrNames = new ScriptObject();
for( %i = 0;; %i ++ )
{
%terrainObject = containerSearchNext();
if( !%terrainObject )
break;
%savedTerrNames.array[ %i ] = %terrainObject.terrainFile;
%terrainFilePath = makeRelativePath( filePath( %terrainObject.terrainFile ), getMainDotCsDir() );
%terrainFileName = fileName( %terrainObject.terrainFile );
// Workaround to have terrains created in an unsaved "New Level..." mission
// moved to the correct place.
if( EditorGui.saveAs && %terrainFilePath $= "tools/art/terrains" )
%terrainFilePath = "art/terrains";
// Try and follow the existing naming convention.
// If we can't, use systematic terrain file names.
if( strstr( %terrainFileName, %oldMissionName ) >= 0 )
%terrainFileName = strreplace( %terrainFileName, %oldMissionName, %newMissionName );
else
%terrainFileName = %newMissionName @ "_" @ %i @ ".ter";
%newTerrainFile = %terrainFilePath @ "/" @ %terrainFileName;
if (!isWriteableFileName(%newTerrainFile))
{
if (MessageBox("Error", "Terrain file \""@ %newTerrainFile @ "\" is read-only. Continue?", "Ok", "Stop") == $MROk)
continue;
else
{
%copyTerrainsFailed = true;
break;
}
}
if( !%terrainObject.save( %newTerrainFile ) )
{
error( "Failed to save '" @ %newTerrainFile @ "'" );
%copyTerrainsFailed = true;
break;
}
%terrainObject.terrainFile = %newTerrainFile;
}
ETerrainEditor.isDirty = false;
// Save the mission.
if(%copyTerrainsFailed || !EditorSaveMission())
{
// It failed, so restore the mission and terrain filenames.
$Server::MissionFile = %saveMissionFile;
initContainerTypeSearch( $TypeMasks::TerrainObjectType );
for( %i = 0;; %i ++ )
{
%terrainObject = containerSearchNext();
if( !%terrainObject )
break;
%terrainObject.terrainFile = %savedTerrNames.array[ %i ];
}
}
%savedTerrNames.delete();
//Make sure we have a selected module so we can create our module
Canvas.pushDialog(AssetBrowser_selectModule);
}
function EditorOpenMission(%filename)
function EditorOpenMission(%levelAsset)
{
if( EditorIsDirty())
{
@ -428,28 +337,31 @@ function EditorOpenMission(%filename)
}
}
if(%filename $= "")
if(%levelAsset $= "")
{
%dlg = new OpenFileDialog()
AssetBrowser.showDialog("LevelAsset", "EditorOpenMission", "", "", "");
return;
}
else
{
//If we got the actual assetdef, just roll with it
if(isObject(%levelAsset))
{
Filters = $Pref::WorldEditor::FileSpec;
DefaultPath = EditorSettings.value("LevelInformation/levelsDirectory");
ChangePath = false;
MustExist = true;
};
%ret = %dlg.Execute();
if(%ret)
%assetDef = %levelAsset;
}
else
{
// Immediately override/set the levelsDirectory
EditorSettings.setValue( "LevelInformation/levelsDirectory", collapseFilename(filePath( %dlg.FileName )) );
%filename = %dlg.FileName;
//parse it out if its
%assetDef = AssetDatabase.acquireAsset(%levelAsset);
}
%dlg.delete();
%filename = %assetDef.levelFile;
if(! %ret)
if(%filename $= "")
{
error("Selected Level Asset doesn't have a valid levelFile path!");
return;
}
}
// close the current editor, it will get cleaned up by MissionCleanup
@ -498,6 +410,22 @@ function EditorOpenSceneAppend(%levelAsset)
}
}
function MakeSelectionASublevel()
{
/*%size = EWorldEditor.getSelectionSize();
if ( %size == 0 )
return;
//Make a new Scene object
for(%i=0; %i < %size; %i++)
{
}
%a = EWorldEditor.getSelectedObject(0);
%b = EWorldEditor.getSelectedObject(1);*/
}
function EditorExportToCollada()
{

View file

@ -132,7 +132,7 @@ function EditorGui::buildMenus(%this)
%fileMenu.appendItem("New Level" TAB "" TAB "schedule( 1, 0, \"EditorNewLevel\" );");
%fileMenu.appendItem("Open Level..." TAB %cmdCtrl SPC "O" TAB "schedule( 1, 0, \"EditorOpenMission\" );");
%fileMenu.appendItem("Save Level" TAB %cmdCtrl SPC "S" TAB "EditorSaveMissionMenu();");
%fileMenu.appendItem("Save Level As..." TAB "" TAB "EditorSaveMissionAs();");
%fileMenu.appendItem("Save Level As..." TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"LevelAsset\", AssetBrowser.selectedModule, \"EditorSaveMissionAs\");");
%fileMenu.appendItem("-");
if( $platform $= "windows" )
@ -339,7 +339,7 @@ function EditorGui::buildMenus(%this)
item[0] = "Network Graph" TAB "n" TAB "toggleNetGraph();";
item[1] = "Profiler" TAB "ctrl F2" TAB "showMetrics(true);";
item[2] = "Torque SimView" TAB "" TAB "tree();";
item[3] = "Make Selected a Mesh" TAB "" TAB "makeSelectedAMesh();";
item[3] = "Make Selected a Mesh" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"ShapeAsset\", AssetBrowser.selectedModule, \"makeSelectedAMesh\");";
};
%this.menuBar.insert(%toolsMenu);