From 0599416f4cc7a73ecc9dc1c2ac7106fece9aeefe Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Thu, 6 Oct 2022 22:22:53 +0200 Subject: [PATCH] add note handling --- MareSynchronos/Configuration.cs | 1 + MareSynchronos/UI/CompactUI.cs | 39 ++++++++++++++++++- MareSynchronos/UI/SettingsUi.cs | 30 ++++++++------ .../ApiController.Functions.Callbacks.cs | 3 ++ 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/MareSynchronos/Configuration.cs b/MareSynchronos/Configuration.cs index 36e2ffd..b121c63 100644 --- a/MareSynchronos/Configuration.cs +++ b/MareSynchronos/Configuration.cs @@ -89,6 +89,7 @@ public class Configuration : IPluginConfiguration public int Version { get; set; } = 5; public bool ShowTransferWindow { get; set; } = true; + public bool OpenPopupOnAdd { get; set; } = false; // the below exist just to make saving less cumbersome public void Initialize(DalamudPluginInterface pluginInterface) diff --git a/MareSynchronos/UI/CompactUI.cs b/MareSynchronos/UI/CompactUI.cs index d0162c1..9176fdd 100644 --- a/MareSynchronos/UI/CompactUI.cs +++ b/MareSynchronos/UI/CompactUI.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Linq; using System.Numerics; using System.Reflection; +using System.Runtime.Serialization.Formatters; using Dalamud.Interface; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; @@ -36,10 +37,12 @@ public class CompactUi : Window, IDisposable public float TransferPartHeight = 0; public float _windowContentWidth = 0; - + private bool _showModalForUserAddition = false; private bool showSyncShells = false; private GroupPanel groupPanel; + private ClientPairDto? _lastAddedUser; + private string _lastAddedUserComment = string.Empty; public CompactUi(WindowSystem windowSystem, UiShared uiShared, Configuration configuration, ApiController apiController) : base("###MareSynchronosMainUI") @@ -89,6 +92,8 @@ public class CompactUi : Window, IDisposable public override void Draw() { + _showModalForUserAddition = _configuration.OpenPopupOnAdd; + _windowContentWidth = UiShared.GetWindowContentRegionWidth(); UiShared.DrawWithID("header", DrawUIDHeader); ImGui.Separator(); @@ -147,6 +152,38 @@ public class CompactUi : Window, IDisposable UiShared.DrawWithID("transfers", DrawTransfers); TransferPartHeight = ImGui.GetCursorPosY() - TransferPartHeight; } + + if (_showModalForUserAddition && _apiController.LastAddedUser != null) + { + _lastAddedUser = _apiController.LastAddedUser; + _apiController.LastAddedUser = null; + ImGui.OpenPopup("Set Notes for New User"); + _showModalForUserAddition = true; + _lastAddedUserComment = string.Empty; + } + + if (ImGui.BeginPopupModal("Set Notes for New User", ref _showModalForUserAddition, ImGuiWindowFlags.AlwaysAutoResize)) + { + if (_lastAddedUser == null) + { + _showModalForUserAddition = false; + } + else + { + var uid = string.IsNullOrEmpty(_lastAddedUser!.VanityUID) ? _lastAddedUser.OtherUID : _lastAddedUser.VanityUID; + UiShared.TextWrapped($"You have successfully added {uid}. Set a local note for the user in the field below:"); + ImGui.InputTextWithHint("##noteforuser", $"Note for {uid}", ref _lastAddedUserComment, 100); + if (UiShared.IconTextButton(FontAwesomeIcon.Save, "Save Note")) + { + _configuration.SetCurrentServerUidComment(_lastAddedUser.OtherUID, _lastAddedUserComment); + _lastAddedUser = null; + _lastAddedUserComment = string.Empty; + _configuration.Save(); + _showModalForUserAddition = false; + } + } + ImGui.EndPopup(); + } } public override void OnClose() diff --git a/MareSynchronos/UI/SettingsUi.cs b/MareSynchronos/UI/SettingsUi.cs index 480b2ad..cbfb3ab 100644 --- a/MareSynchronos/UI/SettingsUi.cs +++ b/MareSynchronos/UI/SettingsUi.cs @@ -11,7 +11,6 @@ using System.Threading.Tasks; using MareSynchronos.API; using MareSynchronos.Utils; using MareSynchronos.WebAPI.Utils; -using System.Diagnostics; using Dalamud.Utility; namespace MareSynchronos.UI; @@ -27,6 +26,7 @@ public class SettingsUi : Window, IDisposable private bool _overwriteExistingLabels = false; private bool? _notesSuccessfullyApplied = null; private string _lastTab = string.Empty; + private bool _openPopupOnAddition; public SettingsUi(WindowSystem windowSystem, UiShared uiShared, Configuration configuration, ApiController apiController) : base("Mare Synchronos Settings") @@ -43,6 +43,7 @@ public class SettingsUi : Window, IDisposable _windowSystem = windowSystem; _apiController = apiController; _uiShared = uiShared; + _openPopupOnAddition = _configuration.OpenPopupOnAdd; windowSystem.AddWindow(this); } @@ -73,6 +74,12 @@ public class SettingsUi : Window, IDisposable ImGui.Separator(); if (ImGui.BeginTabBar("mainTabBar")) { + if (ImGui.BeginTabItem("General")) + { + DrawGeneral(); + ImGui.EndTabItem(); + } + if (ImGui.BeginTabItem("Cache Settings")) { DrawFileCacheSettings(); @@ -100,12 +107,6 @@ public class SettingsUi : Window, IDisposable ImGui.EndTabItem(); } - if (ImGui.BeginTabItem("Privacy")) - { - DrawPrivacy(); - ImGui.EndTabItem(); - } - if (_apiController.IsConnected && _apiController.IsModerator) { if (ImGui.BeginTabItem("Administration")) @@ -124,14 +125,14 @@ public class SettingsUi : Window, IDisposable private string _bannedUserHashEntry = string.Empty; private string _bannedUserReasonEntry = string.Empty; - private void DrawPrivacy() + private void DrawGeneral() { - if (!string.Equals(_lastTab, "Privacy", StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(_lastTab, "General", StringComparison.OrdinalIgnoreCase)) { _notesSuccessfullyApplied = null; } - _lastTab = "Privacy"; + _lastTab = "General"; if (UiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Export all your user notes to clipboard")) { ImGui.SetClipboardText(_uiShared.GetNotes()); @@ -154,10 +155,15 @@ public class SettingsUi : Window, IDisposable { UiShared.ColorTextWrapped("Attempt to import notes from clipboard failed. Check formatting and try again", ImGuiColors.DalamudRed); } + ImGui.Separator(); + if (ImGui.Checkbox("Open Notes Popup on user addition", ref _openPopupOnAddition)) + { + _configuration.OpenPopupOnAdd = _openPopupOnAddition; + _configuration.Save(); + } + UiShared.DrawHelpText("This will open a popup that allows you to set the notes for a user after successfully adding them to your individual pairs."); } - - private void DrawAdministration() { _lastTab = "Administration"; diff --git a/MareSynchronos/WebAPI/ApiController.Functions.Callbacks.cs b/MareSynchronos/WebAPI/ApiController.Functions.Callbacks.cs index 7a5edef..c4b792e 100644 --- a/MareSynchronos/WebAPI/ApiController.Functions.Callbacks.cs +++ b/MareSynchronos/WebAPI/ApiController.Functions.Callbacks.cs @@ -10,6 +10,8 @@ namespace MareSynchronos.WebAPI; public partial class ApiController { + public ClientPairDto? LastAddedUser { get; set; } + private void UserForcedReconnectCallback() { _ = CreateConnections(); @@ -25,6 +27,7 @@ public partial class ApiController } if (entry == null) { + LastAddedUser = dto; PairedClients.Add(dto); return; }