feat: allow specifying name and overwriting

This commit is contained in:
Anna 2021-12-07 06:42:11 -05:00
parent aab3bd84ff
commit 13409664c3
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
4 changed files with 51 additions and 36 deletions

View File

@ -4,6 +4,7 @@ using ImGuiNET;
namespace Glamaholic.Ui.Helpers { namespace Glamaholic.Ui.Helpers {
internal class EditorHelper { internal class EditorHelper {
private PluginUi Ui { get; } private PluginUi Ui { get; }
private string _plateName = string.Empty;
internal EditorHelper(PluginUi ui) { internal EditorHelper(PluginUi ui) {
this.Ui = ui; this.Ui = ui;
@ -27,6 +28,10 @@ namespace Glamaholic.Ui.Helpers {
if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) { if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) {
this.Ui.OpenMainInterface(); this.Ui.OpenMainInterface();
} }
if (HelperUtil.DrawCreatePlateMenu(this.Ui, () => GameFunctions.CurrentPlate, ref this._plateName)) {
this._plateName = string.Empty;
}
} }
} }
} }

View File

@ -6,6 +6,7 @@ using ImGuiNET;
namespace Glamaholic.Ui.Helpers { namespace Glamaholic.Ui.Helpers {
internal class ExamineHelper { internal class ExamineHelper {
private PluginUi Ui { get; } private PluginUi Ui { get; }
private string _nameInput = string.Empty;
internal ExamineHelper(PluginUi ui) { internal ExamineHelper(PluginUi ui) {
this.Ui = ui; this.Ui = ui;
@ -29,8 +30,11 @@ namespace Glamaholic.Ui.Helpers {
if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) { if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) {
this.Ui.OpenMainInterface(); 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")) { if (ImGui.Selectable("Try on")) {
var items = GetItems(); var items = GetItems();
@ -70,26 +74,5 @@ namespace Glamaholic.Ui.Helpers {
return items; 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,
};
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Logging; using Dalamud.Logging;
@ -90,17 +91,27 @@ namespace Glamaholic.Ui.Helpers {
ImGui.End(); ImGui.End();
} }
internal static void DrawCreatePlateMenu(PluginUi ui, Func<SavedPlate?> getter) { internal static bool DrawCreatePlateMenu(PluginUi ui, Func<Dictionary<PlateSlot, SavedGlamourItem>?> getter, ref string nameInput) {
var ret = false;
if (!ImGui.BeginMenu("Create glamour plate")) { if (!ImGui.BeginMenu("Create glamour plate")) {
return; return ret;
} }
if (ImGui.Selectable("New")) { const string msg = "Enter a name and press Enter to create a new plate, or choose a plate below to overwrite.";
var plate = getter(); ImGui.PushTextWrapPos(250);
if (plate != null) { if (Util.DrawTextInput("current-name", ref nameInput, message: msg, flags: ImGuiInputTextFlags.AutoSelectAll)) {
CopyToGlamourPlate(ui, plate, -1); var items = getter();
if (items != null) {
CopyToGlamourPlate(ui, nameInput, items, -1);
ret = true;
} }
} }
ImGui.PopTextWrapPos();
if (ImGui.IsWindowAppearing()) {
ImGui.SetKeyboardFocusHere();
}
ImGui.Separator(); ImGui.Separator();
@ -109,9 +120,10 @@ namespace Glamaholic.Ui.Helpers {
var plate = ui.Plugin.Config.Plates[i]; var plate = ui.Plugin.Config.Plates[i];
var ctrl = ImGui.GetIO().KeyCtrl; var ctrl = ImGui.GetIO().KeyCtrl;
if (ImGui.Selectable($"{plate.Name}##{i}") && ctrl) { if (ImGui.Selectable($"{plate.Name}##{i}") && ctrl) {
var newPlate = getter(); var items = getter();
if (newPlate != null) { if (items != null) {
CopyToGlamourPlate(ui, newPlate, i); CopyToGlamourPlate(ui, plate.Name, items, i);
ret = true;
} }
} }
@ -126,14 +138,20 @@ namespace Glamaholic.Ui.Helpers {
} }
ImGui.EndMenu(); ImGui.EndMenu();
return ret;
} }
private static void CopyToGlamourPlate(PluginUi ui, SavedPlate plate, int idx) { private static void CopyToGlamourPlate(PluginUi ui, string name, Dictionary<PlateSlot, SavedGlamourItem> items, int idx) {
var plate = new SavedPlate(name) {
Items = items,
};
Configuration.SanitisePlate(plate);
if (idx == -1) { if (idx == -1) {
ui.Plugin.Config.AddPlate(plate); ui.Plugin.Config.AddPlate(plate);
} else { } else {
Configuration.SanitisePlate(plate);
plate.Name = ui.Plugin.Config.Plates[idx].Name;
ui.Plugin.Config.Plates[idx] = plate; ui.Plugin.Config.Plates[idx] = plate;
} }
ui.Plugin.SaveConfig(); ui.Plugin.SaveConfig();

View File

@ -8,7 +8,10 @@ using ImGuiNET;
namespace Glamaholic.Ui.Helpers { namespace Glamaholic.Ui.Helpers {
internal class TryOnHelper { internal class TryOnHelper {
private const string PlateName = "Fitting Room";
private PluginUi Ui { get; } private PluginUi Ui { get; }
private string _nameInput = PlateName;
internal TryOnHelper(PluginUi ui) { internal TryOnHelper(PluginUi ui) {
this.Ui = ui; this.Ui = ui;
@ -34,7 +37,13 @@ namespace Glamaholic.Ui.Helpers {
this.Ui.OpenMainInterface(); 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<PlateSlot, SavedGlamourItem> GetTryOnItems() { private static unsafe Dictionary<PlateSlot, SavedGlamourItem> GetTryOnItems() {