diff --git a/GlitchyEditor/resources/Textures/EditorIcons.dds b/GlitchyEditor/resources/Textures/EditorIcons.dds index 1ebc060..8d55e89 100644 Binary files a/GlitchyEditor/resources/Textures/EditorIcons.dds and b/GlitchyEditor/resources/Textures/EditorIcons.dds differ diff --git a/GlitchyEditor/resources/Textures/EditorIcons.psd b/GlitchyEditor/resources/Textures/EditorIcons.psd index 01d9928..4711f9c 100644 Binary files a/GlitchyEditor/resources/Textures/EditorIcons.psd and b/GlitchyEditor/resources/Textures/EditorIcons.psd differ diff --git a/GlitchyEditor/src/Assets/AssetThumbnailManager.bf b/GlitchyEditor/src/Assets/AssetThumbnailManager.bf new file mode 100644 index 0000000..742fee3 --- /dev/null +++ b/GlitchyEditor/src/Assets/AssetThumbnailManager.bf @@ -0,0 +1,32 @@ +using GlitchyEngine.Renderer; +namespace GlitchyEditor.Assets; + +class AssetThumbnailManager +{ + private EditorIcons _icons ~ _.ReleaseRef(); + + public this(EditorIcons icons) + { + _icons = icons..AddRef(); + } + + public SubTexture2D GetThumbnail(AssetNode assetNode) + { + if (assetNode.IsDirectory) + return _icons.Folder; + + if (assetNode.Path.EndsWith(".scene")) + return _icons.File_Scene; + + if (assetNode.Path.EndsWith(".mat")) + return _icons.File_Material; + + if (assetNode.Path.EndsWith(".cs")) + return _icons.File_CSharpScript; + + if (assetNode.Path.EndsWith(".hlsl")) + return _icons.File_Shader; + + return _icons.File; + } +} diff --git a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf index cc9337a..bdf5271 100644 --- a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf +++ b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf @@ -22,6 +22,8 @@ namespace GlitchyEditor.EditWindows private String _fileExtension ~ delete _; private CreateAssetFunc _doCreateAsset ~ delete _; + private SubTexture2D _icon ~ _?.ReleaseRef(); + public delegate void CreateAssetFunc(StringView outputPath); public StringView Name => _name; @@ -30,12 +32,17 @@ namespace GlitchyEditor.EditWindows public CreateAssetFunc CreateAsset => _doCreateAsset; - public this(StringView name, StringView defaultFileName, StringView fileExtension, CreateAssetFunc createAsset) + public SubTexture2D Icon => _icon; + + public this(StringView name, StringView defaultFileName, StringView fileExtension, CreateAssetFunc createAsset, SubTexture2D icon = null) { _name = new String(name); _defaultFileName = new String(defaultFileName); _fileExtension = new String(fileExtension); _doCreateAsset = createAsset; + + _icon = icon; + _icon?.AddRef(); } } @@ -58,6 +65,8 @@ namespace GlitchyEditor.EditWindows private append String _assetToRename = .(); private char8[128] _renameFileNameBuffer; + private AssetThumbnailManager _thumbnailManager; + public static SubTexture2D s_FolderTexture; public static SubTexture2D s_FileTexture; @@ -69,9 +78,10 @@ namespace GlitchyEditor.EditWindows bool _showNewFile = false; AssetCreator _newFileCreator = null; - public this(EditorContentManager contentManager) + public this(EditorContentManager contentManager, AssetThumbnailManager thumbnailManager) { _manager = contentManager; + _thumbnailManager = thumbnailManager; } /// Registers an asset creator that will show up in the "Create new" drop down menu @@ -577,7 +587,7 @@ namespace GlitchyEditor.EditWindows } // TODO: preview images - SubTexture2D image = entry->IsDirectory ? s_FolderTexture : s_FileTexture; + SubTexture2D image = _thumbnailManager.GetThumbnail(entry.Value); ImGui.ImageButton("FileImage", image, (.)IconSize); @@ -713,7 +723,7 @@ namespace GlitchyEditor.EditWindows ImGui.PushStyleColor(.Button, ImGui.Vec4(0, 0, 0, 0)); // TODO: preview images - SubTexture2D image = s_FileTexture; + SubTexture2D image = _newFileCreator.Icon ?? s_FileTexture; ImGui.ImageButton("FileImage", image, (.)IconSize); diff --git a/GlitchyEditor/src/Editor.bf b/GlitchyEditor/src/Editor.bf index adf46ec..11877d6 100644 --- a/GlitchyEditor/src/Editor.bf +++ b/GlitchyEditor/src/Editor.bf @@ -14,6 +14,7 @@ namespace GlitchyEditor private Scene _scene; private EditorContentManager _contentManager; + private AssetThumbnailManager _thumbnailManager; private Project _currentProject; @@ -41,6 +42,8 @@ namespace GlitchyEditor public EditorContentManager ContentManager => _contentManager; + public AssetThumbnailManager ThumbnailManager => _thumbnailManager; + public Project CurrentProject { get => _currentProject; @@ -68,13 +71,14 @@ namespace GlitchyEditor public static Editor Instance => s_Instance; /// Creates a new editor for the given world - public this(Scene scene, EditorContentManager contentManager) + public this(Scene scene, EditorContentManager contentManager, AssetThumbnailManager thumbnailManager) { Log.EngineLogger.AssertDebug(s_Instance == null, "Cannot create a second instance of a singleton."); s_Instance = this; _scene = scene; _contentManager = contentManager; + _thumbnailManager = thumbnailManager; InitWindows(); } @@ -90,7 +94,7 @@ namespace GlitchyEditor _gameViewportWindow = new GameViewportWindow(this); _entityHierarchyWindow = new EntityHierarchyWindow(this, _scene); _componentEditWindow = new ComponentEditWindow(_entityHierarchyWindow); - _contentBrowserWindow = new ContentBrowserWindow((.)Application.Get().ContentManager); + _contentBrowserWindow = new ContentBrowserWindow((.)Application.Get().ContentManager, _thumbnailManager); _propertiesWindow = new PropertiesWindow(this); _assetViewer = new AssetViewer((.)Application.Get().ContentManager); _logWindow = new LogWindow(); diff --git a/GlitchyEditor/src/EditorIcons.bf b/GlitchyEditor/src/EditorIcons.bf index 796b94d..4bc44b3 100644 --- a/GlitchyEditor/src/EditorIcons.bf +++ b/GlitchyEditor/src/EditorIcons.bf @@ -23,6 +23,10 @@ namespace GlitchyEditor public SubTexture2D Warning ~ _.ReleaseRef(); public SubTexture2D Info ~ _.ReleaseRef(); public SubTexture2D Trace ~ _.ReleaseRef(); + public SubTexture2D File_Scene ~ _.ReleaseRef(); + public SubTexture2D File_Material ~ _.ReleaseRef(); + public SubTexture2D File_CSharpScript ~ _.ReleaseRef(); + public SubTexture2D File_Shader ~ _.ReleaseRef(); public SamplerState SamplerState { @@ -49,6 +53,10 @@ namespace GlitchyEditor Warning = GetNextGridTexture(ref pen, iconSize); Info = GetNextGridTexture(ref pen, iconSize); Trace = GetNextGridTexture(ref pen, iconSize); + File_Scene = GetNextGridTexture(ref pen, iconSize); + File_Material = GetNextGridTexture(ref pen, iconSize); + File_CSharpScript = GetNextGridTexture(ref pen, iconSize); + File_Shader = GetNextGridTexture(ref pen, iconSize); } private SubTexture2D GetNextGridTexture(ref float2 pen, float2 iconSize) diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index ab5f103..d804010 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -109,6 +109,8 @@ namespace GlitchyEditor /// Returns whether or not the current scene can be saved. public bool CanSaveScene => _sceneState == .Edit; + private AssetThumbnailManager _thumbnailManager ~ delete _; + [AllowAppend] public this(String[] args, EditorContentManager contentManager) : base("Editor") { @@ -125,7 +127,9 @@ namespace GlitchyEditor _camera = EditorCamera(float3(-3f, 3f, -3f), Quaternion.FromEulerAngles(MathHelper.ToRadians(40), MathHelper.ToRadians(25), 0), MathHelper.ToRadians(75), 0.1f, 1); _camera.RenderTarget = _cameraTarget; - + + _thumbnailManager = new AssetThumbnailManager(_editorIcons); + InitEditor(); RegisterAssetCreators(); @@ -156,7 +160,7 @@ namespace GlitchyEditor { Log.ClientLogger.Error($"Directory \"{path}\" could not be created ({error})."); } - })); + }, _editorIcons.Folder)); Editor.Instance.ContentBrowserWindow.InsertAssetCreatorSeparator(); @@ -166,7 +170,7 @@ namespace GlitchyEditor { SaveScene(newScene, path); } - })); + }, _editorIcons.File_Scene)); Editor.Instance.ContentBrowserWindow.RegisterAssetCreator(new AssetCreator("Material", "New Material", ".mat", new (path) => { @@ -174,7 +178,7 @@ namespace GlitchyEditor { _contentManager.SaveAssetToFile(newMaterial, path); } - })); + }, _editorIcons.File_Material)); Editor.Instance.ContentBrowserWindow.RegisterAssetCreator(new AssetCreator("Script", "New Entity", ".cs", new (path) => { @@ -240,7 +244,7 @@ namespace GlitchyEditor { Log.EngineLogger.Error($"Failed to edit project file ({err}). Please add the file to the project manually."); } - })); + }, _editorIcons.File_CSharpScript)); } private void ToCSharpName(String input, String output) @@ -354,7 +358,7 @@ namespace GlitchyEditor private void InitEditor() { - _editor = new Editor(_editorScene, _contentManager); + _editor = new Editor(_editorScene, _contentManager, _thumbnailManager); _editor.SceneViewportWindow.ViewportSizeChanged.Add(new (s, e) => EditorViewportSizeChanged(s, e)); _editor.GameViewportWindow.ViewportSizeChanged.Add(new (s, e) => GameViewportSizeChanged(s, e)); _editor.CurrentCamera = &_camera;