2023-02-15 22:51:35 +00:00
|
|
|
|
using Dalamud.Interface.Windowing;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
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;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
using System;
|
2023-02-10 19:48:14 +00:00
|
|
|
|
using System.Globalization;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
using System.Linq;
|
2023-02-10 19:48:14 +00:00
|
|
|
|
using Pal.Client.Properties;
|
2023-02-11 13:31:43 +00:00
|
|
|
|
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;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
|
|
|
|
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
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
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;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
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)
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
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;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 20:10:45 +00:00
|
|
|
|
private void OpenConfigUi()
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
Window configWindow;
|
|
|
|
|
if (_configuration.FirstUse)
|
|
|
|
|
configWindow = _serviceProvider.GetRequiredService<AgreementWindow>();
|
2022-10-23 02:38:58 +00:00
|
|
|
|
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;
|
2022-10-25 17:28:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-23 02:38:58 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2023-02-15 22:17:19 +00:00
|
|
|
|
_pluginInterface.UiBuilder.Draw -= Draw;
|
|
|
|
|
_pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi;
|
|
|
|
|
_pluginInterface.LanguageChanged -= LanguageChanged;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 22:17:19 +00:00
|
|
|
|
private void LanguageChanged(string languageCode)
|
2022-12-22 00:01:09 +00:00
|
|
|
|
{
|
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();
|
2022-10-26 21:38:29 +00:00
|
|
|
|
}
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|