PalacePal/Pal.Client/Plugin.cs

80 lines
2.6 KiB
C#
Raw Normal View History

2023-02-15 22:51:35 +00:00
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
2023-02-08 15:06:43 +00:00
using Pal.Client.Rendering;
2022-10-26 18:43:24 +00:00
using Pal.Client.Windows;
using System;
2023-02-10 19:48:14 +00:00
using System.Globalization;
using System.Linq;
2023-02-10 19:48:14 +00:00
using Pal.Client.Properties;
using ECommons;
2023-02-15 22:17:19 +00:00
using Microsoft.Extensions.DependencyInjection;
2023-02-15 01:38:04 +00:00
using Pal.Client.Configuration;
namespace Pal.Client
{
2023-02-16 12:17:55 +00:00
/// <summary>
/// With all DI logic elsewhere, this plugin shell really only takes care of a few things around events that
/// need to be sent to different receivers depending on priority or configuration .
/// </summary>
/// <see cref="DependencyInjection.DependencyInjectionContext"/>
2023-02-15 22:17:19 +00:00
internal sealed class Plugin : IDisposable
{
2023-02-15 22:17:19 +00:00
private readonly IServiceProvider _serviceProvider;
private readonly DalamudPluginInterface _pluginInterface;
private readonly IPalacePalConfiguration _configuration;
private readonly RenderAdapter _renderAdapter;
2023-02-16 21:09:29 +00:00
private readonly WindowSystem _windowSystem;
2023-02-15 22:17:19 +00:00
public Plugin(
IServiceProvider serviceProvider,
DalamudPluginInterface pluginInterface,
IPalacePalConfiguration configuration,
2023-02-16 21:09:29 +00:00
RenderAdapter renderAdapter,
WindowSystem windowSystem)
{
2023-02-15 22:17:19 +00:00
_serviceProvider = serviceProvider;
_pluginInterface = pluginInterface;
_configuration = configuration;
_renderAdapter = renderAdapter;
2023-02-16 21:09:29 +00:00
_windowSystem = windowSystem;
2022-11-30 21:15:26 +00:00
2023-02-15 22:17:19 +00:00
LanguageChanged(pluginInterface.UiLanguage);
2022-10-26 18:43:24 +00:00
2023-02-08 15:06:43 +00:00
pluginInterface.UiBuilder.Draw += Draw;
2023-02-11 20:10:45 +00:00
pluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi;
2023-02-10 19:48:14 +00:00
pluginInterface.LanguageChanged += LanguageChanged;
}
2023-02-11 20:10:45 +00:00
private void OpenConfigUi()
{
2023-02-15 22:17:19 +00:00
Window configWindow;
if (_configuration.FirstUse)
configWindow = _serviceProvider.GetRequiredService<AgreementWindow>();
else
2023-02-15 22:17:19 +00:00
configWindow = _serviceProvider.GetRequiredService<ConfigWindow>();
2023-02-02 16:16:03 +00:00
2023-02-15 22:17:19 +00:00
configWindow.IsOpen = true;
}
public void Dispose()
{
2023-02-15 22:17:19 +00:00
_pluginInterface.UiBuilder.Draw -= Draw;
_pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi;
_pluginInterface.LanguageChanged -= LanguageChanged;
}
2023-02-15 22:17:19 +00:00
private void LanguageChanged(string languageCode)
{
2023-02-15 22:17:19 +00:00
Localization.Culture = new CultureInfo(languageCode);
2023-02-16 21:09:29 +00:00
_windowSystem.Windows.OfType<ILanguageChanged>()
2023-02-16 12:17:55 +00:00
.Each(w => w.LanguageChanged());
2023-02-08 15:06:43 +00:00
}
private void Draw()
{
2023-02-16 12:17:55 +00:00
_renderAdapter.DrawLayers();
2023-02-16 21:09:29 +00:00
_windowSystem.Draw();
}
}
}