add DI, start implementing mediator pattern instead of events
This commit is contained in:
@@ -13,6 +13,7 @@ using MareSynchronos.API.Dto.User;
|
||||
using MareSynchronos.Delegates;
|
||||
using MareSynchronos.Managers;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Mediator;
|
||||
using MareSynchronos.Models;
|
||||
using MareSynchronos.UI.Components;
|
||||
using MareSynchronos.UI.Handlers;
|
||||
@@ -26,6 +27,7 @@ public class CompactUi : Window, IDisposable
|
||||
private readonly ApiController _apiController;
|
||||
private readonly PairManager _pairManager;
|
||||
private readonly ServerConfigurationManager _serverManager;
|
||||
private readonly MareMediator _mediator;
|
||||
private readonly ConfigurationService _configService;
|
||||
private readonly TagHandler _tagHandler;
|
||||
public readonly Dictionary<string, bool> ShowUidForEntry = new(StringComparer.Ordinal);
|
||||
@@ -57,7 +59,7 @@ public class CompactUi : Window, IDisposable
|
||||
|
||||
public CompactUi(WindowSystem windowSystem,
|
||||
UiShared uiShared, ConfigurationService configService, ApiController apiController, PairManager pairManager,
|
||||
ServerConfigurationManager serverManager) : base("###MareSynchronosMainUI")
|
||||
ServerConfigurationManager serverManager, MareMediator mediator) : base("###MareSynchronosMainUI")
|
||||
{
|
||||
|
||||
#if DEBUG
|
||||
@@ -88,6 +90,7 @@ public class CompactUi : Window, IDisposable
|
||||
_apiController = apiController;
|
||||
_pairManager = pairManager;
|
||||
_serverManager = serverManager;
|
||||
_mediator = mediator;
|
||||
_tagHandler = new(_serverManager);
|
||||
|
||||
_groupPanel = new(this, uiShared, _pairManager, _serverManager, _configService);
|
||||
@@ -95,6 +98,9 @@ public class CompactUi : Window, IDisposable
|
||||
_selectPairsForGroupUi = new(_tagHandler);
|
||||
_pairGroupsUi = new(_tagHandler, DrawPairedClient, apiController, _selectPairsForGroupUi);
|
||||
|
||||
_mediator.Subscribe<SwitchToMainUiMessage>(this, (_) => IsOpen = true);
|
||||
_mediator.Subscribe<SwitchToIntroUiMessage>(this, (_) => IsOpen = false);
|
||||
|
||||
_uiShared.GposeStart += UiShared_GposeStart;
|
||||
_uiShared.GposeEnd += UiShared_GposeEnd;
|
||||
|
||||
@@ -118,7 +124,6 @@ public class CompactUi : Window, IDisposable
|
||||
IsOpen = false;
|
||||
}
|
||||
|
||||
public event VoidDelegate? OpenSettingsUi;
|
||||
public void Dispose()
|
||||
{
|
||||
Logger.Verbose("Disposing " + nameof(CompactUi));
|
||||
@@ -700,7 +705,7 @@ public class CompactUi : Window, IDisposable
|
||||
ImGui.SetCursorPosY(originalPos.Y + uidTextSize.Y / 2 - buttonSize.Y / 2);
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Cog))
|
||||
{
|
||||
OpenSettingsUi?.Invoke();
|
||||
_mediator.Publish(new OpenSettingsUiMessage());
|
||||
}
|
||||
UiShared.AttachToolTip("Open the Mare Synchronos Settings");
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using Dalamud.Interface.Windowing;
|
||||
using ImGuiNET;
|
||||
using MareSynchronos.Export;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Mediator;
|
||||
using MareSynchronos.Utils;
|
||||
|
||||
namespace MareSynchronos.UI;
|
||||
@@ -16,17 +17,20 @@ public class GposeUi : Window, IDisposable
|
||||
private readonly DalamudUtil _dalamudUtil;
|
||||
private readonly FileDialogManager _fileDialogManager;
|
||||
private readonly ConfigurationService _configService;
|
||||
private readonly MareMediator _mediator;
|
||||
|
||||
public GposeUi(WindowSystem windowSystem, MareCharaFileManager mareCharaFileManager,
|
||||
DalamudUtil dalamudUtil, FileDialogManager fileDialogManager, ConfigurationService configService) : base("Mare Synchronos Gpose Import UI###MareSynchronosGposeUI")
|
||||
DalamudUtil dalamudUtil, FileDialogManager fileDialogManager, ConfigurationService configService,
|
||||
MareMediator mediator) : base("Mare Synchronos Gpose Import UI###MareSynchronosGposeUI")
|
||||
{
|
||||
_windowSystem = windowSystem;
|
||||
_mareCharaFileManager = mareCharaFileManager;
|
||||
_dalamudUtil = dalamudUtil;
|
||||
_fileDialogManager = fileDialogManager;
|
||||
_configService = configService;
|
||||
_dalamudUtil.GposeStart += StartGpose;
|
||||
_dalamudUtil.GposeEnd += EndGpose;
|
||||
_mediator = mediator;
|
||||
_mediator.Subscribe<GposeStartMessage>(this, (_) => StartGpose());
|
||||
_mediator.Subscribe<GposeEndMessage>(this, (_) => EndGpose());
|
||||
IsOpen = _dalamudUtil.IsInGpose;
|
||||
Flags = ImGuiWindowFlags.AlwaysAutoResize;
|
||||
_windowSystem.AddWindow(this);
|
||||
@@ -45,8 +49,6 @@ public class GposeUi : Window, IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_dalamudUtil.GposeStart -= StartGpose;
|
||||
_dalamudUtil.GposeEnd -= EndGpose;
|
||||
_windowSystem.RemoveWindow(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using MareSynchronos.FileCache;
|
||||
using Dalamud.Interface;
|
||||
using MareSynchronos.Managers;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Delegates;
|
||||
using MareSynchronos.Mediator;
|
||||
|
||||
namespace MareSynchronos.UI;
|
||||
|
||||
@@ -19,11 +19,10 @@ internal class IntroUi : Window, IDisposable
|
||||
private readonly ConfigurationService _configService;
|
||||
private readonly PeriodicFileScanner _fileCacheManager;
|
||||
private readonly ServerConfigurationManager _serverConfigurationManager;
|
||||
private readonly MareMediator _mareMediator;
|
||||
private readonly WindowSystem _windowSystem;
|
||||
private bool _readFirstPage;
|
||||
|
||||
public event VoidDelegate? SwitchToMainUi;
|
||||
|
||||
private string[]? _tosParagraphs;
|
||||
|
||||
private Task? _timeoutTask;
|
||||
@@ -40,7 +39,7 @@ internal class IntroUi : Window, IDisposable
|
||||
}
|
||||
|
||||
public IntroUi(WindowSystem windowSystem, UiShared uiShared, ConfigurationService configService,
|
||||
PeriodicFileScanner fileCacheManager, ServerConfigurationManager serverConfigurationManager) : base("Mare Synchronos Setup")
|
||||
PeriodicFileScanner fileCacheManager, ServerConfigurationManager serverConfigurationManager, MareMediator mareMediator) : base("Mare Synchronos Setup")
|
||||
{
|
||||
Logger.Verbose("Creating " + nameof(IntroUi));
|
||||
|
||||
@@ -48,6 +47,7 @@ internal class IntroUi : Window, IDisposable
|
||||
_configService = configService;
|
||||
_fileCacheManager = fileCacheManager;
|
||||
_serverConfigurationManager = serverConfigurationManager;
|
||||
_mareMediator = mareMediator;
|
||||
_windowSystem = windowSystem;
|
||||
IsOpen = false;
|
||||
|
||||
@@ -59,6 +59,9 @@ internal class IntroUi : Window, IDisposable
|
||||
|
||||
GetToSLocalization();
|
||||
|
||||
_mareMediator.Subscribe<SwitchToMainUiMessage>(this, (_) => IsOpen = false);
|
||||
_mareMediator.Subscribe<SwitchToIntroUiMessage>(this, (_) => IsOpen = true);
|
||||
|
||||
_windowSystem.AddWindow(this);
|
||||
}
|
||||
|
||||
@@ -239,7 +242,7 @@ internal class IntroUi : Window, IDisposable
|
||||
}
|
||||
else
|
||||
{
|
||||
SwitchToMainUi?.Invoke();
|
||||
_mareMediator.Publish(new SwitchToMainUiMessage());
|
||||
IsOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ using MareSynchronos.API.Data;
|
||||
using MareSynchronos.Managers;
|
||||
using MareSynchronos.API.Data.Comparer;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Delegates;
|
||||
using MareSynchronos.Mediator;
|
||||
|
||||
namespace MareSynchronos.UI;
|
||||
|
||||
@@ -25,10 +25,10 @@ public class SettingsUi : Window, IDisposable
|
||||
private readonly MareCharaFileManager _mareCharaFileManager;
|
||||
private readonly PairManager _pairManager;
|
||||
private readonly ServerConfigurationManager _serverConfigurationManager;
|
||||
private readonly MareMediator _mediator;
|
||||
private readonly UiShared _uiShared;
|
||||
public CharacterData? LastCreatedCharacterData { private get; set; }
|
||||
|
||||
public event VoidDelegate? SwitchToIntroUi;
|
||||
private bool _overwriteExistingLabels = false;
|
||||
private bool? _notesSuccessfullyApplied = null;
|
||||
private string _lastTab = string.Empty;
|
||||
@@ -36,7 +36,8 @@ public class SettingsUi : Window, IDisposable
|
||||
|
||||
public SettingsUi(WindowSystem windowSystem,
|
||||
UiShared uiShared, ConfigurationService configService,
|
||||
MareCharaFileManager mareCharaFileManager, PairManager pairManager, ServerConfigurationManager serverConfigurationManager) : base("Mare Synchronos Settings")
|
||||
MareCharaFileManager mareCharaFileManager, PairManager pairManager,
|
||||
ServerConfigurationManager serverConfigurationManager, MareMediator mediator) : base("Mare Synchronos Settings")
|
||||
{
|
||||
Logger.Verbose("Creating " + nameof(SettingsUi));
|
||||
|
||||
@@ -51,9 +52,12 @@ public class SettingsUi : Window, IDisposable
|
||||
_mareCharaFileManager = mareCharaFileManager;
|
||||
_pairManager = pairManager;
|
||||
_serverConfigurationManager = serverConfigurationManager;
|
||||
_mediator = mediator;
|
||||
_uiShared = uiShared;
|
||||
|
||||
|
||||
_mediator.Subscribe<OpenSettingsUiMessage>(this, (_) => Toggle());
|
||||
_mediator.Subscribe<SwitchToIntroUiMessage>(this, (_) => IsOpen = false);
|
||||
_uiShared.GposeStart += UiShared_GposeStart;
|
||||
_uiShared.GposeEnd += UiShared_GposeEnd;
|
||||
|
||||
@@ -211,7 +215,7 @@ public class SettingsUi : Window, IDisposable
|
||||
{
|
||||
Task.Run(() => ApiController.UserDelete());
|
||||
_deleteAccountPopupModalShown = false;
|
||||
SwitchToIntroUi?.Invoke();
|
||||
_mediator.Publish(new SwitchToIntroUiMessage());
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
@@ -14,6 +14,7 @@ using MareSynchronos.FileCache;
|
||||
using MareSynchronos.Localization;
|
||||
using MareSynchronos.Managers;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Mediator;
|
||||
using MareSynchronos.Models;
|
||||
using MareSynchronos.Utils;
|
||||
using MareSynchronos.WebAPI;
|
||||
@@ -34,6 +35,7 @@ public partial class UiShared : IDisposable
|
||||
private readonly DalamudPluginInterface _pluginInterface;
|
||||
private readonly Dalamud.Localization _localization;
|
||||
private readonly ServerConfigurationManager _serverConfigurationManager;
|
||||
private readonly MareMediator _mediator;
|
||||
|
||||
public long FileCacheSize => _cacheScanner.FileCacheSize;
|
||||
public string PlayerName => _dalamudUtil.PlayerName;
|
||||
@@ -57,7 +59,7 @@ public partial class UiShared : IDisposable
|
||||
|
||||
public UiShared(IpcManager ipcManager, ApiController apiController, PeriodicFileScanner cacheScanner, FileDialogManager fileDialogManager,
|
||||
ConfigurationService configService, DalamudUtil dalamudUtil, DalamudPluginInterface pluginInterface, Dalamud.Localization localization,
|
||||
ServerConfigurationManager serverManager)
|
||||
ServerConfigurationManager serverManager, MareMediator mediator)
|
||||
{
|
||||
_ipcManager = ipcManager;
|
||||
_apiController = apiController;
|
||||
@@ -68,13 +70,14 @@ public partial class UiShared : IDisposable
|
||||
_pluginInterface = pluginInterface;
|
||||
_localization = localization;
|
||||
_serverConfigurationManager = serverManager;
|
||||
_mediator = mediator;
|
||||
_isDirectoryWritable = IsDirectoryWritable(_configService.Current.CacheFolder);
|
||||
|
||||
_pluginInterface.UiBuilder.BuildFonts += BuildFont;
|
||||
_pluginInterface.UiBuilder.RebuildFonts();
|
||||
|
||||
_dalamudUtil.GposeStart += DalamudUtil_GposeStart;
|
||||
_dalamudUtil.GposeEnd += DalamudUtil_GposeEnd;
|
||||
_mediator.Subscribe<GposeStartMessage>(this, (_) => DalamudUtil_GposeStart());
|
||||
_mediator.Subscribe<GposeEndMessage>(this, (_) => DalamudUtil_GposeEnd());
|
||||
}
|
||||
|
||||
private void DalamudUtil_GposeEnd()
|
||||
@@ -673,7 +676,5 @@ public partial class UiShared : IDisposable
|
||||
public void Dispose()
|
||||
{
|
||||
_pluginInterface.UiBuilder.BuildFonts -= BuildFont;
|
||||
_dalamudUtil.GposeStart -= DalamudUtil_GposeStart;
|
||||
_dalamudUtil.GposeEnd -= DalamudUtil_GposeEnd;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user