feat: add overwrite to helper menus
This commit is contained in:
parent
6562b1898d
commit
aab3bd84ff
|
@ -14,14 +14,17 @@ namespace Glamaholic {
|
||||||
public bool ShowTryOnMenu = true;
|
public bool ShowTryOnMenu = true;
|
||||||
public bool ShowKofiButton = true;
|
public bool ShowKofiButton = true;
|
||||||
|
|
||||||
internal void AddPlate(SavedPlate plate) {
|
internal static void SanitisePlate(SavedPlate plate) {
|
||||||
var valid = Enum.GetValues<PlateSlot>();
|
var valid = Enum.GetValues<PlateSlot>();
|
||||||
foreach (var slot in plate.Items.Keys.ToArray()) {
|
foreach (var slot in plate.Items.Keys.ToArray()) {
|
||||||
if (!valid.Contains(slot)) {
|
if (!valid.Contains(slot)) {
|
||||||
plate.Items.Remove(slot);
|
plate.Items.Remove(slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void AddPlate(SavedPlate plate) {
|
||||||
|
SanitisePlate(plate);
|
||||||
this.Plates.Add(plate);
|
this.Plates.Add(plate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,12 @@ namespace Glamaholic.Ui.Helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawDropdown() {
|
private void DrawDropdown() {
|
||||||
if (ImGui.Selectable("Create glamour plate")) {
|
if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) {
|
||||||
this.CopyToGlamourPlate();
|
this.Ui.OpenMainInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HelperUtil.DrawCreatePlateMenu(this.Ui, this.GetPlate);
|
||||||
|
|
||||||
if (ImGui.Selectable("Try on")) {
|
if (ImGui.Selectable("Try on")) {
|
||||||
var items = GetItems();
|
var items = GetItems();
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
|
@ -69,10 +71,10 @@ namespace Glamaholic.Ui.Helpers {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void CopyToGlamourPlate() {
|
private unsafe SavedPlate? GetPlate() {
|
||||||
var inventory = InventoryManager.Instance()->GetInventoryContainer(InventoryType.Examine);
|
var inventory = InventoryManager.Instance()->GetInventoryContainer(InventoryType.Examine);
|
||||||
if (inventory == null) {
|
if (inventory == null) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = this.Ui.Plugin.Functions.ExamineName;
|
var name = this.Ui.Plugin.Functions.ExamineName;
|
||||||
|
@ -82,17 +84,12 @@ namespace Glamaholic.Ui.Helpers {
|
||||||
|
|
||||||
var items = GetItems();
|
var items = GetItems();
|
||||||
if (items == null) {
|
if (items == null) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var plate = new SavedPlate(name) {
|
return new SavedPlate(name) {
|
||||||
Items = items,
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,5 +89,56 @@ namespace Glamaholic.Ui.Helpers {
|
||||||
|
|
||||||
ImGui.End();
|
ImGui.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void DrawCreatePlateMenu(PluginUi ui, Func<SavedPlate?> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,15 +30,11 @@ namespace Glamaholic.Ui.Helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawDropdown() {
|
private void DrawDropdown() {
|
||||||
if (ImGui.Selectable("Create glamour plate")) {
|
if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) {
|
||||||
this.Ui.Plugin.Config.AddPlate(new SavedPlate("Fitting Room") {
|
|
||||||
Items = GetTryOnItems(),
|
|
||||||
});
|
|
||||||
this.Ui.Plugin.SaveConfig();
|
|
||||||
|
|
||||||
this.Ui.OpenMainInterface();
|
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<PlateSlot, SavedGlamourItem> GetTryOnItems() {
|
private static unsafe Dictionary<PlateSlot, SavedGlamourItem> GetTryOnItems() {
|
||||||
|
|
Loading…
Reference in New Issue