mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-30 12:23:39 +01:00
haplo-tier
This commit is contained in:
parent
861b4da392
commit
de4ffd23c9
6 changed files with 189 additions and 9 deletions
77
Dalamud/Fools/FoolsManager.cs
Normal file
77
Dalamud/Fools/FoolsManager.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Dalamud.Fools.Plugins;
|
||||||
|
using Dalamud.Logging.Internal;
|
||||||
|
|
||||||
|
namespace Dalamud.Fools;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Manager for all the IFoolsPlugin instances.
|
||||||
|
/// </summary>
|
||||||
|
[ServiceManager.BlockingEarlyLoadedService]
|
||||||
|
internal class FoolsManager : IDisposable, IServiceType
|
||||||
|
{
|
||||||
|
public readonly List<FoolsPluginMetadata> FoolsPlugins = new();
|
||||||
|
public readonly Dictionary<string, IFoolsPlugin> ActivatedPlugins = new();
|
||||||
|
|
||||||
|
private static readonly ModuleLog Log = new("FOOLS");
|
||||||
|
|
||||||
|
[ServiceManager.ServiceConstructor]
|
||||||
|
private FoolsManager()
|
||||||
|
{
|
||||||
|
// reflect over all IFoolsPlugin implementations
|
||||||
|
this.FoolsPlugins = new List<FoolsPluginMetadata>
|
||||||
|
{
|
||||||
|
new("Test Fool Plugin", "TestFoolPlugin", "this is a test", "NotNite", typeof(TestFoolPlugin)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ActivatePlugin(string plugin)
|
||||||
|
{
|
||||||
|
if (this.ActivatedPlugins.ContainsKey(plugin))
|
||||||
|
{
|
||||||
|
Log.Warning("Trying to activate plugin {0} that is already activated", plugin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pluginMetadata = this.FoolsPlugins.FirstOrDefault(x => x.InternalName == plugin);
|
||||||
|
if (pluginMetadata == null)
|
||||||
|
{
|
||||||
|
Log.Warning("Trying to activate plugin {0} that does not exist", plugin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pluginInstance = (IFoolsPlugin)Activator.CreateInstance(pluginMetadata.Type);
|
||||||
|
this.ActivatedPlugins.Add(plugin, pluginInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsPluginActivated(string plugin)
|
||||||
|
{
|
||||||
|
return this.ActivatedPlugins.ContainsKey(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeactivatePlugin(string plugin)
|
||||||
|
{
|
||||||
|
if (!this.ActivatedPlugins.ContainsKey(plugin))
|
||||||
|
{
|
||||||
|
Log.Warning("Trying to deactivate plugin {0} that is not activated", plugin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pluginInstance = this.ActivatedPlugins[plugin];
|
||||||
|
pluginInstance.Dispose();
|
||||||
|
this.ActivatedPlugins.Remove(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
foreach (var plugin in this.ActivatedPlugins.Values)
|
||||||
|
{
|
||||||
|
plugin.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ActivatedPlugins.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
25
Dalamud/Fools/FoolsPluginMetadata.cs
Normal file
25
Dalamud/Fools/FoolsPluginMetadata.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Dalamud.Fools;
|
||||||
|
|
||||||
|
public class FoolsPluginMetadata
|
||||||
|
{
|
||||||
|
public string Name { get; }
|
||||||
|
|
||||||
|
public string InternalName { get; }
|
||||||
|
|
||||||
|
public string Description { get; }
|
||||||
|
|
||||||
|
public string Author { get; }
|
||||||
|
|
||||||
|
public Type Type { get; }
|
||||||
|
|
||||||
|
public FoolsPluginMetadata(string name, string internalName, string description, string author, Type type)
|
||||||
|
{
|
||||||
|
this.Name = name;
|
||||||
|
this.InternalName = internalName;
|
||||||
|
this.Description = description;
|
||||||
|
this.Author = author;
|
||||||
|
this.Type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Dalamud/Fools/IFoolsPlugin.cs
Normal file
8
Dalamud/Fools/IFoolsPlugin.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
using Dalamud.Plugin;
|
||||||
|
|
||||||
|
namespace Dalamud.Fools;
|
||||||
|
|
||||||
|
public interface IFoolsPlugin : IDalamudPlugin
|
||||||
|
{
|
||||||
|
public void DrawUI() { }
|
||||||
|
}
|
||||||
16
Dalamud/Fools/Plugins/TestFoolPlugin.cs
Normal file
16
Dalamud/Fools/Plugins/TestFoolPlugin.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
namespace Dalamud.Fools.Plugins;
|
||||||
|
|
||||||
|
public class TestFoolPlugin : IFoolsPlugin
|
||||||
|
{
|
||||||
|
public string Name => "TestFoolPlugin";
|
||||||
|
|
||||||
|
public string Description => "TestFoolPlugin";
|
||||||
|
|
||||||
|
public string InternalName => "TestFoolPlugin";
|
||||||
|
|
||||||
|
public string Author => "NotNite";
|
||||||
|
|
||||||
|
public TestFoolPlugin() { }
|
||||||
|
|
||||||
|
public void Dispose() { }
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using CheapLoc;
|
using CheapLoc;
|
||||||
using Dalamud.Plugin.Internal;
|
using Dalamud.Plugin.Internal;
|
||||||
using Dalamud.Plugin.Internal.Types;
|
using Dalamud.Plugin.Internal.Types;
|
||||||
|
|
@ -23,11 +22,13 @@ internal class PluginCategoryManager
|
||||||
{
|
{
|
||||||
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(1, "special.isTesting", () => Locs.Category_IsTesting, CategoryInfo.AppearCondition.DoPluginTest),
|
||||||
new(2, "special.availableForTesting", () => Locs.Category_AvailableForTesting, 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),
|
||||||
new(13, "special.plugins", () => Locs.Category_Plugins),
|
new(13, "special.plugins", () => Locs.Category_Plugins),
|
||||||
|
new(14, "special.alternateReality", () => "Alternate Reality"),
|
||||||
new(FirstTagBasedCategoryId + 0, "other", () => Locs.Category_Other),
|
new(FirstTagBasedCategoryId + 0, "other", () => Locs.Category_Other),
|
||||||
new(FirstTagBasedCategoryId + 1, "jobs", () => Locs.Category_Jobs),
|
new(FirstTagBasedCategoryId + 1, "jobs", () => Locs.Category_Jobs),
|
||||||
new(FirstTagBasedCategoryId + 2, "ui", () => Locs.Category_UI),
|
new(FirstTagBasedCategoryId + 2, "ui", () => Locs.Category_UI),
|
||||||
|
|
@ -36,7 +37,6 @@ internal class PluginCategoryManager
|
||||||
new(FirstTagBasedCategoryId + 5, "sound", () => Locs.Category_Sound),
|
new(FirstTagBasedCategoryId + 5, "sound", () => Locs.Category_Sound),
|
||||||
new(FirstTagBasedCategoryId + 6, "social", () => Locs.Category_Social),
|
new(FirstTagBasedCategoryId + 6, "social", () => Locs.Category_Social),
|
||||||
new(FirstTagBasedCategoryId + 7, "utility", () => Locs.Category_Utility),
|
new(FirstTagBasedCategoryId + 7, "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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -46,6 +46,7 @@ internal class PluginCategoryManager
|
||||||
new(GroupKind.Installed, () => Locs.Group_Installed, 0, 1),
|
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),
|
||||||
|
new(GroupKind.AlternateReality, () => "Alternate Reality", 14),
|
||||||
|
|
||||||
// order important, used for drawing, keep in sync with defaults for currentGroupIdx
|
// order important, used for drawing, keep in sync with defaults for currentGroupIdx
|
||||||
};
|
};
|
||||||
|
|
@ -81,6 +82,11 @@ internal class PluginCategoryManager
|
||||||
/// UI group: changelog of plugins.
|
/// UI group: changelog of plugins.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Changelog,
|
Changelog,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// April fools!
|
||||||
|
/// </summary>
|
||||||
|
AlternateReality
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -167,7 +173,8 @@ internal class PluginCategoryManager
|
||||||
foreach (var tag in pluginCategoryTags)
|
foreach (var tag in pluginCategoryTags)
|
||||||
{
|
{
|
||||||
// only tags from whitelist can be accepted
|
// only tags from whitelist can be accepted
|
||||||
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 categoryId = this.CategoryList[matchIdx].CategoryId;
|
||||||
|
|
@ -235,7 +242,9 @@ internal class PluginCategoryManager
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var selectedCategoryInfo = Array.Find(this.categoryList, x => x.CategoryId == groupInfo.Categories[this.currentCategoryIdx]);
|
var selectedCategoryInfo = Array.Find(this.categoryList,
|
||||||
|
x => x.CategoryId ==
|
||||||
|
groupInfo.Categories[this.currentCategoryIdx]);
|
||||||
|
|
||||||
foreach (var plugin in plugins)
|
foreach (var plugin in plugins)
|
||||||
{
|
{
|
||||||
|
|
@ -330,7 +339,8 @@ internal class PluginCategoryManager
|
||||||
/// <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(
|
||||||
|
int categoryId, string tag, Func<string> nameFunc, AppearCondition condition = AppearCondition.None)
|
||||||
{
|
{
|
||||||
this.CategoryId = categoryId;
|
this.CategoryId = categoryId;
|
||||||
this.Tag = tag;
|
this.Tag = tag;
|
||||||
|
|
@ -403,7 +413,8 @@ internal class PluginCategoryManager
|
||||||
public string Name => this.nameFunc();
|
public string Name => this.nameFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "locs")]
|
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented",
|
||||||
|
Justification = "locs")]
|
||||||
internal static class Locs
|
internal static class Locs
|
||||||
{
|
{
|
||||||
#region UI groups
|
#region UI groups
|
||||||
|
|
@ -424,9 +435,11 @@ internal class PluginCategoryManager
|
||||||
|
|
||||||
public static string Category_IsTesting => Loc.Localize("InstallerCategoryIsTesting", "Currently Testing");
|
public static string Category_IsTesting => Loc.Localize("InstallerCategoryIsTesting", "Currently Testing");
|
||||||
|
|
||||||
public static string Category_AvailableForTesting => Loc.Localize("InstallerCategoryAvailableForTesting", "Testing Available");
|
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";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
using CheapLoc;
|
using CheapLoc;
|
||||||
using Dalamud.Configuration.Internal;
|
using Dalamud.Configuration.Internal;
|
||||||
|
using Dalamud.Fools;
|
||||||
using Dalamud.Game.Command;
|
using Dalamud.Game.Command;
|
||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Components;
|
using Dalamud.Interface.Components;
|
||||||
|
|
@ -1236,6 +1237,11 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PluginCategoryManager.GroupKind.AlternateReality:
|
||||||
|
this.DrawAlternateRealityPlugins();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this.DrawAvailablePluginList();
|
this.DrawAvailablePluginList();
|
||||||
break;
|
break;
|
||||||
|
|
@ -1244,6 +1250,41 @@ internal class PluginInstallerWindow : Window, IDisposable
|
||||||
ImGui.PopStyleVar();
|
ImGui.PopStyleVar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DrawAlternateRealityPlugins()
|
||||||
|
{
|
||||||
|
var manager = Service<FoolsManager>.Get();
|
||||||
|
|
||||||
|
foreach (var plugin in manager.FoolsPlugins)
|
||||||
|
{
|
||||||
|
// dropdown
|
||||||
|
if (ImGui.CollapsingHeader($"{plugin.Name}##AprilFools_{plugin.Name}"))
|
||||||
|
{
|
||||||
|
ImGui.Indent();
|
||||||
|
ImGui.Text(plugin.Name);
|
||||||
|
ImGui.SameLine();
|
||||||
|
|
||||||
|
ImGui.TextColored(ImGuiColors.DalamudGrey3, $" by {plugin.Author}");
|
||||||
|
|
||||||
|
ImGui.TextWrapped(plugin.Description);
|
||||||
|
|
||||||
|
if (manager.IsPluginActivated(plugin.InternalName))
|
||||||
|
{
|
||||||
|
if (ImGui.Button("Disable"))
|
||||||
|
{
|
||||||
|
manager.DeactivatePlugin(plugin.InternalName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ImGui.Button("Install"))
|
||||||
|
{
|
||||||
|
manager.ActivatePlugin(plugin.InternalName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawImageTester()
|
private void DrawImageTester()
|
||||||
{
|
{
|
||||||
var sectionSize = ImGuiHelpers.GlobalScale * 66;
|
var sectionSize = ImGuiHelpers.GlobalScale * 66;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue