From 13409664c3b6bc2f34f2561aa5cc0080cf6fcb7f Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Tue, 7 Dec 2021 06:42:11 -0500 Subject: [PATCH] feat: allow specifying name and overwriting --- Glamaholic/Ui/Helpers/EditorHelper.cs | 5 +++ Glamaholic/Ui/Helpers/ExamineHelper.cs | 29 ++++-------------- Glamaholic/Ui/Helpers/HelperUtil.cs | 42 ++++++++++++++++++-------- Glamaholic/Ui/Helpers/TryOnHelper.cs | 11 ++++++- 4 files changed, 51 insertions(+), 36 deletions(-) diff --git a/Glamaholic/Ui/Helpers/EditorHelper.cs b/Glamaholic/Ui/Helpers/EditorHelper.cs index 96ee3ba..7ba900a 100755 --- a/Glamaholic/Ui/Helpers/EditorHelper.cs +++ b/Glamaholic/Ui/Helpers/EditorHelper.cs @@ -4,6 +4,7 @@ using ImGuiNET; namespace Glamaholic.Ui.Helpers { internal class EditorHelper { private PluginUi Ui { get; } + private string _plateName = string.Empty; internal EditorHelper(PluginUi ui) { this.Ui = ui; @@ -27,6 +28,10 @@ namespace Glamaholic.Ui.Helpers { if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) { this.Ui.OpenMainInterface(); } + + if (HelperUtil.DrawCreatePlateMenu(this.Ui, () => GameFunctions.CurrentPlate, ref this._plateName)) { + this._plateName = string.Empty; + } } } } diff --git a/Glamaholic/Ui/Helpers/ExamineHelper.cs b/Glamaholic/Ui/Helpers/ExamineHelper.cs index 8b7d829..9d50146 100755 --- a/Glamaholic/Ui/Helpers/ExamineHelper.cs +++ b/Glamaholic/Ui/Helpers/ExamineHelper.cs @@ -6,6 +6,7 @@ using ImGuiNET; namespace Glamaholic.Ui.Helpers { internal class ExamineHelper { private PluginUi Ui { get; } + private string _nameInput = string.Empty; internal ExamineHelper(PluginUi ui) { this.Ui = ui; @@ -29,8 +30,11 @@ namespace Glamaholic.Ui.Helpers { if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) { this.Ui.OpenMainInterface(); } - - HelperUtil.DrawCreatePlateMenu(this.Ui, this.GetPlate); + + if (ImGui.IsWindowAppearing()) { + this._nameInput = this.Ui.Plugin.Functions.ExamineName ?? "Copied glamour"; + } + HelperUtil.DrawCreatePlateMenu(this.Ui, GetItems, ref this._nameInput); if (ImGui.Selectable("Try on")) { var items = GetItems(); @@ -70,26 +74,5 @@ namespace Glamaholic.Ui.Helpers { return items; } - - private unsafe SavedPlate? GetPlate() { - var inventory = InventoryManager.Instance()->GetInventoryContainer(InventoryType.Examine); - if (inventory == null) { - return null; - } - - var name = this.Ui.Plugin.Functions.ExamineName; - if (string.IsNullOrEmpty(name)) { - name = "Copied glamour"; - } - - var items = GetItems(); - if (items == null) { - return null; - } - - return new SavedPlate(name) { - Items = items, - }; - } } } diff --git a/Glamaholic/Ui/Helpers/HelperUtil.cs b/Glamaholic/Ui/Helpers/HelperUtil.cs index 78311e1..147f982 100755 --- a/Glamaholic/Ui/Helpers/HelperUtil.cs +++ b/Glamaholic/Ui/Helpers/HelperUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Numerics; using Dalamud.Interface; using Dalamud.Logging; @@ -90,17 +91,27 @@ namespace Glamaholic.Ui.Helpers { ImGui.End(); } - internal static void DrawCreatePlateMenu(PluginUi ui, Func getter) { + internal static bool DrawCreatePlateMenu(PluginUi ui, Func?> getter, ref string nameInput) { + var ret = false; + if (!ImGui.BeginMenu("Create glamour plate")) { - return; + return ret; } - if (ImGui.Selectable("New")) { - var plate = getter(); - if (plate != null) { - CopyToGlamourPlate(ui, plate, -1); + const string msg = "Enter a name and press Enter to create a new plate, or choose a plate below to overwrite."; + ImGui.PushTextWrapPos(250); + if (Util.DrawTextInput("current-name", ref nameInput, message: msg, flags: ImGuiInputTextFlags.AutoSelectAll)) { + var items = getter(); + if (items != null) { + CopyToGlamourPlate(ui, nameInput, items, -1); + ret = true; } } + ImGui.PopTextWrapPos(); + + if (ImGui.IsWindowAppearing()) { + ImGui.SetKeyboardFocusHere(); + } ImGui.Separator(); @@ -109,9 +120,10 @@ namespace Glamaholic.Ui.Helpers { var plate = ui.Plugin.Config.Plates[i]; var ctrl = ImGui.GetIO().KeyCtrl; if (ImGui.Selectable($"{plate.Name}##{i}") && ctrl) { - var newPlate = getter(); - if (newPlate != null) { - CopyToGlamourPlate(ui, newPlate, i); + var items = getter(); + if (items != null) { + CopyToGlamourPlate(ui, plate.Name, items, i); + ret = true; } } @@ -126,14 +138,20 @@ namespace Glamaholic.Ui.Helpers { } ImGui.EndMenu(); + + return ret; } - private static void CopyToGlamourPlate(PluginUi ui, SavedPlate plate, int idx) { + private static void CopyToGlamourPlate(PluginUi ui, string name, Dictionary items, int idx) { + var plate = new SavedPlate(name) { + Items = items, + }; + + Configuration.SanitisePlate(plate); + if (idx == -1) { ui.Plugin.Config.AddPlate(plate); } else { - Configuration.SanitisePlate(plate); - plate.Name = ui.Plugin.Config.Plates[idx].Name; ui.Plugin.Config.Plates[idx] = plate; } ui.Plugin.SaveConfig(); diff --git a/Glamaholic/Ui/Helpers/TryOnHelper.cs b/Glamaholic/Ui/Helpers/TryOnHelper.cs index ebbe79f..e11ca4e 100755 --- a/Glamaholic/Ui/Helpers/TryOnHelper.cs +++ b/Glamaholic/Ui/Helpers/TryOnHelper.cs @@ -8,7 +8,10 @@ using ImGuiNET; namespace Glamaholic.Ui.Helpers { internal class TryOnHelper { + private const string PlateName = "Fitting Room"; + private PluginUi Ui { get; } + private string _nameInput = PlateName; internal TryOnHelper(PluginUi ui) { this.Ui = ui; @@ -34,7 +37,13 @@ namespace Glamaholic.Ui.Helpers { this.Ui.OpenMainInterface(); } - HelperUtil.DrawCreatePlateMenu(this.Ui, () => new SavedPlate("Fitting Room") { Items = GetTryOnItems() }); + if (ImGui.IsWindowAppearing()) { + this._nameInput = PlateName; + } + + if (HelperUtil.DrawCreatePlateMenu(this.Ui, GetTryOnItems, ref this._nameInput)) { + this._nameInput = PlateName; + } } private static unsafe Dictionary GetTryOnItems() {