Files
ClubPenguinClient/MareSynchronos/UI/Handlers/UidDisplayHandler.cs
Loporrit d601b6fcd1 Merge tag '0.9.17' into mare-classic
* tag '0.9.17':
  add census popup on connection
  api update
  census update
  heave fewer redraws as main method for data application, minor fixes
  remove unnecessary exists check
  add visibility for loaded mods size for pair, use menu bar for settings, remove settings button
  fix staging issues
  add download throttling, change header of mare, fix reverting players when going offline/paused when not visible
  use name for glamourer revert
  fix startup breaking
  add inner exception stacktraces
  calc correct button size
  wording
  add permission popup ui
  fix getting identifier during zoning
  indent nonscaled
  remove unnecessary usings
  ui icon boogaloo
  fix cache dict wtf
  add normalized icons
  add owner/moderator/pinned user icons
  check tokentime more precisely in both directions
  more cleanup
  fix sorting and cleanup
  make local groups more usable for pause/resume
  fix outlined font
  rework creation of popout windows into factory and some refactoring in general
  make syncshell admin ui to standalone window
  remove close button on intro ui
  do not allow to open main ui without finishing setup
  readonly bla
  wait for plugin disposal
  fix palette
  wording
  fix palette application and add experimental less redraws option
  some minor fixes
  check for timezone
  idk
  adjust token handling
  fix total user count in syncshell (distinct by UIDs)
  fix text alignment
  fix some shit maybe
  idk some fixes I guess
  fix offset for transfer bar at the bottom, use async collections, clear filter on tab change + add button to clear, require ctrl for align syncshells
  blah
  Some display options for DTR tooltip (#66)
  add ordering
  adjust api to latest
  rework main ui
  add total count on mouseover, make syncshell windows non-blocking
  fix token for character change, add online count to syncshells and groups
  argh
  fix broken font in header
  add more options for the compactui
  fix icons and text of buttons being static in place
  remove logspam
2023-12-08 16:35:14 +00:00

176 lines
6.1 KiB
C#

using Dalamud.Interface;
using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services.ServerConfiguration;
using MareSynchronos.MareConfiguration;
using ImGuiScene;
using MareSynchronos.Services.Mediator;
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;
private TextureWrap? _textureWrap;
public UidDisplayHandler(MareMediator mediator, PairManager pairManager,
ServerConfigurationManager serverManager, MareConfigService mareConfigService)
{
_mediator = mediator;
_pairManager = pairManager;
_serverManager = serverManager;
_mareConfigService = mareConfigService;
}
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;
_textureWrap?.Dispose();
_textureWrap = null;
}
}
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("", "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.ShowCharacterNameInsteadOfNotesForVisible && pair.IsVisible && !showUidInsteadOfName)
{
playerText = pair.PlayerName;
textIsUid = false;
if (_mareConfigService.Current.PreferNotesOverNamesForVisible)
{
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));
}
private bool ShowUidInsteadOfName(Pair pair)
{
_showUidForEntry.TryGetValue(pair.UserData.UID, out var showUidInsteadOfName);
return showUidInsteadOfName;
}
}