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