1
0
forked from liza/Deliveroo

Turn-In window: Enabling/disabling & Sorting items

This commit is contained in:
Liza 2023-10-15 14:31:49 +02:00
parent af3ada80c8
commit 5c973395c0
Signed by: liza
GPG Key ID: 7199F8D727D55F67
2 changed files with 112 additions and 34 deletions

View File

@ -24,6 +24,7 @@ internal sealed class Configuration : IPluginConfiguration
{ {
public uint ItemId { get; set; } public uint ItemId { get; set; }
public int Limit { get; set; } public int Limit { get; set; }
public bool Enabled { get; set; } = true;
} }
public bool AddVentureIfNoItemToPurchaseSelected() public bool AddVentureIfNoItemToPurchaseSelected()

View File

@ -72,7 +72,8 @@ internal sealed class TurnInWindow : Window
var rank = _plugin.GetGrandCompanyRank(); var rank = _plugin.GetGrandCompanyRank();
return ItemsWrapper.GetItemsToPurchase() return ItemsWrapper.GetItemsToPurchase()
.Where(x => x.ItemId != 0) .Where(x => x.ItemId != GcRewardItem.None.ItemId)
.Where(x => x.Enabled)
.Select(x => new { Item = x, Reward = _gcRewardsCache.GetReward(x.ItemId) }) .Select(x => new { Item = x, Reward = _gcRewardsCache.GetReward(x.ItemId) })
.Where(x => x.Reward.GrandCompanies.Contains(grandCompany)) .Where(x => x.Reward.GrandCompanies.Contains(grandCompany))
.Where(x => x.Reward.RequiredRank <= rank) .Where(x => x.Reward.RequiredRank <= rank)
@ -191,10 +192,23 @@ internal sealed class TurnInWindow : Window
} }
int? itemToRemove = null; int? itemToRemove = null;
Configuration.PurchasePriority? itemToAdd = null;
int indexToAdd = 0;
for (int i = 0; i < itemsWrapper.GetItemsToPurchase().Count; ++i) for (int i = 0; i < itemsWrapper.GetItemsToPurchase().Count; ++i)
{ {
ImGui.PushID($"ItemToBuy{i}"); ImGui.PushID($"ItemToBuy{i}");
var item = itemsWrapper.GetItemsToPurchase()[i]; var item = itemsWrapper.GetItemsToPurchase()[i];
bool enabled = item.Enabled;
ImGui.PushID($"Enable{i}");
if (ImGui.Checkbox("", ref enabled))
{
item.Enabled = enabled;
itemsWrapper.Save();
}
ImGui.PopID();
ImGui.SameLine(0, 3);
ImGui.BeginDisabled(!enabled);
int comboValueIndex = comboValues.FindIndex(x => x.ItemId == item.ItemId); int comboValueIndex = comboValues.FindIndex(x => x.ItemId == item.ItemId);
if (comboValueIndex < 0) if (comboValueIndex < 0)
{ {
@ -211,13 +225,37 @@ internal sealed class TurnInWindow : Window
itemsWrapper.Save(); itemsWrapper.Save();
} }
ImGui.EndDisabled();
if (itemsWrapper.GetItemsToPurchase().Count >= 2) if (itemsWrapper.GetItemsToPurchase().Count >= 2)
{ {
ImGui.SameLine();
if (ImGuiComponents.IconButton($"##Up{i}", FontAwesomeIcon.ArrowUp))
{
itemToAdd = item;
if (i > 0)
indexToAdd = i - 1;
else
indexToAdd = itemsWrapper.GetItemsToPurchase().Count - 1;
}
ImGui.SameLine(0, 0);
if (ImGuiComponents.IconButton($"##Down{i}", FontAwesomeIcon.ArrowDown))
{
itemToAdd = item;
if (i < itemsWrapper.GetItemsToPurchase().Count - 1)
indexToAdd = i + 1;
else
indexToAdd = 0;
}
ImGui.SameLine(); ImGui.SameLine();
if (ImGuiComponents.IconButton($"###Remove{i}", FontAwesomeIcon.Times)) if (ImGuiComponents.IconButton($"###Remove{i}", FontAwesomeIcon.Times))
itemToRemove = i; itemToRemove = i;
} }
if (enabled)
{
ImGui.Indent(27); ImGui.Indent(27);
if (comboValueIndex > 0) if (comboValueIndex > 0)
{ {
@ -257,9 +295,18 @@ internal sealed class TurnInWindow : Window
} }
ImGui.Unindent(27); ImGui.Unindent(27);
}
ImGui.PopID(); ImGui.PopID();
} }
if (itemToAdd != null)
{
itemsWrapper.Remove(itemToAdd);
itemsWrapper.Insert(indexToAdd, itemToAdd);
itemsWrapper.Save();
}
if (itemToRemove != null) if (itemToRemove != null)
{ {
itemsWrapper.RemoveAt(itemToRemove.Value); itemsWrapper.RemoveAt(itemToRemove.Value);
@ -270,9 +317,25 @@ internal sealed class TurnInWindow : Window
itemsWrapper.GetItemsToPurchase().All(y => x != y.ItemId))) itemsWrapper.GetItemsToPurchase().All(y => x != y.ItemId)))
{ {
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Plus, "Add Item")) if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Plus, "Add Item"))
ImGui.OpenPopup("##AddItem");
if (ImGui.BeginPopupContextItem("##AddItem", ImGuiPopupFlags.NoOpenOverItems))
{ {
itemsWrapper.Add(new Configuration.PurchasePriority { ItemId = GcRewardItem.None.ItemId, Limit = 0 }); foreach (var itemId in _configuration.ItemsAvailableForPurchase.Distinct())
{
if (_gcRewardsCache.RewardLookup.TryGetValue(itemId, out var reward))
{
if (ImGui.MenuItem($"{reward.Name}##{itemId}"))
{
itemsWrapper.Add(new Configuration.PurchasePriority { ItemId = itemId, Limit = 0 });
itemsWrapper.Save(); itemsWrapper.Save();
ImGui.CloseCurrentPopup();
}
}
}
ImGui.EndPopup();
} }
} }
} }
@ -310,6 +373,8 @@ internal sealed class TurnInWindow : Window
IReadOnlyList<Configuration.PurchasePriority> GetItemsToPurchase(); IReadOnlyList<Configuration.PurchasePriority> GetItemsToPurchase();
void Add(Configuration.PurchasePriority purchasePriority); void Add(Configuration.PurchasePriority purchasePriority);
void Insert(int index, Configuration.PurchasePriority purchasePriority);
void Remove(Configuration.PurchasePriority purchasePriority);
void RemoveAt(int index); void RemoveAt(int index);
void Save(); void Save();
} }
@ -334,6 +399,12 @@ internal sealed class TurnInWindow : Window
public void Add(Configuration.PurchasePriority purchasePriority) public void Add(Configuration.PurchasePriority purchasePriority)
=> _characterConfiguration.ItemsToPurchase.Add(purchasePriority); => _characterConfiguration.ItemsToPurchase.Add(purchasePriority);
public void Insert(int index, Configuration.PurchasePriority purchasePriority)
=> _characterConfiguration.ItemsToPurchase.Insert(index, purchasePriority);
public void Remove(Configuration.PurchasePriority purchasePriority)
=> _characterConfiguration.ItemsToPurchase.Remove(purchasePriority);
public void RemoveAt(int index) public void RemoveAt(int index)
=> _characterConfiguration.ItemsToPurchase.RemoveAt(index); => _characterConfiguration.ItemsToPurchase.RemoveAt(index);
@ -360,6 +431,12 @@ internal sealed class TurnInWindow : Window
public void Add(Configuration.PurchasePriority purchasePriority) public void Add(Configuration.PurchasePriority purchasePriority)
=> _configuration.ItemsToPurchase.Add(purchasePriority); => _configuration.ItemsToPurchase.Add(purchasePriority);
public void Insert(int index, Configuration.PurchasePriority purchasePriority)
=> _configuration.ItemsToPurchase.Insert(index, purchasePriority);
public void Remove(Configuration.PurchasePriority purchasePriority)
=> _configuration.ItemsToPurchase.Remove(purchasePriority);
public void RemoveAt(int index) public void RemoveAt(int index)
=> _configuration.ItemsToPurchase.RemoveAt(index); => _configuration.ItemsToPurchase.RemoveAt(index);