Browse Source

Added functionality to ProjectLibrary to retrieve resource metas

Marko Pintera 11 years ago
parent
commit
bd280bba52

+ 2 - 0
BansheeEditor/Include/BsProjectLibrary.h

@@ -58,6 +58,8 @@ namespace BansheeEngine
 		const LibraryEntry* getRootEntry() const { return mRootEntry; }
 		LibraryEntry* findEntry(const Path& fullPath) const;
 
+		ResourceMetaPtr findResourceMeta(const String& uuid) const;
+
 		void moveEntry(const Path& oldPath, const Path& newPath);
 		void deleteEntry(const Path& path);
 

+ 4 - 1
BansheeEditor/Include/BsResourceMeta.h

@@ -13,13 +13,16 @@ namespace BansheeEngine
 	public:
 		explicit ResourceMeta(const ConstructPrivately&);
 
-		static ResourceMetaPtr create(const String& uuid, const ImportOptionsPtr& importOptions);
+		static ResourceMetaPtr create(const String& uuid, const WString& displayName, 
+			const ImportOptionsPtr& importOptions);
 
 		const String& getUUID() const { return mUUID; }
+		const WString& getDisplayName() const { return mDisplayName; }
 		const ImportOptionsPtr& getImportOptions() const { return mImportOptions; }
 
 	private:
 		String mUUID;
+		WString mDisplayName;
 		ImportOptionsPtr mImportOptions;
 
 		/************************************************************************/

+ 4 - 0
BansheeEditor/Include/BsResourceMetaRTTI.h

@@ -13,6 +13,9 @@ namespace BansheeEngine
 		String& getUUID(ResourceMeta* obj) { return obj->mUUID; }
 		void setUUID(ResourceMeta* obj, String& val) { obj->mUUID = val; } 
 
+		WString& getDisplayName(ResourceMeta* obj) { return obj->mDisplayName; }
+		void setDisplayName(ResourceMeta* obj, WString& val) { obj->mDisplayName = val; }
+
 		ImportOptionsPtr getImportOptions(ResourceMeta* obj) { return obj->mImportOptions; }
 		void setImportOptions(ResourceMeta* obj, ImportOptionsPtr val) { obj->mImportOptions = val; }
 
@@ -21,6 +24,7 @@ namespace BansheeEngine
 		{
 			addPlainField("mUUID", 0, &ResourceMetaRTTI::getUUID, &ResourceMetaRTTI::setUUID);
 			addReflectablePtrField("mImportOptions", 1, &ResourceMetaRTTI::getImportOptions, &ResourceMetaRTTI::setImportOptions);
+			addPlainField("mDisplayName", 2, &ResourceMetaRTTI::getDisplayName, &ResourceMetaRTTI::setDisplayName);
 		}
 
 		virtual const String& getRTTIName()

+ 21 - 1
BansheeEditor/Source/BsProjectLibrary.cpp

@@ -13,6 +13,7 @@
 #include "BsFolderMonitor.h"
 #include "BsDebug.h"
 #include "BsProjectLibraryEntries.h"
+#include "BsResource.h"
 
 using namespace std::placeholders;
 
@@ -377,7 +378,9 @@ namespace BansheeEngine
 			{
 				importedResource = Importer::instance().import(resource->path, importOptions);
 
-				resource->meta = ResourceMeta::create(importedResource.getUUID(), importOptions);
+				WString displayName = toWString(importedResource->getName());
+
+				resource->meta = ResourceMeta::create(importedResource.getUUID(), displayName, importOptions);
 				FileSerializer fs;
 				fs.encode(resource->meta.get(), metaPath);
 			}
@@ -460,6 +463,23 @@ namespace BansheeEngine
 		return nullptr;
 	}
 
+	ResourceMetaPtr ProjectLibrary::findResourceMeta(const String& uuid) const
+	{
+		if (mResourceManifest == nullptr)
+			return nullptr;
+
+		Path filePath;
+		if (!mResourceManifest->uuidToFilePath(uuid, filePath))
+			return nullptr;
+
+		LibraryEntry* libEntry = findEntry(filePath);
+		if (libEntry == nullptr || libEntry->type != LibraryEntryType::File)
+			return nullptr;
+
+		ResourceEntry* resEntry = static_cast<ResourceEntry*>(libEntry);
+		return resEntry->meta;
+	}
+
 	void ProjectLibrary::moveEntry(const Path& oldPath, const Path& newPath)
 	{
 		if(FileSystem::isFile(oldPath) || FileSystem::isDirectory(oldPath))

+ 2 - 1
BansheeEditor/Source/BsResourceMeta.cpp

@@ -8,10 +8,11 @@ namespace BansheeEngine
 
 	}
 
-	ResourceMetaPtr ResourceMeta::create(const String& uuid, const ImportOptionsPtr& importOptions)
+	ResourceMetaPtr ResourceMeta::create(const String& uuid, const WString& displayName, const ImportOptionsPtr& importOptions)
 	{
 		ResourceMetaPtr meta = bs_shared_ptr<ResourceMeta>(ConstructPrivately());
 		meta->mUUID = uuid;
+		meta->mDisplayName = displayName;
 		meta->mImportOptions = importOptions;
 
 		return meta;

+ 4 - 7
Inspector.txt

@@ -1,6 +1,10 @@
 Update C# GUIElementStyle
 Update GUIFoldout with sub styles
 
+GUIResourceField needs to be able to check resource type without loading it
+ - I need this for ProjectLibrary too (so I can display valid icons in TreeView)
+ - But I need a more exact version since resources could be custom C# classes (This will likely need to be supported in some special way)
+
 TODO:
  - Hook up int field set/get callbacks
     - Ensure int field isn't updated from app when in focus
@@ -9,22 +13,15 @@ TODO:
  - Entire foldout should be clickable, not just the toggle button
  - Extend text field so it can be multi-line
  - Port to C#:
-   - GameObjectField
-   - ResourceField
    - Create InspectableObjects for all different field types
  - Ensure get/set value from inspector fields works 
  - Add array fields and ensure they work/update properly
- - Extend GameObject field so it can only accept a certain type
  - Ensure Undo/redo works as intended
    - This task needs decomposing. Likely need to port UndoRedo to C# first.
  - GUIColor needs to be hooked up to a window that actually changes its value.
- - Need to add GUIResourceField along with GUIGameObjectField and figure out a way to make them
-   accept arbitrary types.
-     - Probably move them to SBansheeEditor
  - I need to register UndoRedo command after user finishes modifying a field. This should be referencing an object using an URI?
 
 TO PONDER:
- - How to limit resource/object fields to a custom type (user created type possibly)
  - How will I create undo/redo operations for serializable fields?
    - UndoRedo.RecordField - Saves current state of the field, before you modify it
      - Accepts a source object and a path that allows us to follow its properties to the exact modified field

+ 1 - 0
SBansheeEditor/Source/BsGUIResourceField.cpp

@@ -13,6 +13,7 @@
 #include "BsRuntimeScriptObjects.h"
 #include "BsMonoClass.h"
 #include "BsResources.h"
+#include "BsProjectLibrary.h"
 #include "BsEditorGUI.h"
 
 using namespace std::placeholders;