rework creation of popout windows into factory and some refactoring in general

This commit is contained in:
rootdarkarchon
2023-10-27 02:51:26 +02:00
parent a8bc5386ea
commit 5c9415b6e9
15 changed files with 239 additions and 260 deletions

View File

@@ -91,30 +91,11 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton((s) => new ServerTagConfigService(pluginInterface.ConfigDirectory.FullName)); collection.AddSingleton((s) => new ServerTagConfigService(pluginInterface.ConfigDirectory.FullName));
collection.AddSingleton((s) => new TransientConfigService(pluginInterface.ConfigDirectory.FullName)); collection.AddSingleton((s) => new TransientConfigService(pluginInterface.ConfigDirectory.FullName));
collection.AddSingleton((s) => new ConfigurationMigrator(s.GetRequiredService<ILogger<ConfigurationMigrator>>(), pluginInterface)); collection.AddSingleton((s) => new ConfigurationMigrator(s.GetRequiredService<ILogger<ConfigurationMigrator>>(), pluginInterface));
collection.AddSingleton((s) => new HubFactory(s.GetRequiredService<ILogger<HubFactory>>(), s.GetRequiredService<MareMediator>(), collection.AddSingleton<HubFactory>();
s.GetRequiredService<ServerConfigurationManager>(), s.GetRequiredService<MareConfigService>(),
s.GetRequiredService<TokenProvider>(), pluginLog));
// func factory method singletons
collection.AddSingleton(s =>
new Func<Pair, StandaloneProfileUi>((pair) =>
new StandaloneProfileUi(s.GetRequiredService<ILogger<StandaloneProfileUi>>(),
s.GetRequiredService<MareMediator>(),
s.GetRequiredService<UiSharedService>(),
s.GetRequiredService<ServerConfigurationManager>(),
s.GetRequiredService<MareProfileManager>(),
s.GetRequiredService<PairManager>(), pair)));
collection.AddSingleton(s =>
new Func<GroupFullInfoDto, SyncshellAdminUI>((dto) =>
new SyncshellAdminUI(s.GetRequiredService<ILogger<SyncshellAdminUI>>(),
s.GetRequiredService<MareMediator>(),
dto,
s.GetRequiredService<ApiController>(),
s.GetRequiredService<UiSharedService>(),
s.GetRequiredService<PairManager>())));
// add scoped services // add scoped services
collection.AddScoped<PeriodicFileScanner>(); collection.AddScoped<PeriodicFileScanner>();
collection.AddScoped<UiFactory>();
collection.AddScoped<WindowMediatorSubscriberBase, SettingsUi>(); collection.AddScoped<WindowMediatorSubscriberBase, SettingsUi>();
collection.AddScoped<WindowMediatorSubscriberBase, CompactUi>(); collection.AddScoped<WindowMediatorSubscriberBase, CompactUi>();
collection.AddScoped<WindowMediatorSubscriberBase, GposeUi>(); collection.AddScoped<WindowMediatorSubscriberBase, GposeUi>();
@@ -135,10 +116,9 @@ public sealed class Plugin : IDalamudPlugin
collection.AddScoped<TransientResourceManager>(); collection.AddScoped<TransientResourceManager>();
collection.AddScoped<PlayerDataFactory>(); collection.AddScoped<PlayerDataFactory>();
collection.AddScoped<OnlinePlayerManager>(); collection.AddScoped<OnlinePlayerManager>();
collection.AddScoped((s) => new UiService(s.GetRequiredService<ILogger<UiService>>(), pluginInterface, s.GetRequiredService<MareConfigService>(), collection.AddScoped((s) => new UiService(s.GetRequiredService<ILogger<UiService>>(), pluginInterface.UiBuilder, s.GetRequiredService<MareConfigService>(),
s.GetRequiredService<WindowSystem>(), s.GetServices<WindowMediatorSubscriberBase>(), s.GetRequiredService<WindowSystem>(), s.GetServices<WindowMediatorSubscriberBase>(),
s.GetRequiredService<Func<Pair, StandaloneProfileUi>>(), s.GetRequiredService<UiFactory>(),
s.GetRequiredService<Func<GroupFullInfoDto, SyncshellAdminUI>>(),
s.GetRequiredService<FileDialogManager>(), s.GetRequiredService<MareMediator>())); s.GetRequiredService<FileDialogManager>(), s.GetRequiredService<MareMediator>()));
collection.AddScoped((s) => new CommandManagerService(commandManager, s.GetRequiredService<PerformanceCollectorService>(), collection.AddScoped((s) => new CommandManagerService(commandManager, s.GetRequiredService<PerformanceCollectorService>(),
s.GetRequiredService<ServerConfigurationManager>(), s.GetRequiredService<PeriodicFileScanner>(), s.GetRequiredService<ApiController>(), s.GetRequiredService<ServerConfigurationManager>(), s.GetRequiredService<PeriodicFileScanner>(), s.GetRequiredService<ApiController>(),

View File

@@ -0,0 +1,46 @@
using MareSynchronos.API.Dto.Group;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using MareSynchronos.UI;
using MareSynchronos.UI.Components.Popup;
using MareSynchronos.WebAPI;
using Microsoft.Extensions.Logging;
namespace MareSynchronos.Services;
public class UiFactory
{
private readonly ILoggerFactory _loggerFactory;
private readonly MareMediator _mareMediator;
private readonly ApiController _apiController;
private readonly UiSharedService _uiSharedService;
private readonly PairManager _pairManager;
private readonly ServerConfigurationManager _serverConfigManager;
private readonly MareProfileManager _mareProfileManager;
public UiFactory(ILoggerFactory loggerFactory, MareMediator mareMediator, ApiController apiController,
UiSharedService uiSharedService, PairManager pairManager, ServerConfigurationManager serverConfigManager,
MareProfileManager mareProfileManager)
{
_loggerFactory = loggerFactory;
_mareMediator = mareMediator;
_apiController = apiController;
_uiSharedService = uiSharedService;
_pairManager = pairManager;
_serverConfigManager = serverConfigManager;
_mareProfileManager = mareProfileManager;
}
public SyncshellAdminUI CreateSyncshellAdminUi(GroupFullInfoDto dto)
{
return new SyncshellAdminUI(_loggerFactory.CreateLogger<SyncshellAdminUI>(), _mareMediator,
_apiController, _uiSharedService, _pairManager, dto);
}
public StandaloneProfileUi CreateStandaloneProfileUi(Pair pair)
{
return new StandaloneProfileUi(_loggerFactory.CreateLogger<StandaloneProfileUi>(), _mareMediator,
_uiSharedService, _serverConfigManager, _mareProfileManager, _pairManager, pair);
}
}

View File

@@ -1,9 +1,7 @@
using Dalamud.Interface.ImGuiFileDialog; using Dalamud.Interface;
using Dalamud.Interface.ImGuiFileDialog;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using MareSynchronos.API.Dto.Group;
using MareSynchronos.MareConfiguration; using MareSynchronos.MareConfiguration;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services.Mediator; using MareSynchronos.Services.Mediator;
using MareSynchronos.UI; using MareSynchronos.UI;
using MareSynchronos.UI.Components.Popup; using MareSynchronos.UI.Components.Popup;
@@ -14,32 +12,31 @@ namespace MareSynchronos.Services;
public sealed class UiService : DisposableMediatorSubscriberBase public sealed class UiService : DisposableMediatorSubscriberBase
{ {
private readonly List<WindowMediatorSubscriberBase> _createdWindows = []; private readonly List<WindowMediatorSubscriberBase> _createdWindows = [];
private readonly DalamudPluginInterface _dalamudPluginInterface; private readonly UiBuilder _uiBuilder;
private readonly FileDialogManager _fileDialogManager; private readonly FileDialogManager _fileDialogManager;
private readonly ILogger<UiService> _logger; private readonly ILogger<UiService> _logger;
private readonly MareConfigService _mareConfigService; private readonly MareConfigService _mareConfigService;
private readonly WindowSystem _windowSystem; private readonly WindowSystem _windowSystem;
private readonly Func<GroupFullInfoDto, SyncshellAdminUI> _syncshellAdminUiFactory; private readonly UiFactory _uiFactory;
public UiService(ILogger<UiService> logger, DalamudPluginInterface dalamudPluginInterface, public UiService(ILogger<UiService> logger, UiBuilder uiBuilder,
MareConfigService mareConfigService, WindowSystem windowSystem, MareConfigService mareConfigService, WindowSystem windowSystem,
IEnumerable<WindowMediatorSubscriberBase> windows, IEnumerable<WindowMediatorSubscriberBase> windows,
Func<Pair, StandaloneProfileUi> standaloneProfileUiFactory, UiFactory uiFactory, FileDialogManager fileDialogManager,
Func<GroupFullInfoDto, SyncshellAdminUI> syncshellAdminUiFactory, MareMediator mareMediator) : base(logger, mareMediator)
FileDialogManager fileDialogManager, MareMediator mareMediator) : base(logger, mareMediator)
{ {
_logger = logger; _logger = logger;
_logger.LogTrace("Creating {type}", GetType().Name); _logger.LogTrace("Creating {type}", GetType().Name);
_dalamudPluginInterface = dalamudPluginInterface; _uiBuilder = uiBuilder;
_mareConfigService = mareConfigService; _mareConfigService = mareConfigService;
_windowSystem = windowSystem; _windowSystem = windowSystem;
_syncshellAdminUiFactory = syncshellAdminUiFactory; _uiFactory = uiFactory;
_fileDialogManager = fileDialogManager; _fileDialogManager = fileDialogManager;
_dalamudPluginInterface.UiBuilder.DisableGposeUiHide = true; _uiBuilder.DisableGposeUiHide = true;
_dalamudPluginInterface.UiBuilder.Draw += Draw; _uiBuilder.Draw += Draw;
_dalamudPluginInterface.UiBuilder.OpenConfigUi += ToggleUi; _uiBuilder.OpenConfigUi += ToggleUi;
_dalamudPluginInterface.UiBuilder.OpenMainUi += ToggleMainUi; _uiBuilder.OpenMainUi += ToggleMainUi;
foreach (var window in windows) foreach (var window in windows)
{ {
@@ -51,7 +48,7 @@ public sealed class UiService : DisposableMediatorSubscriberBase
if (!_createdWindows.Exists(p => p is StandaloneProfileUi ui if (!_createdWindows.Exists(p => p is StandaloneProfileUi ui
&& string.Equals(ui.Pair.UserData.AliasOrUID, msg.Pair.UserData.AliasOrUID, StringComparison.Ordinal))) && string.Equals(ui.Pair.UserData.AliasOrUID, msg.Pair.UserData.AliasOrUID, StringComparison.Ordinal)))
{ {
var window = standaloneProfileUiFactory(msg.Pair); var window = _uiFactory.CreateStandaloneProfileUi(msg.Pair);
_createdWindows.Add(window); _createdWindows.Add(window);
_windowSystem.AddWindow(window); _windowSystem.AddWindow(window);
} }
@@ -62,7 +59,7 @@ public sealed class UiService : DisposableMediatorSubscriberBase
if (!_createdWindows.Exists(p => p is SyncshellAdminUI ui if (!_createdWindows.Exists(p => p is SyncshellAdminUI ui
&& string.Equals(ui.GroupFullInfo.GID, msg.GroupInfo.GID, StringComparison.Ordinal))) && string.Equals(ui.GroupFullInfo.GID, msg.GroupInfo.GID, StringComparison.Ordinal)))
{ {
var window = _syncshellAdminUiFactory(msg.GroupInfo); var window = _uiFactory.CreateSyncshellAdminUi(msg.GroupInfo);
_createdWindows.Add(window); _createdWindows.Add(window);
_windowSystem.AddWindow(window); _windowSystem.AddWindow(window);
} }
@@ -105,9 +102,9 @@ public sealed class UiService : DisposableMediatorSubscriberBase
window.Dispose(); window.Dispose();
} }
_dalamudPluginInterface.UiBuilder.Draw -= Draw; _uiBuilder.Draw -= Draw;
_dalamudPluginInterface.UiBuilder.OpenConfigUi -= ToggleUi; _uiBuilder.OpenConfigUi -= ToggleUi;
_dalamudPluginInterface.UiBuilder.OpenMainUi -= ToggleMainUi; _uiBuilder.OpenMainUi -= ToggleMainUi;
} }
private void Draw() private void Draw()

View File

@@ -115,21 +115,22 @@ public class CompactUi : WindowMediatorSubscriberBase
$"It is highly recommended to keep Mare Synchronos up to date. Open /xlplugins and update the plugin.", ImGuiColors.DalamudRed); $"It is highly recommended to keep Mare Synchronos up to date. Open /xlplugins and update the plugin.", ImGuiColors.DalamudRed);
} }
UiSharedService.DrawWithID("header", DrawUIDHeader); using (ImRaii.PushId("header")) DrawUIDHeader();
ImGui.Separator(); ImGui.Separator();
UiSharedService.DrawWithID("serverstatus", DrawServerStatus); using (ImRaii.PushId("serverstatus")) DrawServerStatus();
ImGui.Separator(); ImGui.Separator();
if (_apiController.ServerState is ServerState.Connected) if (_apiController.ServerState is ServerState.Connected)
{ {
UiSharedService.DrawWithID("global-topmenu", () => _tabMenu.Draw()); using (ImRaii.PushId("global-topmenu")) _tabMenu.Draw();
UiSharedService.DrawWithID("pairlist", DrawPairList); using (ImRaii.PushId("pairlist")) DrawPairs();
TransferPartHeight = ImGui.GetCursorPosY();
ImGui.Separator(); ImGui.Separator();
UiSharedService.DrawWithID("transfers", DrawTransfers); using (ImRaii.PushId("transfers")) DrawTransfers();
TransferPartHeight = ImGui.GetCursorPosY() - TransferPartHeight - ImGui.GetTextLineHeight(); TransferPartHeight = ImGui.GetCursorPosY() - TransferPartHeight - ImGui.GetTextLineHeight();
UiSharedService.DrawWithID("group-user-popup", () => _selectPairsForGroupUi.Draw(_pairManager.DirectPairs)); using (ImRaii.PushId("group-user-popup")) _selectPairsForGroupUi.Draw(_pairManager.DirectPairs);
UiSharedService.DrawWithID("grouping-popup", () => _selectGroupForPairUi.Draw()); using (ImRaii.PushId("grouping-popup")) _selectGroupForPairUi.Draw();
} }
if (_configService.Current.OpenPopupOnAdd && _pairManager.LastAddedUser != null) if (_configService.Current.OpenPopupOnAdd && _pairManager.LastAddedUser != null)
@@ -173,12 +174,6 @@ public class CompactUi : WindowMediatorSubscriberBase
} }
} }
private void DrawPairList()
{
UiSharedService.DrawWithID("pairs", DrawPairs);
TransferPartHeight = ImGui.GetCursorPosY();
}
private void DrawPairs() private void DrawPairs()
{ {
var ySize = TransferPartHeight == 0 var ySize = TransferPartHeight == 0
@@ -277,14 +272,16 @@ public class CompactUi : WindowMediatorSubscriberBase
if (_apiController.ServerState is not (ServerState.Reconnecting or ServerState.Disconnecting)) if (_apiController.ServerState is not (ServerState.Reconnecting or ServerState.Disconnecting))
{ {
ImGui.PushStyleColor(ImGuiCol.Text, color); using (ImRaii.PushColor(ImGuiCol.Text, color))
if (ImGuiComponents.IconButton(connectedIcon))
{ {
_serverManager.CurrentServer.FullPause = !_serverManager.CurrentServer.FullPause; if (ImGuiComponents.IconButton(connectedIcon))
_serverManager.Save(); {
_ = _apiController.CreateConnections(); _serverManager.CurrentServer.FullPause = !_serverManager.CurrentServer.FullPause;
_serverManager.Save();
_ = _apiController.CreateConnections();
}
} }
ImGui.PopStyleColor();
UiSharedService.AttachToolTip(!_serverManager.CurrentServer.FullPause ? "Disconnect from " + _serverManager.CurrentServer.ServerName : "Connect to " + _serverManager.CurrentServer.ServerName); UiSharedService.AttachToolTip(!_serverManager.CurrentServer.FullPause ? "Disconnect from " + _serverManager.CurrentServer.ServerName : "Connect to " + _serverManager.CurrentServer.ServerName);
} }
} }
@@ -292,9 +289,7 @@ public class CompactUi : WindowMediatorSubscriberBase
private void DrawTransfers() private void DrawTransfers()
{ {
var currentUploads = _fileTransferManager.CurrentUploads.ToList(); var currentUploads = _fileTransferManager.CurrentUploads.ToList();
ImGui.PushFont(UiBuilder.IconFont); UiSharedService.FontText(FontAwesomeIcon.Upload.ToIconString(), UiBuilder.IconFont);
ImGui.TextUnformatted(FontAwesomeIcon.Upload.ToIconString());
ImGui.PopFont();
ImGui.SameLine(35 * ImGuiHelpers.GlobalScale); ImGui.SameLine(35 * ImGuiHelpers.GlobalScale);
if (currentUploads.Any()) if (currentUploads.Any())
@@ -317,9 +312,7 @@ public class CompactUi : WindowMediatorSubscriberBase
} }
var currentDownloads = _currentDownloads.SelectMany(d => d.Value.Values).ToList(); var currentDownloads = _currentDownloads.SelectMany(d => d.Value.Values).ToList();
ImGui.PushFont(UiBuilder.IconFont); UiSharedService.FontText(FontAwesomeIcon.Download.ToIconString(), UiBuilder.IconFont);
ImGui.TextUnformatted(FontAwesomeIcon.Download.ToIconString());
ImGui.PopFont();
ImGui.SameLine(35 * ImGuiHelpers.GlobalScale); ImGui.SameLine(35 * ImGuiHelpers.GlobalScale);
if (currentDownloads.Any()) if (currentDownloads.Any())

