diff --git a/Glamaholic/Configuration.cs b/Glamaholic/Configuration.cs index a54896c..def3b5a 100755 --- a/Glamaholic/Configuration.cs +++ b/Glamaholic/Configuration.cs @@ -14,14 +14,17 @@ namespace Glamaholic { public bool ShowTryOnMenu = true; public bool ShowKofiButton = true; - internal void AddPlate(SavedPlate plate) { + internal static void SanitisePlate(SavedPlate plate) { var valid = Enum.GetValues(); foreach (var slot in plate.Items.Keys.ToArray()) { if (!valid.Contains(slot)) { plate.Items.Remove(slot); } } + } + internal void AddPlate(SavedPlate plate) { + SanitisePlate(plate); this.Plates.Add(plate); } } diff --git a/Glamaholic/Ui/Helpers/ExamineHelper.cs b/Glamaholic/Ui/Helpers/ExamineHelper.cs index 03e5bf7..8b7d829 100755 --- a/Glamaholic/Ui/Helpers/ExamineHelper.cs +++ b/Glamaholic/Ui/Helpers/ExamineHelper.cs @@ -26,9 +26,11 @@ namespace Glamaholic.Ui.Helpers { } private void DrawDropdown() { - if (ImGui.Selectable("Create glamour plate")) { - this.CopyToGlamourPlate(); + if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) { + this.Ui.OpenMainInterface(); } + + HelperUtil.DrawCreatePlateMenu(this.Ui, this.GetPlate); if (ImGui.Selectable("Try on")) { var items = GetItems(); @@ -69,10 +71,10 @@ namespace Glamaholic.Ui.Helpers { return items; } - private unsafe void CopyToGlamourPlate() { + private unsafe SavedPlate? GetPlate() { var inventory = InventoryManager.Instance()->GetInventoryContainer(InventoryType.Examine); if (inventory == null) { - return; + return null; } var name = this.Ui.Plugin.Functions.ExamineName; @@ -82,17 +84,12 @@ namespace Glamaholic.Ui.Helpers { var items = GetItems(); if (items == null) { - return; + return null; } - var plate = new SavedPlate(name) { + return new SavedPlate(name) { Items = items, }; - - this.Ui.Plugin.Config.AddPlate(plate); - this.Ui.Plugin.SaveConfig(); - this.Ui.OpenMainInterface(); - this.Ui.SwitchPlate(this.Ui.Plugin.Config.Plates.Count - 1, true); } } } diff --git a/Glamaholic/Ui/Helpers/HelperUtil.cs b/Glamaholic/Ui/Helpers/HelperUtil.cs index b0aba80..78311e1 100755 --- a/Glamaholic/Ui/Helpers/HelperUtil.cs +++ b/Glamaholic/Ui/Helpers/HelperUtil.cs @@ -89,5 +89,56 @@ namespace Glamaholic.Ui.Helpers { ImGui.End(); } + + internal static void DrawCreatePlateMenu(PluginUi ui, Func getter) { + if (!ImGui.BeginMenu("Create glamour plate")) { + return; + } + + if (ImGui.Selectable("New")) { + var plate = getter(); + if (plate != null) { + CopyToGlamourPlate(ui, plate, -1); + } + } + + ImGui.Separator(); + + if (ImGui.BeginChild("helper-overwrite", new Vector2(250, 350))) { + for (var i = 0; i < ui.Plugin.Config.Plates.Count; i++) { + 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); + } + } + + if (!ctrl && ImGui.IsItemHovered()) { + ImGui.BeginTooltip(); + ImGui.TextUnformatted("Hold Control and click to overwrite."); + ImGui.EndTooltip(); + } + } + + ImGui.EndChild(); + } + + ImGui.EndMenu(); + } + + private static void CopyToGlamourPlate(PluginUi ui, SavedPlate plate, int idx) { + 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(); + ui.OpenMainInterface(); + ui.SwitchPlate(idx == -1 ? ui.Plugin.Config.Plates.Count - 1 : idx, true); + } } } diff --git a/Glamaholic/Ui/Helpers/TryOnHelper.cs b/Glamaholic/Ui/Helpers/TryOnHelper.cs index 352fa8c..ebbe79f 100755 --- a/Glamaholic/Ui/Helpers/TryOnHelper.cs +++ b/Glamaholic/Ui/Helpers/TryOnHelper.cs @@ -30,15 +30,11 @@ namespace Glamaholic.Ui.Helpers { } private void DrawDropdown() { - if (ImGui.Selectable("Create glamour plate")) { - this.Ui.Plugin.Config.AddPlate(new SavedPlate("Fitting Room") { - Items = GetTryOnItems(), - }); - this.Ui.Plugin.SaveConfig(); - + if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) { this.Ui.OpenMainInterface(); - this.Ui.SwitchPlate(this.Ui.Plugin.Config.Plates.Count - 1, true); } + + HelperUtil.DrawCreatePlateMenu(this.Ui, () => new SavedPlate("Fitting Room") { Items = GetTryOnItems() }); } private static unsafe Dictionary GetTryOnItems() {