Initial
This commit is contained in:
85
MareSynchronos/UI/Handlers/TagHandler.cs
Normal file
85
MareSynchronos/UI/Handlers/TagHandler.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using MareSynchronos.Services.ServerConfiguration;
|
||||
|
||||
namespace MareSynchronos.UI.Handlers;
|
||||
|
||||
public class TagHandler
|
||||
{
|
||||
public const string CustomOfflineTag = "Mare_Offline";
|
||||
public const string CustomOfflineSyncshellTag = "Mare_OfflineSyncshell";
|
||||
public const string CustomOnlineTag = "Mare_Online";
|
||||
public const string CustomUnpairedTag = "Mare_Unpaired";
|
||||
public const string CustomVisibleTag = "Mare_Visible";
|
||||
private readonly ServerConfigurationManager _serverConfigurationManager;
|
||||
|
||||
public TagHandler(ServerConfigurationManager serverConfigurationManager)
|
||||
{
|
||||
_serverConfigurationManager = serverConfigurationManager;
|
||||
}
|
||||
|
||||
public void AddTag(string tag)
|
||||
{
|
||||
_serverConfigurationManager.AddTag(tag);
|
||||
}
|
||||
|
||||
public void AddTagToPairedUid(string uid, string tagName)
|
||||
{
|
||||
_serverConfigurationManager.AddTagForUid(uid, tagName);
|
||||
}
|
||||
|
||||
public List<string> GetAllTagsSorted()
|
||||
{
|
||||
return
|
||||
[
|
||||
.. _serverConfigurationManager.GetServerAvailablePairTags()
|
||||
.OrderBy(s => s, StringComparer.OrdinalIgnoreCase)
|
||||
,
|
||||
];
|
||||
}
|
||||
|
||||
public HashSet<string> GetOtherUidsForTag(string tag)
|
||||
{
|
||||
return _serverConfigurationManager.GetUidsForTag(tag);
|
||||
}
|
||||
|
||||
public bool HasAnyTag(string uid)
|
||||
{
|
||||
return _serverConfigurationManager.HasTags(uid);
|
||||
}
|
||||
|
||||
public bool HasTag(string uid, string tagName)
|
||||
{
|
||||
return _serverConfigurationManager.ContainsTag(uid, tagName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is this tag opened in the paired clients UI?
|
||||
/// </summary>
|
||||
/// <param name="tag">the tag</param>
|
||||
/// <returns>open true/false</returns>
|
||||
public bool IsTagOpen(string tag)
|
||||
{
|
||||
return _serverConfigurationManager.ContainsOpenPairTag(tag);
|
||||
}
|
||||
|
||||
public void RemoveTag(string tag)
|
||||
{
|
||||
_serverConfigurationManager.RemoveTag(tag);
|
||||
}
|
||||
|
||||
public void RemoveTagFromPairedUid(string uid, string tagName)
|
||||
{
|
||||
_serverConfigurationManager.RemoveTagForUid(uid, tagName);
|
||||
}
|
||||
|
||||
public void SetTagOpen(string tag, bool open)
|
||||
{
|
||||
if (open)
|
||||
{
|
||||
_serverConfigurationManager.AddOpenPairTag(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
_serverConfigurationManager.RemoveOpenPairTag(tag);
|
||||
}
|
||||
}
|
||||
}
|
204
MareSynchronos/UI/Handlers/UidDisplayHandler.cs
Normal file
204
MareSynchronos/UI/Handlers/UidDisplayHandler.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using Dalamud.Bindings.ImGui;
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.PlayerData.Pairs;
|
||||
using MareSynchronos.Services.Mediator;
|
||||
using MareSynchronos.Services.ServerConfiguration;
|
||||
using MareSynchronos.UI.Components;
|
||||
|
||||
namespace MareSynchronos.UI.Handlers;
|
||||
|
||||
public class UidDisplayHandler
|
||||
{
|
||||
private readonly MareConfigService _mareConfigService;
|
||||
private readonly MareMediator _mediator;
|
||||
private readonly PairManager _pairManager;
|
||||
private readonly ServerConfigurationManager _serverManager;
|
||||
private readonly Dictionary<string, bool> _showUidForEntry = new(StringComparer.Ordinal);
|
||||
private string _editNickEntry = string.Empty;
|
||||
private string _editUserComment = string.Empty;
|
||||
private string _lastMouseOverUid = string.Empty;
|
||||
private bool _popupShown = false;
|
||||
private DateTime? _popupTime;
|
||||
|
||||
public UidDisplayHandler(MareMediator mediator, PairManager pairManager,
|
||||
ServerConfigurationManager serverManager, MareConfigService mareConfigService)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_pairManager = pairManager;
|
||||
_serverManager = serverManager;
|
||||
_mareConfigService = mareConfigService;
|
||||
}
|
||||
|
||||
public void RenderPairList(IEnumerable<DrawPairBase> pairs)
|
||||
{
|
||||
var textHeight = ImGui.GetFontSize();
|
||||
var style = ImGui.GetStyle();
|
||||
var framePadding = style.FramePadding;
|
||||
var spacing = style.ItemSpacing;
|
||||
var lineHeight = textHeight + framePadding.Y * 2 + spacing.Y;
|
||||
var startY = ImGui.GetCursorStartPos().Y;
|
||||
var cursorY = ImGui.GetCursorPosY();
|
||||
var contentHeight = UiSharedService.GetWindowContentRegionHeight();
|
||||
|
||||
foreach (var entry in pairs)
|
||||
{
|
||||
if ((startY + cursorY) < -lineHeight || (startY + cursorY) > contentHeight)
|
||||
{
|
||||
cursorY += lineHeight;
|
||||
ImGui.SetCursorPosY(cursorY);
|
||||
continue;
|
||||
}
|
||||
|
||||
using (ImRaii.PushId(entry.ImGuiID)) entry.DrawPairedClient();
|
||||
cursorY += lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawPairText(string id, Pair pair, float textPosX, float originalY, Func<float> editBoxWidth)
|
||||
{
|
||||
ImGui.SameLine(textPosX);
|
||||
(bool textIsUid, string playerText) = GetPlayerText(pair);
|
||||
if (!string.Equals(_editNickEntry, pair.UserData.UID, StringComparison.Ordinal))
|
||||
{
|
||||
ImGui.SetCursorPosY(originalY);
|
||||
|
||||
using (ImRaii.PushFont(UiBuilder.MonoFont, textIsUid)) ImGui.TextUnformatted(playerText);
|
||||
|
||||
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 + Environment.NewLine
|
||||
+ "Middle Mouse Button to open their profile in a separate window");
|
||||
}
|
||||
else if (_popupTime < DateTime.UtcNow && !_popupShown)
|
||||
{
|
||||
_popupShown = true;
|
||||
_mediator.Publish(new ProfilePopoutToggle(pair));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.Equals(_lastMouseOverUid, id))
|
||||
{
|
||||
_mediator.Publish(new ProfilePopoutToggle(null));
|
||||
_lastMouseOverUid = string.Empty;
|
||||
_popupShown = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
|
||||
{
|
||||
var prevState = textIsUid;
|
||||
if (_showUidForEntry.ContainsKey(pair.UserData.UID))
|
||||
{
|
||||
prevState = _showUidForEntry[pair.UserData.UID];
|
||||
}
|
||||
_showUidForEntry[pair.UserData.UID] = !prevState;
|
||||
}
|
||||
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Right))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Middle))
|
||||
{
|
||||
_mediator.Publish(new ProfileOpenStandaloneMessage(pair));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.SetCursorPosY(originalY);
|
||||
|
||||
ImGui.SetNextItemWidth(editBoxWidth.Invoke());
|
||||
if (ImGui.InputTextWithHint("##" + pair.UserData.UID, "Nick/Notes", ref _editUserComment, 255, ImGuiInputTextFlags.EnterReturnsTrue))
|
||||
{
|
||||
_serverManager.SetNoteForUid(pair.UserData.UID, _editUserComment);
|
||||
_serverManager.SaveNotes();
|
||||
_editNickEntry = string.Empty;
|
||||
}
|
||||
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Right))
|
||||
{
|
||||
_editNickEntry = string.Empty;
|
||||
}
|
||||
UiSharedService.AttachToolTip("Hit ENTER to save\nRight click to cancel");
|
||||
}
|
||||
}
|
||||
|
||||
public (bool isUid, string text) GetPlayerText(Pair pair)
|
||||
{
|
||||
var textIsUid = true;
|
||||
bool showUidInsteadOfName = ShowUidInsteadOfName(pair);
|
||||
string? playerText = _serverManager.GetNoteForUid(pair.UserData.UID);
|
||||
if (!showUidInsteadOfName && playerText != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(playerText))
|
||||
{
|
||||
playerText = pair.UserData.AliasOrUID;
|
||||
}
|
||||
else
|
||||
{
|
||||
textIsUid = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
playerText = pair.UserData.AliasOrUID;
|
||||
}
|
||||
|
||||
if (_mareConfigService.Current.ShowCharacterNames && textIsUid && !showUidInsteadOfName)
|
||||
{
|
||||
var name = pair.PlayerName;
|
||||
if (name != null)
|
||||
{
|
||||
playerText = name;
|
||||
textIsUid = false;
|
||||
var note = pair.GetNote();
|
||||
if (note != null)
|
||||
{
|
||||
playerText = note;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (textIsUid, playerText!);
|
||||
}
|
||||
|
||||
internal void Clear()
|
||||
{
|
||||
_editNickEntry = string.Empty;
|
||||
_editUserComment = string.Empty;
|
||||
}
|
||||
|
||||
internal void OpenProfile(Pair entry)
|
||||
{
|
||||
_mediator.Publish(new ProfileOpenStandaloneMessage(entry));
|
||||
}
|
||||
|
||||
internal void OpenAnalysis(Pair entry)
|
||||
{
|
||||
_mediator.Publish(new OpenPairAnalysisWindow(entry));
|
||||
}
|
||||
|
||||
private bool ShowUidInsteadOfName(Pair pair)
|
||||
{
|
||||
_showUidForEntry.TryGetValue(pair.UserData.UID, out var showUidInsteadOfName);
|
||||
|
||||
return showUidInsteadOfName;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user