diff --git a/Deliveroo/Configuration.cs b/Deliveroo/Configuration.cs index 609c340..d7764d2 100644 --- a/Deliveroo/Configuration.cs +++ b/Deliveroo/Configuration.cs @@ -11,10 +11,13 @@ namespace Deliveroo; internal sealed class Configuration : IPluginConfiguration { - public int Version { get; set; } = 1; + public int Version { get; set; } = 2; - public List ItemsAvailableForPurchase { get; set; } = new(); - public List ItemsToPurchase { get; set; } = new(); + [Obsolete] + public List ItemsAvailableForPurchase { get; set; } = []; + + public List ItemsAvailableToPurchase { get; set; } = []; + public List ItemsToPurchase { get; set; } = []; public int ReservedSealCount { get; set; } public bool ReserveDifferentSealCountAtMaxRank { get; set; } @@ -29,6 +32,13 @@ internal sealed class Configuration : IPluginConfiguration public WindowConfig TurnInWindowConfig { get; } = new(); public WindowConfig ConfigWindowConfig { get; } = new(); + internal sealed class PurchaseOption + { + public uint ItemId { get; set; } + public bool SameQuantityForAllLists { get; set; } + public int GlobalLimit { get; set; } + } + internal sealed class PurchasePriority { [JsonIgnore] @@ -59,9 +69,9 @@ internal sealed class Configuration : IPluginConfiguration public bool AddVentureIfNoItemToPurchaseSelected() { - if (ItemsAvailableForPurchase.Count == 0) + if (ItemsAvailableToPurchase.Count == 0) { - ItemsAvailableForPurchase.Add(ItemIds.Venture); + ItemsAvailableToPurchase.Add(new PurchaseOption { ItemId = ItemIds.Venture }); return true; } diff --git a/Deliveroo/Deliveroo.csproj b/Deliveroo/Deliveroo.csproj index e7c34e7..504b226 100644 --- a/Deliveroo/Deliveroo.csproj +++ b/Deliveroo/Deliveroo.csproj @@ -1,6 +1,6 @@ - 5.3 + 5.4 dist diff --git a/Deliveroo/DeliverooPlugin.cs b/Deliveroo/DeliverooPlugin.cs index 6c9a8e6..b9c3d5f 100644 --- a/Deliveroo/DeliverooPlugin.cs +++ b/Deliveroo/DeliverooPlugin.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Dalamud.Game.Addon.Lifecycle; using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Objects; @@ -74,6 +75,8 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin _keyState = keyState; _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration(); + MigrateConfiguration(); + _gameStrings = new GameStrings(dataManager, _pluginLog); _externalPluginHandler = new ExternalPluginHandler(_pluginInterface, gameConfig, _configuration, _pluginLog); _gameFunctions = new GameFunctions(objectTable, _clientState, targetManager, dataManager, @@ -114,6 +117,23 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin _addonLifecycle.RegisterListener(AddonEvent.PostSetup, "GrandCompanySupplyReward", GrandCompanySupplyRewardPostSetup); } + private void MigrateConfiguration() + { +#pragma warning disable CS0612 // Type or member is obsolete + if (_configuration.Version == 1) + { + _configuration.ItemsAvailableToPurchase = _configuration.ItemsAvailableForPurchase.Select(x => + new Configuration.PurchaseOption + { + ItemId = x, + SameQuantityForAllLists = false, + }).ToList(); + _configuration.Version = 2; + _pluginInterface.SavePluginConfig(_configuration); + } +#pragma warning restore CS0612 // Type or member is obsolete + } + private void ChatMessage(XivChatType type, int timestamp, ref SeString sender, ref SeString message, ref bool isHandled) { diff --git a/Deliveroo/Windows/ConfigWindow.cs b/Deliveroo/Windows/ConfigWindow.cs index 24b55ec..b380a17 100644 --- a/Deliveroo/Windows/ConfigWindow.cs +++ b/Deliveroo/Windows/ConfigWindow.cs @@ -40,7 +40,7 @@ internal sealed class ConfigWindow : LWindow, IPersistableWindowConfig ]; private string _searchString = string.Empty; - private uint _dragDropSource; + private Configuration.PurchaseOption? _dragDropSource; public ConfigWindow(IDalamudPluginInterface pluginInterface, DeliverooPlugin plugin, Configuration configuration, GcRewardsCache gcRewardsCache, IClientState clientState, IPluginLog pluginLog, IconCache iconCache, @@ -89,20 +89,20 @@ internal sealed class ConfigWindow : LWindow, IPersistableWindowConfig { if (ImGui.BeginTabItem("Items for Auto-Buy")) { - uint? itemToRemove = null; - uint? itemToAdd = null; + Configuration.PurchaseOption? itemToRemove = null; + Configuration.PurchaseOption? itemToAdd = null; int indexToAdd = 0; if (ImGui.BeginChild("Items", new Vector2(-1, -ImGui.GetFrameHeightWithSpacing()), true, ImGuiWindowFlags.NoSavedSettings)) { - for (int i = 0; i < _configuration.ItemsAvailableForPurchase.Count; ++i) + for (int i = 0; i < _configuration.ItemsAvailableToPurchase.Count; ++i) { - uint itemId = _configuration.ItemsAvailableForPurchase[i]; + var purchaseOption = _configuration.ItemsAvailableToPurchase[i]; ImGui.PushID($"###Item{i}"); ImGui.BeginDisabled( - _configuration.ItemsAvailableForPurchase.Count == 1 && itemId == ItemIds.Venture); + _configuration.ItemsAvailableToPurchase.Count == 1 && purchaseOption.ItemId == ItemIds.Venture); - var item = _itemLookup[itemId]; + var item = _itemLookup[purchaseOption.ItemId]; var icon = _iconCache.GetIcon(item.IconId); Vector2 pos = ImGui.GetCursorPos(); Vector2 iconSize = new Vector2(ImGui.GetTextLineHeight() + ImGui.GetStyle().ItemSpacing.Y); @@ -114,26 +114,26 @@ internal sealed class ConfigWindow : LWindow, IPersistableWindowConfig ImGui.GetStyle().ItemSpacing.Y / 2)); } - ImGui.Selectable($"{item.Name}{(item.Limited ? $" {SeIconChar.Hyadelyn.ToIconString()}" : "")}", + ImGui.Selectable($"{item.Name}{(item.Limited ? $" {SeIconChar.Hyadelyn.ToIconString()}" : "")}{(purchaseOption.SameQuantityForAllLists ? $" {((SeIconChar)57412).ToIconString()} (Limit: {purchaseOption.GlobalLimit:N0})" : "")}", false, ImGuiSelectableFlags.SpanAllColumns); if (ImGui.BeginDragDropSource()) { ImGui.SetDragDropPayload("DeliverooDragDrop", nint.Zero, 0); - _dragDropSource = itemId; + _dragDropSource = purchaseOption; ImGui.EndDragDropSource(); } if (ImGui.BeginDragDropTarget()) { - if (_dragDropSource > 0 && + if (_dragDropSource != null && ImGui.AcceptDragDropPayload("DeliverooDragDrop").NativePtr != null) { itemToAdd = _dragDropSource; indexToAdd = i; - _dragDropSource = 0; + _dragDropSource = null; } ImGui.EndDragDropTarget(); @@ -142,8 +142,16 @@ internal sealed class ConfigWindow : LWindow, IPersistableWindowConfig ImGui.OpenPopupOnItemClick($"###ctx{i}", ImGuiPopupFlags.MouseButtonRight); if (ImGui.BeginPopup($"###ctx{i}")) { - if (ImGui.Selectable($"Remove {_itemLookup[itemId].Name}")) - itemToRemove = itemId; + bool sameQuantityForAllLists = purchaseOption.SameQuantityForAllLists; + if (ImGui.MenuItem("Use same quantity for global and character-specific lists", null, + ref sameQuantityForAllLists)) + { + purchaseOption.SameQuantityForAllLists = sameQuantityForAllLists; + Save(); + } + + if (ImGui.MenuItem($"Remove {_itemLookup[purchaseOption.ItemId].Name}")) + itemToRemove = purchaseOption; ImGui.EndPopup(); } @@ -166,20 +174,20 @@ internal sealed class ConfigWindow : LWindow, IPersistableWindowConfig if (itemToRemove != null) { - _configuration.ItemsAvailableForPurchase.Remove(itemToRemove.Value); + _configuration.ItemsAvailableToPurchase.Remove(itemToRemove); Save(); } if (itemToAdd != null) { - _configuration.ItemsAvailableForPurchase.Remove(itemToAdd.Value); - _configuration.ItemsAvailableForPurchase.Insert(indexToAdd, itemToAdd.Value); + _configuration.ItemsAvailableToPurchase.Remove(itemToAdd); + _configuration.ItemsAvailableToPurchase.Insert(indexToAdd, itemToAdd); Save(); } List<(uint ItemId, string Name, ushort IconId, bool Limited)> comboValues = _gcRewardsCache.Rewards .Where(x => x.SubCategory is RewardSubCategory.Materials or RewardSubCategory.Materiel) - .Where(x => !_configuration.ItemsAvailableForPurchase.Contains(x.ItemId)) + .Where(x => _configuration.ItemsAvailableToPurchase.All(y => y.ItemId != x.ItemId)) .Select(x => (x.ItemId, x.Name, x.IconId, x.Limited)) .OrderBy(x => x.Name) .ThenBy(x => x.GetHashCode()) @@ -209,7 +217,7 @@ internal sealed class ConfigWindow : LWindow, IPersistableWindowConfig $"{item.Name}{(item.Limited ? $" {SeIconChar.Hyadelyn.ToIconString()}" : "")}##SelectVenture{item.IconId}"); if (addThis || addFirst) { - _configuration.ItemsAvailableForPurchase.Add(item.ItemId); + _configuration.ItemsAvailableToPurchase.Add(new Configuration.PurchaseOption { ItemId = item.ItemId }); if (addFirst) { diff --git a/Deliveroo/Windows/TurnInWindow.cs b/Deliveroo/Windows/TurnInWindow.cs index 4478e02..849912d 100644 --- a/Deliveroo/Windows/TurnInWindow.cs +++ b/Deliveroo/Windows/TurnInWindow.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Numerics; using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Keys; +using Dalamud.Game.Text; using Dalamud.Interface; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; @@ -149,13 +150,16 @@ internal sealed class TurnInWindow : LWindow, IPersistableWindowConfig .Where(x => x.Reward.RequiredRank <= rank) .Select(x => { + var purchaseOption = _configuration.ItemsAvailableToPurchase.Where(y => y.SameQuantityForAllLists) + .FirstOrDefault(y => y.ItemId == x.Item.ItemId); + int limit = purchaseOption?.GlobalLimit ?? x.Item.Limit; var request = new PurchaseItemRequest { ItemId = x.Item.ItemId, Name = x.Reward.Name, EffectiveLimit = CalculateEffectiveLimit( x.Item.ItemId, - x.Item.Limit <= 0 ? uint.MaxValue : (uint)x.Item.Limit, + limit <= 0 ? uint.MaxValue : (uint)limit, x.Reward.StackSize, x.Reward.InventoryLimit), SealCost = x.Reward.SealCost, @@ -340,13 +344,20 @@ internal sealed class TurnInWindow : LWindow, IPersistableWindowConfig { (GcRewardItem.None, GcRewardItem.None.Name, GcRewardItem.None.Name), }; - foreach (uint itemId in _configuration.ItemsAvailableForPurchase) + foreach (Configuration.PurchaseOption purchaseOption in _configuration.ItemsAvailableToPurchase) { - var gcReward = _gcRewardsCache.GetReward(itemId); - int itemCountWithoutRetainers = _gameFunctions.GetItemCount(itemId, false); - int itemCountWithRetainers = _gameFunctions.GetItemCount(itemId, true); + var gcReward = _gcRewardsCache.GetReward(purchaseOption.ItemId); + int itemCountWithoutRetainers = _gameFunctions.GetItemCount(purchaseOption.ItemId, false); + int itemCountWithRetainers = _gameFunctions.GetItemCount(purchaseOption.ItemId, true); string itemNameWithoutRetainers = gcReward.Name; string itemNameWithRetainers = gcReward.Name; + + if (purchaseOption.SameQuantityForAllLists) + { + itemNameWithoutRetainers += $" {((SeIconChar)57412).ToIconString()}"; + itemNameWithRetainers += $" {((SeIconChar)57412).ToIconString()}"; + } + if (itemCountWithoutRetainers > 0) itemNameWithoutRetainers += $" ({itemCountWithoutRetainers:N0})"; if (itemCountWithRetainers > 0) @@ -369,184 +380,7 @@ internal sealed class TurnInWindow : LWindow, IPersistableWindowConfig for (int i = 0; i < itemsWrapper.GetItemsToPurchase().Count; ++i) { - Vector2 topLeft = ImGui.GetCursorScreenPos() + new Vector2(0, -ImGui.GetStyle().ItemSpacing.Y / 2); - - ImGui.PushID($"ItemToBuy{i}"); - Configuration.PurchasePriority item = itemsWrapper.GetItemsToPurchase()[i]; - - float indentX = ImGui.GetCursorPosX(); - bool enabled = item.Enabled; - int popColors = 0; - if (!enabled) - { - ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0.5f, 0.35f, 1f)); - popColors++; - } - - if (ImGui.Button($"{item.GetIcon()}")) - ImGui.OpenPopup($"Configure{i}"); - - ImGui.PopStyleColor(popColors); - - if (ImGui.BeginPopup($"Configure{i}")) - { - if (ImGui.Checkbox($"Enabled##Enabled{i}", ref enabled)) - { - item.Enabled = enabled; - itemsWrapper.Save(); - } - - ImGui.SetNextItemWidth(375 * ImGuiHelpers.GlobalScale); - int type = (int)item.Type; - if (ImGui.Combo($"##Type{i}", ref type, StockingTypeLabels, StockingTypeLabels.Length)) - { - item.Type = (Configuration.PurchaseType)type; - if (item.Type != Configuration.PurchaseType.KeepStocked) - item.CheckRetainerInventory = false; - itemsWrapper.Save(); - } - - if (item.Type == Configuration.PurchaseType.KeepStocked && item.ItemId != ItemIds.Venture) - { - bool checkRetainerInventory = item.CheckRetainerInventory; - if (ImGui.Checkbox("Check Retainer Inventory for items (requires AllaganTools)", - ref checkRetainerInventory)) - { - item.CheckRetainerInventory = checkRetainerInventory; - itemsWrapper.Save(); - } - } - - ImGui.EndPopup(); - } - - ImGui.SameLine(0, 3); - ImGui.BeginDisabled(!enabled); - int comboValueIndex = comboValues.FindIndex(x => x.Item.ItemId == item.ItemId); - if (comboValueIndex < 0) - { - item.ItemId = 0; - item.Limit = 0; - itemsWrapper.Save(); - - comboValueIndex = 0; - } - - var comboItem = comboValues[comboValueIndex]; - var icon = _iconCache.GetIcon(comboItem.Item.IconId); - if (icon.TryGetWrap(out IDalamudTextureWrap? wrap, out _)) - { - ImGui.Image(wrap.ImGuiHandle, new Vector2(ImGui.GetFrameHeight())); - ImGui.SameLine(0, 3); - - wrap.Dispose(); - } - - indentX = ImGui.GetCursorPosX() - indentX; - - ImGui.PushFont(UiBuilder.IconFont); - ImGui.SetNextItemWidth(width - - ImGui.GetStyle().WindowPadding.X - - ImGui.CalcTextSize(FontAwesomeIcon.Circle.ToIconString()).X - - ImGui.CalcTextSize(FontAwesomeIcon.ArrowsUpDown.ToIconString()).X - - ImGui.CalcTextSize(FontAwesomeIcon.Times.ToIconString()).X - - ImGui.GetStyle().FramePadding.X * 8 - - ImGui.GetStyle().ItemSpacing.X * 2 - 3 * 3); - ImGui.PopFont(); - - if (ImGui.Combo("", ref comboValueIndex, - comboValues.Select(x => item.CheckRetainerInventory ? x.NameWithRetainers : x.NameWithoutRetainers) - .ToArray(), comboValues.Count)) - { - comboItem = comboValues[comboValueIndex]; - item.ItemId = comboItem.Item.ItemId; - itemsWrapper.Save(); - } - - ImGui.EndDisabled(); - - if (itemsWrapper.GetItemsToPurchase().Count >= 2) - { - ImGui.PushFont(UiBuilder.IconFont); - ImGui.SameLine(ImGui.GetContentRegionAvail().X + - ImGui.GetStyle().WindowPadding.X - - ImGui.CalcTextSize(FontAwesomeIcon.ArrowsUpDown.ToIconString()).X - - ImGui.CalcTextSize(FontAwesomeIcon.Times.ToIconString()).X - - ImGui.GetStyle().FramePadding.X * 4 - - ImGui.GetStyle().ItemSpacing.X); - ImGui.PopFont(); - - if (_draggedItem == item.InternalId) - { - ImGuiComponents.IconButton("##Move", FontAwesomeIcon.ArrowsUpDown, - ImGui.ColorConvertU32ToFloat4(ImGui.GetColorU32(ImGuiCol.ButtonActive))); - } - else - ImGuiComponents.IconButton("##Move", FontAwesomeIcon.ArrowsUpDown); - - if (_draggedItem == null && ImGui.IsItemActive() && ImGui.IsMouseDragging(ImGuiMouseButton.Left)) - _draggedItem = item.InternalId; - - ImGui.SameLine(); - } - else - { - ImGui.PushFont(UiBuilder.IconFont); - ImGui.SameLine(ImGui.GetContentRegionAvail().X + - ImGui.GetStyle().WindowPadding.X - - ImGui.CalcTextSize(FontAwesomeIcon.Times.ToIconString()).X - - ImGui.GetStyle().FramePadding.X * 2); - ImGui.PopFont(); - } - - if (ImGuiComponents.IconButton($"###Remove{i}", FontAwesomeIcon.Times)) - itemToRemove = item; - - if (enabled) - { - ImGui.Indent(indentX); - if (comboValueIndex > 0) - { - ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 130); - int limit = Math.Min(item.Limit, (int)comboItem.Item.InventoryLimit); - int stepSize = comboItem.Item.StackSize < 99 ? 1 : 50; - string label = item.Type == Configuration.PurchaseType.KeepStocked - ? "Maximum items to buy" - : "Remaining items to buy"; - if (ImGui.InputInt(label, ref limit, stepSize, stepSize * 10)) - { - item.Limit = Math.Min(Math.Max(0, limit), (int)comboItem.Item.InventoryLimit); - itemsWrapper.Save(); - } - } - else if (item.Limit != 0) - { - item.Limit = 0; - itemsWrapper.Save(); - } - - if (comboValueIndex > 0) - { - if (!comboItem.Item.GrandCompanies.Contains(grandCompany)) - { - ImGui.TextColored(ImGuiColors.DalamudRed, - "This item will be skipped, as you are in the wrong Grand Company."); - } - else if (comboItem.Item.RequiredRank > _gameFunctions.GetGrandCompanyRank()) - { - ImGui.TextColored(ImGuiColors.DalamudRed, - "This item will be skipped, your rank isn't high enough to buy it."); - } - } - - ImGui.Unindent(indentX); - } - - ImGui.PopID(); - - Vector2 bottomRight = new Vector2(topLeft.X + width, - ImGui.GetCursorScreenPos().Y - ImGui.GetStyle().ItemSpacing.Y + 2); - itemPositions.Add((topLeft, bottomRight)); + DrawItemToBuy(grandCompany, i, itemsWrapper, comboValues, width, ref itemToRemove, itemPositions); } if (!ImGui.IsMouseDragging(ImGuiMouseButton.Left)) @@ -582,21 +416,21 @@ internal sealed class TurnInWindow : LWindow, IPersistableWindowConfig itemsWrapper.Save(); } - if (_configuration.ItemsAvailableForPurchase.Any(x => - itemsWrapper.GetItemsToPurchase().All(y => x != y.ItemId))) + if (_configuration.ItemsToPurchase.Any(x => + itemsWrapper.GetItemsToPurchase().All(y => x.ItemId != y.ItemId))) { if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Plus, "Add Item")) ImGui.OpenPopup("##AddItem"); if (ImGui.BeginPopupContextItem("##AddItem", ImGuiPopupFlags.NoOpenOverItems)) { - foreach (var itemId in _configuration.ItemsAvailableForPurchase.Distinct()) + foreach (var purchaseOption in _configuration.ItemsAvailableToPurchase.Distinct()) { - if (_gcRewardsCache.RewardLookup.TryGetValue(itemId, out var reward)) + if (_gcRewardsCache.RewardLookup.TryGetValue(purchaseOption.ItemId, out var reward)) { - if (ImGui.MenuItem($"{reward.Name}##{itemId}")) + if (ImGui.MenuItem($"{reward.Name}##{purchaseOption.ItemId}")) { - itemsWrapper.Add(new Configuration.PurchasePriority { ItemId = itemId, Limit = 0 }); + itemsWrapper.Add(new Configuration.PurchasePriority { ItemId = purchaseOption.ItemId, Limit = 0 }); itemsWrapper.Save(); ImGui.CloseCurrentPopup(); } @@ -612,6 +446,204 @@ internal sealed class TurnInWindow : LWindow, IPersistableWindowConfig } } + private void DrawItemToBuy(GrandCompany grandCompany, int i, IItemsToPurchase itemsWrapper, + List<(GcRewardItem Item, string NameWithoutRetainers, string NameWithRetainers)> comboValues, float width, + ref Configuration.PurchasePriority? itemToRemove, List<(Vector2 TopLeft, Vector2 BottomRight)> itemPositions) + { + Vector2 topLeft = ImGui.GetCursorScreenPos() + new Vector2(0, -ImGui.GetStyle().ItemSpacing.Y / 2); + + ImGui.PushID($"ItemToBuy{i}"); + Configuration.PurchasePriority item = itemsWrapper.GetItemsToPurchase()[i]; + + float indentX = ImGui.GetCursorPosX(); + bool enabled = item.Enabled; + int popColors = 0; + if (!enabled) + { + ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0.5f, 0.35f, 1f)); + popColors++; + } + + if (ImGui.Button($"{item.GetIcon()}")) + ImGui.OpenPopup($"Configure{i}"); + + ImGui.PopStyleColor(popColors); + + if (ImGui.BeginPopup($"Configure{i}")) + { + if (ImGui.Checkbox($"Enabled##Enabled{i}", ref enabled)) + { + item.Enabled = enabled; + itemsWrapper.Save(); + } + + ImGui.SetNextItemWidth(375 * ImGuiHelpers.GlobalScale); + int type = (int)item.Type; + if (ImGui.Combo($"##Type{i}", ref type, StockingTypeLabels, StockingTypeLabels.Length)) + { + item.Type = (Configuration.PurchaseType)type; + if (item.Type != Configuration.PurchaseType.KeepStocked) + item.CheckRetainerInventory = false; + itemsWrapper.Save(); + } + + if (item.Type == Configuration.PurchaseType.KeepStocked && item.ItemId != ItemIds.Venture) + { + bool checkRetainerInventory = item.CheckRetainerInventory; + if (ImGui.Checkbox("Check Retainer Inventory for items (requires AllaganTools)", + ref checkRetainerInventory)) + { + item.CheckRetainerInventory = checkRetainerInventory; + itemsWrapper.Save(); + } + } + + ImGui.EndPopup(); + } + + ImGui.SameLine(0, 3); + ImGui.BeginDisabled(!enabled); + int comboValueIndex = comboValues.FindIndex(x => x.Item.ItemId == item.ItemId); + if (comboValueIndex < 0) + { + item.ItemId = 0; + item.Limit = 0; + itemsWrapper.Save(); + + comboValueIndex = 0; + } + + var comboItem = comboValues[comboValueIndex]; + var icon = _iconCache.GetIcon(comboItem.Item.IconId); + if (icon.TryGetWrap(out IDalamudTextureWrap? wrap, out _)) + { + ImGui.Image(wrap.ImGuiHandle, new Vector2(ImGui.GetFrameHeight())); + ImGui.SameLine(0, 3); + + wrap.Dispose(); + } + + indentX = ImGui.GetCursorPosX() - indentX; + + ImGui.PushFont(UiBuilder.IconFont); + ImGui.SetNextItemWidth(width - + ImGui.GetStyle().WindowPadding.X - + ImGui.CalcTextSize(FontAwesomeIcon.Circle.ToIconString()).X - + ImGui.CalcTextSize(FontAwesomeIcon.ArrowsUpDown.ToIconString()).X - + ImGui.CalcTextSize(FontAwesomeIcon.Times.ToIconString()).X - + ImGui.GetStyle().FramePadding.X * 8 - + ImGui.GetStyle().ItemSpacing.X * 2 - 3 * 3); + ImGui.PopFont(); + + if (ImGui.Combo("", ref comboValueIndex, + comboValues.Select(x => item.CheckRetainerInventory ? x.NameWithRetainers : x.NameWithoutRetainers) + .ToArray(), comboValues.Count)) + { + comboItem = comboValues[comboValueIndex]; + item.ItemId = comboItem.Item.ItemId; + itemsWrapper.Save(); + } + + ImGui.EndDisabled(); + + if (itemsWrapper.GetItemsToPurchase().Count >= 2) + { + ImGui.PushFont(UiBuilder.IconFont); + ImGui.SameLine(ImGui.GetContentRegionAvail().X + + ImGui.GetStyle().WindowPadding.X - + ImGui.CalcTextSize(FontAwesomeIcon.ArrowsUpDown.ToIconString()).X - + ImGui.CalcTextSize(FontAwesomeIcon.Times.ToIconString()).X - + ImGui.GetStyle().FramePadding.X * 4 - + ImGui.GetStyle().ItemSpacing.X); + ImGui.PopFont(); + + if (_draggedItem == item.InternalId) + { + ImGuiComponents.IconButton("##Move", FontAwesomeIcon.ArrowsUpDown, + ImGui.ColorConvertU32ToFloat4(ImGui.GetColorU32(ImGuiCol.ButtonActive))); + } + else + ImGuiComponents.IconButton("##Move", FontAwesomeIcon.ArrowsUpDown); + + if (_draggedItem == null && ImGui.IsItemActive() && ImGui.IsMouseDragging(ImGuiMouseButton.Left)) + _draggedItem = item.InternalId; + + ImGui.SameLine(); + } + else + { + ImGui.PushFont(UiBuilder.IconFont); + ImGui.SameLine(ImGui.GetContentRegionAvail().X + + ImGui.GetStyle().WindowPadding.X - + ImGui.CalcTextSize(FontAwesomeIcon.Times.ToIconString()).X - + ImGui.GetStyle().FramePadding.X * 2); + ImGui.PopFont(); + } + + if (ImGuiComponents.IconButton($"###Remove{i}", FontAwesomeIcon.Times)) + itemToRemove = item; + + if (enabled) + { + ImGui.Indent(indentX); + if (comboValueIndex > 0) + { + var purchaseOption = + _configuration.ItemsAvailableToPurchase + .Where(x => x.SameQuantityForAllLists) + .FirstOrDefault(x => x.ItemId == item.ItemId); + + ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 130); + int limit = Math.Min(purchaseOption?.GlobalLimit ?? item.Limit, (int)comboItem.Item.InventoryLimit); + int stepSize = comboItem.Item.StackSize < 99 ? 1 : 50; + string label = item.Type == Configuration.PurchaseType.KeepStocked + ? "Maximum items to buy" + : "Remaining items to buy"; + if (ImGui.InputInt(label, ref limit, stepSize, stepSize * 10)) + { + int newLimit = Math.Min(Math.Max(0, limit), (int)comboItem.Item.InventoryLimit); + if (purchaseOption != null) + { + purchaseOption.GlobalLimit = newLimit; + _pluginInterface.SavePluginConfig(_configuration); + } + else + { + item.Limit = newLimit; + itemsWrapper.Save(); + } + } + } + else if (item.Limit != 0) + { + item.Limit = 0; + itemsWrapper.Save(); + } + + if (comboValueIndex > 0) + { + if (!comboItem.Item.GrandCompanies.Contains(grandCompany)) + { + ImGui.TextColored(ImGuiColors.DalamudRed, + "This item will be skipped, as you are in the wrong Grand Company."); + } + else if (comboItem.Item.RequiredRank > _gameFunctions.GetGrandCompanyRank()) + { + ImGui.TextColored(ImGuiColors.DalamudRed, + "This item will be skipped, your rank isn't high enough to buy it."); + } + } + + ImGui.Unindent(indentX); + } + + ImGui.PopID(); + + Vector2 bottomRight = new Vector2(topLeft.X + width, + ImGui.GetCursorScreenPos().Y - ImGui.GetStyle().ItemSpacing.Y + 2); + itemPositions.Add((topLeft, bottomRight)); + } + private unsafe uint CalculateEffectiveLimit(uint itemId, uint limit, uint stackSize, uint inventoryLimit) { if (itemId == ItemIds.Venture)