fix token for character change, add online count to syncshells and groups

This commit is contained in:
rootdarkarchon
2023-10-18 17:49:24 +02:00
parent c237ae53e6
commit d7bfa2147f
7 changed files with 64 additions and 18 deletions

View File

@@ -91,8 +91,8 @@ public class CompactUi : WindowMediatorSubscriberBase
SizeConstraints = new WindowSizeConstraints()
{
MinimumSize = new Vector2(350, 400),
MaximumSize = new Vector2(350, 2000),
MinimumSize = new Vector2(375, 400),
MaximumSize = new Vector2(375, 2000),
};
}

View File

@@ -12,6 +12,7 @@ public abstract class DrawFolderBase : IDrawFolder
protected readonly string _id;
protected readonly TagHandler _tagHandler;
private float _menuWidth = -1;
public int OnlinePairs => _drawPairs.Count(u => u.Pair.IsOnline);
protected DrawFolderBase(string id, IEnumerable<DrawUserPair> drawPairs, TagHandler tagHandler)
{
_id = id;

View File

@@ -39,16 +39,26 @@ public class DrawFolderGroup : DrawFolderBase
protected override float DrawIcon(float textPosY, float originalY)
{
ImGui.SetCursorPosY(textPosY);
using (ImRaii.PushFont(UiBuilder.IconFont))
ImGui.TextUnformatted(_groupFullInfoDto.GroupPermissions.IsDisableInvites() ? FontAwesomeIcon.Lock.ToIconString() : FontAwesomeIcon.Users.ToIconString());
if (_groupFullInfoDto.GroupPermissions.IsDisableInvites())
{
UiSharedService.AttachToolTip("Syncshell " + _groupFullInfoDto.GroupAliasOrGID + " is closed for invites");
}
if (IsOwner)
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemSpacing.X / 2f }))
{
ImGui.SameLine();
ImGui.SetCursorPosY(textPosY);
ImGui.TextUnformatted("[" + OnlinePairs.ToString() + "]");
}
UiSharedService.AttachToolTip(OnlinePairs + " online in this syncshell");
ImGui.SameLine();
if (IsOwner)
{
ImGui.SameLine();
using (ImRaii.PushFont(UiBuilder.IconFont))
ImGui.TextUnformatted(FontAwesomeIcon.Crown.ToIconString());
UiSharedService.AttachToolTip("You are the owner of " + _groupFullInfoDto.GroupAliasOrGID);
@@ -136,7 +146,7 @@ public class DrawFolderGroup : DrawFolderBase
ImGui.CloseCurrentPopup();
}
if (UiSharedService.IconTextButton(disableVfx ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle, disableVfx ? "Enable VFX Sync" : "Disable VFX Sync",
if (UiSharedService.IconTextButton(disableVfx ? FontAwesomeIcon.Sun : FontAwesomeIcon.Circle, disableVfx ? "Enable VFX Sync" : "Disable VFX Sync",
menuWidth, true))
{
perm.SetDisableVFX(!disableVfx);

View File

@@ -53,22 +53,42 @@ public class DrawFolderTag : DrawFolderBase
_ => true,
} && _drawPairs.Any();
private bool RenderCount => _id switch
{
TagHandler.CustomOfflineSyncshellTag => false,
TagHandler.CustomOfflineTag => false,
TagHandler.CustomUnpairedTag => false,
_ => true
};
protected override float DrawIcon(float textPosY, float originalY)
{
using var font = ImRaii.PushFont(UiBuilder.IconFont);
var icon = _id switch
using (ImRaii.PushFont(UiBuilder.IconFont))
{
TagHandler.CustomUnpairedTag => FontAwesomeIcon.ArrowsLeftRight.ToIconString(),
TagHandler.CustomOnlineTag => FontAwesomeIcon.Link.ToIconString(),
TagHandler.CustomOfflineTag => FontAwesomeIcon.Unlink.ToIconString(),
TagHandler.CustomOfflineSyncshellTag => FontAwesomeIcon.Unlink.ToIconString(),
TagHandler.CustomVisibleTag => FontAwesomeIcon.Eye.ToIconString(),
TagHandler.CustomAllTag => FontAwesomeIcon.User.ToIconString(),
_ => FontAwesomeIcon.Folder.ToIconString()
};
var icon = _id switch
{
TagHandler.CustomUnpairedTag => FontAwesomeIcon.ArrowsLeftRight.ToIconString(),
TagHandler.CustomOnlineTag => FontAwesomeIcon.Link.ToIconString(),
TagHandler.CustomOfflineTag => FontAwesomeIcon.Unlink.ToIconString(),
TagHandler.CustomOfflineSyncshellTag => FontAwesomeIcon.Unlink.ToIconString(),
TagHandler.CustomVisibleTag => FontAwesomeIcon.Eye.ToIconString(),
TagHandler.CustomAllTag => FontAwesomeIcon.User.ToIconString(),
_ => FontAwesomeIcon.Folder.ToIconString()
};
ImGui.SetCursorPosY(textPosY);
ImGui.TextUnformatted(icon);
ImGui.SetCursorPosY(textPosY);
ImGui.TextUnformatted(icon);
}
if (RenderCount)
{
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemSpacing.X / 2f }))
{
ImGui.SameLine();
ImGui.SetCursorPosY(textPosY);
ImGui.TextUnformatted("[" + OnlinePairs.ToString() + "]");
}
UiSharedService.AttachToolTip(OnlinePairs + " online in this group");
}
ImGui.SameLine();
return ImGui.GetCursorPosX();
}

