feat: add categories for "testing available" and "currently testing"

This commit is contained in:
goat 2022-10-30 16:14:14 +01:00
parent 23ffcd12a3
commit ae1d90162a
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
2 changed files with 76 additions and 10 deletions

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using CheapLoc; using CheapLoc;
using Dalamud.Plugin.Internal;
using Dalamud.Plugin.Internal.Types; using Dalamud.Plugin.Internal.Types;
namespace Dalamud.Interface.Internal; namespace Dalamud.Interface.Internal;
@ -20,6 +21,8 @@ internal class PluginCategoryManager
private readonly CategoryInfo[] categoryList = private readonly CategoryInfo[] categoryList =
{ {
new(0, "special.all", () => Locs.Category_All), new(0, "special.all", () => Locs.Category_All),
new(1, "special.isTesting", () => Locs.Category_IsTesting, CategoryInfo.AppearCondition.DoPluginTest),
new(2, "special.availableForTesting", () => Locs.Category_AvailableForTesting, CategoryInfo.AppearCondition.DoPluginTest),
new(10, "special.devInstalled", () => Locs.Category_DevInstalled), new(10, "special.devInstalled", () => Locs.Category_DevInstalled),
new(11, "special.devIconTester", () => Locs.Category_IconTester), new(11, "special.devIconTester", () => Locs.Category_IconTester),
new(12, "special.dalamud", () => Locs.Category_Dalamud), new(12, "special.dalamud", () => Locs.Category_Dalamud),
@ -39,7 +42,7 @@ internal class PluginCategoryManager
private GroupInfo[] groupList = private GroupInfo[] groupList =
{ {
new(GroupKind.DevTools, () => Locs.Group_DevTools, 10, 11), new(GroupKind.DevTools, () => Locs.Group_DevTools, 10, 11),
new(GroupKind.Installed, () => Locs.Group_Installed, 0), new(GroupKind.Installed, () => Locs.Group_Installed, 0, 1),
new(GroupKind.Available, () => Locs.Group_Available, 0), new(GroupKind.Available, () => Locs.Group_Available, 0),
new(GroupKind.Changelog, () => Locs.Group_Changelog, 0, 12, 13), new(GroupKind.Changelog, () => Locs.Group_Changelog, 0, 12, 13),
@ -153,11 +156,11 @@ internal class PluginCategoryManager
var categoryList = new List<int>(); var categoryList = new List<int>();
var allCategoryIndices = new List<int>(); var allCategoryIndices = new List<int>();
foreach (var plugin in availablePlugins) foreach (var manifest in availablePlugins)
{ {
categoryList.Clear(); categoryList.Clear();
var pluginCategoryTags = this.GetCategoryTagsForManifest(plugin); var pluginCategoryTags = this.GetCategoryTagsForManifest(manifest);
if (pluginCategoryTags != null) if (pluginCategoryTags != null)
{ {
foreach (var tag in pluginCategoryTags) foreach (var tag in pluginCategoryTags)
@ -180,12 +183,16 @@ internal class PluginCategoryManager
} }
} }
if (PluginManager.HasTestingVersion(manifest) || manifest.IsTestingExclusive)
categoryList.Add(2);
// always add, even if empty // always add, even if empty
this.mapPluginCategories.Add(plugin, categoryList.ToArray()); this.mapPluginCategories.Add(manifest, categoryList.ToArray());
} }
// sort all categories by their loc name // sort all categories by their loc name
allCategoryIndices.Sort((idxX, idxY) => this.CategoryList[idxX].Name.CompareTo(this.CategoryList[idxY].Name)); allCategoryIndices.Sort((idxX, idxY) => this.CategoryList[idxX].Name.CompareTo(this.CategoryList[idxY].Name));
allCategoryIndices.Insert(0, 2); // "Available for testing"
// rebuild all categories in group, leaving first entry = All intact and always on top // rebuild all categories in group, leaving first entry = All intact and always on top
if (groupAvail.Categories.Count > 1) if (groupAvail.Categories.Count > 1)
@ -321,13 +328,36 @@ internal class PluginCategoryManager
/// <param name="categoryId">Unique id of category.</param> /// <param name="categoryId">Unique id of category.</param>
/// <param name="tag">Tag to match.</param> /// <param name="tag">Tag to match.</param>
/// <param name="nameFunc">Function returning localized name of category.</param> /// <param name="nameFunc">Function returning localized name of category.</param>
public CategoryInfo(int categoryId, string tag, Func<string> nameFunc) /// <param name="condition">Condition to be checked when deciding whether this category should be shown.</param>
public CategoryInfo(int categoryId, string tag, Func<string> nameFunc, AppearCondition condition = AppearCondition.None)
{ {
this.CategoryId = categoryId; this.CategoryId = categoryId;
this.Tag = tag; this.Tag = tag;
this.nameFunc = nameFunc; this.nameFunc = nameFunc;
this.Condition = condition;
} }
/// <summary>
/// Conditions for categories.
/// </summary>
public enum AppearCondition
{
/// <summary>
/// Check no conditions.
/// </summary>
None,
/// <summary>
/// Check if plugin testing is enabled.
/// </summary>
DoPluginTest,
}
/// <summary>
/// Gets or sets the condition to be checked when rendering.
/// </summary>
public AppearCondition Condition { get; set; }
/// <summary> /// <summary>
/// Gets the name of category. /// Gets the name of category.
/// </summary> /// </summary>
@ -390,6 +420,10 @@ internal class PluginCategoryManager
public static string Category_All => Loc.Localize("InstallerCategoryAll", "All"); public static string Category_All => Loc.Localize("InstallerCategoryAll", "All");
public static string Category_IsTesting => Loc.Localize("InstallerCategoryIsTesting", "Currently Testing");
public static string Category_AvailableForTesting => Loc.Localize("InstallerCategoryAvailableForTesting", "Testing Available");
public static string Category_DevInstalled => Loc.Localize("InstallerInstalledDevPlugins", "Installed Dev Plugins"); public static string Category_DevInstalled => Loc.Localize("InstallerInstalledDevPlugins", "Installed Dev Plugins");
public static string Category_IconTester => "Image/Icon Tester"; public static string Category_IconTester => "Image/Icon Tester";

View file

@ -918,9 +918,10 @@ internal class PluginInstallerWindow : Window, IDisposable
} }
} }
private void DrawInstalledPluginList() private void DrawInstalledPluginList(bool filterTesting)
{ {
var pluginList = this.pluginListInstalled; var pluginList = this.pluginListInstalled;
var manager = Service<PluginManager>.Get();
if (pluginList.Count == 0) if (pluginList.Count == 0)
{ {
@ -941,6 +942,9 @@ internal class PluginInstallerWindow : Window, IDisposable
var i = 0; var i = 0;
foreach (var plugin in filteredList) foreach (var plugin in filteredList)
{ {
if (filterTesting && !manager.HasTestingOptIn(plugin.Manifest))
continue;
this.DrawInstalledPlugin(plugin, i++); this.DrawInstalledPlugin(plugin, i++);
} }
} }
@ -1043,6 +1047,19 @@ internal class PluginInstallerWindow : Window, IDisposable
{ {
var categoryInfo = Array.Find(this.categoryManager.CategoryList, x => x.CategoryId == groupInfo.Categories[categoryIdx]); var categoryInfo = Array.Find(this.categoryManager.CategoryList, x => x.CategoryId == groupInfo.Categories[categoryIdx]);
switch (categoryInfo.Condition)
{
case PluginCategoryManager.CategoryInfo.AppearCondition.None:
// Do nothing
break;
case PluginCategoryManager.CategoryInfo.AppearCondition.DoPluginTest:
if (!Service<DalamudConfiguration>.Get().DoPluginTest)
continue;
break;
default:
throw new ArgumentOutOfRangeException();
}
var hasSearchHighlight = this.categoryManager.IsCategoryHighlighted(categoryInfo.CategoryId); var hasSearchHighlight = this.categoryManager.IsCategoryHighlighted(categoryInfo.CategoryId);
if (hasSearchHighlight) if (hasSearchHighlight)
{ {
@ -1135,7 +1152,17 @@ internal class PluginInstallerWindow : Window, IDisposable
break; break;
case PluginCategoryManager.GroupKind.Installed: case PluginCategoryManager.GroupKind.Installed:
this.DrawInstalledPluginList(); switch (this.categoryManager.CurrentCategoryIdx)
{
case 0:
this.DrawInstalledPluginList(false);
break;
case 1:
this.DrawInstalledPluginList(true);
break;
}
break; break;
case PluginCategoryManager.GroupKind.Changelog: case PluginCategoryManager.GroupKind.Changelog:
switch (this.categoryManager.CurrentCategoryIdx) switch (this.categoryManager.CurrentCategoryIdx)
@ -1677,7 +1704,6 @@ internal class PluginInstallerWindow : Window, IDisposable
var pluginManager = Service<PluginManager>.Get(); var pluginManager = Service<PluginManager>.Get();
var useTesting = pluginManager.UseTesting(manifest); var useTesting = pluginManager.UseTesting(manifest);
var activelyTesting = useTesting || manifest.IsTestingExclusive;
var wasSeen = this.WasPluginSeen(manifest.InternalName); var wasSeen = this.WasPluginSeen(manifest.InternalName);
var isOutdated = manifest.DalamudApiLevel < PluginManager.DalamudApiLevel; var isOutdated = manifest.DalamudApiLevel < PluginManager.DalamudApiLevel;
@ -1693,10 +1719,14 @@ internal class PluginInstallerWindow : Window, IDisposable
var label = manifest.Name; var label = manifest.Name;
// Testing // Testing
if (activelyTesting) if (useTesting)
{ {
label += Locs.PluginTitleMod_TestingVersion; label += Locs.PluginTitleMod_TestingVersion;
} }
else if (manifest.IsTestingExclusive)
{
label += Locs.PluginTitleMod_TestingExclusive;
}
else if (configuration.DoPluginTest && PluginManager.HasTestingVersion(manifest)) else if (configuration.DoPluginTest && PluginManager.HasTestingVersion(manifest))
{ {
label += Locs.PluginTitleMod_TestingAvailable; label += Locs.PluginTitleMod_TestingAvailable;
@ -2832,7 +2862,9 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string PluginTitleMod_TestingVersion => Loc.Localize("InstallerTestingVersion", " (testing version)"); public static string PluginTitleMod_TestingVersion => Loc.Localize("InstallerTestingVersion", " (testing version)");
public static string PluginTitleMod_TestingAvailable => Loc.Localize("InstallerTestingAvailable", " (available for testing)"); public static string PluginTitleMod_TestingExclusive => Loc.Localize("InstallerTestingExclusive", " (testing exclusive)");
public static string PluginTitleMod_TestingAvailable => Loc.Localize("InstallerTestingAvailable", " (has testing version)");
public static string PluginTitleMod_DevPlugin => Loc.Localize("InstallerDevPlugin", " (dev plugin)"); public static string PluginTitleMod_DevPlugin => Loc.Localize("InstallerDevPlugin", " (dev plugin)");