Add currencies
This commit is contained in:
@@ -2,7 +2,10 @@ namespace AetherBags.Currency;
|
|||||||
|
|
||||||
public class CurrencyInfo
|
public class CurrencyInfo
|
||||||
{
|
{
|
||||||
public required int Amount { get; set; }
|
public required uint Amount { get; set; }
|
||||||
|
public required uint MaxAmount { get; set; }
|
||||||
public required uint ItemId { get; set; }
|
public required uint ItemId { get; set; }
|
||||||
public required uint IconId { get; set; }
|
public required uint IconId { get; set; }
|
||||||
|
public required bool LimitReached { get; set; }
|
||||||
|
public required bool IsCapped { get; set; }
|
||||||
}
|
}
|
||||||
@@ -250,13 +250,81 @@ public static unsafe class InventoryState
|
|||||||
return $"{used}/140";
|
return $"{used}/140";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CurrencyInfo GetCurrencyInfo(uint itemId)
|
private const uint CurrencyIdLimitedTomestone = 0xFFFF_FFFE;
|
||||||
|
private const uint CurrencyIdNonLimitedTomestone = 0xFFFF_FFFD;
|
||||||
|
|
||||||
|
private static uint? GetLimitedTomestoneItemId()
|
||||||
|
=> Services.DataManager.GetExcelSheet<TomestonesItem>()
|
||||||
|
.FirstOrDefault(t => t.Tomestones.RowId == 3)
|
||||||
|
.Item.RowId;
|
||||||
|
|
||||||
|
private static uint? GetNonLimitedTomestoneItemId()
|
||||||
|
=> Services.DataManager.GetExcelSheet<TomestonesItem>()
|
||||||
|
.FirstOrDefault(t => t.Tomestones.RowId == 2)
|
||||||
|
.Item.RowId;
|
||||||
|
|
||||||
|
private static CurrencyItem ResolveCurrencyItemId(uint currencyId)
|
||||||
{
|
{
|
||||||
|
uint itemId = currencyId;
|
||||||
|
bool isLimited = false;
|
||||||
|
|
||||||
|
if (currencyId == CurrencyIdLimitedTomestone)
|
||||||
|
{
|
||||||
|
itemId = GetLimitedTomestoneItemId() ?? 0;
|
||||||
|
isLimited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currencyId == CurrencyIdNonLimitedTomestone)
|
||||||
|
{
|
||||||
|
itemId = GetNonLimitedTomestoneItemId() ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CurrencyItem(itemId, isLimited);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static IReadOnlyList<CurrencyInfo> GetCurrencyInfoList(uint[] currencyIds)
|
||||||
|
{
|
||||||
|
if (currencyIds.Length == 0) return Array.Empty<CurrencyInfo>();
|
||||||
|
|
||||||
|
List<CurrencyInfo> currencyInfoList = new List<CurrencyInfo>(currencyIds.Length);
|
||||||
|
|
||||||
|
for (int i = 0; i < currencyIds.Length; i++)
|
||||||
|
{
|
||||||
|
CurrencyItem currencyItem = ResolveCurrencyItemId(currencyIds[i]);
|
||||||
|
if (currencyItem.ItemId == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
currencyInfoList.Add(GetCurrencyInfo(currencyItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
return currencyInfoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CurrencyInfo GetCurrencyInfo(CurrencyItem currencyItem)
|
||||||
|
{
|
||||||
|
InventoryManager* inventoryManager = InventoryManager.Instance();
|
||||||
|
var item = Services.DataManager.GetExcelSheet<Item>().GetRow(currencyItem.ItemId);
|
||||||
|
|
||||||
|
uint amount = (uint) inventoryManager->GetInventoryItemCount(currencyItem.ItemId);
|
||||||
|
uint maxAmount = item.StackSize;
|
||||||
|
bool isCapped = false;
|
||||||
|
if (currencyItem.IsLimited)
|
||||||
|
{
|
||||||
|
int weeklyLimit = InventoryManager.GetLimitedTomestoneWeeklyLimit();
|
||||||
|
int weeklyAcquired = inventoryManager->GetWeeklyAcquiredTomestoneCount();
|
||||||
|
isCapped = weeklyAcquired >= weeklyLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
Services.Logger.Info($"Currency {currencyItem.ItemId} amount: {amount}, max: {maxAmount}");
|
||||||
return new CurrencyInfo
|
return new CurrencyInfo
|
||||||
{
|
{
|
||||||
Amount = InventoryManager.Instance()->GetInventoryItemCount(1),
|
Amount = amount,
|
||||||
ItemId = itemId,
|
MaxAmount = item.StackSize,
|
||||||
IconId = Services.DataManager.GetExcelSheet<Item>().GetRow(itemId).Icon
|
ItemId = currencyItem.ItemId,
|
||||||
|
IconId = item.Icon,
|
||||||
|
LimitReached = amount >= maxAmount,
|
||||||
|
IsCapped = isCapped
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,4 +407,6 @@ public static unsafe class InventoryState
|
|||||||
public List<ItemInfo> FilteredItems = null!;
|
public List<ItemInfo> FilteredItems = null!;
|
||||||
public bool Used;
|
public bool Used;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record CurrencyItem(uint ItemId, bool IsLimited);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using AetherBags.Currency;
|
||||||
|
using KamiToolKit.Nodes;
|
||||||
|
|
||||||
|
namespace AetherBags.Nodes;
|
||||||
|
|
||||||
|
public class CurrencyListNode : HorizontalListNode
|
||||||
|
{
|
||||||
|
public List<CurrencyInfo> CurrencyInfoList
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,39 +9,45 @@ namespace AetherBags.Nodes;
|
|||||||
|
|
||||||
public class CurrencyNode : SimpleComponentNode
|
public class CurrencyNode : SimpleComponentNode
|
||||||
{
|
{
|
||||||
private IconImageNode iconImageNode;
|
private readonly IconImageNode _iconImageNode;
|
||||||
private TextNode countNode;
|
private readonly TextNode _countNode;
|
||||||
|
|
||||||
public CurrencyNode()
|
public CurrencyNode()
|
||||||
{
|
{
|
||||||
iconImageNode = new IconImageNode
|
_iconImageNode = new IconImageNode
|
||||||
{
|
{
|
||||||
FitTexture = true
|
FitTexture = true,
|
||||||
|
Size = new Vector2(24f)
|
||||||
};
|
};
|
||||||
iconImageNode.AttachNode(this);
|
_iconImageNode.AttachNode(this);
|
||||||
|
|
||||||
|
_countNode = new TextNode
|
||||||
countNode = new TextNode
|
|
||||||
{
|
{
|
||||||
TextFlags = TextFlags.Emboss,
|
TextFlags = TextFlags.Emboss,
|
||||||
TextColor = ColorHelper.GetColor(8),
|
TextColor = ColorHelper.GetColor(8),
|
||||||
TextOutlineColor = ColorHelper.GetColor(7),
|
TextOutlineColor = ColorHelper.GetColor(7),
|
||||||
|
AlignmentType = AlignmentType.Left,
|
||||||
FontSize = 14,
|
FontSize = 14,
|
||||||
|
Size = new Vector2(120.0f, 28.0f)
|
||||||
};
|
};
|
||||||
countNode.AttachNode(this);
|
_countNode.AttachNode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public required CurrencyInfo Currency {
|
public required CurrencyInfo Currency {
|
||||||
get;
|
get;
|
||||||
set {
|
set {
|
||||||
field = value;
|
field = value;
|
||||||
iconImageNode.IconId = value.IconId;
|
_iconImageNode.IconId = value.IconId;
|
||||||
countNode.String = value.Amount.ToString("N0");
|
_iconImageNode.Position = new Vector2(0f, 2f);
|
||||||
|
|
||||||
countNode.Size = new Vector2(120.0f, 28.0f);
|
_countNode.String = value.Amount.ToString("N0");
|
||||||
countNode.Origin = countNode.Size / 2.0f;
|
_countNode.Position = new Vector2(_iconImageNode.Bounds.Right + 2f, 0f);
|
||||||
countNode.Position = new Vector2(26.0f, 0.0f);
|
|
||||||
iconImageNode.Size = new Vector2(24f);
|
// Limit > Capped > Normal
|
||||||
|
_countNode.TextColor =
|
||||||
|
value.LimitReached ? ColorHelper.GetColor(17) :
|
||||||
|
value.IsCapped ? ColorHelper.GetColor(43) :
|
||||||
|
ColorHelper.GetColor(8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using AetherBags.Currency;
|
using AetherBags.Currency;
|
||||||
using AetherBags.Inventory;
|
using AetherBags.Inventory;
|
||||||
@@ -12,7 +14,7 @@ namespace AetherBags.Nodes;
|
|||||||
public sealed class InventoryFooterNode : SimpleComponentNode
|
public sealed class InventoryFooterNode : SimpleComponentNode
|
||||||
{
|
{
|
||||||
private readonly TextNode _slotAmountTextNode;
|
private readonly TextNode _slotAmountTextNode;
|
||||||
private readonly CurrencyNode _currencyNode;
|
private readonly CurrencyListNode _currencyListNode;
|
||||||
|
|
||||||
public InventoryFooterNode()
|
public InventoryFooterNode()
|
||||||
{
|
{
|
||||||
@@ -28,12 +30,32 @@ public sealed class InventoryFooterNode : SimpleComponentNode
|
|||||||
};
|
};
|
||||||
_slotAmountTextNode.AttachNode(this);
|
_slotAmountTextNode.AttachNode(this);
|
||||||
|
|
||||||
_currencyNode = new CurrencyNode
|
_currencyListNode = new CurrencyListNode
|
||||||
|
{
|
||||||
|
Position = new Vector2(0, 0),
|
||||||
|
Size = new Vector2(120, 28),
|
||||||
|
};
|
||||||
|
_currencyListNode.AttachNode(this);
|
||||||
|
|
||||||
|
RefreshCurrencies();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RefreshCurrencies()
|
||||||
|
{
|
||||||
|
IReadOnlyList<CurrencyInfo> currencyInfoList = InventoryState.GetCurrencyInfoList([1, 28, 0xFFFF_FFFE, 0xFFFF_FFFD]);
|
||||||
|
_currencyListNode.SyncWithListDataByKey<CurrencyInfo, CurrencyNode, uint>(
|
||||||
|
dataList: currencyInfoList,
|
||||||
|
getKeyFromData: c => c.ItemId,
|
||||||
|
getKeyFromNode: n => n.Currency.ItemId,
|
||||||
|
updateNode: (node, data) =>
|
||||||
|
{
|
||||||
|
node.Currency = data;
|
||||||
|
},
|
||||||
|
createNodeMethod: data => new CurrencyNode
|
||||||
{
|
{
|
||||||
Size = new Vector2(120, 28),
|
Size = new Vector2(120, 28),
|
||||||
Currency = InventoryState.GetCurrencyInfo(1)
|
Currency = data
|
||||||
};
|
});
|
||||||
_currencyNode.AttachNode(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SlotAmountText
|
public string SlotAmountText
|
||||||
@@ -46,6 +68,5 @@ public sealed class InventoryFooterNode : SimpleComponentNode
|
|||||||
base.OnSizeChanged();
|
base.OnSizeChanged();
|
||||||
|
|
||||||
_slotAmountTextNode.Position = new Vector2(Size.X - _slotAmountTextNode.Size.X - 10, 0);
|
_slotAmountTextNode.Position = new Vector2(Size.X - _slotAmountTextNode.Size.X - 10, 0);
|
||||||
_currencyNode.Position = new Vector2(0, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
Submodule KamiToolKit updated: aa278153f3...9101fc8a8e
Reference in New Issue
Block a user