using Cielonos.MainGame.Inventory; using Cielonos.MainGame.Interactions; using SLSUtilities.General; using SLSUtilities.UI; using TMPro; using UnityEngine; using UnityEngine.UI; namespace Cielonos.MainGame.UI { /// /// 物流中心(商店)列表中的单个商品选择器条目。 /// 显示物品图标、名称、价格,点击后选中该商品并通知 LogisticCenterUIPage 更新详情面板。 /// 价格以 RareMaterial 数量为单位。 /// public class LogisticsCenterSelector : UIElementBase { private LogisticsCenterUIPage Page => PlayerCanvas.MainGamePages.logisticsCenterPage; public ItemBase item; public int price; [Header("UI References")] public Button button; public Image background; public Image itemIcon; public Image rarityFrame; public Image selectorHint; public TMP_Text itemName; public TMP_Text priceText; public RectTransform tagContainer; [Header("Visual Settings")] public Color normalColor = new Color(0.2f, 0.2f, 0.2f, 0.8f); public Color selectedColor = new Color(0.4f, 0.6f, 0.9f, 0.9f); public Color affordableColor = new Color(1f, 1f, 1f, 1f); public Color unaffordableColor = new Color(1f, 0.3f, 0.3f, 1f); private bool isSelected; /// /// 用给定的商品数据配置此选择器的显示内容。 /// /// 物品组件引用。 /// 售价(RareMaterial 数量)。 public void Setup(ItemBase itemRef, int itemPrice) { item = itemRef; price = itemPrice; if (item == null || item.contentData == null) { Hide(); return; } ContentData data = item.contentData; // 图标 Sprite icon = data.itemType == ItemType.MainWeapon ? data.rectIcon : data.squareIcon; if (itemIcon != null) { itemIcon.sprite = icon; itemIcon.enabled = icon != null; } // 名称(本地化) if (itemName != null) { itemName.text = data.displayNameKey.Localize(); } // 价格 RefreshPriceDisplay(); // 默认取消选中状态 SetSelected(false); // 绑定按钮事件 if (button != null) { button.onClick.RemoveAllListeners(); button.onClick.AddListener(OnClicked); } Show(); } /// /// 设置选中/取消选中的视觉状态。 /// public void SetSelected(bool selected) { isSelected = selected; if (background != null) { background.color = isSelected ? selectedColor : normalColor; } if (selectorHint != null) { selectorHint.enabled = isSelected; } } /// /// 刷新价格文本颜色(根据玩家当前 RareMaterial 持有量)。 /// public void RefreshPriceDisplay() { if (priceText == null) return; priceText.text = price.ToString(); int playerCurrency = MainGameManager.Player.inventorySc.GetRareMaterialAmount(); priceText.color = playerCurrency >= price ? affordableColor : unaffordableColor; } private void OnClicked() { Page?.SelectItem(this); } } }