Slight popup refactoring

This commit is contained in:
RisaDev
2024-02-04 23:36:59 +03:00
parent cc122c6b7b
commit f2456ef920
6 changed files with 53 additions and 23 deletions

View File

@@ -29,11 +29,9 @@ public class FantasiaPlusDetectService : IDisposable
_popupSystem = popupSystem;
_logger = logger;
_popupSystem.RegisterPopup("fantasia_detected_warn", "Customize+ detected that you have Fantasia+ installed.\nPlease delete or turn it off and restart your game to use Customize+.");
if (CheckFantasiaPlusPresence())
{
_popupSystem.ShowPopup("fantasia_detected_warn");
_popupSystem.ShowPopup(PopupSystem.Messages.FantasiaPlusDetected);
_logger.Error("Fantasia+ detected during startup, plugin will be locked");
}
else
@@ -62,7 +60,7 @@ public class FantasiaPlusDetectService : IDisposable
{
if (CheckFantasiaPlusPresence())
{
_popupSystem.ShowPopup("fantasia_detected_warn");
_popupSystem.ShowPopup(PopupSystem.Messages.FantasiaPlusDetected);
_checkTimer!.Stop();
_checkTimer?.Dispose();
_logger.Error("Fantasia+ detected by timer, plugin will be locked");

View File

@@ -51,11 +51,6 @@ public class IPCTestTab //: IDisposable
_gameObjectService = gameObjectService;
_actorManager = actorManager;
_popupSystem.RegisterPopup("ipc_v4_profile_remembered", "Current profile has been copied into memory");
_popupSystem.RegisterPopup("ipc_get_profile_from_character_remembered", "GetProfileFromCharacter result has been copied into memory");
_popupSystem.RegisterPopup("ipc_set_profile_to_character_done", "SetProfileToCharacter has been called with data from memory");
_popupSystem.RegisterPopup("ipc_revert_done", "Revert has been called");
_getApiVersion = pluginInterface.GetIpcSubscriber<(int, int)>("CustomizePlus.GetApiVersion");
_apiVersion = _getApiVersion.InvokeFunc();
@@ -105,7 +100,7 @@ public class IPCTestTab //: IDisposable
return;
_rememberedProfileJson = JsonConvert.SerializeObject(V4ProfileToV3Converter.Convert(profile));
_popupSystem.ShowPopup("ipc_v4_profile_remembered");
_popupSystem.ShowPopup(PopupSystem.Messages.IPCV4ProfileRemembered);
}
if (ImGui.Button("GetProfileFromCharacter into memory"))
@@ -115,7 +110,7 @@ public class IPCTestTab //: IDisposable
return;
_rememberedProfileJson = _getProfileFromCharacter!.InvokeFunc(FindCharacterByAddress(actors[0].Item2.Address));
_popupSystem.ShowPopup("ipc_get_profile_from_character_remembered");
_popupSystem.ShowPopup(PopupSystem.Messages.IPCGetProfileFromChrRemembered);
}
using (var disabled = ImRaii.Disabled(_rememberedProfileJson == null))
@@ -127,7 +122,7 @@ public class IPCTestTab //: IDisposable
return;
_setCharacterProfile!.InvokeAction(_rememberedProfileJson, FindCharacterByAddress(actors[0].Item2.Address));
_popupSystem.ShowPopup("ipc_set_profile_to_character_done");
_popupSystem.ShowPopup(PopupSystem.Messages.IPCSetProfileToChrDone);
}
}
@@ -138,7 +133,7 @@ public class IPCTestTab //: IDisposable
return;
_revertCharacter!.InvokeAction(FindCharacterByAddress(actors[0].Item2.Address));
_popupSystem.ShowPopup("ipc_revert_done");
_popupSystem.ShowPopup(PopupSystem.Messages.IPCRevertDone);
}
}

View File