View File

@@ -99,10 +99,7 @@ public abstract class DrawFolderBase : IDrawFolder
} }
if (ImGui.BeginPopup("User Flyout Menu")) if (ImGui.BeginPopup("User Flyout Menu"))
{ {
UiSharedService.DrawWithID($"buttons-{_id}", () => using (ImRaii.PushId($"buttons-{_id}")) DrawMenu(_menuWidth);
{
DrawMenu(_menuWidth);
});
_menuWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X; _menuWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
ImGui.EndPopup(); ImGui.EndPopup();
} }

View File

@@ -408,7 +408,7 @@ public class DrawUserPair
} }
if (ImGui.BeginPopup("User Flyout Menu")) if (ImGui.BeginPopup("User Flyout Menu"))
{ {
UiSharedService.DrawWithID($"buttons-{_pair.UserData.UID}", () => using (ImRaii.PushId($"buttons-{_pair.UserData.UID}"))
{ {
ImGui.TextUnformatted("Common Pair Functions"); ImGui.TextUnformatted("Common Pair Functions");
DrawCommonClientMenu(); DrawCommonClientMenu();
@@ -418,7 +418,7 @@ public class DrawUserPair
{ {
_menuRenderWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X; _menuRenderWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
} }
}); }
ImGui.EndPopup(); ImGui.EndPopup();
} }

