From 08fcfdd58d2045410bb1e3bf51b2cef5d3d1b238 Mon Sep 17 00:00:00 2001 From: emyhrberg Date: Sat, 17 May 2025 18:40:30 +0200 Subject: [PATCH 1/3] Add tool filters --- Content/Filters/ToolFilters/ToolModFilter.cs | 56 ++++++++++++++++++++ Content/Tools/CustomizeTool.cs | 12 ++++- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Content/Filters/ToolFilters/ToolModFilter.cs diff --git a/Content/Filters/ToolFilters/ToolModFilter.cs b/Content/Filters/ToolFilters/ToolModFilter.cs new file mode 100644 index 0000000..8130621 --- /dev/null +++ b/Content/Filters/ToolFilters/ToolModFilter.cs @@ -0,0 +1,56 @@ +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 => 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"; + string dlPath = $"{mod.Name}/icon"; + + if (mod.Name == "DragonLens") + tex = ModContent.Request(dlPath).Value; + 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..6471817 100644 --- a/Content/Tools/CustomizeTool.cs +++ b/Content/Tools/CustomizeTool.cs @@ -1,4 +1,5 @@ -using DragonLens.Content.GUI; +using DragonLens.Content.Filters.ToolFilters; +using DragonLens.Content.GUI; using DragonLens.Core.Loaders.UILoading; using DragonLens.Core.Systems.ThemeSystem; using DragonLens.Core.Systems.ToolbarSystem; @@ -78,6 +79,15 @@ public override void PopulateGrid(UIGrid grid) grid.AddRange(buttons); } + public override void SetupFilters(FilterPanel filters) + { + // Add only mods that have tools + foreach (Mod mod in ModContent.GetContent().Select(t => t.Mod).Distinct()) + { + filters.AddFilter(new ToolModFilter(mod)); + } + } + public override void SetupSorts() { SortModes.Add(new("Alphabetical", (a, b) => a.Identifier.CompareTo(b.Identifier))); From f9d96bf20971c46d4fc44cf379447a1c2b8d61dd Mon Sep 17 00:00:00 2001 From: emyhrberg Date: Sat, 24 May 2025 00:06:31 +0200 Subject: [PATCH 2/3] Fix tool filter icon and description --- Content/Filters/ToolFilters/ToolModFilter.cs | 8 ++++---- Content/Tools/CustomizeTool.cs | 12 +++++++++--- Localization/Tools/en-US_Mods.DragonLens.Tools.hjson | 10 ++++++++++ Localization/Tools/ru-RU_Mods.DragonLens.Tools.hjson | 10 ++++++++++ .../Tools/zh-Hans_Mods.DragonLens.Tools.hjson | 10 ++++++++++ 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Content/Filters/ToolFilters/ToolModFilter.cs b/Content/Filters/ToolFilters/ToolModFilter.cs index 8130621..34720e8 100644 --- a/Content/Filters/ToolFilters/ToolModFilter.cs +++ b/Content/Filters/ToolFilters/ToolModFilter.cs @@ -15,7 +15,7 @@ public ToolModFilter(Mod mod) : base(null, "", n => FilterByMod(n, mod)) public override string Name => mod.DisplayName; - public override string Description => mod.DisplayName; + public override string Description => Helpers.LocalizationHelper.GetText("Tools.CustomizeTool.Filters.Mod.Description", mod.DisplayName); public static bool FilterByMod(BrowserButton button, Mod mod) { @@ -35,10 +35,10 @@ public override void Draw(SpriteBatch spriteBatch, Rectangle target) Texture2D tex = null; string path = $"{mod.Name}/icon_small"; - string dlPath = $"{mod.Name}/icon"; - if (mod.Name == "DragonLens") - tex = ModContent.Request(dlPath).Value; + //if (mod.Name == "DragonLens") + //tex = ModContent.Request(dlPath).Value; + if (ModContent.HasAsset(path)) tex = ModContent.Request(path).Value; diff --git a/Content/Tools/CustomizeTool.cs b/Content/Tools/CustomizeTool.cs index 6471817..07f90da 100644 --- a/Content/Tools/CustomizeTool.cs +++ b/Content/Tools/CustomizeTool.cs @@ -1,4 +1,5 @@ -using DragonLens.Content.Filters.ToolFilters; +using DragonLens.Content.Filters; +using DragonLens.Content.Filters.ToolFilters; using DragonLens.Content.GUI; using DragonLens.Core.Loaders.UILoading; using DragonLens.Core.Systems.ThemeSystem; @@ -81,8 +82,13 @@ public override void PopulateGrid(UIGrid grid) public override void SetupFilters(FilterPanel filters) { - // Add only mods that have tools - foreach (Mod mod in ModContent.GetContent().Select(t => t.Mod).Distinct()) + 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)); } diff --git a/Localization/Tools/en-US_Mods.DragonLens.Tools.hjson b/Localization/Tools/en-US_Mods.DragonLens.Tools.hjson index 7c677b0..0a28796 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 85801ba..33115ab 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 9a0088b..41cc4a9 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: { From 1180cb4f724d213a5b8b55f62cc78761c2a7b7bd Mon Sep 17 00:00:00 2001 From: emyhrberg Date: Sat, 24 May 2025 00:13:20 +0200 Subject: [PATCH 3/3] Fix tool description again --- Content/Filters/ToolFilters/ToolModFilter.cs | 5 +---- Content/Tools/CustomizeTool.cs | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Content/Filters/ToolFilters/ToolModFilter.cs b/Content/Filters/ToolFilters/ToolModFilter.cs index 34720e8..659f51f 100644 --- a/Content/Filters/ToolFilters/ToolModFilter.cs +++ b/Content/Filters/ToolFilters/ToolModFilter.cs @@ -15,7 +15,7 @@ public ToolModFilter(Mod mod) : base(null, "", n => FilterByMod(n, mod)) public override string Name => mod.DisplayName; - public override string Description => Helpers.LocalizationHelper.GetText("Tools.CustomizeTool.Filters.Mod.Description", mod.DisplayName); + public override string Description => CustomizeTool.GetText("Filters.Mod.Description", mod.DisplayName); public static bool FilterByMod(BrowserButton button, Mod mod) { @@ -36,9 +36,6 @@ public override void Draw(SpriteBatch spriteBatch, Rectangle target) string path = $"{mod.Name}/icon_small"; - //if (mod.Name == "DragonLens") - //tex = ModContent.Request(dlPath).Value; - if (ModContent.HasAsset(path)) tex = ModContent.Request(path).Value; diff --git a/Content/Tools/CustomizeTool.cs b/Content/Tools/CustomizeTool.cs index 07f90da..1dfe1bc 100644 --- a/Content/Tools/CustomizeTool.cs +++ b/Content/Tools/CustomizeTool.cs @@ -22,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)