BITFALL/Assets/Artists/Scripts/UX/UXUtils.cs

43 lines
1019 B
C#
Raw Normal View History

2023-10-24 23:37:59 +08:00
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.UX;
2023-12-03 17:35:43 +08:00
using Steamworks.Data;
2023-10-24 23:37:59 +08:00
using UnityEngine;
using UnityEngine.UIElements;
namespace BITFALL.UX
{
public static class UXUtils
{
public static UXContainer CreateItemContainer(VisualElement visualElement, IBasicItem item)
{
var asset = item.GetAssetable();
var uxContainer = new UXContainer(visualElement);
2023-12-03 17:35:43 +08:00
uxContainer.icon.style.backgroundImage =asset.SquareIcon;
2023-10-24 23:37:59 +08:00
uxContainer.contextLabel.text = asset.Name;
2023-12-03 17:35:43 +08:00
visualElement.userData = item.AddressablePath;
if (uxContainer.numberLabel is not null)
{
if (item.TryGetProperty<ICount>(out var count))
{
uxContainer.numberLabel.text = count.Count.ToString();
uxContainer.numberLabel.SetActive(true);
}
else
{
uxContainer.numberLabel.SetActive(false);
}
}
if (uxContainer.descriptionLabel is not null)
{
uxContainer.descriptionLabel.text = asset.Description;
}
2023-10-24 23:37:59 +08:00
return uxContainer;
}
}
}