mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
pi: don't use indices to refer to groups and categories
Fixes some bugs I bugged into the codebase by adding a new category inbetween two others
This commit is contained in:
parent
3509a0bdca
commit
a8025298ea
2 changed files with 215 additions and 116 deletions
|
|
@ -16,47 +16,49 @@ internal class PluginCategoryManager
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// First categoryId for tag based categories.
|
/// First categoryId for tag based categories.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const int FirstTagBasedCategoryId = 100;
|
private const int FirstTagBasedCategoryId = 100;
|
||||||
|
|
||||||
private readonly CategoryInfo[] categoryList =
|
private readonly CategoryInfo[] categoryList =
|
||||||
{
|
[
|
||||||
new(0, "special.all", () => Locs.Category_All),
|
new(CategoryKind.All, "special.all", () => Locs.Category_All),
|
||||||
new(1, "special.isTesting", () => Locs.Category_IsTesting, CategoryInfo.AppearCondition.DoPluginTest),
|
new(CategoryKind.IsTesting, "special.isTesting", () => Locs.Category_IsTesting, CategoryInfo.AppearCondition.DoPluginTest),
|
||||||
new(2, "special.availableForTesting", () => Locs.Category_AvailableForTesting, CategoryInfo.AppearCondition.DoPluginTest),
|
new(CategoryKind.AvailableForTesting, "special.availableForTesting", () => Locs.Category_AvailableForTesting, CategoryInfo.AppearCondition.DoPluginTest),
|
||||||
new(10, "special.devInstalled", () => Locs.Category_DevInstalled),
|
new(CategoryKind.DevInstalled, "special.devInstalled", () => Locs.Category_DevInstalled),
|
||||||
new(11, "special.devIconTester", () => Locs.Category_IconTester),
|
new(CategoryKind.IconTester, "special.devIconTester", () => Locs.Category_IconTester),
|
||||||
new(12, "special.dalamud", () => Locs.Category_Dalamud),
|
new(CategoryKind.DalamudChangelogs, "special.dalamud", () => Locs.Category_Dalamud),
|
||||||
new(13, "special.plugins", () => Locs.Category_Plugins),
|
new(CategoryKind.PluginChangelogs, "special.plugins", () => Locs.Category_Plugins),
|
||||||
new(14, "special.profiles", () => Locs.Category_PluginProfiles),
|
new(CategoryKind.PluginProfiles, "special.profiles", () => Locs.Category_PluginProfiles),
|
||||||
new(15, "special.updateable", () => Locs.Category_UpdateablePlugins),
|
new(CategoryKind.UpdateablePlugins, "special.updateable", () => Locs.Category_UpdateablePlugins),
|
||||||
new(FirstTagBasedCategoryId + 0, "other", () => Locs.Category_Other),
|
|
||||||
new(FirstTagBasedCategoryId + 1, "jobs", () => Locs.Category_Jobs),
|
// Tag-driven categories
|
||||||
new(FirstTagBasedCategoryId + 2, "ui", () => Locs.Category_UI),
|
new(CategoryKind.Other, "other", () => Locs.Category_Other),
|
||||||
new(FirstTagBasedCategoryId + 3, "minigames", () => Locs.Category_MiniGames),
|
new(CategoryKind.Jobs, "jobs", () => Locs.Category_Jobs),
|
||||||
new(FirstTagBasedCategoryId + 4, "inventory", () => Locs.Category_Inventory),
|
new(CategoryKind.Ui, "ui", () => Locs.Category_UI),
|
||||||
new(FirstTagBasedCategoryId + 5, "sound", () => Locs.Category_Sound),
|
new(CategoryKind.MiniGames, "minigames", () => Locs.Category_MiniGames),
|
||||||
new(FirstTagBasedCategoryId + 6, "social", () => Locs.Category_Social),
|
new(CategoryKind.Inventory, "inventory", () => Locs.Category_Inventory),
|
||||||
new(FirstTagBasedCategoryId + 7, "utility", () => Locs.Category_Utility),
|
new(CategoryKind.Sound, "sound", () => Locs.Category_Sound),
|
||||||
|
new(CategoryKind.Social, "social", () => Locs.Category_Social),
|
||||||
|
new(CategoryKind.Utility, "utility", () => Locs.Category_Utility)
|
||||||
|
|
||||||
// order doesn't matter, all tag driven categories should have Id >= FirstTagBasedCategoryId
|
// order doesn't matter, all tag driven categories should have Id >= FirstTagBasedCategoryId
|
||||||
};
|
];
|
||||||
|
|
||||||
private GroupInfo[] groupList =
|
private GroupInfo[] groupList =
|
||||||
{
|
[
|
||||||
new(GroupKind.DevTools, () => Locs.Group_DevTools, 10, 11),
|
new(GroupKind.DevTools, () => Locs.Group_DevTools, CategoryKind.DevInstalled, CategoryKind.IconTester),
|
||||||
new(GroupKind.Installed, () => Locs.Group_Installed, 0, 1, 15, 14),
|
new(GroupKind.Installed, () => Locs.Group_Installed, CategoryKind.All, CategoryKind.IsTesting, CategoryKind.UpdateablePlugins, CategoryKind.PluginProfiles),
|
||||||
new(GroupKind.Available, () => Locs.Group_Available, 0),
|
new(GroupKind.Available, () => Locs.Group_Available, CategoryKind.All),
|
||||||
new(GroupKind.Changelog, () => Locs.Group_Changelog, 0, 12, 13),
|
new(GroupKind.Changelog, () => Locs.Group_Changelog, CategoryKind.All, CategoryKind.DalamudChangelogs, CategoryKind.PluginChangelogs)
|
||||||
|
|
||||||
// order important, used for drawing, keep in sync with defaults for currentGroupIdx
|
// order important, used for drawing, keep in sync with defaults for currentGroupIdx
|
||||||
};
|
];
|
||||||
|
|
||||||
private int currentGroupIdx = 2;
|
private int currentGroupIdx = 2;
|
||||||
private int currentCategoryIdx = 0;
|
private CategoryKind currentCategoryKind = CategoryKind.All;
|
||||||
private bool isContentDirty;
|
private bool isContentDirty;
|
||||||
|
|
||||||
private Dictionary<PluginManifest, int[]> mapPluginCategories = new();
|
private Dictionary<PluginManifest, CategoryKind[]> mapPluginCategories = new();
|
||||||
private List<int> highlightedCategoryIds = new();
|
private List<CategoryKind> highlightedCategoryKinds = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Type of category group.
|
/// Type of category group.
|
||||||
|
|
@ -84,6 +86,97 @@ internal class PluginCategoryManager
|
||||||
Changelog,
|
Changelog,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Type of category.
|
||||||
|
/// </summary>
|
||||||
|
public enum CategoryKind
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// All plugins.
|
||||||
|
/// </summary>
|
||||||
|
All = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins currently being tested.
|
||||||
|
/// </summary>
|
||||||
|
IsTesting = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins available for testing.
|
||||||
|
/// </summary>
|
||||||
|
AvailableForTesting = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Installed dev plugins.
|
||||||
|
/// </summary>
|
||||||
|
DevInstalled = 10,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Icon tester.
|
||||||
|
/// </summary>
|
||||||
|
IconTester = 11,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changelogs for Dalamud.
|
||||||
|
/// </summary>
|
||||||
|
DalamudChangelogs = 12,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changelogs for plugins.
|
||||||
|
/// </summary>
|
||||||
|
PluginChangelogs = 13,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Change plugin profiles.
|
||||||
|
/// </summary>
|
||||||
|
PluginProfiles = 14,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updateable plugins.
|
||||||
|
/// </summary>
|
||||||
|
UpdateablePlugins = 15,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins tagged as "other".
|
||||||
|
/// </summary>
|
||||||
|
Other = FirstTagBasedCategoryId + 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins tagged as "jobs".
|
||||||
|
/// </summary>
|
||||||
|
Jobs = FirstTagBasedCategoryId + 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins tagged as "ui".
|
||||||
|
/// </summary>
|
||||||
|
Ui = FirstTagBasedCategoryId + 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins tagged as "minigames".
|
||||||
|
/// </summary>
|
||||||
|
MiniGames = FirstTagBasedCategoryId + 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins tagged as "inventory".
|
||||||
|
/// </summary>
|
||||||
|
Inventory = FirstTagBasedCategoryId + 4,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins tagged as "sound".
|
||||||
|
/// </summary>
|
||||||
|
Sound = FirstTagBasedCategoryId + 5,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins tagged as "social".
|
||||||
|
/// </summary>
|
||||||
|
Social = FirstTagBasedCategoryId + 6,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Plugins tagged as "utility".
|
||||||
|
/// </summary>
|
||||||
|
Utility = FirstTagBasedCategoryId + 7,
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of all known categories.
|
/// Gets the list of all known categories.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -93,39 +186,50 @@ internal class PluginCategoryManager
|
||||||
/// Gets the list of all known UI groups.
|
/// Gets the list of all known UI groups.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public GroupInfo[] GroupList => this.groupList;
|
public GroupInfo[] GroupList => this.groupList;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets current group.
|
/// Gets or sets the current group kind.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int CurrentGroupIdx
|
public GroupKind CurrentGroupKind
|
||||||
{
|
{
|
||||||
get => this.currentGroupIdx;
|
get => this.groupList[this.currentGroupIdx].GroupKind;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (this.currentGroupIdx != value)
|
var newIdx = Array.FindIndex(this.groupList, x => x.GroupKind == value);
|
||||||
|
if (newIdx >= 0)
|
||||||
{
|
{
|
||||||
this.currentGroupIdx = value;
|
this.currentGroupIdx = newIdx;
|
||||||
this.currentCategoryIdx = 0;
|
this.currentCategoryKind = this.CurrentGroup.Categories.First();
|
||||||
this.isContentDirty = true;
|
this.isContentDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets current category, index in current Group.Categories array.
|
/// Gets information about currently selected group.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int CurrentCategoryIdx
|
public GroupInfo CurrentGroup => this.groupList[this.currentGroupIdx];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current category kind.
|
||||||
|
/// </summary>
|
||||||
|
public CategoryKind CurrentCategoryKind
|
||||||
{
|
{
|
||||||
get => this.currentCategoryIdx;
|
get => this.currentCategoryKind;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (this.currentCategoryIdx != value)
|
if (this.currentCategoryKind != value)
|
||||||
{
|
{
|
||||||
this.currentCategoryIdx = value;
|
this.currentCategoryKind = value;
|
||||||
this.isContentDirty = true;
|
this.isContentDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets information about currently selected category.
|
||||||
|
/// </summary>
|
||||||
|
public CategoryInfo CurrentCategory => this.categoryList.First(x => x.CategoryKind == this.currentCategoryKind);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether current group + category selection changed recently.
|
/// Gets a value indicating whether current group + category selection changed recently.
|
||||||
|
|
@ -134,13 +238,12 @@ internal class PluginCategoryManager
|
||||||
public bool IsContentDirty => this.isContentDirty;
|
public bool IsContentDirty => this.isContentDirty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether <see cref="CurrentCategoryIdx"/> and <see cref="CurrentGroupIdx"/> are valid.
|
/// Gets a value indicating whether <see cref="CurrentCategoryKind"/> and <see cref="CurrentGroupKind"/> are valid.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsSelectionValid =>
|
public bool IsSelectionValid =>
|
||||||
(this.currentGroupIdx >= 0) &&
|
(this.currentGroupIdx >= 0) &&
|
||||||
(this.currentGroupIdx < this.groupList.Length) &&
|
(this.currentGroupIdx < this.groupList.Length) &&
|
||||||
(this.currentCategoryIdx >= 0) &&
|
this.groupList[this.currentGroupIdx].Categories.Contains(this.currentCategoryKind);
|
||||||
(this.currentCategoryIdx < this.groupList[this.currentGroupIdx].Categories.Count);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rebuild available categories based on currently available plugins.
|
/// Rebuild available categories based on currently available plugins.
|
||||||
|
|
@ -152,10 +255,10 @@ internal class PluginCategoryManager
|
||||||
this.mapPluginCategories.Clear();
|
this.mapPluginCategories.Clear();
|
||||||
|
|
||||||
var groupAvail = Array.Find(this.groupList, x => x.GroupKind == GroupKind.Available);
|
var groupAvail = Array.Find(this.groupList, x => x.GroupKind == GroupKind.Available);
|
||||||
var prevCategoryIds = new List<int>();
|
var prevCategoryIds = new List<CategoryKind>();
|
||||||
prevCategoryIds.AddRange(groupAvail.Categories);
|
prevCategoryIds.AddRange(groupAvail.Categories);
|
||||||
|
|
||||||
var categoryList = new List<int>();
|
var categoryList = new List<CategoryKind>();
|
||||||
var allCategoryIndices = new List<int>();
|
var allCategoryIndices = new List<int>();
|
||||||
|
|
||||||
foreach (var manifest in availablePlugins)
|
foreach (var manifest in availablePlugins)
|
||||||
|
|
@ -171,10 +274,10 @@ internal class PluginCategoryManager
|
||||||
var matchIdx = Array.FindIndex(this.CategoryList, x => x.Tag.Equals(tag, StringComparison.InvariantCultureIgnoreCase));
|
var matchIdx = Array.FindIndex(this.CategoryList, x => x.Tag.Equals(tag, StringComparison.InvariantCultureIgnoreCase));
|
||||||
if (matchIdx >= 0)
|
if (matchIdx >= 0)
|
||||||
{
|
{
|
||||||
var categoryId = this.CategoryList[matchIdx].CategoryId;
|
var categoryKind = this.CategoryList[matchIdx].CategoryKind;
|
||||||
if (categoryId >= FirstTagBasedCategoryId)
|
if ((int)categoryKind >= FirstTagBasedCategoryId)
|
||||||
{
|
{
|
||||||
categoryList.Add(categoryId);
|
categoryList.Add(categoryKind);
|
||||||
|
|
||||||
if (!allCategoryIndices.Contains(matchIdx))
|
if (!allCategoryIndices.Contains(matchIdx))
|
||||||
{
|
{
|
||||||
|
|
@ -186,7 +289,7 @@ internal class PluginCategoryManager
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PluginManager.HasTestingVersion(manifest) || manifest.IsTestingExclusive)
|
if (PluginManager.HasTestingVersion(manifest) || manifest.IsTestingExclusive)
|
||||||
categoryList.Add(2);
|
categoryList.Add(CategoryKind.AvailableForTesting);
|
||||||
|
|
||||||
// always add, even if empty
|
// always add, even if empty
|
||||||
this.mapPluginCategories.Add(manifest, categoryList.ToArray());
|
this.mapPluginCategories.Add(manifest, categoryList.ToArray());
|
||||||
|
|
@ -204,11 +307,11 @@ internal class PluginCategoryManager
|
||||||
|
|
||||||
foreach (var categoryIdx in allCategoryIndices)
|
foreach (var categoryIdx in allCategoryIndices)
|
||||||
{
|
{
|
||||||
groupAvail.Categories.Add(this.CategoryList[categoryIdx].CategoryId);
|
groupAvail.Categories.Add(this.CategoryList[categoryIdx].CategoryKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// compare with prev state and mark as dirty if needed
|
// compare with prev state and mark as dirty if needed
|
||||||
var noCategoryChanges = Enumerable.SequenceEqual(prevCategoryIds, groupAvail.Categories);
|
var noCategoryChanges = prevCategoryIds.SequenceEqual(groupAvail.Categories);
|
||||||
if (!noCategoryChanges)
|
if (!noCategoryChanges)
|
||||||
{
|
{
|
||||||
this.isContentDirty = true;
|
this.isContentDirty = true;
|
||||||
|
|
@ -229,20 +332,20 @@ internal class PluginCategoryManager
|
||||||
{
|
{
|
||||||
var groupInfo = this.groupList[this.currentGroupIdx];
|
var groupInfo = this.groupList[this.currentGroupIdx];
|
||||||
|
|
||||||
var includeAll = (this.currentCategoryIdx == 0) || (groupInfo.GroupKind != GroupKind.Available);
|
var includeAll = (this.currentCategoryKind == CategoryKind.All) || (groupInfo.GroupKind != GroupKind.Available);
|
||||||
if (includeAll)
|
if (includeAll)
|
||||||
{
|
{
|
||||||
result.AddRange(plugins);
|
result.AddRange(plugins);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var selectedCategoryInfo = Array.Find(this.categoryList, x => x.CategoryId == groupInfo.Categories[this.currentCategoryIdx]);
|
var selectedCategoryInfo = Array.Find(this.categoryList, x => x.CategoryKind == this.currentCategoryKind);
|
||||||
|
|
||||||
foreach (var plugin in plugins)
|
foreach (var plugin in plugins)
|
||||||
{
|
{
|
||||||
if (this.mapPluginCategories.TryGetValue(plugin, out var pluginCategoryIds))
|
if (this.mapPluginCategories.TryGetValue(plugin, out var pluginCategoryIds))
|
||||||
{
|
{
|
||||||
var matchIdx = Array.IndexOf(pluginCategoryIds, selectedCategoryInfo.CategoryId);
|
var matchIdx = Array.IndexOf(pluginCategoryIds, selectedCategoryInfo.CategoryKind);
|
||||||
if (matchIdx >= 0)
|
if (matchIdx >= 0)
|
||||||
{
|
{
|
||||||
result.Add(plugin);
|
result.Add(plugin);
|
||||||
|
|
@ -270,20 +373,17 @@ internal class PluginCategoryManager
|
||||||
/// <param name="plugins">List of plugins whose categories should be highlighted.</param>
|
/// <param name="plugins">List of plugins whose categories should be highlighted.</param>
|
||||||
public void SetCategoryHighlightsForPlugins(IEnumerable<PluginManifest> plugins)
|
public void SetCategoryHighlightsForPlugins(IEnumerable<PluginManifest> plugins)
|
||||||
{
|
{
|
||||||
this.highlightedCategoryIds.Clear();
|
this.highlightedCategoryKinds.Clear();
|
||||||
|
|
||||||
if (plugins != null)
|
foreach (var entry in plugins)
|
||||||
{
|
{
|
||||||
foreach (var entry in plugins)
|
if (this.mapPluginCategories.TryGetValue(entry, out var pluginCategories))
|
||||||
{
|
{
|
||||||
if (this.mapPluginCategories.TryGetValue(entry, out var pluginCategories))
|
foreach (var categoryKind in pluginCategories)
|
||||||
{
|
{
|
||||||
foreach (var categoryId in pluginCategories)
|
if (!this.highlightedCategoryKinds.Contains(categoryKind))
|
||||||
{
|
{
|
||||||
if (!this.highlightedCategoryIds.Contains(categoryId))
|
this.highlightedCategoryKinds.Add(categoryKind);
|
||||||
{
|
|
||||||
this.highlightedCategoryIds.Add(categoryId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -293,9 +393,9 @@ internal class PluginCategoryManager
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if category should be highlighted.
|
/// Checks if category should be highlighted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="categoryId">CategoryId to check.</param>
|
/// <param name="categoryKind">CategoryKind to check.</param>
|
||||||
/// <returns>true if highlight is needed.</returns>
|
/// <returns>true if highlight is needed.</returns>
|
||||||
public bool IsCategoryHighlighted(int categoryId) => this.highlightedCategoryIds.Contains(categoryId);
|
public bool IsCategoryHighlighted(CategoryKind categoryKind) => this.highlightedCategoryKinds.Contains(categoryKind);
|
||||||
|
|
||||||
private IEnumerable<string> GetCategoryTagsForManifest(PluginManifest pluginManifest)
|
private IEnumerable<string> GetCategoryTagsForManifest(PluginManifest pluginManifest)
|
||||||
{
|
{
|
||||||
|
|
@ -315,7 +415,7 @@ internal class PluginCategoryManager
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unique Id number of category, tag match based should be greater of equal <see cref="FirstTagBasedCategoryId"/>.
|
/// Unique Id number of category, tag match based should be greater of equal <see cref="FirstTagBasedCategoryId"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int CategoryId;
|
public CategoryKind CategoryKind;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tag from plugin manifest to match.
|
/// Tag from plugin manifest to match.
|
||||||
|
|
@ -327,13 +427,13 @@ internal class PluginCategoryManager
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="CategoryInfo"/> struct.
|
/// Initializes a new instance of the <see cref="CategoryInfo"/> struct.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="categoryId">Unique id of category.</param>
|
/// <param name="categoryKind">Kind of the 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>
|
||||||
/// <param name="condition">Condition to be checked when deciding whether this category should be shown.</param>
|
/// <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)
|
public CategoryInfo(CategoryKind categoryKind, string tag, Func<string> nameFunc, AppearCondition condition = AppearCondition.None)
|
||||||
{
|
{
|
||||||
this.CategoryId = categoryId;
|
this.CategoryKind = categoryKind;
|
||||||
this.Tag = tag;
|
this.Tag = tag;
|
||||||
this.nameFunc = nameFunc;
|
this.nameFunc = nameFunc;
|
||||||
this.Condition = condition;
|
this.Condition = condition;
|
||||||
|
|
@ -379,7 +479,7 @@ internal class PluginCategoryManager
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of categories in container.
|
/// List of categories in container.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<int> Categories;
|
public List<CategoryKind> Categories;
|
||||||
|
|
||||||
private Func<string> nameFunc;
|
private Func<string> nameFunc;
|
||||||
|
|
||||||
|
|
@ -389,7 +489,7 @@ internal class PluginCategoryManager
|
||||||
/// <param name="groupKind">Type of group.</param>
|
/// <param name="groupKind">Type of group.</param>
|
||||||
/// <param name="nameFunc">Function returning localized name of category.</param>
|
/// <param name="nameFunc">Function returning localized name of category.</param>
|
||||||
/// <param name="categories">List of category Ids to hardcode.</param>
|
/// <param name="categories">List of category Ids to hardcode.</param>
|
||||||
public GroupInfo(GroupKind groupKind, Func<string> nameFunc, params int[] categories)
|
public GroupInfo(GroupKind groupKind, Func<string> nameFunc, params CategoryKind[] categories)
|
||||||
{
|
{
|
||||||
this.GroupKind = groupKind;
|
this.GroupKind = groupKind;
|
||||||
this.nameFunc = nameFunc;
|
this.nameFunc = nameFunc;
|
||||||
|
|
|
||||||
|
|
@ -428,27 +428,27 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
{
|
{
|
||||||
case PluginInstallerOpenKind.AllPlugins:
|
case PluginInstallerOpenKind.AllPlugins:
|
||||||
// Plugins group
|
// Plugins group
|
||||||
this.categoryManager.CurrentGroupIdx = 2;
|
this.categoryManager.CurrentGroupKind = PluginCategoryManager.GroupKind.Available;
|
||||||
// All category
|
// All category
|
||||||
this.categoryManager.CurrentCategoryIdx = 0;
|
this.categoryManager.CurrentCategoryKind = PluginCategoryManager.CategoryKind.All;
|
||||||
break;
|
break;
|
||||||
case PluginInstallerOpenKind.InstalledPlugins:
|
case PluginInstallerOpenKind.InstalledPlugins:
|
||||||
// Installed group
|
// Installed group
|
||||||
this.categoryManager.CurrentGroupIdx = 1;
|
this.categoryManager.CurrentGroupKind = PluginCategoryManager.GroupKind.Installed;
|
||||||
// All category
|
// All category
|
||||||
this.categoryManager.CurrentCategoryIdx = 0;
|
this.categoryManager.CurrentCategoryKind = PluginCategoryManager.CategoryKind.All;
|
||||||
break;
|
break;
|
||||||
case PluginInstallerOpenKind.UpdateablePlugins:
|
case PluginInstallerOpenKind.UpdateablePlugins:
|
||||||
// Installed group
|
// Installed group
|
||||||
this.categoryManager.CurrentGroupIdx = 1;
|
this.categoryManager.CurrentGroupKind = PluginCategoryManager.GroupKind.Installed;
|
||||||
// Updateable category
|
// Updateable category
|
||||||
this.categoryManager.CurrentCategoryIdx = 15;
|
this.categoryManager.CurrentCategoryKind = PluginCategoryManager.CategoryKind.UpdateablePlugins;
|
||||||
break;
|
break;
|
||||||
case PluginInstallerOpenKind.Changelogs:
|
case PluginInstallerOpenKind.Changelogs:
|
||||||
// Changelog group
|
// Changelog group
|
||||||
this.categoryManager.CurrentGroupIdx = 3;
|
this.categoryManager.CurrentGroupKind = PluginCategoryManager.GroupKind.Changelog;
|
||||||
// Plugins category
|
// Plugins category
|
||||||
this.categoryManager.CurrentCategoryIdx = 2;
|
this.categoryManager.CurrentCategoryKind = PluginCategoryManager.CategoryKind.All;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
|
throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
|
||||||
|
|
@ -611,7 +611,8 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
ImGui.SetCursorPosX(windowSize.X - sortSelectWidth - (style.ItemSpacing.X * 2) - searchInputWidth - searchClearButtonWidth);
|
ImGui.SetCursorPosX(windowSize.X - sortSelectWidth - (style.ItemSpacing.X * 2) - searchInputWidth - searchClearButtonWidth);
|
||||||
|
|
||||||
var isProfileManager =
|
var isProfileManager =
|
||||||
this.categoryManager.CurrentGroupIdx == 1 && this.categoryManager.CurrentCategoryIdx == 2;
|
this.categoryManager.CurrentGroupKind == PluginCategoryManager.GroupKind.Installed &&
|
||||||
|
this.categoryManager.CurrentCategoryKind == PluginCategoryManager.CategoryKind.PluginProfiles;
|
||||||
|
|
||||||
// Disable search if profile editor
|
// Disable search if profile editor
|
||||||
using (ImRaii.Disabled(isProfileManager))
|
using (ImRaii.Disabled(isProfileManager))
|
||||||
|
|
@ -641,7 +642,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable sort if changelogs or profile editor
|
// Disable sort if changelogs or profile editor
|
||||||
using (ImRaii.Disabled(this.categoryManager.CurrentGroupIdx == 3 || isProfileManager))
|
using (ImRaii.Disabled(this.categoryManager.CurrentGroupKind == PluginCategoryManager.GroupKind.Changelog || isProfileManager))
|
||||||
{
|
{
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
ImGui.SetCursorPosY(downShift);
|
ImGui.SetCursorPosY(downShift);
|
||||||
|
|
@ -781,9 +782,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
Service<PluginManager>.Get().PrintUpdatedPlugins(this.updatedPlugins, Locs.PluginUpdateHeader_Chatbox);
|
Service<PluginManager>.Get().PrintUpdatedPlugins(this.updatedPlugins, Locs.PluginUpdateHeader_Chatbox);
|
||||||
notifications.AddNotification(Locs.Notifications_UpdatesInstalled(this.updatePluginCount), Locs.Notifications_UpdatesInstalledTitle, NotificationType.Success);
|
notifications.AddNotification(Locs.Notifications_UpdatesInstalled(this.updatePluginCount), Locs.Notifications_UpdatesInstalledTitle, NotificationType.Success);
|
||||||
|
|
||||||
var installedGroupIdx = this.categoryManager.GroupList.TakeWhile(
|
this.categoryManager.CurrentGroupKind = PluginCategoryManager.GroupKind.Installed;
|
||||||
x => x.GroupKind != PluginCategoryManager.GroupKind.Installed).Count();
|
|
||||||
this.categoryManager.CurrentGroupIdx = installedGroupIdx;
|
|
||||||
}
|
}
|
||||||
else if (this.updatePluginCount == 0)
|
else if (this.updatePluginCount == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -1373,29 +1372,29 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var groupIdx = 0; groupIdx < this.categoryManager.GroupList.Length; groupIdx++)
|
foreach (var groupInfo in this.categoryManager.GroupList)
|
||||||
{
|
{
|
||||||
var groupInfo = this.categoryManager.GroupList[groupIdx];
|
|
||||||
var canShowGroup = (groupInfo.GroupKind != PluginCategoryManager.GroupKind.DevTools) || this.hasDevPlugins;
|
var canShowGroup = (groupInfo.GroupKind != PluginCategoryManager.GroupKind.DevTools) || this.hasDevPlugins;
|
||||||
if (!canShowGroup)
|
if (!canShowGroup)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.SetNextItemOpen(groupIdx == this.categoryManager.CurrentGroupIdx);
|
var isCurrent = groupInfo.GroupKind == this.categoryManager.CurrentGroupKind;
|
||||||
if (ImGui.CollapsingHeader(groupInfo.Name, groupIdx == this.categoryManager.CurrentGroupIdx ? ImGuiTreeNodeFlags.OpenOnDoubleClick : ImGuiTreeNodeFlags.None))
|
ImGui.SetNextItemOpen(isCurrent);
|
||||||
|
if (ImGui.CollapsingHeader(groupInfo.Name, isCurrent ? ImGuiTreeNodeFlags.OpenOnDoubleClick : ImGuiTreeNodeFlags.None))
|
||||||
{
|
{
|
||||||
if (this.categoryManager.CurrentGroupIdx != groupIdx)
|
if (!isCurrent)
|
||||||
{
|
{
|
||||||
this.categoryManager.CurrentGroupIdx = groupIdx;
|
this.categoryManager.CurrentGroupKind = groupInfo.GroupKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Indent();
|
ImGui.Indent();
|
||||||
var categoryItemSize = new Vector2(ImGui.GetContentRegionAvail().X - (5 * ImGuiHelpers.GlobalScale), ImGui.GetTextLineHeight());
|
var categoryItemSize = new Vector2(ImGui.GetContentRegionAvail().X - (5 * ImGuiHelpers.GlobalScale), ImGui.GetTextLineHeight());
|
||||||
for (var categoryIdx = 0; categoryIdx < groupInfo.Categories.Count; categoryIdx++)
|
foreach (var categoryKind in groupInfo.Categories)
|
||||||
{
|
{
|
||||||
var categoryInfo = Array.Find(this.categoryManager.CategoryList, x => x.CategoryId == groupInfo.Categories[categoryIdx]);
|
var categoryInfo = this.categoryManager.CategoryList.First(x => x.CategoryKind == categoryKind);
|
||||||
|
|
||||||
switch (categoryInfo.Condition)
|
switch (categoryInfo.Condition)
|
||||||
{
|
{
|
||||||
case PluginCategoryManager.CategoryInfo.AppearCondition.None:
|
case PluginCategoryManager.CategoryInfo.AppearCondition.None:
|
||||||
|
|
@ -1409,15 +1408,15 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasSearchHighlight = this.categoryManager.IsCategoryHighlighted(categoryInfo.CategoryId);
|
var hasSearchHighlight = this.categoryManager.IsCategoryHighlighted(categoryInfo.CategoryKind);
|
||||||
if (hasSearchHighlight)
|
if (hasSearchHighlight)
|
||||||
{
|
{
|
||||||
ImGui.PushStyleColor(ImGuiCol.Text, colorSearchHighlight);
|
ImGui.PushStyleColor(ImGuiCol.Text, colorSearchHighlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui.Selectable(categoryInfo.Name, this.categoryManager.CurrentCategoryIdx == categoryIdx, ImGuiSelectableFlags.None, categoryItemSize))
|
if (ImGui.Selectable(categoryInfo.Name, this.categoryManager.CurrentCategoryKind == categoryKind, ImGuiSelectableFlags.None, categoryItemSize))
|
||||||
{
|
{
|
||||||
this.categoryManager.CurrentCategoryIdx = categoryIdx;
|
this.categoryManager.CurrentCategoryKind = categoryKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSearchHighlight)
|
if (hasSearchHighlight)
|
||||||
|
|
@ -1427,11 +1426,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Unindent();
|
ImGui.Unindent();
|
||||||
|
ImGuiHelpers.ScaledDummy(5);
|
||||||
if (groupIdx != this.categoryManager.GroupList.Length - 1)
|
|
||||||
{
|
|
||||||
ImGuiHelpers.ScaledDummy(5);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1467,7 +1462,7 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
|
|
||||||
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, ImGuiHelpers.ScaledVector2(1, 3));
|
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, ImGuiHelpers.ScaledVector2(1, 3));
|
||||||
|
|
||||||
var groupInfo = this.categoryManager.GroupList[this.categoryManager.CurrentGroupIdx];
|
var groupInfo = this.categoryManager.CurrentGroup;
|
||||||
if (this.categoryManager.IsContentDirty)
|
if (this.categoryManager.IsContentDirty)
|
||||||
{
|
{
|
||||||
// reset opened list of collapsibles when switching between categories
|
// reset opened list of collapsibles when switching between categories
|
||||||
|
|
@ -1484,13 +1479,13 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
{
|
{
|
||||||
case PluginCategoryManager.GroupKind.DevTools:
|
case PluginCategoryManager.GroupKind.DevTools:
|
||||||
// this one is never sorted and remains in hardcoded order from group ctor
|
// this one is never sorted and remains in hardcoded order from group ctor
|
||||||
switch (this.categoryManager.CurrentCategoryIdx)
|
switch (this.categoryManager.CurrentCategoryKind)
|
||||||
{
|
{
|
||||||
case 0:
|
case PluginCategoryManager.CategoryKind.DevInstalled:
|
||||||
this.DrawInstalledPluginList(InstalledPluginListFilter.Dev);
|
this.DrawInstalledPluginList(InstalledPluginListFilter.Dev);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case PluginCategoryManager.CategoryKind.IconTester:
|
||||||
this.DrawImageTester();
|
this.DrawImageTester();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -1501,21 +1496,21 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case PluginCategoryManager.GroupKind.Installed:
|
case PluginCategoryManager.GroupKind.Installed:
|
||||||
switch (this.categoryManager.CurrentCategoryIdx)
|
switch (this.categoryManager.CurrentCategoryKind)
|
||||||
{
|
{
|
||||||
case 0:
|
case PluginCategoryManager.CategoryKind.All:
|
||||||
this.DrawInstalledPluginList(InstalledPluginListFilter.None);
|
this.DrawInstalledPluginList(InstalledPluginListFilter.None);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case PluginCategoryManager.CategoryKind.IsTesting:
|
||||||
this.DrawInstalledPluginList(InstalledPluginListFilter.Testing);
|
this.DrawInstalledPluginList(InstalledPluginListFilter.Testing);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case PluginCategoryManager.CategoryKind.UpdateablePlugins:
|
||||||
this.DrawInstalledPluginList(InstalledPluginListFilter.Updateable);
|
this.DrawInstalledPluginList(InstalledPluginListFilter.Updateable);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case PluginCategoryManager.CategoryKind.PluginProfiles:
|
||||||
this.profileManagerWidget.Draw();
|
this.profileManagerWidget.Draw();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -1526,19 +1521,23 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case PluginCategoryManager.GroupKind.Changelog:
|
case PluginCategoryManager.GroupKind.Changelog:
|
||||||
switch (this.categoryManager.CurrentCategoryIdx)
|
switch (this.categoryManager.CurrentCategoryKind)
|
||||||
{
|
{
|
||||||
case 0:
|
case PluginCategoryManager.CategoryKind.All:
|
||||||
this.DrawChangelogList(true, true);
|
this.DrawChangelogList(true, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case PluginCategoryManager.CategoryKind.DalamudChangelogs:
|
||||||
this.DrawChangelogList(true, false);
|
this.DrawChangelogList(true, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case PluginCategoryManager.CategoryKind.PluginChangelogs:
|
||||||
this.DrawChangelogList(false, true);
|
this.DrawChangelogList(false, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ImGui.TextUnformatted("You found a quiet category. Please don't wake it up.");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue