Add up button und split scrolling in content browser

- Add Parent to TreeNode
- Start of Rename handling
This commit is contained in:
Simon Lübeß
2023-03-18 19:59:56 +01:00
parent 50714976e9
commit 793aa40975
5 changed files with 142 additions and 43 deletions
+63 -2
View File
@@ -108,7 +108,8 @@ class AssetHierarchy
fsw.OnRenamed.Add(new (oldName, newName) => {
Log.EngineLogger.Trace($"File renamed (From \"{oldName}\" to \"{newName}\")");
_fileSystemDirty = true;
//_fileSystemDirty = true;
FileRenamed(oldName, newName);
/*String contentFilePath = scope String();
Path.InternalCombine(contentFilePath, ContentDirectory, oldName);
@@ -161,6 +162,7 @@ class AssetHierarchy
_assetHierarchy = new TreeNode<AssetNode>(new AssetNode());
_assetHierarchy->Path = new String(ContentDirectory);
_assetHierarchy->Name = new String("Content");
_assetHierarchy->IsDirectory = true;
Log.EngineLogger.Trace($"Created directory node for: \"{_assetHierarchy->Path}\"");
@@ -333,11 +335,70 @@ class AssetHierarchy
return;
OnFileContentChanged(node.Value);
}
// TODO: Handle file changes (reload asset, etc...)
private void FileRenamed(StringView oldFilePath, StringView newFilePath)
{
var oldFilePath;
// Ignore Config files.
if (oldFilePath.EndsWith(AssetFile.ConfigFileExtension))
return;
String oldFileNameWithContentRoot = scope .();
Path.InternalCombine(oldFileNameWithContentRoot, _contentDirectory, oldFilePath);
String newFileNameWithContentRoot = scope .();
Path.InternalCombine(newFileNameWithContentRoot, _contentDirectory, newFilePath);
// Rename config file
{
String oldConfigFileName = scope $"{oldFileNameWithContentRoot}{AssetFile.ConfigFileExtension}";
String newConfigFileName = scope $"{newFileNameWithContentRoot}{AssetFile.ConfigFileExtension}";
if (File.Exists(oldConfigFileName) && !File.Exists(newConfigFileName))
{
if (File.Move(oldConfigFileName, newConfigFileName) case .Err(let value))
{
Log.EngineLogger.Error($"Failed to move file {oldConfigFileName} to {newConfigFileName}. Code: {value}");
}
}
}
var nodeResult = GetNodeFromPath(oldFileNameWithContentRoot);
TreeNode<AssetNode> node = null;
if (!(nodeResult case .Ok(out node)))
{
// This happens, when we create new files.
Log.EngineLogger.Trace($"Could not find node for file \"{oldFileNameWithContentRoot}\"");
return;
}
_pathToAssetNode.Remove(oldFileNameWithContentRoot);
node->Path.Set(newFileNameWithContentRoot);
_pathToAssetNode.Add(newFileNameWithContentRoot, node);
node->Name.Clear();
Path.GetFileName(newFileNameWithContentRoot, node->Name);
String oldIdentifier = scope .(node->AssetFile.[Friend]_identifier);
node->AssetFile.[Friend]_path.Set(node->Path);
node->AssetFile.[Friend]_identifier.Set(newFilePath);
node->AssetFile.[Friend]_assetConfigPath..Set(node->Path).Append(AssetFile.ConfigFileExtension);
OnFileRenamed(node.Value, oldIdentifier);
}
public delegate void FileContentChangedFunc(AssetNode node);
public Event<FileContentChangedFunc> OnFileContentChanged ~ _.Dispose();
public delegate void FileRenamedFunc(AssetNode node, StringView oldName);
public Event<FileRenamedFunc> OnFileRenamed ~ _.Dispose();
}
@@ -86,7 +86,7 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor
AssetHandle<Texture2D> newTexture = Content.LoadAsset(path);
newTexture.Get().SamplerState = SamplerStateManager.AnisotropicWrap;
//newTexture.Get().SamplerState = SamplerStateManager.AnisotropicWrap;
material.SetTexture(texture.key, newTexture.Cast<Texture>());
}
@@ -14,9 +14,6 @@ namespace GlitchyEditor.EditWindows
class ContentBrowserWindow : EditorWindow
{
// TODO: Get from project
//const String ContentDirectory = "./content";
private append String _currentDirectory = .();
private append String _selectedFile = .();
@@ -58,12 +55,20 @@ namespace GlitchyEditor.EditWindows
ImGui.Columns(2);
ImGui.BeginChild("Sidebar");
DrawDirectorySideBar();
ImGui.EndChild();
ImGui.NextColumn();
ImGui.BeginChild("Files");
DrawCurrentDirectory();
ImGui.EndChild();
ImGui.Columns(1);
ImGui.End();
@@ -149,6 +154,24 @@ namespace GlitchyEditor.EditWindows
return;
}
if (currentDirectoryNode->Parent != null)
{
ImGui.PushID("Back");
DrawBackButton(currentDirectoryNode->Parent);
// X-Coordinate of the right side of the current entry.
float currentButtonRight = ImGui.GetItemRectMax().x;
// Expected right-Coordinate if next entry was on the same line.
float expectedButtonRight = currentButtonRight + style.ItemSpacing.x + DirectoryItemSize.X;
// If the next button won't fit on the same line we start a new line.
if (expectedButtonRight < window_visible_x2)
ImGui.SameLine();
ImGui.PopID();
}
for (var entry in currentDirectoryNode->Children)
{
ImGui.PushID(entry->Name);
@@ -168,6 +191,45 @@ namespace GlitchyEditor.EditWindows
}
}
/// Renders the button for the given directory item.
private void DrawBackButton(TreeNode<AssetNode> entry)
{
ImGui.BeginChild("item", (.)DirectoryItemSize);
if (entry->Path == _selectedFile)
{
var color = ImGui.GetStyleColorVec4(.ButtonHovered);
ImGui.PushStyleColor(.Button, *color);
}
else
{
ImGui.PushStyleColor(.Button, ImGui.Vec4(0, 0, 0, 0));
}
SubTexture2D image = s_FolderTexture;
ImGui.ImageButton(image, (.)(DirectoryItemSize - padding));
ImGui.PopStyleColor();
if (ImGui.IsItemHovered() && ImGui.IsMouseClicked(.Left))
{
if (_selectedFile != entry->Path)
{
_selectedFile.Set(entry->Path);
}
}
if (ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(.Left))
{
EntryDoubleClicked(entry);
}
ImGui.TextUnformatted("..");
ImGui.EndChild();
}
/// Renders the button for the given directory item.
private void DrawDirectoryItem(TreeNode<AssetNode> entry)
{
+8 -34
View File
@@ -34,6 +34,7 @@ class EditorContentManager : IContentManager
public this()
{
_assetHierarchy.OnFileContentChanged.Add(new => OnFileContentChanged);
_assetHierarchy.OnFileRenamed.Add(new => OnFileRenamed);
}
public ~this()
@@ -43,52 +44,25 @@ class EditorContentManager : IContentManager
private void OnFileContentChanged(AssetNode assetNode)
{
// TODO: update for AssetHandles
// TODO: Subassets break reloading because we can't find them when we only receive the file that changed...
// Asset isn't loaded so we don't need to reload it.
if (assetNode.AssetFile.LoadedAsset == null)
return;
_reloadQueue.Add(assetNode.AssetFile.LoadedAsset.Handle);
/*String neededAssetLoaderName = assetNode.AssetFile.AssetConfig?.AssetLoader;
if (String.IsNullOrWhiteSpace(neededAssetLoaderName))
return;
IAssetLoader assetLoader = null;
String loaderNameBuffer = scope String(64);
for (IAssetLoader loader in _assetLoaders)
{
loader.GetType().GetName(loaderNameBuffer..Clear());
if (loaderNameBuffer == neededAssetLoaderName)
{
assetLoader = loader;
break;
}
}
if (assetLoader == null)
public void OnFileRenamed(AssetNode assetNode, StringView oldIdentifier)
{
Log.EngineLogger.Error($"Could not find asset loader \"{neededAssetLoaderName}\"");
// Asset isn't loaded so we don't need to reload it.
if (assetNode.AssetFile.LoadedAsset == null)
return;
}*/
/*if (var assetReloader = assetLoader as IReloadingAssetLoader)
{
Stream stream = GetStream(assetNode.Path);
Asset asset = assetNode.AssetFile.LoadedAsset;
// TODO: reload asset
asset.Identifier = assetNode.AssetFile.Identifier;
//assetReloader.ReloadAsset(assetNode.AssetFile, stream);
delete stream;
}*/
_identiferToHandle.Remove(oldIdentifier);
_identiferToHandle.Add(asset.Identifier, asset.Handle);
}
public void SetContentDirectory(StringView contentDirectory)
@@ -11,6 +11,7 @@ namespace GlitchyEngine.Collections
{
public T Value;
public Self Parent;
public List<Self> Children = new .() ~ DeleteContainerAndItems!(_);
public this() {}
@@ -29,6 +30,7 @@ namespace GlitchyEngine.Collections
}
Self newChild = new .(value);
newChild.Parent = this;
Children.Add(newChild);