forked from liza/ARControl
Add 'Check Retainer Inventory' for lists to keep in stock
This commit is contained in:
parent
e78cd642cd
commit
ec256ac090
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
<TargetFramework>net7.0-windows</TargetFramework>
|
||||||
<Version>3.2</Version>
|
<Version>3.3</Version>
|
||||||
<LangVersion>11.0</LangVersion>
|
<LangVersion>11.0</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
@ -36,6 +36,7 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin
|
|||||||
private readonly GameCache _gameCache;
|
private readonly GameCache _gameCache;
|
||||||
private readonly IconCache _iconCache;
|
private readonly IconCache _iconCache;
|
||||||
private readonly VentureResolver _ventureResolver;
|
private readonly VentureResolver _ventureResolver;
|
||||||
|
private readonly AllaganToolsIpc _allaganToolsIpc;
|
||||||
private readonly ConfigWindow _configWindow;
|
private readonly ConfigWindow _configWindow;
|
||||||
private readonly AutoRetainerApi _autoRetainerApi;
|
private readonly AutoRetainerApi _autoRetainerApi;
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin
|
|||||||
_iconCache = new IconCache(textureProvider);
|
_iconCache = new IconCache(textureProvider);
|
||||||
_ventureResolver = new VentureResolver(_gameCache, _pluginLog);
|
_ventureResolver = new VentureResolver(_gameCache, _pluginLog);
|
||||||
DiscardHelperIpc discardHelperIpc = new(_pluginInterface);
|
DiscardHelperIpc discardHelperIpc = new(_pluginInterface);
|
||||||
|
_allaganToolsIpc = new AllaganToolsIpc(pluginInterface, pluginLog);
|
||||||
_configWindow =
|
_configWindow =
|
||||||
new ConfigWindow(_pluginInterface, _configuration, _gameCache, _clientState, _commandManager, _iconCache,
|
new ConfigWindow(_pluginInterface, _configuration, _gameCache, _clientState, _commandManager, _iconCache,
|
||||||
discardHelperIpc, _pluginLog);
|
discardHelperIpc, _pluginLog);
|
||||||
@ -189,8 +191,9 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin
|
|||||||
{
|
{
|
||||||
QueuedItem = x,
|
QueuedItem = x,
|
||||||
InventoryCount = inventoryManager->GetInventoryItemCount(x.ItemId) +
|
InventoryCount = inventoryManager->GetInventoryItemCount(x.ItemId) +
|
||||||
(venturesInProgress.TryGetValue(x.ItemId, out int inProgress)
|
venturesInProgress.GetValueOrDefault(x.ItemId, 0) +
|
||||||
? inProgress
|
(list.CheckRetainerInventory
|
||||||
|
? (int)_allaganToolsIpc.GetRetainerItemCount(x.ItemId)
|
||||||
: 0),
|
: 0),
|
||||||
})
|
})
|
||||||
.Where(x => x.InventoryCount < x.RequestedCount)
|
.Where(x => x.InventoryCount < x.RequestedCount)
|
||||||
|
@ -21,6 +21,7 @@ internal sealed class Configuration : IPluginConfiguration
|
|||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
public required ListType Type { get; set; } = ListType.CollectOneTime;
|
public required ListType Type { get; set; } = ListType.CollectOneTime;
|
||||||
public required ListPriority Priority { get; set; } = ListPriority.InOrder;
|
public required ListPriority Priority { get; set; } = ListPriority.InOrder;
|
||||||
|
public bool CheckRetainerInventory { get; set; }
|
||||||
public List<QueuedItem> Items { get; set; } = new();
|
public List<QueuedItem> Items { get; set; } = new();
|
||||||
|
|
||||||
public string GetIcon()
|
public string GetIcon()
|
||||||
|
48
ARControl/External/AllaganToolsIpc.cs
vendored
Normal file
48
ARControl/External/AllaganToolsIpc.cs
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using Dalamud.Plugin;
|
||||||
|
using Dalamud.Plugin.Ipc;
|
||||||
|
using Dalamud.Plugin.Ipc.Exceptions;
|
||||||
|
using Dalamud.Plugin.Services;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
|
|
||||||
|
namespace ARControl.External;
|
||||||
|
|
||||||
|
public class AllaganToolsIpc
|
||||||
|
{
|
||||||
|
private readonly IPluginLog _pluginLog;
|
||||||
|
|
||||||
|
private static readonly uint[] RetainerInventoryTypes = new[]
|
||||||
|
{
|
||||||
|
InventoryType.RetainerPage1,
|
||||||
|
InventoryType.RetainerPage2,
|
||||||
|
InventoryType.RetainerPage3,
|
||||||
|
InventoryType.RetainerPage4,
|
||||||
|
InventoryType.RetainerPage5,
|
||||||
|
InventoryType.RetainerPage6,
|
||||||
|
InventoryType.RetainerPage7,
|
||||||
|
}
|
||||||
|
.Select(x => (uint)x).ToArray();
|
||||||
|
|
||||||
|
private readonly ICallGateSubscriber<uint, bool, uint[], uint> _itemCountOwned;
|
||||||
|
|
||||||
|
public AllaganToolsIpc(DalamudPluginInterface pluginInterface, IPluginLog pluginLog)
|
||||||
|
{
|
||||||
|
_pluginLog = pluginLog;
|
||||||
|
_itemCountOwned = pluginInterface.GetIpcSubscriber<uint, bool, uint[], uint>("AllaganTools.ItemCountOwned");
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint GetRetainerItemCount(uint itemId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint itemCount = _itemCountOwned.InvokeFunc(itemId, true, RetainerInventoryTypes);
|
||||||
|
_pluginLog.Verbose($"Found {itemCount} items in retainer inventories for itemId {itemId}");
|
||||||
|
return itemCount;
|
||||||
|
}
|
||||||
|
catch (IpcError e)
|
||||||
|
{
|
||||||
|
_pluginLog.Warning("Could not query allagantools for retainer inventory counts");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ using Dalamud.Interface;
|
|||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Components;
|
using Dalamud.Interface.Components;
|
||||||
using Dalamud.Interface.Internal;
|
using Dalamud.Interface.Internal;
|
||||||
|
using Dalamud.Interface.Utility;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using ECommons;
|
using ECommons;
|
||||||
@ -55,7 +56,8 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
{
|
{
|
||||||
Name = string.Empty,
|
Name = string.Empty,
|
||||||
ListType = Configuration.ListType.CollectOneTime,
|
ListType = Configuration.ListType.CollectOneTime,
|
||||||
ListPriority = Configuration.ListPriority.InOrder
|
ListPriority = Configuration.ListPriority.InOrder,
|
||||||
|
CheckRetainerInventory = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
public ConfigWindow(
|
public ConfigWindow(
|
||||||
@ -115,6 +117,7 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
Name = list.Name,
|
Name = list.Name,
|
||||||
ListType = list.Type,
|
ListType = list.Type,
|
||||||
ListPriority = list.Priority,
|
ListPriority = list.Priority,
|
||||||
|
CheckRetainerInventory = list.CheckRetainerInventory,
|
||||||
};
|
};
|
||||||
ImGui.OpenPopup($"##EditList{list.Id}");
|
ImGui.OpenPopup($"##EditList{list.Id}");
|
||||||
}
|
}
|
||||||
@ -163,7 +166,8 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
var (save, canSave) = DrawVentureListEditor(temporaryConfig, list);
|
var (save, canSave) = DrawVentureListEditor(temporaryConfig, list);
|
||||||
ImGui.BeginDisabled(!canSave || (list.Name == temporaryConfig.Name &&
|
ImGui.BeginDisabled(!canSave || (list.Name == temporaryConfig.Name &&
|
||||||
list.Type == temporaryConfig.ListType &&
|
list.Type == temporaryConfig.ListType &&
|
||||||
list.Priority == temporaryConfig.ListPriority));
|
list.Priority == temporaryConfig.ListPriority &&
|
||||||
|
list.CheckRetainerInventory == temporaryConfig.CheckRetainerInventory));
|
||||||
save |= ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Save, "Save");
|
save |= ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Save, "Save");
|
||||||
ImGui.EndDisabled();
|
ImGui.EndDisabled();
|
||||||
|
|
||||||
@ -173,9 +177,15 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
list.Type = temporaryConfig.ListType;
|
list.Type = temporaryConfig.ListType;
|
||||||
|
|
||||||
if (list.Type == Configuration.ListType.CollectOneTime)
|
if (list.Type == Configuration.ListType.CollectOneTime)
|
||||||
|
{
|
||||||
list.Priority = Configuration.ListPriority.InOrder;
|
list.Priority = Configuration.ListPriority.InOrder;
|
||||||
|
list.CheckRetainerInventory = false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
list.Priority = temporaryConfig.ListPriority;
|
list.Priority = temporaryConfig.ListPriority;
|
||||||
|
list.CheckRetainerInventory = temporaryConfig.CheckRetainerInventory;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.CloseCurrentPopup();
|
ImGui.CloseCurrentPopup();
|
||||||
Save();
|
Save();
|
||||||
@ -230,13 +240,15 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
Name = _newList.Name,
|
Name = _newList.Name,
|
||||||
Type = _newList.ListType,
|
Type = _newList.ListType,
|
||||||
Priority = _newList.ListPriority,
|
Priority = _newList.ListPriority,
|
||||||
|
CheckRetainerInventory = _newList.CheckRetainerInventory,
|
||||||
});
|
});
|
||||||
|
|
||||||
_newList = new()
|
_newList = new()
|
||||||
{
|
{
|
||||||
Name = string.Empty,
|
Name = string.Empty,
|
||||||
ListType = Configuration.ListType.CollectOneTime,
|
ListType = Configuration.ListType.CollectOneTime,
|
||||||
ListPriority = Configuration.ListPriority.InOrder
|
ListPriority = Configuration.ListPriority.InOrder,
|
||||||
|
CheckRetainerInventory = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
ImGui.CloseCurrentPopup();
|
ImGui.CloseCurrentPopup();
|
||||||
@ -250,6 +262,7 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
private (bool Save, bool CanSave) DrawVentureListEditor(TemporaryConfig temporaryConfig,
|
private (bool Save, bool CanSave) DrawVentureListEditor(TemporaryConfig temporaryConfig,
|
||||||
Configuration.ItemList? list)
|
Configuration.ItemList? list)
|
||||||
{
|
{
|
||||||
|
ImGui.SetNextItemWidth(375 * ImGuiHelpers.GlobalScale);
|
||||||
string listName = temporaryConfig.Name;
|
string listName = temporaryConfig.Name;
|
||||||
bool save = ImGui.InputTextWithHint("", "List Name...", ref listName, 64,
|
bool save = ImGui.InputTextWithHint("", "List Name...", ref listName, 64,
|
||||||
ImGuiInputTextFlags.EnterReturnsTrue);
|
ImGuiInputTextFlags.EnterReturnsTrue);
|
||||||
@ -257,6 +270,7 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
temporaryConfig.Name = listName;
|
temporaryConfig.Name = listName;
|
||||||
|
|
||||||
ImGui.PushID($"Type{list?.Id ?? Guid.Empty}");
|
ImGui.PushID($"Type{list?.Id ?? Guid.Empty}");
|
||||||
|
ImGui.SetNextItemWidth(375 * ImGuiHelpers.GlobalScale);
|
||||||
int type = (int)temporaryConfig.ListType;
|
int type = (int)temporaryConfig.ListType;
|
||||||
if (ImGui.Combo("", ref type, StockingTypeLabels, StockingTypeLabels.Length))
|
if (ImGui.Combo("", ref type, StockingTypeLabels, StockingTypeLabels.Length))
|
||||||
{
|
{
|
||||||
@ -270,10 +284,18 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
if (temporaryConfig.ListType == Configuration.ListType.KeepStocked)
|
if (temporaryConfig.ListType == Configuration.ListType.KeepStocked)
|
||||||
{
|
{
|
||||||
ImGui.PushID($"Priority{list?.Id ?? Guid.Empty}");
|
ImGui.PushID($"Priority{list?.Id ?? Guid.Empty}");
|
||||||
|
ImGui.SetNextItemWidth(375 * ImGuiHelpers.GlobalScale);
|
||||||
int priority = (int)temporaryConfig.ListPriority;
|
int priority = (int)temporaryConfig.ListPriority;
|
||||||
if (ImGui.Combo("", ref priority, PriorityLabels, PriorityLabels.Length))
|
if (ImGui.Combo("", ref priority, PriorityLabels, PriorityLabels.Length))
|
||||||
temporaryConfig.ListPriority = (Configuration.ListPriority)priority;
|
temporaryConfig.ListPriority = (Configuration.ListPriority)priority;
|
||||||
ImGui.PopID();
|
ImGui.PopID();
|
||||||
|
|
||||||
|
ImGui.PushID($"CheckRetainerInventory{list?.Id ?? Guid.Empty}");
|
||||||
|
bool checkRetainerInventory = temporaryConfig.CheckRetainerInventory;
|
||||||
|
if (ImGui.Checkbox("Check Retainer Inventory for items (requires AllaganTools)",
|
||||||
|
ref checkRetainerInventory))
|
||||||
|
temporaryConfig.CheckRetainerInventory = checkRetainerInventory;
|
||||||
|
ImGui.PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (save, canSave);
|
return (save, canSave);
|
||||||
@ -1038,6 +1060,7 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
Name = "---",
|
Name = "---",
|
||||||
Type = Configuration.ListType.CollectOneTime,
|
Type = Configuration.ListType.CollectOneTime,
|
||||||
Priority = Configuration.ListPriority.InOrder,
|
Priority = Configuration.ListPriority.InOrder,
|
||||||
|
CheckRetainerInventory = false,
|
||||||
}
|
}
|
||||||
}.Concat(_configuration.ItemLists)
|
}.Concat(_configuration.ItemLists)
|
||||||
.Select(x => (x.Id, $"{x.Name} {x.GetIcon()}".TrimEnd(), x)).ToList();
|
.Select(x => (x.Id, $"{x.Name} {x.GetIcon()}".TrimEnd(), x)).ToList();
|
||||||
@ -1303,5 +1326,6 @@ internal sealed class ConfigWindow : LImGui.LWindow
|
|||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
public Configuration.ListType ListType { get; set; }
|
public Configuration.ListType ListType { get; set; }
|
||||||
public Configuration.ListPriority ListPriority { get; set; }
|
public Configuration.ListPriority ListPriority { get; set; }
|
||||||
|
public bool CheckRetainerInventory { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user