From 7593828ca7d3201075641eb3961e596f6da3e017 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sun, 8 Sep 2024 17:53:52 +0100 Subject: [PATCH] Add basic fam tree construction --- project/code/TMV/UI/TextureBrowser.cs | 30 ++++++++++++++----- .../scenes/asset_browser/asset_browser.tscn | 13 ++++---- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/project/code/TMV/UI/TextureBrowser.cs b/project/code/TMV/UI/TextureBrowser.cs index 9578285..bf655cb 100644 --- a/project/code/TMV/UI/TextureBrowser.cs +++ b/project/code/TMV/UI/TextureBrowser.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Godot; @@ -27,7 +28,7 @@ public partial class TextureBrowser : Node { // !HACK TEMP Context.Instance.PathManager.Init("/stuff/Games/thief/drive_c/GOG Games/TG ND 1.27 (MAPPING)/"); - Context.Instance.CampaignName = "TheBlackParade_1_0"; + Context.Instance.CampaignName = "Endless Rain"; _folderTree = GetNode("%FolderTree"); _searchBar = GetNode("%SearchBar"); @@ -48,13 +49,28 @@ public partial class TextureBrowser : Node private void BuildFolderTree() { _folderTree.Clear(); - _folderTree.SetColumnTitle(0, "Name"); - _folderTree.SetColumnTitle(1, "Count"); - // TODO: We need some way to get family names - // Maybe PathManager and CampaignResource should be expanded so that we - // can get the resource itself and query things - var pathManager = Context.Instance.PathManager; + var context = Context.Instance; + var textureNames = context.PathManager.GetResourceNames(LGS.ResourceType.Texture, context.CampaignName); + + var treeItems = new Dictionary(); + treeItems.Add("", _folderTree.CreateItem()); + foreach (var name in textureNames) + { + var tokens = name.Split('/'); + var fams = new string[tokens.Length + 1]; + fams[0] = ""; + for (var i = 1; i < tokens.Length; i++) + { + fams[i] = tokens[..i].Join("/"); + if (!treeItems.ContainsKey(fams[i])) + { + var item = _folderTree.CreateItem(treeItems[fams[i - 1]]); + item.SetText(0, tokens[i - 1]); + treeItems.Add(fams[i], item); + } + } + } } private void BuildTextureList() diff --git a/project/scenes/asset_browser/asset_browser.tscn b/project/scenes/asset_browser/asset_browser.tscn index ba85194..706ed52 100644 --- a/project/scenes/asset_browser/asset_browser.tscn +++ b/project/scenes/asset_browser/asset_browser.tscn @@ -47,8 +47,7 @@ size_flags_vertical = 3 unique_name_in_owner = true custom_minimum_size = Vector2(256, 0) layout_mode = 2 -columns = 2 -column_titles_visible = true +hide_root = true [node name="HSplitContainer" type="HSplitContainer" parent="TabContainer/Textures/VBoxContainer/HSplitContainer"] layout_mode = 2 @@ -76,14 +75,15 @@ tooltip_text = "Sort Mode" icon = ExtResource("3_0k1fm") icon_alignment = 1 item_count = 4 -popup/item_0/text = "Family" +popup/item_0/text = "Name" popup/item_0/checkable = 2 -popup/item_0/id = 1 -popup/item_1/text = "Name" +popup/item_0/checked = true +popup/item_1/text = "Family" popup/item_1/checkable = 2 -popup/item_1/id = 2 +popup/item_1/id = 1 popup/item_2/text = "Index" popup/item_2/checkable = 2 +popup/item_2/id = 2 popup/item_2/disabled = true popup/item_3/text = "Count" popup/item_3/checkable = 2 @@ -110,6 +110,7 @@ popup/item_0/id = 1 popup/item_1/text = "Show Custom" popup/item_1/checkable = 1 popup/item_1/checked = true +popup/item_1/id = 1 popup/item_2/text = "Show Family Name" popup/item_2/checkable = 1 popup/item_2/id = 2