Glamaholic/Glamaholic/Ui/Helpers/ExamineHelper.cs

79 lines
2.6 KiB
C#
Raw Normal View History

2021-11-21 07:17:58 +00:00
using System.Collections.Generic;
2021-11-19 17:55:07 +00:00
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET;
namespace Glamaholic.Ui.Helpers {
internal class ExamineHelper {
private PluginUi Ui { get; }
private string _nameInput = string.Empty;
2021-11-19 17:55:07 +00:00
internal ExamineHelper(PluginUi ui) {
this.Ui = ui;
}
internal unsafe void Draw() {
if (!this.Ui.Plugin.Config.ShowExamineMenu) {
return;
}
var examineAddon = (AtkUnitBase*) this.Ui.Plugin.GameGui.GetAddonByName("CharacterInspect", 1);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
2021-11-23 18:41:58 +00:00
if (examineAddon == null || !examineAddon->IsVisible) {
2021-11-19 17:55:07 +00:00
return;
}
2021-11-23 18:41:58 +00:00
HelperUtil.DrawHelper(examineAddon, "glamaholic-helper-examine", false, this.DrawDropdown);
}
2021-11-19 17:55:07 +00:00
2021-11-23 18:41:58 +00:00
private void DrawDropdown() {
2021-12-07 11:19:58 +00:00
if (ImGui.Selectable($"Open {this.Ui.Plugin.Name}")) {
this.Ui.OpenMainInterface();
2021-11-23 18:41:58 +00:00
}
if (ImGui.IsWindowAppearing()) {
this._nameInput = this.Ui.Plugin.Functions.ExamineName ?? "Copied glamour";
}
HelperUtil.DrawCreatePlateMenu(this.Ui, GetItems, ref this._nameInput);
2021-11-19 17:55:07 +00:00
2021-11-23 18:41:58 +00:00
if (ImGui.Selectable("Try on")) {
var items = GetItems();
if (items != null) {
this.Ui.TryOn(items.Values);
2021-11-19 17:55:07 +00:00
}
}
}
2021-11-21 07:17:58 +00:00
private static unsafe Dictionary<PlateSlot, SavedGlamourItem>? GetItems() {
var inventory = InventoryManager.Instance()->GetInventoryContainer(InventoryType.Examine);
if (inventory == null) {
return null;
}
var items = new Dictionary<PlateSlot, SavedGlamourItem>();
for (var i = 0; i < inventory->Size && i < (int) (PlateSlot.LeftRing + 2); i++) {
var item = inventory->Items[i];
var itemId = item.GlamourID;
if (itemId == 0) {
itemId = item.ItemID;
}
if (itemId == 0) {
continue;
}
var stainId = item.Stain;
2021-12-07 01:58:17 +00:00
// for some reason, this still accounts for belts in EW
var slot = i > 5 ? i - 1 : i;
items[(PlateSlot) slot] = new SavedGlamourItem {
2021-11-21 07:17:58 +00:00
ItemId = itemId,
StainId = stainId,
};
}
return items;
}
2021-11-19 17:55:07 +00:00
}
}