From 52e1da9dfc73516bfd1e9de09c405b55d669c3a4 Mon Sep 17 00:00:00 2001 From: Redbat <4107444+redbatz@users.noreply.github.com> Date: Wed, 8 Apr 2026 22:10:23 +0200 Subject: [PATCH] Preload button icons --- source/MechLabFiltering/UIHandler.cs | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/source/MechLabFiltering/UIHandler.cs b/source/MechLabFiltering/UIHandler.cs index 1e8ec7a..1b7a923 100644 --- a/source/MechLabFiltering/UIHandler.cs +++ b/source/MechLabFiltering/UIHandler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using BattleTech; using BattleTech.Data; @@ -9,6 +10,7 @@ using CustomFilters.MechLabScrolling; using CustomFilters.Settings; using FluffyUnderware.DevTools.Extensions; +using SVGImporter; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -79,6 +81,8 @@ internal UIHandler(MechLabPanel mechLab) text.SetText(tabInfo.Caption); _tabRadioSet.RadioButtons.Add(radio); maxButtons = Math.Max(maxButtons, tabInfo.Buttons.Length); + + PreloadIconsCache(tabInfo); } Log.Main.Trace?.Log("-- create small buttons"); @@ -110,6 +114,51 @@ internal UIHandler(MechLabPanel mechLab) _widget.filterRadioSet.Reset(); } + private void PreloadIconsCache(TabInfo tabInfo) + { + foreach (ButtonInfo buttonInfo in tabInfo.Buttons) + { + string? buttonInfoIcon = buttonInfo.Icon; + if (!string.IsNullOrEmpty(buttonInfoIcon)) + { + loadIcon(buttonInfoIcon); + } + } + } + + private void loadIcon(string? buttonInfoIcon) + { + try + { + VersionManifestEntry entry = _mechLab.dataManager.ResourceLocator.EntryByID(buttonInfoIcon, BattleTechResourceType.SVGAsset); + if (entry == null) + { + Log.Main.Warning?.Log(buttonInfoIcon + " not found in SVG manifest"); + return; + } + + string entryFilePath = entry.FilePath; + if (!File.Exists(entryFilePath)) + { + return; + } + + SVGAsset svg = SVGAsset.Load(File.ReadAllText(entryFilePath)); + if (svg != null) + { + _iconCache.AddSVGAsset(buttonInfoIcon, svg); + } + else + { + Log.Main.Warning?.Log("Failed to load SVG:" + buttonInfoIcon + " " + entry.FilePath); + } + } + catch (Exception e) + { + Log.Main.Error?.Log("Unable to load icon", e); + } + } + public void ResetFilters() { _widget.filterBtnAll.SetActive(false);