some profile ui rework

This commit is contained in:
rootdarkarchon
2023-03-22 17:14:05 +01:00
parent 814b24ebd8
commit 38d83eff77
17 changed files with 582 additions and 210 deletions

View File

@@ -21,6 +21,7 @@ public class MareConfig : IMareConfiguration
public bool OpenPopupOnAdd { get; set; } = true;
public int ParallelDownloads { get; set; } = 10;
public float ProfileDelay { get; set; } = 2;
public bool ProfilePopoutRight { get; set; } = true;
public bool ProfilesAllowNsfw { get; set; } = false;
public bool ProfilesShow { get; set; } = true;
public bool ReverseUserSort { get; set; } = false;

View File

@@ -57,15 +57,16 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
Mods = 4
}
public string? PlayerName { get; private set; }
public string PlayerNameHash => OnlineUser.Ident;
private OnlineUserIdentDto OnlineUser { get; set; }
public IntPtr PlayerCharacter => _charaHandler?.Address ?? IntPtr.Zero;
public unsafe uint PlayerCharacterId => (_charaHandler?.Address ?? IntPtr.Zero) == IntPtr.Zero
? uint.MaxValue
: ((GameObject*)_charaHandler.Address)->ObjectID;
public string? PlayerName { get; private set; }
public string PlayerNameHash => OnlineUser.Ident;
private OnlineUserIdentDto OnlineUser { get; set; }
public void ApplyCharacterData(CharacterData characterData, OptionalPluginWarning warning, bool forced = false)
{
SetUploading(false);
@@ -339,21 +340,21 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
}
bool heelsOffsetDifferent = oldData.HeelsOffset != newData.HeelsOffset;
if (heelsOffsetDifferent || forced)
if (heelsOffsetDifferent || (forced && newData.HeelsOffset != 0))
{
Logger.LogDebug("Updating {object}/{kind} (Diff heels data) => {change}", this, objectKind, PlayerChanges.Heels);
charaDataToUpdate[objectKind].Add(PlayerChanges.Heels);
}
bool customizeDataDifferent = !string.Equals(oldData.CustomizePlusData, newData.CustomizePlusData, StringComparison.Ordinal);
if (customizeDataDifferent || forced)
if (customizeDataDifferent || (forced && !string.IsNullOrEmpty(newData.CustomizePlusData)))
{
Logger.LogDebug("Updating {object}/{kind} (Diff customize data) => {change}", this, objectKind, PlayerChanges.Customize);
charaDataToUpdate[objectKind].Add(PlayerChanges.Customize);
}
bool palettePlusDataDifferent = !string.Equals(oldData.PalettePlusData, newData.PalettePlusData, StringComparison.Ordinal);
if (palettePlusDataDifferent || forced)
if (palettePlusDataDifferent || (forced && !string.IsNullOrEmpty(newData.PalettePlusData)))
{
Logger.LogDebug("Updating {object}/{kind} (Diff palette data) => {change}", this, objectKind, PlayerChanges.Palette);
charaDataToUpdate[objectKind].Add(PlayerChanges.Palette);

View File

@@ -1,5 +1,4 @@
using Dalamud.ContextMenu;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Utility;
using MareSynchronos.API.Data;
using MareSynchronos.API.Data.Comparer;
@@ -7,6 +6,7 @@ using MareSynchronos.API.Data.Extensions;
using MareSynchronos.API.Dto.Group;
using MareSynchronos.API.Dto.User;
using MareSynchronos.MareConfiguration;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using MareSynchronos.Utils;
using Microsoft.Extensions.Logging;
@@ -18,14 +18,17 @@ public class Pair
private readonly Func<OnlineUserIdentDto, CachedPlayer> _cachedPlayerFactory;
private readonly MareConfigService _configService;
private readonly ILogger<Pair> _logger;
private readonly MareMediator _mediator;
private readonly ServerConfigurationManager _serverConfigurationManager;
private OnlineUserIdentDto? _onlineUserIdentDto = null;
private OptionalPluginWarning? _pluginWarnings;
public Pair(ILogger<Pair> logger, Func<OnlineUserIdentDto, CachedPlayer> cachedPlayerFactory, MareConfigService configService, ServerConfigurationManager serverConfigurationManager)
public Pair(ILogger<Pair> logger, Func<OnlineUserIdentDto, CachedPlayer> cachedPlayerFactory,
MareMediator mediator, MareConfigService configService, ServerConfigurationManager serverConfigurationManager)
{
_logger = logger;
_cachedPlayerFactory = cachedPlayerFactory;
_mediator = mediator;
_configService = configService;
_serverConfigurationManager = serverConfigurationManager;
}
@@ -46,6 +49,30 @@ public class Pair
public UserPairDto? UserPair { get; set; }
private CachedPlayer? CachedPlayer { get; set; }
public void AddContextMenu(GameObjectContextMenuOpenArgs args)
{
if (CachedPlayer == null || args.ObjectId != CachedPlayer.PlayerCharacterId) return;
if (!IsPaused)
{
args.AddCustomItem(new GameObjectContextMenuItem("[Mare] Open Profile", (a) =>
{
_mediator.Publish(new ProfileOpenStandaloneMessage(this));
}));
}
args.AddCustomItem(new GameObjectContextMenuItem("[Mare] Reapply last data", (a) =>
{
ApplyLastReceivedData(true);
}, false));
if (UserPair != null && UserPair.OtherPermissions.IsPaired() && UserPair.OwnPermissions.IsPaired())
{
args.AddCustomItem(new GameObjectContextMenuItem("[Mare] Cycle pause state", (a) =>
{
_mediator.Publish(new CyclePauseMessage(UserData));
}, false));
}
}
public void ApplyData(OnlineUserCharaDataDto data)
{
if (CachedPlayer == null) throw new InvalidOperationException("CachedPlayer not initialized");
@@ -172,14 +199,4 @@ public class Pair
return data;
}
public void AddContextMenu(GameObjectContextMenuOpenArgs args)
{
if (CachedPlayer == null || args.ObjectId != CachedPlayer.PlayerCharacterId) return;
args.AddCustomItem(new GameObjectContextMenuItem("Reapply last data", (a) =>
{
ApplyLastReceivedData(true);
} ,true));
}
}

View File

