Implement service locator

This commit is contained in:
Raymond 2021-08-20 11:59:35 -04:00
parent 06b1163a52
commit ff1d7f2829
101 changed files with 1614 additions and 1436 deletions

View file

@ -1,6 +1,6 @@
using System;
using System.IO;
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using Dalamud.Plugin;
@ -14,7 +14,8 @@ namespace Dalamud.CorePlugin
public sealed class PluginImpl : IDalamudPlugin
{
private readonly WindowSystem windowSystem = new("Dalamud.CorePlugin");
private Localization localizationManager;
// private Localization localizationManager;
/// <inheritdoc/>
public string Name => "Dalamud.CorePlugin";
@ -29,16 +30,16 @@ namespace Dalamud.CorePlugin
{
try
{
this.InitLoc();
// this.InitLoc();
this.Interface = pluginInterface;
this.windowSystem.AddWindow(new PluginWindow(Dalamud.Instance));
this.windowSystem.AddWindow(new PluginWindow());
this.Interface.UiBuilder.Draw += this.OnDraw;
this.Interface.UiBuilder.OpenConfigUi += this.OnOpenConfigUi;
this.Interface.CommandManager.AddHandler("/di", new(this.OnCommand) { HelpMessage = $"Access the {this.Name} plugin." });
var commandManager = Service<CommandManager>.Get();
commandManager.AddHandler("/di", new(this.OnCommand) { HelpMessage = $"Access the {this.Name} plugin." });
}
catch (Exception ex)
{
@ -58,20 +59,23 @@ namespace Dalamud.CorePlugin
this.Interface.Dispose();
}
private void InitLoc()
{
// CheapLoc needs to be reinitialized here because it tracks the setup by assembly name. New assembly, new setup.
this.localizationManager = new Localization(Path.Combine(Dalamud.Instance.AssetDirectory.FullName, "UIRes", "loc", "dalamud"), "dalamud_");
if (!string.IsNullOrEmpty(Dalamud.Instance.Configuration.LanguageOverride))
{
this.localizationManager.SetupWithLangCode(Dalamud.Instance.Configuration.LanguageOverride);
}
else
{
this.localizationManager.SetupWithUiCulture();
}
}
// private void InitLoc()
// {
// // CheapLoc needs to be reinitialized here because it tracks the setup by assembly name. New assembly, new setup.
// this.localizationManager = new Localization(Path.Combine(Dalamud.Instance.AssetDirectory.FullName, "UIRes", "loc", "dalamud"), "dalamud_");
// if (!string.IsNullOrEmpty(Dalamud.Instance.Configuration.LanguageOverride))
// {
// this.localizationManager.SetupWithLangCode(Dalamud.Instance.Configuration.LanguageOverride);
// }
// else
// {
// this.localizationManager.SetupWithUiCulture();
// }
// }
/// <summary>
/// Draw the window system.
/// </summary>
private void OnDraw()
{
try