mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Basic asset thumbnails
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,8 @@ namespace GlitchyEditor.EditWindows
|
|||||||
private String _fileExtension ~ delete _;
|
private String _fileExtension ~ delete _;
|
||||||
private CreateAssetFunc _doCreateAsset ~ delete _;
|
private CreateAssetFunc _doCreateAsset ~ delete _;
|
||||||
|
|
||||||
|
private SubTexture2D _icon ~ _?.ReleaseRef();
|
||||||
|
|
||||||
public delegate void CreateAssetFunc(StringView outputPath);
|
public delegate void CreateAssetFunc(StringView outputPath);
|
||||||
|
|
||||||
public StringView Name => _name;
|
public StringView Name => _name;
|
||||||
@@ -30,12 +32,17 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
public CreateAssetFunc CreateAsset => _doCreateAsset;
|
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);
|
_name = new String(name);
|
||||||
_defaultFileName = new String(defaultFileName);
|
_defaultFileName = new String(defaultFileName);
|
||||||
_fileExtension = new String(fileExtension);
|
_fileExtension = new String(fileExtension);
|
||||||
_doCreateAsset = createAsset;
|
_doCreateAsset = createAsset;
|
||||||
|
|
||||||
|
_icon = icon;
|
||||||
|
_icon?.AddRef();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +65,8 @@ namespace GlitchyEditor.EditWindows
|
|||||||
private append String _assetToRename = .();
|
private append String _assetToRename = .();
|
||||||
private char8[128] _renameFileNameBuffer;
|
private char8[128] _renameFileNameBuffer;
|
||||||
|
|
||||||
|
private AssetThumbnailManager _thumbnailManager;
|
||||||
|
|
||||||
public static SubTexture2D s_FolderTexture;
|
public static SubTexture2D s_FolderTexture;
|
||||||
public static SubTexture2D s_FileTexture;
|
public static SubTexture2D s_FileTexture;
|
||||||
|
|
||||||
@@ -69,9 +78,10 @@ namespace GlitchyEditor.EditWindows
|
|||||||
bool _showNewFile = false;
|
bool _showNewFile = false;
|
||||||
AssetCreator _newFileCreator = null;
|
AssetCreator _newFileCreator = null;
|
||||||
|
|
||||||
public this(EditorContentManager contentManager)
|
public this(EditorContentManager contentManager, AssetThumbnailManager thumbnailManager)
|
||||||
{
|
{
|
||||||
_manager = contentManager;
|
_manager = contentManager;
|
||||||
|
_thumbnailManager = thumbnailManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registers an asset creator that will show up in the "Create new" drop down menu
|
/// 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
|
// TODO: preview images
|
||||||
SubTexture2D image = entry->IsDirectory ? s_FolderTexture : s_FileTexture;
|
SubTexture2D image = _thumbnailManager.GetThumbnail(entry.Value);
|
||||||
|
|
||||||
ImGui.ImageButton("FileImage", image, (.)IconSize);
|
ImGui.ImageButton("FileImage", image, (.)IconSize);
|
||||||
|
|
||||||
@@ -713,7 +723,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
ImGui.PushStyleColor(.Button, ImGui.Vec4(0, 0, 0, 0));
|
ImGui.PushStyleColor(.Button, ImGui.Vec4(0, 0, 0, 0));
|
||||||
|
|
||||||
// TODO: preview images
|
// TODO: preview images
|
||||||
SubTexture2D image = s_FileTexture;
|
SubTexture2D image = _newFileCreator.Icon ?? s_FileTexture;
|
||||||
|
|
||||||
ImGui.ImageButton("FileImage", image, (.)IconSize);
|
ImGui.ImageButton("FileImage", image, (.)IconSize);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace GlitchyEditor
|
|||||||
private Scene _scene;
|
private Scene _scene;
|
||||||
|
|
||||||
private EditorContentManager _contentManager;
|
private EditorContentManager _contentManager;
|
||||||
|
private AssetThumbnailManager _thumbnailManager;
|
||||||
|
|
||||||
private Project _currentProject;
|
private Project _currentProject;
|
||||||
|
|
||||||
@@ -41,6 +42,8 @@ namespace GlitchyEditor
|
|||||||
|
|
||||||
public EditorContentManager ContentManager => _contentManager;
|
public EditorContentManager ContentManager => _contentManager;
|
||||||
|
|
||||||
|
public AssetThumbnailManager ThumbnailManager => _thumbnailManager;
|
||||||
|
|
||||||
public Project CurrentProject
|
public Project CurrentProject
|
||||||
{
|
{
|
||||||
get => _currentProject;
|
get => _currentProject;
|
||||||
@@ -68,13 +71,14 @@ namespace GlitchyEditor
|
|||||||
public static Editor Instance => s_Instance;
|
public static Editor Instance => s_Instance;
|
||||||
|
|
||||||
/// Creates a new editor for the given world
|
/// 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.");
|
Log.EngineLogger.AssertDebug(s_Instance == null, "Cannot create a second instance of a singleton.");
|
||||||
s_Instance = this;
|
s_Instance = this;
|
||||||
|
|
||||||
_scene = scene;
|
_scene = scene;
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
|
_thumbnailManager = thumbnailManager;
|
||||||
|
|
||||||
InitWindows();
|
InitWindows();
|
||||||
}
|
}
|
||||||
@@ -90,7 +94,7 @@ namespace GlitchyEditor
|
|||||||
_gameViewportWindow = new GameViewportWindow(this);
|
_gameViewportWindow = new GameViewportWindow(this);
|
||||||
_entityHierarchyWindow = new EntityHierarchyWindow(this, _scene);
|
_entityHierarchyWindow = new EntityHierarchyWindow(this, _scene);
|
||||||
_componentEditWindow = new ComponentEditWindow(_entityHierarchyWindow);
|
_componentEditWindow = new ComponentEditWindow(_entityHierarchyWindow);
|
||||||
_contentBrowserWindow = new ContentBrowserWindow((.)Application.Get().ContentManager);
|
_contentBrowserWindow = new ContentBrowserWindow((.)Application.Get().ContentManager, _thumbnailManager);
|
||||||
_propertiesWindow = new PropertiesWindow(this);
|
_propertiesWindow = new PropertiesWindow(this);
|
||||||
_assetViewer = new AssetViewer((.)Application.Get().ContentManager);
|
_assetViewer = new AssetViewer((.)Application.Get().ContentManager);
|
||||||
_logWindow = new LogWindow();
|
_logWindow = new LogWindow();
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ namespace GlitchyEditor
|
|||||||
public SubTexture2D Warning ~ _.ReleaseRef();
|
public SubTexture2D Warning ~ _.ReleaseRef();
|
||||||
public SubTexture2D Info ~ _.ReleaseRef();
|
public SubTexture2D Info ~ _.ReleaseRef();
|
||||||
public SubTexture2D Trace ~ _.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
|
public SamplerState SamplerState
|
||||||
{
|
{
|
||||||
@@ -49,6 +53,10 @@ namespace GlitchyEditor
|
|||||||
Warning = GetNextGridTexture(ref pen, iconSize);
|
Warning = GetNextGridTexture(ref pen, iconSize);
|
||||||
Info = GetNextGridTexture(ref pen, iconSize);
|
Info = GetNextGridTexture(ref pen, iconSize);
|
||||||
Trace = 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)
|
private SubTexture2D GetNextGridTexture(ref float2 pen, float2 iconSize)
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ namespace GlitchyEditor
|
|||||||
/// Returns whether or not the current scene can be saved.
|
/// Returns whether or not the current scene can be saved.
|
||||||
public bool CanSaveScene => _sceneState == .Edit;
|
public bool CanSaveScene => _sceneState == .Edit;
|
||||||
|
|
||||||
|
private AssetThumbnailManager _thumbnailManager ~ delete _;
|
||||||
|
|
||||||
[AllowAppend]
|
[AllowAppend]
|
||||||
public this(String[] args, EditorContentManager contentManager) : base("Editor")
|
public this(String[] args, EditorContentManager contentManager) : base("Editor")
|
||||||
{
|
{
|
||||||
@@ -126,6 +128,8 @@ namespace GlitchyEditor
|
|||||||
_camera = EditorCamera(float3(-3f, 3f, -3f), Quaternion.FromEulerAngles(MathHelper.ToRadians(40), MathHelper.ToRadians(25), 0), MathHelper.ToRadians(75), 0.1f, 1);
|
_camera = EditorCamera(float3(-3f, 3f, -3f), Quaternion.FromEulerAngles(MathHelper.ToRadians(40), MathHelper.ToRadians(25), 0), MathHelper.ToRadians(75), 0.1f, 1);
|
||||||
_camera.RenderTarget = _cameraTarget;
|
_camera.RenderTarget = _cameraTarget;
|
||||||
|
|
||||||
|
_thumbnailManager = new AssetThumbnailManager(_editorIcons);
|
||||||
|
|
||||||
InitEditor();
|
InitEditor();
|
||||||
|
|
||||||
RegisterAssetCreators();
|
RegisterAssetCreators();
|
||||||
@@ -156,7 +160,7 @@ namespace GlitchyEditor
|
|||||||
{
|
{
|
||||||
Log.ClientLogger.Error($"Directory \"{path}\" could not be created ({error}).");
|
Log.ClientLogger.Error($"Directory \"{path}\" could not be created ({error}).");
|
||||||
}
|
}
|
||||||
}));
|
}, _editorIcons.Folder));
|
||||||
|
|
||||||
Editor.Instance.ContentBrowserWindow.InsertAssetCreatorSeparator();
|
Editor.Instance.ContentBrowserWindow.InsertAssetCreatorSeparator();
|
||||||
|
|
||||||
@@ -166,7 +170,7 @@ namespace GlitchyEditor
|
|||||||
{
|
{
|
||||||
SaveScene(newScene, path);
|
SaveScene(newScene, path);
|
||||||
}
|
}
|
||||||
}));
|
}, _editorIcons.File_Scene));
|
||||||
|
|
||||||
Editor.Instance.ContentBrowserWindow.RegisterAssetCreator(new AssetCreator("Material", "New Material", ".mat", new (path) =>
|
Editor.Instance.ContentBrowserWindow.RegisterAssetCreator(new AssetCreator("Material", "New Material", ".mat", new (path) =>
|
||||||
{
|
{
|
||||||
@@ -174,7 +178,7 @@ namespace GlitchyEditor
|
|||||||
{
|
{
|
||||||
_contentManager.SaveAssetToFile(newMaterial, path);
|
_contentManager.SaveAssetToFile(newMaterial, path);
|
||||||
}
|
}
|
||||||
}));
|
}, _editorIcons.File_Material));
|
||||||
|
|
||||||
Editor.Instance.ContentBrowserWindow.RegisterAssetCreator(new AssetCreator("Script", "New Entity", ".cs", new (path) =>
|
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.");
|
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)
|
private void ToCSharpName(String input, String output)
|
||||||
@@ -354,7 +358,7 @@ namespace GlitchyEditor
|
|||||||
|
|
||||||
private void InitEditor()
|
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.SceneViewportWindow.ViewportSizeChanged.Add(new (s, e) => EditorViewportSizeChanged(s, e));
|
||||||
_editor.GameViewportWindow.ViewportSizeChanged.Add(new (s, e) => GameViewportSizeChanged(s, e));
|
_editor.GameViewportWindow.ViewportSizeChanged.Add(new (s, e) => GameViewportSizeChanged(s, e));
|
||||||
_editor.CurrentCamera = &_camera;
|
_editor.CurrentCamera = &_camera;
|
||||||
|
|||||||
Reference in New Issue
Block a user