1
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// UI装备栏
|
||||
/// </summary>
|
||||
public class UIEquipment : ModuleUIPanel {
|
||||
|
||||
public Equipment equipment;
|
||||
/// <summary> 插槽字典 </summary>
|
||||
public Dictionary<string, UIEquipmentSlot> dictionary = new Dictionary<string, UIEquipmentSlot>();
|
||||
|
||||
public UIEquipment(VisualElement element) : base(element) {
|
||||
InitialSlot(1, EquipmentSlotType.主手);
|
||||
InitialSlot(2, EquipmentSlotType.副手);
|
||||
InitialSlot(3, EquipmentSlotType.上衣);
|
||||
InitialSlot(4, EquipmentSlotType.项链);
|
||||
|
||||
InitialSlot(5, EquipmentSlotType.戒指1);
|
||||
InitialSlot(6, EquipmentSlotType.戒指2);
|
||||
InitialSlot(7, EquipmentSlotType.手镯1);
|
||||
InitialSlot(8, EquipmentSlotType.手镯2);
|
||||
|
||||
InitialSlot(9, EquipmentSlotType.头盔);
|
||||
InitialSlot(10, EquipmentSlotType.手套);
|
||||
InitialSlot(11, EquipmentSlotType.腰带);
|
||||
InitialSlot(12, EquipmentSlotType.鞋子);
|
||||
}
|
||||
public void Dispose() {
|
||||
|
||||
}
|
||||
|
||||
public void Settings(Equipment equipment) {
|
||||
if (this.equipment != null) { Dispose(); }
|
||||
this.equipment = equipment;
|
||||
if (equipment == null) { return; }
|
||||
equipment.ForEach(Settings);
|
||||
}
|
||||
public void Settings(string key, InventorySlot slot) {
|
||||
if (!dictionary.ContainsKey(key)) { return; }
|
||||
UIEquipmentSlot uiSlot = dictionary[key];
|
||||
uiSlot.Settings(slot);
|
||||
}
|
||||
|
||||
private void InitialSlot(int index, EquipmentSlotType type) {
|
||||
VisualElement element = Q<VisualElement>($"EquipmentSlot{index}");
|
||||
UIEquipmentSlot uiSlot = new UIEquipmentSlot(element);
|
||||
dictionary.Add(type.ToString(), uiSlot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bad4c66685a426345b174ec593f67f56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// UI装备插槽
|
||||
/// </summary>
|
||||
public class UIEquipmentSlot : ModuleUIPanel, InventoryDrag {
|
||||
|
||||
public InventorySlot value;
|
||||
|
||||
public Label CountLabel => Q<Label>("Count");
|
||||
public VisualElement Image => Q<VisualElement>("Image");
|
||||
|
||||
public int Count => 1;
|
||||
public InventoryItem Item => value.item;
|
||||
public VisualElement Anchor => element;
|
||||
|
||||
public UIEquipmentSlot(VisualElement element) : base(element) {
|
||||
element.RegisterCallback<MouseDownEvent>(MouseDownEvent);
|
||||
element.RegisterCallback<MouseOverEvent>(MouseOverEvent);
|
||||
element.RegisterCallback<MouseLeaveEvent>(MouseLeaveEvent);
|
||||
element.RegisterCallback<ClickEvent>(ClickEvent);
|
||||
}
|
||||
private void MouseDownEvent(MouseDownEvent evt) {
|
||||
UIPopupManager.I.inventoryDrag.Settings(this);
|
||||
Image.EnableInClassList("equipment-image-drag", true);
|
||||
}
|
||||
private void MouseOverEvent(MouseOverEvent evt) {
|
||||
if (!Verify()) { return; }
|
||||
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(InventorySlot value) {
|
||||
this.value = value;
|
||||
UpdatePreview();
|
||||
}
|
||||
public void Settings(InventoryItem item, int count) {
|
||||
value.Settings(item, count);
|
||||
UpdatePreview();
|
||||
}
|
||||
public void Cancel() {
|
||||
Image.EnableInClassList("equipment-image-drag", false);
|
||||
}
|
||||
|
||||
private void UpdatePreview() {
|
||||
Sprite sprite = value == null || value.item == null ? null : value.item.sprite;
|
||||
Image.style.backgroundImage = new StyleBackground(sprite);
|
||||
}
|
||||
private bool Verify() {
|
||||
InventoryDrag container = UIPopupManager.I.inventoryDrag.container;
|
||||
if (container == null) { return false; }
|
||||
// if (container.Item is Equipment equipment) { return value.verify.Invoke(equipment); }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99dc774aaeb03bc44b6607bd012c0e6e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 装备提示
|
||||
/// </summary>
|
||||
public class UIEquipmentTip : ModuleUIPanel {
|
||||
public UIEquipmentTip(VisualElement element) : base(element) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d2e2ebf18434ab489d8a0918806f5af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user