feat: allow specifying name and overwriting
This commit is contained in:
parent
aab3bd84ff
commit
13409664c3
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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")) {
|
||||
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<PlateSlot, SavedGlamourItem> 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();
|
||||
|
|
|
@ -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<PlateSlot, SavedGlamourItem> GetTryOnItems() {
|
||||
|
|
Loading…
Reference in New Issue