2024-09-08 16:22:47 +00:00
|
|
|
using System.Linq;
|
2024-09-08 16:07:12 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2024-09-08 13:45:52 +00:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
namespace KeepersCompound.TMV.UI;
|
|
|
|
|
|
|
|
public partial class TextureBrowser : Node
|
|
|
|
{
|
2024-09-08 16:22:47 +00:00
|
|
|
enum SortMode
|
|
|
|
{
|
|
|
|
Name,
|
|
|
|
Family,
|
|
|
|
Index,
|
|
|
|
Count,
|
|
|
|
}
|
|
|
|
|
2024-09-08 13:45:52 +00:00
|
|
|
private Tree _folderTree;
|
|
|
|
private LineEdit _searchBar;
|
|
|
|
private MenuButton _sortMenu;
|
|
|
|
private Button _openFolderButton;
|
|
|
|
private MenuButton _browserMenu;
|
|
|
|
private HFlowContainer _textureList;
|
|
|
|
private TextureRect _previewTexture;
|
|
|
|
private LineEdit _texturePath;
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
// !HACK TEMP
|
|
|
|
Context.Instance.PathManager.Init("/stuff/Games/thief/drive_c/GOG Games/TG ND 1.27 (MAPPING)/");
|
|
|
|
Context.Instance.CampaignName = "TheBlackParade_1_0";
|
|
|
|
|
|
|
|
_folderTree = GetNode<Tree>("%FolderTree");
|
|
|
|
_searchBar = GetNode<LineEdit>("%SearchBar");
|
|
|
|
_sortMenu = GetNode<MenuButton>("%SortMenu");
|
|
|
|
_openFolderButton = GetNode<Button>("%OpenTextureFolderButton");
|
|
|
|
_browserMenu = GetNode<MenuButton>("%BrowserOverflowMenu");
|
|
|
|
_textureList = GetNode<HFlowContainer>("%TextureList");
|
|
|
|
_previewTexture = GetNode<TextureRect>("%PreviewTexture");
|
|
|
|
_texturePath = GetNode<LineEdit>("%PathBox");
|
|
|
|
|
2024-09-08 16:07:12 +00:00
|
|
|
_searchBar.TextChanged += ApplySearchFilter;
|
2024-09-08 16:22:47 +00:00
|
|
|
_sortMenu.GetPopup().IdPressed += ApplySortMode;
|
2024-09-08 16:07:12 +00:00
|
|
|
|
2024-09-08 13:45:52 +00:00
|
|
|
BuildFolderTree();
|
|
|
|
BuildTextureList(); // TODO: This should be triggered on folder change
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void BuildTextureList()
|
|
|
|
{
|
|
|
|
foreach (var child in _textureList.GetChildren())
|
|
|
|
{
|
|
|
|
child.QueueFree();
|
|
|
|
}
|
|
|
|
|
|
|
|
var pathManager = Context.Instance.PathManager;
|
|
|
|
var campaign = Context.Instance.CampaignName;
|
|
|
|
var resType = LGS.ResourceType.Texture;
|
|
|
|
var textureNames = pathManager.GetResourceNames(resType, campaign);
|
|
|
|
foreach (var name in textureNames)
|
|
|
|
{
|
|
|
|
var (_, path) = pathManager.GetResourcePath(resType, campaign, name);
|
|
|
|
var texture = TextureLoader.LoadTexture(path);
|
|
|
|
|
|
|
|
var textureRect = new TextureRect();
|
|
|
|
textureRect.Texture = texture;
|
|
|
|
textureRect.ExpandMode = TextureRect.ExpandModeEnum.IgnoreSize;
|
|
|
|
textureRect.StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered;
|
|
|
|
textureRect.SetAnchorsPreset(Control.LayoutPreset.FullRect);
|
|
|
|
|
|
|
|
var slot = new Panel();
|
2024-09-08 16:07:12 +00:00
|
|
|
slot.Name = name;
|
2024-09-08 13:45:52 +00:00
|
|
|
slot.CustomMinimumSize = new Vector2(128, 128);
|
|
|
|
slot.AddChild(textureRect);
|
|
|
|
slot.GuiInput += (input) =>
|
|
|
|
{
|
|
|
|
if (input is InputEventMouseButton mouseEvent &&
|
|
|
|
mouseEvent.Pressed &&
|
|
|
|
mouseEvent.ButtonIndex == MouseButton.Left)
|
|
|
|
{
|
|
|
|
SetPreviewTexture(name, texture);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_textureList.AddChild(slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetPreviewTexture(string name, Texture2D texture)
|
|
|
|
{
|
|
|
|
_previewTexture.Texture = texture;
|
|
|
|
_texturePath.Text = name;
|
|
|
|
}
|
2024-09-08 16:07:12 +00:00
|
|
|
|
|
|
|
private void ApplySearchFilter(string filter)
|
|
|
|
{
|
|
|
|
var regexString = "^.*" + Regex.Escape(filter).Replace("\\*", ".*") + ".*$";
|
|
|
|
foreach (var node in _textureList.GetChildren())
|
|
|
|
{
|
|
|
|
var panel = (Panel)node;
|
|
|
|
panel.Visible = Regex.IsMatch(panel.Name.ToString(), regexString);
|
|
|
|
}
|
|
|
|
}
|
2024-09-08 16:22:47 +00:00
|
|
|
|
|
|
|
private void ApplySortMode(long id)
|
|
|
|
{
|
|
|
|
var popup = _sortMenu.GetPopup();
|
|
|
|
for (var i = 0; i < popup.ItemCount; i++)
|
|
|
|
{
|
|
|
|
popup.SetItemChecked(i, popup.GetItemId(i) == id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Actualy sort
|
|
|
|
}
|
2024-09-08 13:45:52 +00:00
|
|
|
}
|