Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Content/Filters/ToolFilters/ToolModFilter.cs
Original file line number Diff line number Diff line change
@@ -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<Texture2D>(path).Value;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would override if DL ever adds an icon_small, is this the intended behavior?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally if this does happen the external logic checkifn tfor the mod is removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, used vanilla asset for DragonLens tools


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);
}
}
}
}
23 changes: 22 additions & 1 deletion Content/Tools/CustomizeTool.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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<DragonLens>())) { isModFilter = true });

// Add any other mods that have tools, excluding DragonLens
foreach (Mod mod in ModContent.GetContent<Tool>().Select(t => t.Mod).Distinct().Where(mod => mod != ModContent.GetInstance<DragonLens>()))
{
filters.AddFilter(new ToolModFilter(mod));
}
}

public override void SetupSorts()
{
SortModes.Add(new("Alphabetical", (a, b) => a.Identifier.CompareTo(b.Identifier)));
Expand Down
10 changes: 10 additions & 0 deletions Localization/Tools/en-US_Mods.DragonLens.Tools.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
10 changes: 10 additions & 0 deletions Localization/Tools/ru-RU_Mods.DragonLens.Tools.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
10 changes: 10 additions & 0 deletions Localization/Tools/zh-Hans_Mods.DragonLens.Tools.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down