View File

@@ -1,6 +1,7 @@
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Components; using Dalamud.Interface.Components;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Utility; using Dalamud.Utility;
using ImGuiNET; using ImGuiNET;
using MareSynchronos.PlayerData.Pairs; using MareSynchronos.PlayerData.Pairs;
@@ -66,7 +67,7 @@ public class SelectTagForPairUi
{ {
foreach (var tag in tags) foreach (var tag in tags)
{ {
UiSharedService.DrawWithID($"groups-pair-{_pair.UserData.UID}-{tag}", () => DrawGroupName(_pair, tag)); using (ImRaii.PushId($"groups-pair-{_pair.UserData.UID}-{tag}")) DrawGroupName(_pair, tag);
} }
ImGui.EndChild(); ImGui.EndChild();
} }

View File

@@ -95,9 +95,8 @@ public class IdDisplayHandler
{ {
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
if (textIsUid) ImGui.PushFont(UiBuilder.MonoFont); using (ImRaii.PushFont(UiBuilder.MonoFont, textIsUid)) ImGui.TextUnformatted(playerText);
ImGui.TextUnformatted(playerText);
if (textIsUid) ImGui.PopFont();
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
{ {
if (!string.Equals(_lastMouseOverUid, id)) if (!string.Equals(_lastMouseOverUid, id))

View File

@@ -1,5 +1,6 @@
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Utility; using Dalamud.Utility;
using ImGuiNET; using ImGuiNET;
using MareSynchronos.FileCache; using MareSynchronos.FileCache;
@@ -62,9 +63,7 @@ public class IntroUi : WindowMediatorSubscriberBase
if (!_configService.Current.AcceptedAgreement && !_readFirstPage) if (!_configService.Current.AcceptedAgreement && !_readFirstPage)
{ {
if (_uiShared.UidFontBuilt) ImGui.PushFont(_uiShared.UidFont); _uiShared.BigText("Welcome to Mare Synchronos");
ImGui.TextUnformatted("Welcome to Mare Synchronos");
if (_uiShared.UidFontBuilt) ImGui.PopFont();
ImGui.Separator(); ImGui.Separator();
UiSharedService.TextWrapped("Mare Synchronos is a plugin that will replicate your full current character state including all Penumbra mods to other paired Mare Synchronos users. " + UiSharedService.TextWrapped("Mare Synchronos is a plugin that will replicate your full current character state including all Penumbra mods to other paired Mare Synchronos users. " +
"Note that you will have to have Penumbra as well as Glamourer installed to use this plugin."); "Note that you will have to have Penumbra as well as Glamourer installed to use this plugin.");

View File

@@ -2,6 +2,7 @@
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET; using ImGuiNET;
using MareSynchronos.API.Data.Extensions; using MareSynchronos.API.Data.Extensions;
using MareSynchronos.MareConfiguration; using MareSynchronos.MareConfiguration;
@@ -110,9 +111,9 @@ public class PopoutProfileUi : WindowMediatorSubscriberBase
var rectMin = drawList.GetClipRectMin(); var rectMin = drawList.GetClipRectMin();
var rectMax = drawList.GetClipRectMax(); var rectMax = drawList.GetClipRectMax();
if (_uiSharedService.UidFontBuilt) ImGui.PushFont(_uiSharedService.UidFont); using (ImRaii.PushFont(_uiSharedService.UidFont, _uiSharedService.UidFontBuilt))
UiSharedService.ColorText(_pair.UserData.AliasOrUID, ImGuiColors.HealerGreen); UiSharedService.ColorText(_pair.UserData.AliasOrUID, ImGuiColors.HealerGreen);
if (_uiSharedService.UidFontBuilt) ImGui.PopFont();
ImGui.Dummy(new(spacing.Y, spacing.Y)); ImGui.Dummy(new(spacing.Y, spacing.Y));
var textPos = ImGui.GetCursorPosY(); var textPos = ImGui.GetCursorPosY();
ImGui.Separator(); ImGui.Separator();

View File

@@ -20,6 +20,7 @@ using MareSynchronos.WebAPI.Files.Models;
using MareSynchronos.WebAPI.SignalR.Utils; using MareSynchronos.WebAPI.SignalR.Utils;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Globalization;
using System.Numerics; using System.Numerics;
using System.Text.Json; using System.Text.Json;
@@ -249,14 +250,14 @@ public class SettingsUi : WindowMediatorSubscriberBase
foreach (var transfer in _fileTransferManager.CurrentUploads.ToArray()) foreach (var transfer in _fileTransferManager.CurrentUploads.ToArray())
{ {
var color = UiSharedService.UploadColor((transfer.Transferred, transfer.Total)); var color = UiSharedService.UploadColor((transfer.Transferred, transfer.Total));
ImGui.PushStyleColor(ImGuiCol.Text, color); var col = ImRaii.PushColor(ImGuiCol.Text, color);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TextUnformatted(transfer.Hash); ImGui.TextUnformatted(transfer.Hash);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TextUnformatted(UiSharedService.ByteToString(transfer.Transferred)); ImGui.TextUnformatted(UiSharedService.ByteToString(transfer.Transferred));
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TextUnformatted(UiSharedService.ByteToString(transfer.Total)); ImGui.TextUnformatted(UiSharedService.ByteToString(transfer.Total));
ImGui.PopStyleColor(); col.Dispose();
ImGui.TableNextRow(); ImGui.TableNextRow();
} }
@@ -282,13 +283,13 @@ public class SettingsUi : WindowMediatorSubscriberBase
ImGui.TextUnformatted(userName); ImGui.TextUnformatted(userName);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TextUnformatted(entry.Key); ImGui.TextUnformatted(entry.Key);
ImGui.PushStyleColor(ImGuiCol.Text, color); var col = ImRaii.PushColor(ImGuiCol.Text, color);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TextUnformatted(entry.Value.TransferredFiles + "/" + entry.Value.TotalFiles); ImGui.TextUnformatted(entry.Value.TransferredFiles + "/" + entry.Value.TotalFiles);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TextUnformatted(UiSharedService.ByteToString(entry.Value.TransferredBytes) + "/" + UiSharedService.ByteToString(entry.Value.TotalBytes)); ImGui.TextUnformatted(UiSharedService.ByteToString(entry.Value.TransferredBytes) + "/" + UiSharedService.ByteToString(entry.Value.TotalBytes));
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.PopStyleColor(); col.Dispose();
ImGui.TableNextRow(); ImGui.TableNextRow();
} }
} }
@@ -352,7 +353,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
} }
UiSharedService.DrawHelpText("Enabling this can incur a (slight) performance impact. Enabling this for extended periods of time is not recommended."); UiSharedService.DrawHelpText("Enabling this can incur a (slight) performance impact. Enabling this for extended periods of time is not recommended.");
if (!logPerformance) ImGui.BeginDisabled(); using var disabled = ImRaii.Disabled(!logPerformance);
if (UiSharedService.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog")) if (UiSharedService.IconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog"))
{ {
_performanceCollector.PrintPerformanceStats(); _performanceCollector.PrintPerformanceStats();
@@ -362,7 +363,6 @@ public class SettingsUi : WindowMediatorSubscriberBase
{ {
_performanceCollector.PrintPerformanceStats(60); _performanceCollector.PrintPerformanceStats(60);
} }
if (!logPerformance) ImGui.EndDisabled();
} }
private void DrawFileStorageSettings() private void DrawFileStorageSettings()
@@ -763,7 +763,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
} }
UiSharedService.DrawHelpText("Enabling this will show a small notification (type: Info) in the bottom right corner when pairs go online."); UiSharedService.DrawHelpText("Enabling this will show a small notification (type: Info) in the bottom right corner when pairs go online.");
if (!onlineNotifs) ImGui.BeginDisabled(); using var disabled = ImRaii.Disabled(!onlineNotifs);
if (ImGui.Checkbox("Notify only for individual pairs", ref onlineNotifsPairsOnly)) if (ImGui.Checkbox("Notify only for individual pairs", ref onlineNotifsPairsOnly))
{ {
_configService.Current.ShowOnlineNotificationsOnlyForIndividualPairs = onlineNotifsPairsOnly; _configService.Current.ShowOnlineNotificationsOnlyForIndividualPairs = onlineNotifsPairsOnly;
@@ -776,7 +776,6 @@ public class SettingsUi : WindowMediatorSubscriberBase
_configService.Save(); _configService.Save();
} }
UiSharedService.DrawHelpText("Enabling this will only show online notifications (type: Info) for pairs where you have set an individual note."); UiSharedService.DrawHelpText("Enabling this will only show online notifications (type: Info) for pairs where you have set an individual note.");
if (!onlineNotifs) ImGui.EndDisabled();
} }
private void DrawServerConfiguration() private void DrawServerConfiguration()
@@ -885,59 +884,58 @@ public class SettingsUi : WindowMediatorSubscriberBase
int i = 0; int i = 0;
foreach (var item in selectedServer.Authentications.ToList()) foreach (var item in selectedServer.Authentications.ToList())
{ {
UiSharedService.DrawWithID("selectedChara" + i, () => using var charaId = ImRaii.PushId("selectedChara" + i);
var worldIdx = (ushort)item.WorldId;
var data = _uiShared.WorldData.OrderBy(u => u.Value, StringComparer.Ordinal).ToDictionary(k => k.Key, k => k.Value);
if (!data.TryGetValue(worldIdx, out string? worldPreview))
{ {
var worldIdx = (ushort)item.WorldId; worldPreview = data.First().Value;
var data = _uiShared.WorldData.OrderBy(u => u.Value, StringComparer.Ordinal).ToDictionary(k => k.Key, k => k.Value); }
if (!data.TryGetValue(worldIdx, out string? worldPreview))
var secretKeyIdx = item.SecretKeyIdx;
var keys = selectedServer.SecretKeys;
if (!keys.TryGetValue(secretKeyIdx, out var secretKey))
{
secretKey = new();
}
var friendlyName = secretKey.FriendlyName;
if (ImGui.TreeNode($"chara", $"Character: {item.CharacterName}, World: {worldPreview}, Secret Key: {friendlyName}"))
{
var charaName = item.CharacterName;
if (ImGui.InputText("Character Name", ref charaName, 64))
{ {
worldPreview = data.First().Value; item.CharacterName = charaName;
_serverConfigurationManager.Save();
} }
var secretKeyIdx = item.SecretKeyIdx; _uiShared.DrawCombo("World##" + item.CharacterName + i, data, (w) => w.Value,
var keys = selectedServer.SecretKeys; (w) =>
if (!keys.TryGetValue(secretKeyIdx, out var secretKey))
{
secretKey = new();
}
var friendlyName = secretKey.FriendlyName;
if (ImGui.TreeNode($"chara", $"Character: {item.CharacterName}, World: {worldPreview}, Secret Key: {friendlyName}"))
{
var charaName = item.CharacterName;
if (ImGui.InputText("Character Name", ref charaName, 64))
{ {
item.CharacterName = charaName; if (item.WorldId != w.Key)
_serverConfigurationManager.Save();
}
_uiShared.DrawCombo("World##" + item.CharacterName + i, data, (w) => w.Value,
(w) =>
{ {
if (item.WorldId != w.Key) item.WorldId = w.Key;
{ _serverConfigurationManager.Save();
item.WorldId = w.Key; }
_serverConfigurationManager.Save(); }, EqualityComparer<KeyValuePair<ushort, string>>.Default.Equals(data.FirstOrDefault(f => f.Key == worldIdx), default) ? data.First() : data.First(f => f.Key == worldIdx));
}
}, EqualityComparer<KeyValuePair<ushort, string>>.Default.Equals(data.FirstOrDefault(f => f.Key == worldIdx), default) ? data.First() : data.First(f => f.Key == worldIdx));
_uiShared.DrawCombo("Secret Key##" + item.CharacterName + i, keys, (w) => w.Value.FriendlyName, _uiShared.DrawCombo("Secret Key##" + item.CharacterName + i, keys, (w) => w.Value.FriendlyName,
(w) => (w) =>
{
if (w.Key != item.SecretKeyIdx)
{ {
if (w.Key != item.SecretKeyIdx) item.SecretKeyIdx = w.Key;
{ _serverConfigurationManager.Save();
item.SecretKeyIdx = w.Key; }
_serverConfigurationManager.Save(); }, EqualityComparer<KeyValuePair<int, SecretKey>>.Default.Equals(keys.FirstOrDefault(f => f.Key == item.SecretKeyIdx), default) ? keys.First() : keys.First(f => f.Key == item.SecretKeyIdx));
}
}, EqualityComparer<KeyValuePair<int, SecretKey>>.Default.Equals(keys.FirstOrDefault(f => f.Key == item.SecretKeyIdx), default) ? keys.First() : keys.First(f => f.Key == item.SecretKeyIdx));
if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Character") && UiSharedService.CtrlPressed()) if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Character") && UiSharedService.CtrlPressed())
_serverConfigurationManager.RemoveCharacterFromServer(idx, item); _serverConfigurationManager.RemoveCharacterFromServer(idx, item);
UiSharedService.AttachToolTip("Hold CTRL to delete this entry."); UiSharedService.AttachToolTip("Hold CTRL to delete this entry.");
ImGui.TreePop(); ImGui.TreePop();
} }
});
i++; i++;
} }
@@ -970,34 +968,32 @@ public class SettingsUi : WindowMediatorSubscriberBase
{ {
foreach (var item in selectedServer.SecretKeys.ToList()) foreach (var item in selectedServer.SecretKeys.ToList())
{ {
UiSharedService.DrawWithID("key" + item.Key, () => using var id = ImRaii.PushId("key" + item.Key);
var friendlyName = item.Value.FriendlyName;
if (ImGui.InputText("Secret Key Display Name", ref friendlyName, 255))
{ {
var friendlyName = item.Value.FriendlyName; item.Value.FriendlyName = friendlyName;
if (ImGui.InputText("Secret Key Display Name", ref friendlyName, 255)) _serverConfigurationManager.Save();
}
var key = item.Value.Key;
if (ImGui.InputText("Secret Key", ref key, 64))
{
item.Value.Key = key;
_serverConfigurationManager.Save();
}
if (!selectedServer.Authentications.Exists(p => p.SecretKeyIdx == item.Key))
{
if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Secret Key") && UiSharedService.CtrlPressed())
{ {
item.Value.FriendlyName = friendlyName; selectedServer.SecretKeys.Remove(item.Key);
_serverConfigurationManager.Save(); _serverConfigurationManager.Save();
} }
var key = item.Value.Key; UiSharedService.AttachToolTip("Hold CTRL to delete this secret key entry");
if (ImGui.InputText("Secret Key", ref key, 64)) }
{ else
item.Value.Key = key; {
_serverConfigurationManager.Save(); UiSharedService.ColorTextWrapped("This key is in use and cannot be deleted", ImGuiColors.DalamudYellow);
} }
if (!selectedServer.Authentications.Exists(p => p.SecretKeyIdx == item.Key))
{
if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Secret Key") && UiSharedService.CtrlPressed())
{
selectedServer.SecretKeys.Remove(item.Key);
_serverConfigurationManager.Save();
}
UiSharedService.AttachToolTip("Hold CTRL to delete this secret key entry");
}
else
{
UiSharedService.ColorTextWrapped("This key is in use and cannot be deleted", ImGuiColors.DalamudYellow);
}
});
if (item.Key != selectedServer.SecretKeys.Keys.LastOrDefault()) if (item.Key != selectedServer.SecretKeys.Keys.LastOrDefault())
ImGui.Separator(); ImGui.Separator();
@@ -1136,7 +1132,21 @@ public class SettingsUi : WindowMediatorSubscriberBase
private void DrawSettingsContent() private void DrawSettingsContent()
{ {
_uiShared.PrintServerState(); if (_apiController.ServerState is ServerState.Connected)
{
ImGui.TextUnformatted("Service " + _serverConfigurationManager.CurrentServer!.ServerName + ":");
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.ParsedGreen, "Available");
ImGui.SameLine();
ImGui.TextUnformatted("(");
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.ParsedGreen, _apiController.OnlineUsers.ToString(CultureInfo.InvariantCulture));
ImGui.SameLine();
ImGui.TextUnformatted("Users Online");
ImGui.SameLine();
ImGui.TextUnformatted(")");
}
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted("Community and Support:"); ImGui.TextUnformatted("Community and Support:");
ImGui.SameLine(); ImGui.SameLine();

View File

@@ -2,6 +2,7 @@
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET; using ImGuiNET;
using MareSynchronos.API.Data.Extensions; using MareSynchronos.API.Data.Extensions;
using MareSynchronos.PlayerData.Pairs; using MareSynchronos.PlayerData.Pairs;
@@ -76,9 +77,9 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
var rectMax = drawList.GetClipRectMax(); var rectMax = drawList.GetClipRectMax();
var headerSize = ImGui.GetCursorPosY() - ImGui.GetStyle().WindowPadding.Y; var headerSize = ImGui.GetCursorPosY() - ImGui.GetStyle().WindowPadding.Y;
if (_uiSharedService.UidFontBuilt) ImGui.PushFont(_uiSharedService.UidFont); using (ImRaii.PushFont(_uiSharedService.UidFont, _uiSharedService.UidFontBuilt))
UiSharedService.ColorText(Pair.UserData.AliasOrUID, ImGuiColors.HealerGreen); UiSharedService.ColorText(Pair.UserData.AliasOrUID, ImGuiColors.HealerGreen);
if (_uiSharedService.UidFontBuilt) ImGui.PopFont();
ImGuiHelpers.ScaledDummy(new Vector2(spacing.Y, spacing.Y)); ImGuiHelpers.ScaledDummy(new Vector2(spacing.Y, spacing.Y));
var textPos = ImGui.GetCursorPosY() - headerSize; var textPos = ImGui.GetCursorPosY() - headerSize;
ImGui.Separator(); ImGui.Separator();

View File

@@ -24,7 +24,8 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
private int _multiInvites; private int _multiInvites;
private string _newPassword; private string _newPassword;
private bool _pwChangeSuccess; private bool _pwChangeSuccess;
public SyncshellAdminUI(ILogger<SyncshellAdminUI> logger, MareMediator mediator, GroupFullInfoDto groupFullInfo, ApiController apiController, UiSharedService uiSharedService, PairManager pairManager) public SyncshellAdminUI(ILogger<SyncshellAdminUI> logger, MareMediator mediator, ApiController apiController,
UiSharedService uiSharedService, PairManager pairManager, GroupFullInfoDto groupFullInfo)
: base(logger, mediator, "Syncshell Admin Panel (" + groupFullInfo.GID + ")") : base(logger, mediator, "Syncshell Admin Panel (" + groupFullInfo.GID + ")")
{ {
GroupFullInfo = groupFullInfo; GroupFullInfo = groupFullInfo;

View File

@@ -207,16 +207,14 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public static void ColorText(string text, Vector4 color) public static void ColorText(string text, Vector4 color)
{ {
ImGui.PushStyleColor(ImGuiCol.Text, color); using var raiicolor = ImRaii.PushColor(ImGuiCol.Text, color);
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
ImGui.PopStyleColor();
} }
public static void ColorTextWrapped(string text, Vector4 color) public static void ColorTextWrapped(string text, Vector4 color)
{ {
ImGui.PushStyleColor(ImGuiCol.Text, color); using var raiicolor = ImRaii.PushColor(ImGuiCol.Text, color);
TextWrapped(text); TextWrapped(text);
ImGui.PopStyleColor();
} }
public static bool CtrlPressed() => (GetKeyState(0xA2) & 0x8000) != 0 || (GetKeyState(0xA3) & 0x8000) != 0; public static bool CtrlPressed() => (GetKeyState(0xA2) & 0x8000) != 0 || (GetKeyState(0xA3) & 0x8000) != 0;
@@ -224,18 +222,19 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public static void DrawHelpText(string helpText) public static void DrawHelpText(string helpText)
{ {
ImGui.SameLine(); ImGui.SameLine();
ImGui.PushFont(UiBuilder.IconFont); using (ImRaii.PushFont(UiBuilder.IconFont))
ImGui.SetWindowFontScale(0.8f); {
ImGui.TextDisabled(FontAwesomeIcon.Question.ToIconString()); ImGui.SetWindowFontScale(0.8f);
ImGui.SetWindowFontScale(1.0f); ImGui.TextDisabled(FontAwesomeIcon.Question.ToIconString());
ImGui.PopFont(); ImGui.SetWindowFontScale(1.0f);
}
if (ImGui.IsItemHovered()) if (ImGui.IsItemHovered())
{ {
ImGui.BeginTooltip(); using var tooltip = ImRaii.Tooltip();
ImGui.PushTextWrapPos(ImGui.GetFontSize() * 35.0f); ImGui.PushTextWrapPos(ImGui.GetFontSize() * 35.0f);
ImGui.TextUnformatted(helpText); ImGui.TextUnformatted(helpText);
ImGui.PopTextWrapPos(); ImGui.PopTextWrapPos();
ImGui.EndTooltip();
} }
} }
@@ -243,31 +242,34 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
{ {
var original = ImGui.GetCursorPos(); var original = ImGui.GetCursorPos();
ImGui.PushStyleColor(ImGuiCol.Text, outlineColor); using (ImRaii.PushColor(ImGuiCol.Text, outlineColor))
ImGui.SetCursorPos(original with { Y = original.Y - thickness }); {
ImGui.TextUnformatted(text); ImGui.PushStyleColor(ImGuiCol.Text, outlineColor);
ImGui.SetCursorPos(original with { X = original.X - thickness }); ImGui.SetCursorPos(original with { Y = original.Y - thickness });
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { Y = original.Y + thickness }); ImGui.SetCursorPos(original with { X = original.X - thickness });
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X + thickness }); ImGui.SetCursorPos(original with { Y = original.Y + thickness });
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X - thickness, Y = original.Y - thickness }); ImGui.SetCursorPos(original with { X = original.X + thickness });
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X + thickness, Y = original.Y + thickness }); ImGui.SetCursorPos(original with { X = original.X - thickness, Y = original.Y - thickness });
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X - thickness, Y = original.Y + thickness }); ImGui.SetCursorPos(original with { X = original.X + thickness, Y = original.Y + thickness });
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
ImGui.SetCursorPos(original with { X = original.X + thickness, Y = original.Y - thickness }); ImGui.SetCursorPos(original with { X = original.X - thickness, Y = original.Y + thickness });
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
ImGui.PopStyleColor(); ImGui.SetCursorPos(original with { X = original.X + thickness, Y = original.Y - thickness });
ImGui.TextUnformatted(text);
}
ImGui.PushStyleColor(ImGuiCol.Text, fontColor); using (ImRaii.PushColor(ImGuiCol.Text, fontColor))
ImGui.SetCursorPos(original); {
ImGui.TextUnformatted(text); ImGui.SetCursorPos(original);
ImGui.SetCursorPos(original); ImGui.TextUnformatted(text);
ImGui.TextUnformatted(text); ImGui.SetCursorPos(original);
ImGui.PopStyleColor(); ImGui.TextUnformatted(text);
}
} }
public static void DrawOutlinedFont(ImDrawListPtr drawList, string text, Vector2 textPos, uint fontColor, uint outlineColor, int thickness) public static void DrawOutlinedFont(ImDrawListPtr drawList, string text, Vector2 textPos, uint fontColor, uint outlineColor, int thickness)
@@ -293,13 +295,6 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
drawList.AddText(textPos, fontColor, text); drawList.AddText(textPos, fontColor, text);
} }
public static void DrawWithID(string id, Action drawSubSection)
{
ImGui.PushID(id);
drawSubSection.Invoke();
ImGui.PopID();
}
public static void FontText(string text, ImFontPtr font, Vector4? color = null) public static void FontText(string text, ImFontPtr font, Vector4? color = null)
{ {
using var pushedFont = ImRaii.PushFont(font); using var pushedFont = ImRaii.PushFont(font);
@@ -309,22 +304,17 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public static Vector4 GetBoolColor(bool input) => input ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed; public static Vector4 GetBoolColor(bool input) => input ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed;
public static Vector4 GetCpuLoadColor(double input) => input < 50 ? ImGuiColors.ParsedGreen :
input < 90 ? ImGuiColors.DalamudYellow : ImGuiColors.DalamudRed;
public static Vector2 GetIconButtonSize(FontAwesomeIcon icon) public static Vector2 GetIconButtonSize(FontAwesomeIcon icon)
{ {
ImGui.PushFont(UiBuilder.IconFont); using var font = ImRaii.PushFont(UiBuilder.IconFont);
var buttonSize = ImGuiHelpers.GetButtonSize(icon.ToIconString()); var buttonSize = ImGuiHelpers.GetButtonSize(icon.ToIconString());
ImGui.PopFont();
return buttonSize; return buttonSize;
} }
public static Vector2 GetIconSize(FontAwesomeIcon icon) public static Vector2 GetIconSize(FontAwesomeIcon icon)
{ {
ImGui.PushFont(UiBuilder.IconFont); using var font = ImRaii.PushFont(UiBuilder.IconFont);
var iconSize = ImGui.CalcTextSize(icon.ToIconString()); var iconSize = ImGui.CalcTextSize(icon.ToIconString());
ImGui.PopFont();
return iconSize; return iconSize;
} }
@@ -449,23 +439,6 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
} }
} }
public static void OutlineTextWrapped(string text, Vector4 textcolor, Vector4 outlineColor, float dist = 3)
{
var cursorPos = ImGui.GetCursorPos();
ColorTextWrapped(text, outlineColor);
ImGui.SetCursorPos(new(cursorPos.X, cursorPos.Y + dist));
ColorTextWrapped(text, outlineColor);
ImGui.SetCursorPos(new(cursorPos.X + dist, cursorPos.Y));
ColorTextWrapped(text, outlineColor);
ImGui.SetCursorPos(new(cursorPos.X + dist, cursorPos.Y + dist));
ColorTextWrapped(text, outlineColor);
ImGui.SetCursorPos(new(cursorPos.X + dist / 2, cursorPos.Y + dist / 2));
ColorTextWrapped(text, textcolor);
ImGui.SetCursorPos(new(cursorPos.X + dist / 2, cursorPos.Y + dist / 2));
ColorTextWrapped(text, textcolor);
}
public static void SetScaledWindowSize(float width, bool centerWindow = true) public static void SetScaledWindowSize(float width, bool centerWindow = true)
{ {
var newLineHeight = ImGui.GetCursorPosY(); var newLineHeight = ImGui.GetCursorPosY();
@@ -537,9 +510,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public void BigText(string text) public void BigText(string text)
{ {
if (UidFontBuilt) ImGui.PushFont(UidFont); using var font = ImRaii.PushFont(UidFont, UidFontBuilt);
ImGui.TextUnformatted(text); ImGui.TextUnformatted(text);
if (UidFontBuilt) ImGui.PopFont();
} }
public void DrawCacheDirectorySetting() public void DrawCacheDirectorySetting()
@@ -854,24 +826,6 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
Strings.ToS = new Strings.ToSStrings(); Strings.ToS = new Strings.ToSStrings();
} }
public void PrintServerState()
{
if (_apiController.ServerState is ServerState.Connected)
{
ImGui.TextUnformatted("Service " + _serverConfigurationManager.CurrentServer!.ServerName + ":");
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.ParsedGreen, "Available");
ImGui.SameLine();
ImGui.TextUnformatted("(");
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.ParsedGreen, _apiController.OnlineUsers.ToString(CultureInfo.InvariantCulture));
ImGui.SameLine();
ImGui.TextUnformatted("Users Online");
ImGui.SameLine();
ImGui.TextUnformatted(")");
}
}
public void RecalculateFileCacheSize() public void RecalculateFileCacheSize()
{ {
_cacheScanner.InvokeScan(forced: true); _cacheScanner.InvokeScan(forced: true);
@@ -903,7 +857,9 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
ImGui.SetWindowPos(new Vector2(center.X - width / 2, center.Y - height / 2), cond); ImGui.SetWindowPos(new Vector2(center.X - width / 2, center.Y - height / 2), cond);
} }
#pragma warning disable MA0009 // Add regex evaluation timeout
[GeneratedRegex(@"^(?:[a-zA-Z]:\\[\w\s\-\\]+?|\/(?:[\w\s\-\/])+?)$", RegexOptions.ECMAScript)] [GeneratedRegex(@"^(?:[a-zA-Z]:\\[\w\s\-\\]+?|\/(?:[\w\s\-\/])+?)$", RegexOptions.ECMAScript)]
#pragma warning restore MA0009 // Add regex evaluation timeout
private static partial Regex PathRegex(); private static partial Regex PathRegex();
private void BuildFont() private void BuildFont()

