add note handling

This commit is contained in:
Stanley Dimant
2022-10-06 22:22:53 +02:00
parent 58ad7153d3
commit 0599416f4c
4 changed files with 60 additions and 13 deletions

View File

@@ -89,6 +89,7 @@ public class Configuration : IPluginConfiguration
public int Version { get; set; } = 5; public int Version { get; set; } = 5;
public bool ShowTransferWindow { get; set; } = true; public bool ShowTransferWindow { get; set; } = true;
public bool OpenPopupOnAdd { get; set; } = false;
// the below exist just to make saving less cumbersome // the below exist just to make saving less cumbersome
public void Initialize(DalamudPluginInterface pluginInterface) public void Initialize(DalamudPluginInterface pluginInterface)

View File

@@ -5,6 +5,7 @@ using System.Globalization;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Reflection; using System.Reflection;
using System.Runtime.Serialization.Formatters;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Components; using Dalamud.Interface.Components;
@@ -36,10 +37,12 @@ public class CompactUi : Window, IDisposable
public float TransferPartHeight = 0; public float TransferPartHeight = 0;
public float _windowContentWidth = 0; public float _windowContentWidth = 0;
private bool _showModalForUserAddition = false;
private bool showSyncShells = false; private bool showSyncShells = false;
private GroupPanel groupPanel; private GroupPanel groupPanel;
private ClientPairDto? _lastAddedUser;
private string _lastAddedUserComment = string.Empty;
public CompactUi(WindowSystem windowSystem, public CompactUi(WindowSystem windowSystem,
UiShared uiShared, Configuration configuration, ApiController apiController) : base("###MareSynchronosMainUI") UiShared uiShared, Configuration configuration, ApiController apiController) : base("###MareSynchronosMainUI")
@@ -89,6 +92,8 @@ public class CompactUi : Window, IDisposable
public override void Draw() public override void Draw()
{ {
_showModalForUserAddition = _configuration.OpenPopupOnAdd;
_windowContentWidth = UiShared.GetWindowContentRegionWidth(); _windowContentWidth = UiShared.GetWindowContentRegionWidth();
UiShared.DrawWithID("header", DrawUIDHeader); UiShared.DrawWithID("header", DrawUIDHeader);
ImGui.Separator(); ImGui.Separator();
@@ -147,6 +152,38 @@ public class CompactUi : Window, IDisposable
UiShared.DrawWithID("transfers", DrawTransfers); UiShared.DrawWithID("transfers", DrawTransfers);
TransferPartHeight = ImGui.GetCursorPosY() - TransferPartHeight; 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() public override void OnClose()

View File

@@ -11,7 +11,6 @@ using System.Threading.Tasks;
using MareSynchronos.API; using MareSynchronos.API;
using MareSynchronos.Utils; using MareSynchronos.Utils;
using MareSynchronos.WebAPI.Utils; using MareSynchronos.WebAPI.Utils;
using System.Diagnostics;
using Dalamud.Utility; using Dalamud.Utility;
namespace MareSynchronos.UI; namespace MareSynchronos.UI;
@@ -27,6 +26,7 @@ public class SettingsUi : Window, IDisposable
private bool _overwriteExistingLabels = false; private bool _overwriteExistingLabels = false;
private bool? _notesSuccessfullyApplied = null; private bool? _notesSuccessfullyApplied = null;
private string _lastTab = string.Empty; private string _lastTab = string.Empty;
private bool _openPopupOnAddition;
public SettingsUi(WindowSystem windowSystem, public SettingsUi(WindowSystem windowSystem,
UiShared uiShared, Configuration configuration, ApiController apiController) : base("Mare Synchronos Settings") UiShared uiShared, Configuration configuration, ApiController apiController) : base("Mare Synchronos Settings")
@@ -43,6 +43,7 @@ public class SettingsUi : Window, IDisposable
_windowSystem = windowSystem; _windowSystem = windowSystem;
_apiController = apiController; _apiController = apiController;
_uiShared = uiShared; _uiShared = uiShared;
_openPopupOnAddition = _configuration.OpenPopupOnAdd;
windowSystem.AddWindow(this); windowSystem.AddWindow(this);
} }
@@ -73,6 +74,12 @@ public class SettingsUi : Window, IDisposable
ImGui.Separator(); ImGui.Separator();
if (ImGui.BeginTabBar("mainTabBar")) if (ImGui.BeginTabBar("mainTabBar"))
{ {
if (ImGui.BeginTabItem("General"))
{
DrawGeneral();
ImGui.EndTabItem();
}
if (ImGui.BeginTabItem("Cache Settings")) if (ImGui.BeginTabItem("Cache Settings"))
{ {
DrawFileCacheSettings(); DrawFileCacheSettings();
@@ -100,12 +107,6 @@ public class SettingsUi : Window, IDisposable
ImGui.EndTabItem(); ImGui.EndTabItem();
} }
if (ImGui.BeginTabItem("Privacy"))
{
DrawPrivacy();
ImGui.EndTabItem();
}
if (_apiController.IsConnected && _apiController.IsModerator) if (_apiController.IsConnected && _apiController.IsModerator)
{ {
if (ImGui.BeginTabItem("Administration")) if (ImGui.BeginTabItem("Administration"))
@@ -124,14 +125,14 @@ public class SettingsUi : Window, IDisposable
private string _bannedUserHashEntry = string.Empty; private string _bannedUserHashEntry = string.Empty;
private string _bannedUserReasonEntry = 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; _notesSuccessfullyApplied = null;
} }
_lastTab = "Privacy"; _lastTab = "General";
if (UiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Export all your user notes to clipboard")) if (UiShared.IconTextButton(FontAwesomeIcon.StickyNote, "Export all your user notes to clipboard"))
{ {
ImGui.SetClipboardText(_uiShared.GetNotes()); ImGui.SetClipboardText(_uiShared.GetNotes());
@@ -154,9 +155,14 @@ public class SettingsUi : Window, IDisposable
{ {
UiShared.ColorTextWrapped("Attempt to import notes from clipboard failed. Check formatting and try again", ImGuiColors.DalamudRed); 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() private void DrawAdministration()
{ {

View File

@@ -10,6 +10,8 @@ namespace MareSynchronos.WebAPI;
public partial class ApiController public partial class ApiController
{ {
public ClientPairDto? LastAddedUser { get; set; }
private void UserForcedReconnectCallback() private void UserForcedReconnectCallback()
{ {
_ = CreateConnections(); _ = CreateConnections();
@@ -25,6 +27,7 @@ public partial class ApiController
} }
if (entry == null) if (entry == null)
{ {
LastAddedUser = dto;
PairedClients.Add(dto); PairedClients.Add(dto);
return; return;
} }