feat: add try on to examine window

This commit is contained in:
Anna 2021-11-21 02:17:58 -05:00
parent f56c80080c
commit 0fb1c4758d
3 changed files with 85 additions and 55 deletions

View File

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using Glamaholic.Ui;
using Glamaholic.Ui.Helpers;
using ImGuiScene;
@ -65,5 +67,20 @@ namespace Glamaholic {
internal void SwitchPlate(int idx, bool scrollTo = false) {
this.MainInterface.SwitchPlate(idx, scrollTo);
}
internal unsafe void TryOn(IEnumerable<SavedGlamourItem> items) {
void SetTryOnSave(bool save) {
var tryOnAgent = (IntPtr) Framework.Instance()->GetUiModule()->GetAgentModule()->GetAgentByInternalId(AgentId.Tryon);
if (tryOnAgent != IntPtr.Zero) {
*(byte*) (tryOnAgent + 0x2E2) = (byte) (save ? 1 : 0);
}
}
SetTryOnSave(false);
foreach (var mirage in items) {
this.Plugin.Functions.TryOn(mirage.ItemId, mirage.StainId);
SetTryOnSave(true);
}
}
}
}

View File

@ -1,4 +1,5 @@
using Dalamud.Interface;
using System.Collections.Generic;
using Dalamud.Interface;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Component.GUI;
using ImGuiNET;
@ -38,46 +39,14 @@ namespace Glamaholic.Ui.Helpers {
ImGui.SetNextItemWidth(ImGui.CalcTextSize(this.Ui.Plugin.Name).X + ImGui.GetStyle().ItemInnerSpacing.X * 2 + 32 * ImGuiHelpers.GlobalScale);
if (ImGui.BeginCombo("##glamaholic-helper-examine-combo", this.Ui.Plugin.Name)) {
if (ImGui.Selectable("Create glamour plate")) {
void DoIt() {
var inventory = InventoryManager.Instance()->GetInventoryContainer(InventoryType.Examine);
if (inventory == null) {
return;
}
this.CopyToGlamourPlate();
}
var name = this.Ui.Plugin.Functions.ExamineName;
if (string.IsNullOrEmpty(name)) {
name = "Copied glamour";
}
var plate = new SavedPlate(name);
for (var i = 0; i < inventory->Size; i++) {
var item = inventory->Items[i];
var itemId = item.GlamourID;
if (itemId == 0) {
itemId = item.ItemID;
}
if (itemId == 0) {
continue;
}
var stainId = item.Stain;
// TODO: remove this logic in endwalker
var slot = i > 5 ? i - 1 : i;
plate.Items[(PlateSlot) slot] = new SavedGlamourItem {
ItemId = itemId,
StainId = stainId,
};
}
this.Ui.Plugin.Config.AddPlate(plate);
this.Ui.Plugin.SaveConfig();
this.Ui.OpenMainInterface();
this.Ui.SwitchPlate(this.Ui.Plugin.Config.Plates.Count - 1, true);
if (ImGui.Selectable("Try on")) {
var items = GetItems();
if (items != null) {
this.Ui.TryOn(items.Values);
}
DoIt();
}
ImGui.EndCombo();
@ -85,5 +54,62 @@ namespace Glamaholic.Ui.Helpers {
ImGui.End();
}
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;
// TODO: remove this logic in endwalker
var slot = i > 5 ? i - 1 : i;
items[(PlateSlot) slot] = new SavedGlamourItem {
ItemId = itemId,
StainId = stainId,
};
}
return items;
}
private unsafe void CopyToGlamourPlate() {
var inventory = InventoryManager.Instance()->GetInventoryContainer(InventoryType.Examine);
if (inventory == null) {
return;
}
var name = this.Ui.Plugin.Functions.ExamineName;
if (string.IsNullOrEmpty(name)) {
name = "Copied glamour";
}
var items = GetItems();
if (items == null) {
return;
}
var plate = 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);
}
}
}

View File

@ -5,8 +5,6 @@ using System.Linq;
using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using FFXIVClientStructs.FFXIV.Client.System.Framework;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json;
@ -326,7 +324,7 @@ namespace Glamaholic.Ui {
ImGui.EndPopup();
}
private unsafe void DrawItemPopup(string itemPopup, SavedPlate plate, PlateSlot slot) {
if (!ImGui.BeginPopup(itemPopup)) {
return;
@ -485,7 +483,7 @@ namespace Glamaholic.Ui {
ImGui.EndTable();
}
private unsafe void DrawPlateButtons(SavedPlate plate) {
private void DrawPlateButtons(SavedPlate plate) {
if (this._editing || !ImGui.BeginTable("plate buttons", 5, ImGuiTableFlags.SizingFixedFit)) {
return;
}
@ -497,18 +495,7 @@ namespace Glamaholic.Ui {
ImGui.TableNextColumn();
if (Util.IconButton(FontAwesomeIcon.Search, tooltip: "Try on")) {
void SetTryOnSave(bool save) {
var tryOnAgent = (IntPtr) Framework.Instance()->GetUiModule()->GetAgentModule()->GetAgentByInternalId(AgentId.Tryon);
if (tryOnAgent != IntPtr.Zero) {
*(byte*) (tryOnAgent + 0x2E2) = (byte) (save ? 1 : 0);
}
}
SetTryOnSave(false);
foreach (var mirage in plate.Items.Values) {
this.Ui.Plugin.Functions.TryOn(mirage.ItemId, mirage.StainId);
SetTryOnSave(true);
}
this.Ui.TryOn(plate.Items.Values);
}
ImGui.TableNextColumn();