@@ -94,8 +94,6 @@ public class TemplateFileSystemSelector : FileSystemSelector<Template, TemplateS
_logger = logger;
_popupSystem = popupSystem;
_popupSystem.RegisterPopup("template_editor_active_warn", "You need to stop bone editing before doing this action"/*, false, new Vector2(5, 12)*/);
_popupSystem.RegisterPopup("clipboard_data_unsupported_version", "Clipboard data you are trying to use cannot be used in this version of Customize+.");
_templateChangedEvent.Subscribe(OnTemplateChange, TemplateChanged.Priority.TemplateFileSystemSelector);
_profileChangedEvent.Subscribe(OnProfileChange, ProfileChanged.Priority.TemplateFileSystemSelector);
@@ -157,7 +155,7 @@ public class TemplateFileSystemSelector : FileSystemSelector<Template, TemplateS
private void ShowEditorWarningPopup()
{
_popupSystem.ShowPopup("template_editor_active_warn");
_popupSystem.ShowPopup(PopupSystem.Messages.TemplateEditorActiveWarning);
}
private void DrawNewTemplatePopup()
@@ -181,7 +179,7 @@ public class TemplateFileSystemSelector : FileSystemSelector<Template, TemplateS
if (template is Template tpl && tpl != null)
_templateManager.Clone(tpl, _newName, true);
else
_popupSystem.ShowPopup("clipboard_data_unsupported_version");
_popupSystem.ShowPopup(PopupSystem.Messages.ClipboardDataUnsupported);
}
else if (_cloneTemplate != null)
{
@@ -195,7 +193,7 @@ public class TemplateFileSystemSelector : FileSystemSelector<Template, TemplateS
catch(Exception ex)
{
_logger.Error($"Error while performing clipboard/clone/create template action: {ex}");
_popupSystem.ShowPopup("action_error");
_popupSystem.ShowPopup(PopupSystem.Messages.ActionError);
}
finally
{

View File

@@ -51,7 +51,6 @@ public class TemplatePanel
_popupSystem = popupSystem;
_logger = logger;
_popupSystem.RegisterPopup("clipboard_data_not_longterm", "Warning: clipboard data is not designed to be used as long-term way of storing your templates.\nCompatibility of copied data between different Customize+ versions is not guaranteed.", true, new Vector2(5, 10));
}
public void Draw()
@@ -225,12 +224,12 @@ public class TemplatePanel
try
{
Clipboard.SetText(Base64Helper.ExportToBase64(_selector.Selected!, Constants.ConfigurationVersion));
_popupSystem.ShowPopup("clipboard_data_not_longterm");
_popupSystem.ShowPopup(PopupSystem.Messages.ClipboardDataNotLongTerm);
}
catch (Exception ex)
{
_logger.Error($"Could not copy data from template {_selector.Selected!.UniqueId} to clipboard: {ex}");
_popupSystem.ShowPopup("action_error");
_popupSystem.ShowPopup(PopupSystem.Messages.ActionError);
}
}
}

View File

@@ -0,0 +1,40 @@
using System.Numerics;
namespace CustomizePlus.UI.Windows;
public partial class PopupSystem
{
public static class Messages
{
public const string ActionError = "action_error";
public const string FantasiaPlusDetected = "fantasia_detected_warn";
public const string IPCV4ProfileRemembered = "ipc_v4_profile_remembered";
public const string IPCGetProfileFromChrRemembered = "ipc_get_profile_from_character_remembered";
public const string IPCSetProfileToChrDone = "ipc_set_profile_to_character_done";
public const string IPCRevertDone = "ipc_revert_done";
public const string TemplateEditorActiveWarning = "template_editor_active_warn";
public const string ClipboardDataUnsupported = "clipboard_data_unsupported_version";
public const string ClipboardDataNotLongTerm = "clipboard_data_not_longterm";
}
private void RegisterMessages()
{
RegisterPopup(Messages.ActionError, "Error while performing selected action.\nDetails have been printed to Dalamud log (/xllog in chat).");
RegisterPopup(Messages.FantasiaPlusDetected, "Customize+ detected that you have Fantasia+ installed.\nPlease delete or turn it off and restart your game to use Customize+.");
RegisterPopup(Messages.IPCV4ProfileRemembered, "Current profile has been copied into memory");
RegisterPopup(Messages.IPCGetProfileFromChrRemembered, "GetProfileFromCharacter result has been copied into memory");
RegisterPopup(Messages.IPCSetProfileToChrDone, "SetProfileToCharacter has been called with data from memory");
RegisterPopup(Messages.IPCRevertDone, "Revert has been called");
RegisterPopup(Messages.TemplateEditorActiveWarning, "You need to stop bone editing before doing this action");
RegisterPopup(Messages.ClipboardDataUnsupported, "Clipboard data you are trying to use cannot be used in this version of Customize+.");
RegisterPopup(Messages.ClipboardDataNotLongTerm, "Warning: clipboard data is not designed to be used as long-term way of storing your templates.\nCompatibility of copied data between different Customize+ versions is not guaranteed.", true, new Vector2(5, 10));
}
}

View File

@@ -10,7 +10,7 @@ using CustomizePlus.Configuration.Data;
namespace CustomizePlus.UI.Windows;
public class PopupSystem
public partial class PopupSystem
{
private readonly Logger _logger;
private readonly PluginConfiguration _configuration;
@@ -23,7 +23,7 @@ public class PopupSystem
_logger = logger;
_configuration = configuration;
RegisterPopup("action_error", "Error while performing selected action.\nDetails have been printed to Dalamud log (/xllog in chat).");
RegisterMessages();
}
public void RegisterPopup(string name, string text, bool displayOnce = false, Vector2? sizeDividers = null)