Add search bar functionality to texture browser

This commit is contained in:
Jarrod Doyle 2024-09-08 17:07:12 +01:00
parent b13d27c0b8
commit e76bc13ef5
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 14 additions and 0 deletions

View File

@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using Godot;
namespace KeepersCompound.TMV.UI;
@ -28,6 +29,8 @@ public partial class TextureBrowser : Node
_previewTexture = GetNode<TextureRect>("%PreviewTexture");
_texturePath = GetNode<LineEdit>("%PathBox");
_searchBar.TextChanged += ApplySearchFilter;
BuildFolderTree();
BuildTextureList(); // TODO: This should be triggered on folder change
}
@ -67,6 +70,7 @@ public partial class TextureBrowser : Node
textureRect.SetAnchorsPreset(Control.LayoutPreset.FullRect);
var slot = new Panel();
slot.Name = name;
slot.CustomMinimumSize = new Vector2(128, 128);
slot.AddChild(textureRect);
slot.GuiInput += (input) =>
@ -88,4 +92,14 @@ public partial class TextureBrowser : Node
_previewTexture.Texture = texture;
_texturePath.Text = name;
}
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);
}
}
}