diff --git a/Content/Filters/ToolFilters/ToolModFilter.cs b/Content/Filters/ToolFilters/ToolModFilter.cs new file mode 100644 index 0000000..659f51f --- /dev/null +++ b/Content/Filters/ToolFilters/ToolModFilter.cs @@ -0,0 +1,53 @@ +using DragonLens.Content.GUI; +using DragonLens.Content.Tools; + +namespace DragonLens.Content.Filters.ToolFilters +{ + internal class ToolModFilter : Filter + { + public Mod mod; + + public ToolModFilter(Mod mod) : base(null, "", n => FilterByMod(n, mod)) + { + this.mod = mod; + isModFilter = true; + } + + public override string Name => mod.DisplayName; + + public override string Description => CustomizeTool.GetText("Filters.Mod.Description", mod.DisplayName); + + public static bool FilterByMod(BrowserButton button, Mod mod) + { + if (button is ToolBrowserButton) + { + var tb = button as ToolBrowserButton; + + if (tb.tool.Mod != null && tb.tool.Mod == mod) + return false; + } + + return true; + } + + public override void Draw(SpriteBatch spriteBatch, Rectangle target) + { + Texture2D tex = null; + + string path = $"{mod.Name}/icon_small"; + + if (ModContent.HasAsset(path)) + tex = ModContent.Request(path).Value; + + if (tex != null) + { + int widest = tex.Width > tex.Height ? tex.Width : tex.Height; + spriteBatch.Draw(tex, target.Center.ToVector2(), null, Color.White, 0, tex.Size() / 2f, target.Width / (float)widest, 0, 0); + } + else + { + Utils.DrawBorderString(spriteBatch, mod.DisplayName[..2], target.Center.ToVector2(), Color.White, 1, 0.5f, 0.4f); + } + } + } +} diff --git a/Content/Tools/CustomizeTool.cs b/Content/Tools/CustomizeTool.cs index 057bf02..1dfe1bc 100644 --- a/Content/Tools/CustomizeTool.cs +++ b/Content/Tools/CustomizeTool.cs @@ -1,4 +1,6 @@ -using DragonLens.Content.GUI; +using DragonLens.Content.Filters; +using DragonLens.Content.Filters.ToolFilters; +using DragonLens.Content.GUI; using DragonLens.Core.Loaders.UILoading; using DragonLens.Core.Systems.ThemeSystem; using DragonLens.Core.Systems.ToolbarSystem; @@ -20,6 +22,11 @@ internal class CustomizeTool : Tool public override string IconKey => "Customize"; + public static string GetText(string key, params object[] args) + { + return LocalizationHelper.GetText($"Tools.CustomizeTool.{key}", args); + } + public override void OnActivate() { if (!customizing) @@ -78,6 +85,20 @@ public override void PopulateGrid(UIGrid grid) grid.AddRange(buttons); } + public override void SetupFilters(FilterPanel filters) + { + filters.AddSeperator("Tools.CustomizeTool.FilterCategories.Mod"); + + // Add tools from DragonLens + filters.AddFilter(new Filter(Assets.Filters.Vanilla, "Tools.CustomizeTool.Filters.DragonLens", n => !(n is ToolBrowserButton && (n as ToolBrowserButton).tool.Mod == ModContent.GetInstance())) { isModFilter = true }); + + // Add any other mods that have tools, excluding DragonLens + foreach (Mod mod in ModContent.GetContent().Select(t => t.Mod).Distinct().Where(mod => mod != ModContent.GetInstance())) + { + filters.AddFilter(new ToolModFilter(mod)); + } + } + public override void SetupSorts() { SortModes.Add(new("Alphabetical", (a, b) => a.Identifier.CompareTo(b.Identifier))); diff --git a/Localization/Tools/en-US_Mods.DragonLens.Tools.hjson b/Localization/Tools/en-US_Mods.DragonLens.Tools.hjson index 545ccba..538938c 100644 --- a/Localization/Tools/en-US_Mods.DragonLens.Tools.hjson +++ b/Localization/Tools/en-US_Mods.DragonLens.Tools.hjson @@ -650,6 +650,16 @@ CustomizeTool: { DisplayName: Customize tool Description: Customize your toolbar layout! ToolBrowser: Add tool + FilterCategories.Mod: Mod filters + + Filters: { + Mod.Description: Tools added by the mod {0} + + DragonLens: { + Name: DragonLens + Description: Tools added by DragonLens + } + } } SoundSpawner: { diff --git a/Localization/Tools/ru-RU_Mods.DragonLens.Tools.hjson b/Localization/Tools/ru-RU_Mods.DragonLens.Tools.hjson index d0fea7d..9272a04 100644 --- a/Localization/Tools/ru-RU_Mods.DragonLens.Tools.hjson +++ b/Localization/Tools/ru-RU_Mods.DragonLens.Tools.hjson @@ -671,6 +671,16 @@ CustomizeTool: { DisplayName: Кастомизация инструментов Description: Позволяет настраивать панели инструментов этого мода под себя. ToolBrowser: Добавить инструмент + // FilterCategories.Mod: Mod filters + + Filters: { + // Mod.Description: Tools added by the mod {0} + + DragonLens: { + // Name: DragonLens + // Description: Tools added by DragonLens + } + } } SoundSpawner: { diff --git a/Localization/Tools/zh-Hans_Mods.DragonLens.Tools.hjson b/Localization/Tools/zh-Hans_Mods.DragonLens.Tools.hjson index fa57b99..a02f657 100644 --- a/Localization/Tools/zh-Hans_Mods.DragonLens.Tools.hjson +++ b/Localization/Tools/zh-Hans_Mods.DragonLens.Tools.hjson @@ -646,6 +646,16 @@ CustomizeTool: { DisplayName: 自定义工具 Description: 自定义你的工具栏布局! ToolBrowser: 添加工具 + // FilterCategories.Mod: Mod filters + + Filters: { + // Mod.Description: Tools added by the mod {0} + + DragonLens: { + // Name: DragonLens + // Description: Tools added by DragonLens + } + } } SoundSpawner: {