Skip to content

Commit 6c75faa

Browse files
authored
Merge pull request #12 from Scutlet/feature/ts-asset-aliases
Asset Aliases
2 parents cda8b58 + e42b17b commit 6c75faa

4 files changed

Lines changed: 35 additions & 20 deletions

File tree

src/Dialogs/DialogHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public static void RenderActiveWindows()
5050

5151
public static void ShowException(Exception ex)
5252
{
53-
string message = ex.Message.Replace("'", "");
53+
// Replace both ' and " with nothing. Messages with these values cause INVALID MESSAGE WITH QUOTES
54+
string message = ex.Message.Replace("'", "").Replace("\"", "");
5455

5556
Clipboard.SetText($"{ex.Message} \n{ex.StackTrace}");
5657
TinyFileDialog.MessageBoxErrorOk($"{message} Details copied to clipboard!");

src/DockedWindows/AssetWindow/AssetViewWindow.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,19 +515,32 @@ private string TextEplislon(string text, float textWidth, float itemWidth)
515515

516516
#region Asset Loading
517517

518+
/// <summary>
519+
/// Filters assets based on its visibility and some search term.
520+
/// </summary>
521+
/// <param name="assets">Full list of assets</param>
522+
/// <returns>Filtered list of assets</returns>
518523
private List<AssetItem> UpdateSearch(List<AssetItem> assets)
519524
{
520525
List<AssetItem> filtered = new List<AssetItem>();
521526
for (int i = 0; i < assets.Count; i++)
522527
{
523-
bool HasText = assets[i].Name != null &&
524-
assets[i].Name.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) >= 0;
525-
526528
if (!assets[i].Visible)
529+
// Not visible
527530
continue;
528531

529-
if (isSearch && HasText || !isSearch)
530-
filtered.Add(assets[i]);
532+
if (isSearch)
533+
{
534+
// Search for matches if filtering is applied
535+
bool hasText = assets[i].Name != null &&
536+
assets[i].Name.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) >= 0;
537+
538+
hasText |= assets[i].Aliases.Any(s => s.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) >= 0);
539+
540+
if (!hasText)
541+
continue;
542+
}
543+
filtered.Add(assets[i]);
531544
}
532545
return filtered;
533546
}
@@ -667,6 +680,11 @@ public class AssetItem
667680

668681
public string DisplayName { get; internal set; }
669682

683+
/// <summary>
684+
/// Aliases of the asset, which are also valid search terms
685+
/// </summary>
686+
public string[] Aliases { get; set; } = Array.Empty<string>();
687+
670688
/// <summary>
671689
/// The image ID of the icon.
672690
/// </summary>

src/DockedWindows/Outliner/Outliner.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ public void ScrollToSelected(NodeBase target)
144144

145145
private bool GetNodePosition(NodeBase target, NodeBase parent, ref float pos, float itemHeight)
146146
{
147-
bool HasText = parent.Header != null &&
148-
parent.Header.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) >= 0;
147+
bool HasText = parent.IsNameMatch(_searchText);
149148

150149
//Search is active and node is found but is not in results so skip scrolling
151150
if (isSearch && parent == target && !HasText)
@@ -303,8 +302,7 @@ private void SetupNodes(NodeBase node)
303302

304303
private void CalculateCount(NodeBase node, ref int counter)
305304
{
306-
bool HasText = node.Header != null &&
307-
node.Header.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) >= 0;
305+
bool HasText = node.IsNameMatch(_searchText);
308306

309307
if (isSearch && HasText || !isSearch)
310308
{
@@ -328,8 +326,7 @@ public void DeselectAll()
328326

329327
public void DrawNode(NodeBase node, float itemHeight, int level = 0)
330328
{
331-
bool HasText = node.Header != null &&
332-
node.Header.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) >= 0;
329+
bool HasText = node.IsNameMatch(_searchText);
333330

334331
char icon = IconManager.FOLDER_ICON;
335332
if (node.Tag is STGenericMesh)
@@ -818,14 +815,7 @@ private bool SelectNodeRange(NodeBase node, NodeBase selectedNode1, NodeBase sel
818815

819816
private List<NodeBase> GetSearchableNodes(List<NodeBase> nodes)
820817
{
821-
List<NodeBase> nodeList = new List<NodeBase>();
822-
foreach (var node in nodes)
823-
{
824-
bool hasText = node.Header != null && node.Header.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) >= 0;
825-
if (hasText)
826-
nodeList.Add(node);
827-
}
828-
return nodeList;
818+
return nodes.Where(n => n.IsNameMatch(_searchText)).ToList();
829819
}
830820

831821
private void LoadTextureIcon(NodeBase node)

src/Icons/IconManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class IconManager
8888
public const char DESELECT_ICON = '\uf850';
8989
public const char SELECT_ICON = '\uf84c';
9090

91+
public const char INFO_ICON = '\uf05a';
9192
public const char WARNING_ICON = '\uf071';
9293

9394
public const char VIDEO_ICON = '\uf03d';
@@ -103,6 +104,11 @@ public class IconManager
103104
public const char PATH_CONNECT = '\uf337';
104105
public const char PATH_CONNECT_AUTO = '\uf126';
105106

107+
public const char ICON_WII_U = '\uf0a0'; // HDD
108+
public const char ICON_SWITCH = '\uf11b'; // gamepad
109+
public const char ICON_MOD = '\uf0ad'; // wrench
110+
public const char ICON_DOWNLOAD = '\uf019';
111+
106112
public const int ICON_SIZE = 18;
107113

108114
static bool init = false;

0 commit comments

Comments
 (0)