add mare profiles

This commit is contained in:
rootdarkarchon
2023-03-19 19:00:22 +01:00
parent f6a471f457
commit 2b829af4f8
22 changed files with 625 additions and 57 deletions

View File

@@ -3,53 +3,186 @@ 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;
namespace MareSynchronos.UI.Handlers;
public class UidDisplayHandler
{
private readonly ILogger<UidDisplayHandler> _logger;
private readonly MareConfigService _mareConfigService;
private readonly MareProfileManager _mareProfileManager;
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 DateTime? _popupTime;
private TextureWrap? _textureWrap;
public UidDisplayHandler(PairManager pairManager, ServerConfigurationManager serverManager, MareConfigService mareConfigService)
public UidDisplayHandler(ILogger<UidDisplayHandler> logger, UiBuilder uiBuilder, MareProfileManager mareProfileManager,
UiSharedService uiSharedService, PairManager pairManager, ServerConfigurationManager serverManager, MareConfigService mareConfigService)
{
_logger = logger;
_uiBuilder = uiBuilder;
_mareProfileManager = mareProfileManager;
_uiSharedService = uiSharedService;
_pairManager = pairManager;
_serverManager = serverManager;
_mareConfigService = mareConfigService;
}
public void DrawPairText(Pair entry, float textPosX, float originalY, Func<float> editBoxWidth)
public void DrawPairText(string id, Pair pair, float textPosX, float originalY, Func<float> editBoxWidth)
{
ImGui.SameLine(textPosX);
(bool textIsUid, string playerText) = GetPlayerText(entry);
if (!string.Equals(_editNickEntry, entry.UserData.UID, StringComparison.Ordinal))
(bool textIsUid, string playerText) = GetPlayerText(pair);
if (!string.Equals(_editNickEntry, pair.UserData.UID, StringComparison.Ordinal))
{
ImGui.SetCursorPosY(originalY);
if (textIsUid) ImGui.PushFont(UiBuilder.MonoFont);
ImGui.TextUnformatted(playerText);
if (textIsUid) ImGui.PopFont();
UiSharedService.AttachToolTip("Left click to switch between UID display and nick" + Environment.NewLine +
"Right click to change nick for " + entry.UserData.UID);
if (ImGui.IsItemHovered())
{
if (!string.Equals(_lastMouseOverUid, id))
{
_popupTime = DateTime.UtcNow.AddSeconds(_mareConfigService.Current.ProfileDelay);
}
_lastMouseOverUid = id;
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);
}
else
{
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();
UiSharedService.TextWrapped(mareProfile.Profile.Description);
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);
}
}
}
else
{
if (string.Equals(_lastMouseOverUid, id))
{
_lastProfilePicture = Array.Empty<byte>();
_lastMouseOverUid = string.Empty;
_textureWrap?.Dispose();
_textureWrap = null;
}
}
if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
{
var prevState = textIsUid;
if (_showUidForEntry.ContainsKey(entry.UserData.UID))
if (_showUidForEntry.ContainsKey(pair.UserData.UID))
{
prevState = _showUidForEntry[entry.UserData.UID];
prevState = _showUidForEntry[pair.UserData.UID];
}
_showUidForEntry[entry.UserData.UID] = !prevState;
_showUidForEntry[pair.UserData.UID] = !prevState;
}
if (ImGui.IsItemClicked(ImGuiMouseButton.Right))
{
var pair = _pairManager.DirectPairs.Find(p => string.Equals(p.UserData.UID, _editNickEntry, StringComparison.Ordinal));
pair?.SetNote(_editUserComment);
_editUserComment = entry.GetNote() ?? string.Empty;
_editNickEntry = entry.UserData.UID;
var nickEntryPair = _pairManager.DirectPairs.Find(p => string.Equals(p.UserData.UID, _editNickEntry, StringComparison.Ordinal));
nickEntryPair?.SetNote(_editUserComment);
_editUserComment = pair.GetNote() ?? string.Empty;
_editNickEntry = pair.UserData.UID;
}
}
else
@@ -59,7 +192,7 @@ public class UidDisplayHandler
ImGui.SetNextItemWidth(editBoxWidth.Invoke());
if (ImGui.InputTextWithHint("", "Nick/Notes", ref _editUserComment, 255, ImGuiInputTextFlags.EnterReturnsTrue))
{
_serverManager.SetNoteForUid(entry.UserData.UID, _editUserComment);
_serverManager.SetNoteForUid(pair.UserData.UID, _editUserComment);
_serverManager.SaveNotes();
_editNickEntry = string.Empty;
}
@@ -81,7 +214,7 @@ public class UidDisplayHandler
{
if (string.IsNullOrEmpty(playerText))
{
playerText = pair.UserData.UID;
playerText = pair.UserData.AliasOrUID;
}
else
{
@@ -90,7 +223,7 @@ public class UidDisplayHandler
}
else
{
playerText = pair.UserData.UID;
playerText = pair.UserData.AliasOrUID;
}
if (_mareConfigService.Current.ShowCharacterNameInsteadOfNotesForVisible && pair.IsVisible && !showUidInsteadOfName)