View File

@@ -9,6 +9,7 @@ public class DrawGroupedGroupFolder : IDrawFolder
{
private readonly IEnumerable<IDrawFolder> _groups;
private readonly TagHandler _tagHandler;
public int OnlinePairs => _groups.Sum(g => g.OnlinePairs);
public DrawGroupedGroupFolder(IEnumerable<IDrawFolder> groups, TagHandler tagHandler)
{
@@ -33,6 +34,12 @@ public class DrawGroupedGroupFolder : IDrawFolder
ImGui.SameLine();
using (ImRaii.PushFont(UiBuilder.IconFont))
ImGui.TextUnformatted(FontAwesomeIcon.UsersRectangle.ToIconString());
using (ImRaii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing with { X = ImGui.GetStyle().ItemSpacing.X / 2f }))
{
ImGui.SameLine();
ImGui.TextUnformatted("[" + OnlinePairs.ToString() + "]");
}
UiSharedService.AttachToolTip(OnlinePairs + " online all of your syncshells");
ImGui.SameLine();
ImGui.TextUnformatted("All Syncshells");
ImGui.Separator();

View File

@@ -2,5 +2,6 @@
public interface IDrawFolder
{
int OnlinePairs { get; }
void Draw();
}

View File

@@ -1,5 +1,6 @@
using MareSynchronos.API.Routes;
using MareSynchronos.Services;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using MareSynchronos.Utils;
using Microsoft.Extensions.Logging;
@@ -10,7 +11,7 @@ using System.Reflection;
namespace MareSynchronos.WebAPI.SignalR;
public sealed class TokenProvider : IDisposable
public sealed class TokenProvider : IDisposable, IMediatorSubscriber
{
private readonly DalamudUtilService _dalamudUtil;
private readonly HttpClient _httpClient;
@@ -18,20 +19,26 @@ public sealed class TokenProvider : IDisposable
private readonly ServerConfigurationManager _serverManager;
private readonly ConcurrentDictionary<JwtIdentifier, string> _tokenCache = new();
public TokenProvider(ILogger<TokenProvider> logger, ServerConfigurationManager serverManager, DalamudUtilService dalamudUtil)
public TokenProvider(ILogger<TokenProvider> logger, ServerConfigurationManager serverManager, DalamudUtilService dalamudUtil, MareMediator mareMediator)
{
_logger = logger;
_serverManager = serverManager;
_dalamudUtil = dalamudUtil;
_httpClient = new();
var ver = Assembly.GetExecutingAssembly().GetName().Version;
Mediator = mareMediator;
Mediator.Subscribe<DalamudLogoutMessage>(this, (_) => _tokenCache.Clear());
Mediator.Subscribe<DalamudLoginMessage>(this, (_) => _tokenCache.Clear());
_httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("MareSynchronos", ver!.Major + "." + ver!.Minor + "." + ver!.Build));
}
public MareMediator Mediator { get; }
private JwtIdentifier CurrentIdentifier => new(_serverManager.CurrentApiUrl, _serverManager.GetSecretKey()!);
public void Dispose()
{
Mediator.UnsubscribeAll(this);
_httpClient.Dispose();
}