using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using MuHua;
///
/// UI库存插槽
///
public class UIInventorySlot : ModuleUIItem, InventoryDrag {
public Label CountLabel => Q("Count");
public VisualElement Image => Q("Image");
public int Count => value.count;
public InventoryItem Item => value.item;
public VisualElement Anchor => element;
public UIInventorySlot(InventorySlot value, VisualElement element) : base(value, element) {
UpdatePreview();
element.RegisterCallback(MouseDownEvent);
element.RegisterCallback(MouseOverEvent);
element.RegisterCallback(MouseLeaveEvent);
element.RegisterCallback(ClickEvent);
}
private void MouseDownEvent(MouseDownEvent evt) {
UIPopupManager.I.inventoryDrag.Settings(this);
Image.EnableInClassList("inventory-image-drag", true);
}
private void MouseOverEvent(MouseOverEvent evt) {
UIPopupManager.I.inventoryDrag.EnterContainer(this);
}
private void MouseLeaveEvent(MouseLeaveEvent evt) {
UIPopupManager.I.inventoryDrag.ExitContainer(this);
}
private void ClickEvent(ClickEvent evt) {
// Debug.Log("sss");
}
public void Settings(InventoryItem item, int count) {
value.Settings(item, count);
UpdatePreview();
}
public void Cancel() {
Image.EnableInClassList("inventory-image-drag", false);
}
private void UpdatePreview() {
CountLabel.text = value.count.ToString();
CountLabel.EnableInClassList("inventory-count-hide", value.count <= 1);
Image.style.backgroundImage = new StyleBackground(value.Sprite);
}
}