View File

@@ -16,21 +16,19 @@ namespace MareSynchronos.WebAPI.SignalR;
public class HubFactory : MediatorSubscriberBase public class HubFactory : MediatorSubscriberBase
{ {
private readonly MareConfigService _configService; private readonly ILoggerProvider _loggingProvider;
private readonly IPluginLog _pluginLog;
private readonly ServerConfigurationManager _serverConfigurationManager; private readonly ServerConfigurationManager _serverConfigurationManager;
private readonly TokenProvider _tokenProvider; private readonly TokenProvider _tokenProvider;
private HubConnection? _instance; private HubConnection? _instance;
private bool _isDisposed = false; private bool _isDisposed = false;
public HubFactory(ILogger<HubFactory> logger, MareMediator mediator, public HubFactory(ILogger<HubFactory> logger, MareMediator mediator,
ServerConfigurationManager serverConfigurationManager, MareConfigService configService, ServerConfigurationManager serverConfigurationManager,
TokenProvider tokenProvider, IPluginLog pluginLog) : base(logger, mediator) TokenProvider tokenProvider, ILoggerProvider pluginLog) : base(logger, mediator)
{ {
_serverConfigurationManager = serverConfigurationManager; _serverConfigurationManager = serverConfigurationManager;
_configService = configService;
_tokenProvider = tokenProvider; _tokenProvider = tokenProvider;
_pluginLog = pluginLog; _loggingProvider = pluginLog;
} }
public async Task DisposeHubAsync() public async Task DisposeHubAsync()
@@ -92,7 +90,7 @@ public class HubFactory : MediatorSubscriberBase
.WithAutomaticReconnect(new ForeverRetryPolicy(Mediator)) .WithAutomaticReconnect(new ForeverRetryPolicy(Mediator))
.ConfigureLogging(a => .ConfigureLogging(a =>
{ {
a.ClearProviders().AddProvider(new DalamudLoggingProvider(_configService, _pluginLog)); a.ClearProviders().AddProvider(_loggingProvider);
a.SetMinimumLevel(LogLevel.Information); a.SetMinimumLevel(LogLevel.Information);
}) })
.Build(); .Build();