@@ -69,10 +69,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton<FileTransferOrchestrator>();
collection.AddSingleton<MarePlugin>();
collection.AddSingleton<MareProfileManager>();
collection.AddSingleton<UidDisplayHandler>((s) => new UidDisplayHandler(s.GetRequiredService<ILogger<UidDisplayHandler>>(), pluginInterface.UiBuilder,
s.GetRequiredService<MareProfileManager>(),
s.GetRequiredService<UiSharedService>(), s.GetRequiredService<PairManager>(),
s.GetRequiredService<ServerConfigurationManager>(), s.GetRequiredService<MareConfigService>()));
collection.AddSingleton<UidDisplayHandler>();
collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService<ILogger<DalamudUtilService>>(),
clientState, objectTable, framework, gameGui, condition, gameData,
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PerformanceCollectorService>()));
@@ -109,6 +106,7 @@ public sealed class Plugin : IDalamudPlugin
new Func<Pair>(()
=> new Pair(s.GetRequiredService<ILogger<Pair>>(),
s.GetRequiredService<Func<OnlineUserIdentDto, CachedPlayer>>(),
s.GetRequiredService<MareMediator>(),
s.GetRequiredService<MareConfigService>(),
s.GetRequiredService<ServerConfigurationManager>())));
collection.AddSingleton(s =>
@@ -117,6 +115,13 @@ public sealed class Plugin : IDalamudPlugin
s.GetRequiredService<MareMediator>(),
s.GetRequiredService<FileTransferOrchestrator>(),
s.GetRequiredService<FileCacheManager>())));
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>(), pair)));
// add scoped services
collection.AddScoped<PeriodicFileScanner>();
@@ -125,6 +130,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddScoped<WindowMediatorSubscriberBase, GposeUi>();
collection.AddScoped<WindowMediatorSubscriberBase, IntroUi>();
collection.AddScoped<WindowMediatorSubscriberBase, DownloadUi>();
collection.AddScoped<WindowMediatorSubscriberBase, PopoutProfileUi>();
collection.AddScoped<WindowMediatorSubscriberBase, EditProfileUi>((s) => new EditProfileUi(s.GetRequiredService<ILogger<EditProfileUi>>(),
s.GetRequiredService<MareMediator>(), s.GetRequiredService<ApiController>(), pluginInterface.UiBuilder, s.GetRequiredService<UiSharedService>(),
s.GetRequiredService<FileDialogManager>(), s.GetRequiredService<MareProfileManager>()));
@@ -133,7 +139,8 @@ public sealed class Plugin : IDalamudPlugin
collection.AddScoped<PlayerDataFactory>();
collection.AddScoped<OnlinePlayerManager>();
collection.AddScoped((s) => new UiService(s.GetRequiredService<ILogger<UiService>>(), pluginInterface, s.GetRequiredService<MareConfigService>(),
s.GetRequiredService<WindowSystem>(), s.GetServices<WindowMediatorSubscriberBase>(), s.GetRequiredService<FileDialogManager>(), s.GetRequiredService<MareMediator>()));
s.GetRequiredService<WindowSystem>(), s.GetServices<WindowMediatorSubscriberBase>(), s.GetRequiredService<Func<Pair, StandaloneProfileUi>>(),
s.GetRequiredService<FileDialogManager>(), s.GetRequiredService<MareMediator>()));
collection.AddScoped((s) => new CommandManagerService(commandManager, s.GetRequiredService<PerformanceCollectorService>(), s.GetRequiredService<UiService>(),
s.GetRequiredService<ServerConfigurationManager>(), s.GetRequiredService<PeriodicFileScanner>(), s.GetRequiredService<ApiController>(), s.GetRequiredService<MareMediator>()));
collection.AddScoped((s) => new NotificationService(s.GetRequiredService<ILogger<NotificationService>>(),

File diff suppressed because one or more lines are too long

View File

@@ -3,7 +3,9 @@ using Dalamud.Interface.Internal.Notifications;
using MareSynchronos.API.Data;
using MareSynchronos.API.Dto;
using MareSynchronos.PlayerData.Handlers;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.WebAPI.Files.Models;
using System.Numerics;
namespace MareSynchronos.Services.Mediator;
@@ -56,5 +58,10 @@ public record DownloadFinishedMessage(GameObjectHandler DownloadId) : IMessage;
public record UiToggleMessage(Type UiType) : IMessage;
public record PlayerUploadingMessage(GameObjectHandler Handler, bool IsUploading) : IMessage;
public record ClearProfileDataMessage(UserData? UserData = null) : IMessage;
public record CyclePauseMessage(UserData UserData) : IMessage;
public record ProfilePopoutToggle(Pair? Pair) : IMessage;
public record CompactUiChange(Vector2 Size, Vector2 Position) : IMessage;
public record ProfileOpenStandaloneMessage(Pair Pair) : IMessage;
public record RemoveWindowMessage(WindowMediatorSubscriberBase Window) : IMessage;
#pragma warning restore MA0048 // File name must match type name

View File

@@ -5,22 +5,23 @@ using MareSynchronos.UI;
using MareSynchronos.MareConfiguration;
using MareSynchronos.Services.Mediator;
using Microsoft.Extensions.Logging;
using MareSynchronos.PlayerData.Pairs;
namespace MareSynchronos.Services;
public sealed class UiService : IDisposable
public sealed class UiService : DisposableMediatorSubscriberBase
{
private readonly List<WindowMediatorSubscriberBase> _createdWindows = new();
private readonly DalamudPluginInterface _dalamudPluginInterface;
private readonly FileDialogManager _fileDialogManager;
private readonly ILogger<UiService> _logger;
private readonly MareConfigService _mareConfigService;
private readonly MareMediator _mareMediator;
private readonly WindowSystem _windowSystem;
public UiService(ILogger<UiService> logger, DalamudPluginInterface dalamudPluginInterface,
MareConfigService mareConfigService, WindowSystem windowSystem,
IEnumerable<WindowMediatorSubscriberBase> windows,
FileDialogManager fileDialogManager, MareMediator mareMediator)
IEnumerable<WindowMediatorSubscriberBase> windows, Func<Pair, StandaloneProfileUi> standaloneProfileUiFactory,
FileDialogManager fileDialogManager, MareMediator mareMediator) : base(logger, mareMediator)
{
_logger = logger;
_logger.LogTrace("Creating {type}", GetType().Name);
@@ -28,7 +29,6 @@ public sealed class UiService : IDisposable
_mareConfigService = mareConfigService;
_windowSystem = windowSystem;
_fileDialogManager = fileDialogManager;
_mareMediator = mareMediator;
_dalamudPluginInterface.UiBuilder.DisableGposeUiHide = true;
_dalamudPluginInterface.UiBuilder.Draw += Draw;
@@ -38,24 +38,49 @@ public sealed class UiService : IDisposable
{
_windowSystem.AddWindow(window);
}
}
public void Dispose()
{
_logger.LogTrace("Disposing {type}", GetType().Name);
Mediator.Subscribe<ProfileOpenStandaloneMessage>(this, (msg) =>
{
if (!_createdWindows.Any(p => p is StandaloneProfileUi
&& string.Equals(((StandaloneProfileUi)p).Pair.UserData.AliasOrUID, msg.Pair.UserData.AliasOrUID, StringComparison.Ordinal)))
{
var window = standaloneProfileUiFactory(msg.Pair);
_createdWindows.Add(window);
_windowSystem.AddWindow(window);
}
});
_windowSystem.RemoveAllWindows();
_dalamudPluginInterface.UiBuilder.Draw -= Draw;
_dalamudPluginInterface.UiBuilder.OpenConfigUi -= ToggleUi;
Mediator.Subscribe<RemoveWindowMessage>(this, (msg) =>
{
_windowSystem.RemoveWindow(msg.Window);
_createdWindows.Remove(msg.Window);
msg.Window.Dispose();
});
}
public void ToggleUi()
{
if (_mareConfigService.Current.HasValidSetup())
_mareMediator.Publish(new UiToggleMessage(typeof(CompactUi)));
Mediator.Publish(new UiToggleMessage(typeof(CompactUi)));
else
_mareMediator.Publish(new UiToggleMessage(typeof(IntroUi)));
Mediator.Publish(new UiToggleMessage(typeof(IntroUi)));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_logger.LogTrace("Disposing {type}", GetType().Name);
_windowSystem.RemoveAllWindows();
foreach (var window in _createdWindows)
{
window.Dispose();
}
_dalamudPluginInterface.UiBuilder.Draw -= Draw;
_dalamudPluginInterface.UiBuilder.OpenConfigUi -= ToggleUi;
}
private void Draw()

View File

@@ -46,6 +46,8 @@ public class CompactUi : WindowMediatorSubscriberBase
private string _characterOrCommentFilter = string.Empty;
private Pair? _lastAddedUser;
private string _lastAddedUserComment = string.Empty;
private Vector2 _lastPosition = Vector2.One;
private Vector2 _lastSize = Vector2.One;
private string _pairToAdd = string.Empty;
private int _secretKeyIdx = 0;
private bool _showModalForUserAddition;
@@ -197,6 +199,15 @@ public class CompactUi : WindowMediatorSubscriberBase
UiSharedService.SetScaledWindowSize(275);
ImGui.EndPopup();
}
var pos = ImGui.GetWindowPos();
var size = ImGui.GetWindowSize();
if (_lastSize != size || _lastPosition != pos)
{
_lastSize = size;
_lastPosition = pos;
Mediator.Publish(new CompactUiChange(_lastSize, _lastPosition));
}
}
public override void OnClose()
@@ -346,52 +357,6 @@ public class CompactUi : WindowMediatorSubscriberBase
}
}
private void DrawPairedClientMenu(Pair entry)
{
if (entry.IsVisible)
{
if (UiSharedService.IconTextButton(FontAwesomeIcon.Sync, "Reload last data"))
{
entry.ApplyLastReceivedData(forced: true);
ImGui.CloseCurrentPopup();
}
UiSharedService.AttachToolTip("This reapplies the last received character data to this character");
}
var entryUID = entry.UserData.AliasOrUID;
if (UiSharedService.IconTextButton(FontAwesomeIcon.Folder, "Pair Groups"))
{
_selectGroupForPairUi.Open(entry);
}
UiSharedService.AttachToolTip("Choose pair groups for " + entryUID);
var isDisableSounds = entry.UserPair!.OwnPermissions.IsDisableSounds();
string disableSoundsText = isDisableSounds ? "Enable sound sync" : "Disable sound sync";
var disableSoundsIcon = isDisableSounds ? FontAwesomeIcon.VolumeUp : FontAwesomeIcon.VolumeMute;
if (UiSharedService.IconTextButton(disableSoundsIcon, disableSoundsText))
{
var permissions = entry.UserPair.OwnPermissions;
permissions.SetDisableSounds(!isDisableSounds);
_ = _apiController.UserSetPairPermissions(new UserPermissionsDto(entry.UserData, permissions));
}
var isDisableAnims = entry.UserPair!.OwnPermissions.IsDisableAnimations();
string disableAnimsText = isDisableAnims ? "Enable animation sync" : "Disable animation sync";
var disableAnimsIcon = isDisableAnims ? FontAwesomeIcon.Running : FontAwesomeIcon.Stop;
if (UiSharedService.IconTextButton(disableAnimsIcon, disableAnimsText))
{
var permissions = entry.UserPair.OwnPermissions;
permissions.SetDisableAnimations(!isDisableAnims);
_ = _apiController.UserSetPairPermissions(new UserPermissionsDto(entry.UserData, permissions));
}
if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Unpair Permanently") && UiSharedService.CtrlPressed())
{
_ = _apiController.UserRemovePair(new(entry.UserData));
}
UiSharedService.AttachToolTip("Hold CTRL and click to unpair permanently from " + entryUID);
}
private void DrawPairList()
{
UiSharedService.DrawWithID("addpair", DrawAddPair);

View File

@@ -11,10 +11,10 @@ public abstract class DrawPairBase
{
protected static bool _showModalReport = false;
protected readonly ApiController _apiController;
protected readonly UidDisplayHandler _displayHandler;
protected Pair _pair;
private static bool _reportPopupOpen = false;
private static string _reportReason = string.Empty;
private readonly UidDisplayHandler _displayHandler;
private readonly string _id;
protected DrawPairBase(string id, Pair entry, ApiController apiController, UidDisplayHandler uIDDisplayHandler)

View File

@@ -26,7 +26,7 @@ public class DrawUserPair : DrawPairBase
public bool IsVisible => _pair.IsVisible;
public UserPairDto UserPair => _pair.UserPair!;
protected override void DrawLeftSide(float textPos, float originalY)
protected override void DrawLeftSide(float textPosY, float originalY)
{
FontAwesomeIcon connectionIcon;
Vector4 connectionColor;
@@ -50,7 +50,7 @@ public class DrawUserPair : DrawPairBase
connectionColor = ImGuiColors.ParsedGreen;
}
ImGui.SetCursorPosY(textPos);
ImGui.SetCursorPosY(textPosY);
ImGui.PushFont(UiBuilder.IconFont);
UiSharedService.ColorText(connectionIcon.ToIconString(), connectionColor);
ImGui.PopFont();
@@ -58,7 +58,7 @@ public class DrawUserPair : DrawPairBase
if (_pair is { IsOnline: true, IsVisible: true })
{
ImGui.SameLine();
ImGui.SetCursorPosY(textPos);
ImGui.SetCursorPosY(textPosY);
ImGui.PushFont(UiBuilder.IconFont);
UiSharedService.ColorText(FontAwesomeIcon.Eye.ToIconString(), ImGuiColors.ParsedGreen);
ImGui.PopFont();
@@ -165,6 +165,15 @@ public class DrawUserPair : DrawPairBase
private void DrawPairedClientMenu(Pair entry)
{
if (!entry.IsPaused)
{
if (UiSharedService.IconTextButton(FontAwesomeIcon.User, "Open Profile"))
{
_displayHandler.OpenProfile(entry);
ImGui.CloseCurrentPopup();
}
UiSharedService.AttachToolTip("Opens the profile for this user in a new window");
}
if (entry.IsVisible)
{
if (UiSharedService.IconTextButton(FontAwesomeIcon.Sync, "Reload last data"))
@@ -175,6 +184,11 @@ public class DrawUserPair : DrawPairBase
UiSharedService.AttachToolTip("This reapplies the last received character data to this character");
}
if (UiSharedService.IconTextButton(FontAwesomeIcon.PlayCircle, "Cycle pause state"))
{
_ = _apiController.CyclePause(entry.UserData);
ImGui.CloseCurrentPopup();
}
var entryUID = entry.UserData.AliasOrUID;
if (UiSharedService.IconTextButton(FontAwesomeIcon.Folder, "Pair Groups"))
{

View File

@@ -100,6 +100,7 @@ public class EditProfileUi : WindowMediatorSubscriberBase
ImGui.BeginDisabled();
ImGui.Checkbox("Is NSFW", ref nsfw);
ImGui.EndDisabled();
ImGui.NewLine();
ImGui.PushFont(_uiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont);
UiSharedService.TextWrapped("Description:" + Environment.NewLine + profile.Description);
ImGui.PopFont();

View File

@@ -3,40 +3,29 @@ using ImGuiNET;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services.ServerConfiguration;
using MareSynchronos.MareConfiguration;
using Dalamud.Interface.Colors;
using MareSynchronos.API.Data.Extensions;
using ImGuiScene;
using System.Numerics;
using Microsoft.Extensions.Logging;
using MareSynchronos.Services;
using Dalamud.Interface.GameFonts;
using MareSynchronos.Services.Mediator;
namespace MareSynchronos.UI.Handlers;
public class UidDisplayHandler
{
private readonly ILogger<UidDisplayHandler> _logger;
private readonly MareConfigService _mareConfigService;
private readonly MareProfileManager _mareProfileManager;
private readonly MareMediator _mediator;
private readonly PairManager _pairManager;
private readonly ServerConfigurationManager _serverManager;
private readonly Dictionary<string, bool> _showUidForEntry = new(StringComparer.Ordinal);
private readonly UiBuilder _uiBuilder;
private readonly UiSharedService _uiSharedService;
private string _editNickEntry = string.Empty;
private string _editUserComment = string.Empty;
private string _lastMouseOverUid = string.Empty;
private byte[] _lastProfilePicture = Array.Empty<byte>();
private bool _popupShown = false;
private DateTime? _popupTime;
private TextureWrap? _textureWrap;
public UidDisplayHandler(ILogger<UidDisplayHandler> logger, UiBuilder uiBuilder, MareProfileManager mareProfileManager,
UiSharedService uiSharedService, PairManager pairManager, ServerConfigurationManager serverManager, MareConfigService mareConfigService)
public UidDisplayHandler(MareMediator mediator, PairManager pairManager,
ServerConfigurationManager serverManager, MareConfigService mareConfigService)
{
_logger = logger;
_uiBuilder = uiBuilder;
_mareProfileManager = mareProfileManager;
_uiSharedService = uiSharedService;
_mediator = mediator;
_pairManager = pairManager;
_serverManager = serverManager;
_mareConfigService = mareConfigService;
@@ -63,108 +52,23 @@ public class UidDisplayHandler
if (_popupTime > DateTime.UtcNow || !_mareConfigService.Current.ProfilesShow)
{
ImGui.SetTooltip("Left click to switch between UID display and nick" + Environment.NewLine + "Right click to change nick for " + pair.UserData.AliasOrUID);
ImGui.SetTooltip("Left click to switch between UID display and nick" + Environment.NewLine
+ "Right click to change nick for " + pair.UserData.AliasOrUID + Environment.NewLine
+ "Middle Mouse Button to open their profile in a separate window");
}
else
else if (_popupTime < DateTime.UtcNow && !_popupShown)
{
try
{
var spacing = ImGui.GetStyle().ItemSpacing;
ImGui.SetNextWindowSizeConstraints(new Vector2(512 + spacing.X * 4, 256 + spacing.Y * 3), new Vector2(512 + spacing.X * 4, 512 + spacing.Y * 3));
ImGui.BeginTooltip();
var mareProfile = _mareProfileManager.GetMareProfile(pair.UserData);
if (_textureWrap == null || !mareProfile.Profile.ImageData.Value.SequenceEqual(_lastProfilePicture))
{
_textureWrap?.Dispose();
_lastProfilePicture = mareProfile.Profile.ImageData.Value;
_textureWrap = _uiBuilder.LoadImage(_lastProfilePicture);
}
var drawList = ImGui.GetWindowDrawList();
var rect = drawList.GetClipRectMin();
var rectMax = drawList.GetClipRectMax();
ImGui.Indent(256 + spacing.X * 2);
if (_uiSharedService.UidFontBuilt) ImGui.PushFont(_uiSharedService.UidFont);
UiSharedService.ColorText(pair.UserData.AliasOrUID, ImGuiColors.HealerGreen);
if (_uiSharedService.UidFontBuilt) ImGui.PopFont();
var pos = ImGui.GetCursorPos();
var note = _serverManager.GetNoteForUid(pair.UserData.UID);
if (!string.IsNullOrEmpty(note))
{
UiSharedService.ColorText(note, ImGuiColors.DalamudGrey);
}
string status = pair.IsVisible ? "Visible" : (pair.IsOnline ? "Online" : "Offline");
UiSharedService.ColorText(status, (pair.IsVisible || pair.IsOnline) ? ImGuiColors.HealerGreen : ImGuiColors.DalamudRed);
if (pair.IsVisible)
{
ImGui.SameLine();
ImGui.TextUnformatted($"({pair.PlayerName})");
}
if (pair.UserPair != null)
{
ImGui.TextUnformatted("Directly paired");
if (pair.UserPair.OwnPermissions.IsPaused())
{
ImGui.SameLine();
UiSharedService.ColorText("You: paused", ImGuiColors.DalamudYellow);
}
if (pair.UserPair.OtherPermissions.IsPaused())
{
ImGui.SameLine();
UiSharedService.ColorText("They: paused", ImGuiColors.DalamudYellow);
}
}
if (pair.GroupPair.Any())
{
ImGui.TextUnformatted("Paired through Syncshells:");
foreach (var groupPair in pair.GroupPair)
{
ImGui.TextUnformatted("- " + groupPair.Key.GroupAliasOrGID);
}
}
var posDone = ImGui.GetCursorPos();
ImGui.PushFont(_uiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont);
UiSharedService.TextWrapped(mareProfile.Profile.Description);
ImGui.PopFont();
ImGui.Unindent();
var sepColor = ImGui.GetStyle().Colors[(int)ImGuiCol.Separator];
bool tallerThanWide = _textureWrap.Height >= _textureWrap.Width;
var stretchFactor = tallerThanWide ? 256f / _textureWrap.Height : 256f / _textureWrap.Width;
var newWidth = _textureWrap.Width * stretchFactor;
var newHeight = _textureWrap.Height * stretchFactor;
var remainingWidth = (256f - newWidth) / 2f;
var remainingHeight = (256f - newHeight) / 2f;
drawList.AddImage(_textureWrap.ImGuiHandle, new Vector2(rect.X + spacing.X + remainingWidth, rect.Y + spacing.Y + remainingHeight),
new Vector2(rect.X + spacing.X + remainingWidth + newWidth, rect.Y + spacing.Y + remainingHeight + newHeight));
drawList.AddLine(new Vector2(rect.X + 256 + spacing.X * 2, rect.Y + pos.Y - spacing.Y),
new Vector2(rectMax.X - spacing.X, rect.Y + pos.Y - spacing.Y),
UiSharedService.Color((byte)(sepColor.X * 255), (byte)(sepColor.Y * 255), (byte)(sepColor.Z * 255), (byte)(sepColor.W * 255)));
drawList.AddLine(new Vector2(rect.X + 256 + spacing.X * 2, rect.Y + posDone.Y - spacing.Y),
new Vector2(rectMax.X - spacing.X, rect.Y + posDone.Y - spacing.Y),
UiSharedService.Color((byte)(sepColor.X * 255), (byte)(sepColor.Y * 255), (byte)(sepColor.Z * 255), (byte)(sepColor.W * 255)));
ImGui.EndTooltip();
}
catch (Exception ex)
{
_logger.LogWarning("Error during draw tooltip", ex);
}
_popupShown = true;
_mediator.Publish(new ProfilePopoutToggle(pair));
}
}
else
{
if (string.Equals(_lastMouseOverUid, id))
{
_lastProfilePicture = Array.Empty<byte>();
_mediator.Publish(new ProfilePopoutToggle(null));
_lastMouseOverUid = string.Empty;
_popupShown = false;
_textureWrap?.Dispose();
_textureWrap = null;
}
@@ -187,6 +91,11 @@ public class UidDisplayHandler
_editUserComment = pair.GetNote() ?? string.Empty;
_editNickEntry = pair.UserData.UID;
}
if (ImGui.IsItemClicked(ImGuiMouseButton.Middle))
{
_mediator.Publish(new ProfileOpenStandaloneMessage(pair));
}
}
else
{
@@ -244,6 +153,11 @@ public class UidDisplayHandler
_editUserComment = string.Empty;
}
internal void OpenProfile(Pair entry)
{
_mediator.Publish(new ProfileOpenStandaloneMessage(entry));
}
private bool ShowUidInsteadOfName(Pair pair)
{
_showUidForEntry.TryGetValue(pair.UserData.UID, out var showUidInsteadOfName);

View File

@@ -0,0 +1,191 @@
using Dalamud.Interface.Colors;
using ImGuiNET;
using ImGuiScene;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using Microsoft.Extensions.Logging;
using System.Numerics;
using MareSynchronos.API.Data.Extensions;
using MareSynchronos.MareConfiguration;
using Dalamud.Interface;
namespace MareSynchronos.UI;
public class PopoutProfileUi : WindowMediatorSubscriberBase
{
private readonly MareProfileManager _mareProfileManager;
private readonly ServerConfigurationManager _serverManager;
private readonly UiSharedService _uiSharedService;
private Vector2 _lastMainPos = Vector2.Zero;
private Vector2 _lastMainSize = Vector2.Zero;
private byte[] _lastProfilePicture = Array.Empty<byte>();
private byte[] _lastSupporterPicture = Array.Empty<byte>();
private Pair? _pair;
private TextureWrap? _supporterTextureWrap;
private TextureWrap? _textureWrap;
public PopoutProfileUi(ILogger<PopoutProfileUi> logger, MareMediator mediator, UiSharedService uiBuilder,
ServerConfigurationManager serverManager, MareConfigService mareConfigService,
MareProfileManager mareProfileManager) : base(logger, mediator, "###MareSynchronosPopoutProfileUI")
{
_uiSharedService = uiBuilder;
_serverManager = serverManager;
_mareProfileManager = mareProfileManager;
Flags = ImGuiWindowFlags.NoDecoration;
Mediator.Subscribe<ProfilePopoutToggle>(this, (msg) =>
{
IsOpen = msg.Pair != null;
_pair = msg.Pair;
_lastProfilePicture = Array.Empty<byte>();
_lastSupporterPicture = Array.Empty<byte>();
_textureWrap?.Dispose();
_textureWrap = null;
_supporterTextureWrap?.Dispose();
_supporterTextureWrap = null;
});
Mediator.Subscribe<CompactUiChange>(this, (msg) =>
{
if (msg.Size != Vector2.Zero)
{
var border = ImGui.GetStyle().WindowBorderSize;
var padding = ImGui.GetStyle().WindowPadding;
var spacing = ImGui.GetStyle().ItemSpacing;
Size = new(256 + (padding.X * 2) + border, msg.Size.Y / ImGuiHelpers.GlobalScale);
_lastMainSize = msg.Size;
}
var mainPos = msg.Position == Vector2.Zero ? _lastMainPos : msg.Position;
if (mareConfigService.Current.ProfilePopoutRight)
{
Position = new(mainPos.X + _lastMainSize.X * ImGuiHelpers.GlobalScale, mainPos.Y);
}
else
{
Position = new(mainPos.X - Size.Value.X * ImGuiHelpers.GlobalScale, mainPos.Y);
}
if (msg.Position != Vector2.Zero)
{
_lastMainPos = msg.Position;
}
});
IsOpen = false;
}
public override void Draw()
{
if (_pair == null) return;
try
{
var spacing = ImGui.GetStyle().ItemSpacing;
var mareProfile = _mareProfileManager.GetMareProfile(_pair.UserData);
if (_textureWrap == null || !mareProfile.Profile.ImageData.Value.SequenceEqual(_lastProfilePicture))
{
_textureWrap?.Dispose();
_lastProfilePicture = mareProfile.Profile.ImageData.Value;
_textureWrap = _uiSharedService.LoadImage(_lastProfilePicture);
}
if (_supporterTextureWrap == null || !mareProfile.Profile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture))
{
_supporterTextureWrap?.Dispose();
_supporterTextureWrap = null;
if (!string.IsNullOrEmpty(mareProfile.Profile.Base64SupporterPicture))
{
_lastSupporterPicture = mareProfile.Profile.SupporterImageData.Value;
_supporterTextureWrap = _uiSharedService.LoadImage(_lastSupporterPicture);
}
}
var drawList = ImGui.GetWindowDrawList();
var rectMin = drawList.GetClipRectMin();
var rectMax = drawList.GetClipRectMax();
if (_uiSharedService.UidFontBuilt) ImGui.PushFont(_uiSharedService.UidFont);
UiSharedService.ColorText(_pair.UserData.AliasOrUID, ImGuiColors.HealerGreen);
if (_uiSharedService.UidFontBuilt) ImGui.PopFont();
ImGui.Dummy(new(spacing.Y, spacing.Y));
var textPos = ImGui.GetCursorPosY();
ImGui.Separator();
var imagePos = ImGui.GetCursorPos();
ImGui.Dummy(new(256, 256 * ImGuiHelpers.GlobalScale + spacing.Y));
var note = _serverManager.GetNoteForUid(_pair.UserData.UID);
if (!string.IsNullOrEmpty(note))
{
UiSharedService.ColorText(note, ImGuiColors.DalamudGrey);
}
string status = _pair.IsVisible ? "Visible" : (_pair.IsOnline ? "Online" : "Offline");
UiSharedService.ColorText(status, (_pair.IsVisible || _pair.IsOnline) ? ImGuiColors.HealerGreen : ImGuiColors.DalamudRed);
if (_pair.IsVisible)
{
ImGui.SameLine();
ImGui.TextUnformatted($"({_pair.PlayerName})");
}
if (_pair.UserPair != null)
{
ImGui.TextUnformatted("Directly paired");
if (_pair.UserPair.OwnPermissions.IsPaused())
{
ImGui.SameLine();
UiSharedService.ColorText("You: paused", ImGuiColors.DalamudYellow);
}
if (_pair.UserPair.OtherPermissions.IsPaused())
{
ImGui.SameLine();
UiSharedService.ColorText("They: paused", ImGuiColors.DalamudYellow);
}
}
if (_pair.GroupPair.Any())
{
ImGui.TextUnformatted("Paired through Syncshells:");
foreach (var groupPair in _pair.GroupPair)
{
ImGui.TextUnformatted("- " + groupPair.Key.GroupAliasOrGID);
}
}
ImGui.Separator();
ImGui.PushFont(_uiSharedService.GetGameFontHandle());
var remaining = ImGui.GetWindowContentRegionMax().Y - ImGui.GetCursorPosY();
var descText = mareProfile.Profile.Description;
var textSize = ImGui.CalcTextSize(descText, 256f * ImGuiHelpers.GlobalScale);
bool trimmed = textSize.Y > remaining;
while (textSize.Y > remaining && descText.Contains(' '))
{
descText = descText.Substring(0, descText.LastIndexOf(' ')).TrimEnd();
textSize = ImGui.CalcTextSize(descText + $"...{Environment.NewLine}[Open Full Profile for complete description]", 256f * ImGuiHelpers.GlobalScale);
}
UiSharedService.TextWrapped(trimmed ? descText + $"...{Environment.NewLine}[Open Full Profile for complete description]" : mareProfile.Profile.Description);
ImGui.PopFont();
var padding = ImGui.GetStyle().WindowPadding.X / 2;
bool tallerThanWide = _textureWrap.Height >= _textureWrap.Width;
var stretchFactor = tallerThanWide ? 256f * ImGuiHelpers.GlobalScale / _textureWrap.Height : 256f * ImGuiHelpers.GlobalScale / _textureWrap.Width;
var newWidth = _textureWrap.Width * stretchFactor;
var newHeight = _textureWrap.Height * stretchFactor;
var remainingWidth = (256f * ImGuiHelpers.GlobalScale - newWidth) / 2f;
var remainingHeight = (256f * ImGuiHelpers.GlobalScale - newHeight) / 2f;
drawList.AddImage(_textureWrap.ImGuiHandle, new Vector2(rectMin.X + padding + remainingWidth, rectMin.Y + spacing.Y + imagePos.Y + remainingHeight),
new Vector2(rectMin.X + padding + remainingWidth + newWidth, rectMin.Y + spacing.Y + imagePos.Y + remainingHeight + newHeight));
if (_supporterTextureWrap != null)
{
const float iconSize = 38;
drawList.AddImage(_supporterTextureWrap.ImGuiHandle,
new Vector2(rectMax.X - iconSize - spacing.X, rectMin.Y + (textPos / 2) - (iconSize / 2)),
new Vector2(rectMax.X - spacing.X, rectMin.Y + iconSize + (textPos / 2) - (iconSize / 2)));
}
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Error during draw tooltip");
}
}
}

View File

@@ -495,6 +495,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
var showProfiles = _configService.Current.ProfilesShow;
var showNsfwProfiles = _configService.Current.ProfilesAllowNsfw;
var profileDelay = _configService.Current.ProfileDelay;
var profileOnRight = _configService.Current.ProfilePopoutRight;
if (ImGui.Checkbox("Show separate Visible group", ref showVisibleSeparate))
{
@@ -526,6 +527,13 @@ public class SettingsUi : WindowMediatorSubscriberBase
UiSharedService.DrawHelpText("This will show the configured user profile after a set delay");
ImGui.Indent();
if (!showProfiles) ImGui.BeginDisabled();
if (ImGui.Checkbox("Popout profiles on the right", ref profileOnRight))
{
_configService.Current.ProfilePopoutRight = profileOnRight;
_configService.Save();
Mediator.Publish(new CompactUiChange(Vector2.Zero, Vector2.Zero));
}
UiSharedService.DrawHelpText("Will show profiles on the right side of the main UI");
if (ImGui.Checkbox("Show profiles marked as NSFW", ref showNsfwProfiles))
{
Mediator.Publish(new ClearProfileDataMessage());

View File

@@ -0,0 +1,176 @@
using Dalamud.Interface.Colors;
using ImGuiNET;
using ImGuiScene;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using Microsoft.Extensions.Logging;
using System.Numerics;
using MareSynchronos.API.Data.Extensions;
using Dalamud.Interface;
namespace MareSynchronos.UI;
public class StandaloneProfileUi : WindowMediatorSubscriberBase
{
private readonly MareProfileManager _mareProfileManager;
private readonly ServerConfigurationManager _serverManager;
private readonly UiSharedService _uiSharedService;
private bool _adjustedForScrollBars = false;
private byte[] _lastProfilePicture = Array.Empty<byte>();
private byte[] _lastSupporterPicture = Array.Empty<byte>();
private TextureWrap? _supporterTextureWrap;
private TextureWrap? _textureWrap;
public StandaloneProfileUi(ILogger<StandaloneProfileUi> logger, MareMediator mediator, UiSharedService uiBuilder,
ServerConfigurationManager serverManager, MareProfileManager mareProfileManager, Pair pair)
: base(logger, mediator, "Mare Profile of " + pair.UserData.AliasOrUID + "##MareSynchronosStandaloneProfileUI" + pair.UserData.AliasOrUID)
{
_uiSharedService = uiBuilder;
_serverManager = serverManager;
_mareProfileManager = mareProfileManager;
Pair = pair;
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.AlwaysAutoResize;
var spacing = ImGui.GetStyle().ItemSpacing;
Size = new(512 + spacing.X * 3 + ImGui.GetStyle().WindowPadding.X + ImGui.GetStyle().WindowBorderSize, 512);
IsOpen = true;
}
public Pair Pair { get; init; }
public override void Draw()
{
try
{
var spacing = ImGui.GetStyle().ItemSpacing;
var mareProfile = _mareProfileManager.GetMareProfile(Pair.UserData);
if (_textureWrap == null || !mareProfile.Profile.ImageData.Value.SequenceEqual(_lastProfilePicture))
{
_textureWrap?.Dispose();
_lastProfilePicture = mareProfile.Profile.ImageData.Value;
_textureWrap = _uiSharedService.LoadImage(_lastProfilePicture);
}
if (_supporterTextureWrap == null || !mareProfile.Profile.SupporterImageData.Value.SequenceEqual(_lastSupporterPicture))
{
_supporterTextureWrap?.Dispose();
_supporterTextureWrap = null;
if (!string.IsNullOrEmpty(mareProfile.Profile.Base64SupporterPicture))
{
_lastSupporterPicture = mareProfile.Profile.SupporterImageData.Value;
_supporterTextureWrap = _uiSharedService.LoadImage(_lastSupporterPicture);
}
}
var drawList = ImGui.GetWindowDrawList();
var rectMin = drawList.GetClipRectMin();
var rectMax = drawList.GetClipRectMax();
var headerSize = ImGui.GetCursorPosY() - ImGui.GetStyle().WindowPadding.Y;
if (_uiSharedService.UidFontBuilt) ImGui.PushFont(_uiSharedService.UidFont);
UiSharedService.ColorText(Pair.UserData.AliasOrUID, ImGuiColors.HealerGreen);
if (_uiSharedService.UidFontBuilt) ImGui.PopFont();
ImGuiHelpers.ScaledDummy(new Vector2(spacing.Y, spacing.Y));
var textPos = ImGui.GetCursorPosY() - headerSize;
ImGui.Separator();
var pos = ImGui.GetCursorPos() with { Y = ImGui.GetCursorPosY() - headerSize };
ImGuiHelpers.ScaledDummy(new Vector2(256, 256 + spacing.Y));
var postDummy = ImGui.GetCursorPosY();
ImGui.SameLine();
var descriptionTextSize = ImGui.CalcTextSize(mareProfile.Profile.Description, 256f);
var descriptionChildHeight = rectMax.Y - pos.Y - rectMin.Y - spacing.Y * 2;
if (descriptionTextSize.Y > descriptionChildHeight && !_adjustedForScrollBars)
{
Size = Size.Value with { X = Size.Value.X + ImGui.GetStyle().ScrollbarSize };
_adjustedForScrollBars = true;
}
else if (descriptionTextSize.Y < descriptionChildHeight && _adjustedForScrollBars)
{
Size = Size.Value with { X = Size.Value.X - ImGui.GetStyle().ScrollbarSize };
_adjustedForScrollBars = false;
}
var childFrame = ImGuiHelpers.ScaledVector2(256 + ImGui.GetStyle().WindowPadding.X + ImGui.GetStyle().WindowBorderSize, descriptionChildHeight);
childFrame = childFrame with
{
X = childFrame.X + (_adjustedForScrollBars ? ImGui.GetStyle().ScrollbarSize : 0),
Y = childFrame.Y / ImGuiHelpers.GlobalScale
};
if (ImGui.BeginChildFrame(1000, childFrame))
{
ImGui.PushFont(_uiSharedService.GetGameFontHandle());
ImGui.TextWrapped(mareProfile.Profile.Description);
ImGui.PopFont();
}
ImGui.EndChildFrame();
ImGui.SetCursorPosY(postDummy);
var note = _serverManager.GetNoteForUid(Pair.UserData.UID);
if (!string.IsNullOrEmpty(note))
{
UiSharedService.ColorText(note, ImGuiColors.DalamudGrey);
}
string status = Pair.IsVisible ? "Visible" : (Pair.IsOnline ? "Online" : "Offline");
UiSharedService.ColorText(status, (Pair.IsVisible || Pair.IsOnline) ? ImGuiColors.HealerGreen : ImGuiColors.DalamudRed);
if (Pair.IsVisible)
{
ImGui.SameLine();
ImGui.TextUnformatted($"({Pair.PlayerName})");
}
if (Pair.UserPair != null)
{
ImGui.TextUnformatted("Directly paired");
if (Pair.UserPair.OwnPermissions.IsPaused())
{
ImGui.SameLine();
UiSharedService.ColorText("You: paused", ImGuiColors.DalamudYellow);
}
if (Pair.UserPair.OtherPermissions.IsPaused())
{
ImGui.SameLine();
UiSharedService.ColorText("They: paused", ImGuiColors.DalamudYellow);
}
}
if (Pair.GroupPair.Any())
{
ImGui.TextUnformatted("Paired through Syncshells:");
foreach (var groupPair in Pair.GroupPair)
{
ImGui.TextUnformatted("- " + groupPair.Key.GroupAliasOrGID);
}
}
var padding = ImGui.GetStyle().WindowPadding.X / 2;
bool tallerThanWide = _textureWrap.Height >= _textureWrap.Width;
var stretchFactor = tallerThanWide ? 256f * ImGuiHelpers.GlobalScale / _textureWrap.Height : 256f * ImGuiHelpers.GlobalScale / _textureWrap.Width;
var newWidth = _textureWrap.Width * stretchFactor;
var newHeight = _textureWrap.Height * stretchFactor;
var remainingWidth = (256f * ImGuiHelpers.GlobalScale - newWidth) / 2f;
var remainingHeight = (256f * ImGuiHelpers.GlobalScale - newHeight) / 2f;
drawList.AddImage(_textureWrap.ImGuiHandle, new Vector2(rectMin.X + padding + remainingWidth, rectMin.Y + spacing.Y + pos.Y + remainingHeight),
new Vector2(rectMin.X + padding + remainingWidth + newWidth, rectMin.Y + spacing.Y + pos.Y + remainingHeight + newHeight));
if (_supporterTextureWrap != null)
{
const float iconSize = 38;
drawList.AddImage(_supporterTextureWrap.ImGuiHandle,
new Vector2(rectMax.X - iconSize - spacing.X, rectMin.Y + (textPos / 2) - (iconSize / 2)),
new Vector2(rectMax.X - spacing.X, rectMin.Y + iconSize + (textPos / 2) - (iconSize / 2)));
}
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Error during draw tooltip");
}
}
public override void OnClose()
{
Mediator.Publish(new RemoveWindowMessage(this));
}
}

View File

@@ -1,9 +1,11 @@
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Interface.GameFonts;
using Dalamud.Interface.ImGuiFileDialog;
using Dalamud.Plugin;
using Dalamud.Utility;
using ImGuiNET;
using ImGuiScene;
using MareSynchronos.FileCache;
using MareSynchronos.Interop;
using MareSynchronos.Localization;
@@ -43,17 +45,11 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
private readonly MareConfigService _configService;
private readonly DalamudUtilService _dalamudUtil;
private readonly IpcManager _ipcManager;
private readonly Dalamud.Localization _localization;
private readonly DalamudPluginInterface _pluginInterface;
private readonly Dictionary<string, object> _selectedComboItems = new(StringComparer.Ordinal);
private readonly ServerConfigurationManager _serverConfigurationManager;
private bool _cacheDirectoryHasOtherFilesThanCache = false;
private bool _cacheDirectoryIsValidPath = true;
@@ -78,7 +74,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
private int _serverSelectionIndex = -1;
public UiSharedService(ILogger<UiSharedService> logger, IpcManager ipcManager, ApiController apiController, PeriodicFileScanner cacheScanner, FileDialogManager fileDialogManager,
public UiSharedService(ILogger<UiSharedService> logger, IpcManager ipcManager, ApiController apiController,
PeriodicFileScanner cacheScanner, FileDialogManager fileDialogManager,
MareConfigService configService, DalamudUtilService dalamudUtil, DalamudPluginInterface pluginInterface, Dalamud.Localization localization,
ServerConfigurationManager serverManager, MareMediator mediator) : base(logger, mediator)
{
@@ -761,6 +758,16 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
[LibraryImport("user32")]
internal static partial short GetKeyState(int nVirtKey);
internal ImFontPtr GetGameFontHandle()
{
return _pluginInterface.UiBuilder.GetGameFontHandle(new GameFontStyle(GameFontFamilyAndSize.Axis12)).ImFont;
}
internal TextureWrap LoadImage(byte[] imageData)
{
return _pluginInterface.UiBuilder.LoadImage(imageData);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

View File

@@ -12,6 +12,8 @@ using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using MareSynchronos.Services;
using MareSynchronos.API.Data.Extensions;
using MareSynchronos.API.Data;
namespace MareSynchronos.WebAPI;
@@ -46,6 +48,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
Mediator.Subscribe<HubClosedMessage>(this, (msg) => MareHubOnClosed(msg.Exception));
Mediator.Subscribe<HubReconnectedMessage>(this, (msg) => _ = Task.Run(MareHubOnReconnected));
Mediator.Subscribe<HubReconnectingMessage>(this, (msg) => MareHubOnReconnecting(msg.Exception));
Mediator.Subscribe<CyclePauseMessage>(this, (msg) => CyclePause(msg.UserData));
ServerState = ServerState.Offline;
@@ -56,12 +59,19 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
}
public string AuthFailureMessage { get; private set; } = string.Empty;
public Version CurrentClientVersion => _connectionDto?.CurrentClientVersion ?? new Version(0, 0, 0);
public string DisplayName => _connectionDto?.User.AliasOrUID ?? string.Empty;
public bool IsConnected => ServerState == ServerState.Connected;
public bool IsCurrentVersion => (Assembly.GetExecutingAssembly().GetName().Version ?? new Version(0, 0, 0, 0)) >= (_connectionDto?.CurrentClientVersion ?? new Version(0, 0, 0, 0));
public int OnlineUsers => SystemInfoDto.OnlineUsers;
public bool ServerAlive => ServerState is ServerState.Connected or ServerState.RateLimited or ServerState.Unauthorized or ServerState.Disconnected;
public ServerInfo ServerInfo => _connectionDto?.ServerInfo ?? new ServerInfo();
public ServerState ServerState
@@ -75,6 +85,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
}
public SystemInfoDto SystemInfoDto { get; private set; } = new();
public string UID => _connectionDto?.User.UID ?? string.Empty;
public async Task<bool> CheckClientHealth()
@@ -190,6 +201,29 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
}
}
public Task CyclePause(UserData userData)
{
CancellationTokenSource cts = new();
cts.CancelAfter(TimeSpan.FromSeconds(5));
Task.Run(async () =>
{
var pair = _pairManager.GetOnlineUserPairs().Single(p => p.UserPair != null && p.UserData == userData);
var perm = pair.UserPair!.OwnPermissions;
perm.SetPaused(true);
await UserSetPairPermissions(new API.Dto.User.UserPermissionsDto(userData, perm)).ConfigureAwait(false);
// wait until it's changed
while (pair.UserPair!.OwnPermissions != perm)
{
await Task.Delay(250, cts.Token).ConfigureAwait(false);
Logger.LogTrace("Waiting for permissions change for {data}", userData);
}
perm.SetPaused(false);
await UserSetPairPermissions(new API.Dto.User.UserPermissionsDto(userData, perm)).ConfigureAwait(false);
}, cts.Token).ContinueWith((t) => cts.Dispose());
return Task.CompletedTask;
}
public async Task<ConnectionDto> GetConnectionDto()
{
var dto = await _mareHub!.InvokeAsync<ConnectionDto>(nameof(GetConnectionDto)).ConfigureAwait(false);