/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using FL.Data.Items; using System.Collections.Generic; using XGame.Database; using XGame.Framework.UI; namespace FL.FGUI { /// /// UI逻辑处理类 /// /// public partial class EquipEquipItemNestedCtrl : UIController { private Dictionary _basicAttrItemMap; private List _allAttrTypeList; // 装备全部属性类型列表 private List _specialAttrTypeList; protected override void OnEnable(object intent) { AddUIListenres(); } protected override void OnDisable() { RemoveUIListenres(); _basicAttrItemMap?.Clear(); _basicAttrItemMap = null; _allAttrTypeList?.Clear(); _allAttrTypeList = null; _specialAttrTypeList?.Clear(); _specialAttrTypeList = null; } #region UI事件 private void AddUIListenres() { } private void RemoveUIListenres() { } #endregion private void InitUI() { if (_basicAttrItemMap == null) { _basicAttrItemMap = new Dictionary(); } else { _basicAttrItemMap.Clear(); } _basicAttrItemMap.Add(EAttributeType.Hp, VM.HpAttrItem); _basicAttrItemMap.Add(EAttributeType.Atk, VM.AtkAttrItem); _basicAttrItemMap.Add(EAttributeType.Def, VM.DefAttrItem); _basicAttrItemMap.Add(EAttributeType.AtkSpeed, VM.SpeedAttrItem); VM.SpecialAttrItem1.Ctrl.ResetUI(); VM.SpecialAttrItem2.Ctrl.ResetUI(); if (_allAttrTypeList == null) _allAttrTypeList = new List(); else _allAttrTypeList.Clear(); if (_specialAttrTypeList == null) _specialAttrTypeList = new List(); else _specialAttrTypeList.Clear(); } public void ShowUI(EquipAttr newEquip, EquipAttr wearEquip, bool bWear = false) { VM.State.selectedIndex = bWear ? 0 : 1; EquipAttr equipData = bWear ? wearEquip : newEquip; ShowEquipItemUI(equipData); ShowAttrUi(equipData, wearEquip, bWear); } private void ShowEquipItemUI(EquipAttr equipData) { var equipBase = new EquipItemBase(); if (equipData.Id == 0) { equipBase.InitByEquipPart(equipData.EquipType); } else { equipBase.InitById(equipData.Id); } VM.ItemBtn.Ctrl.ShowUI(equipBase); VM.NameLabel.text = equipData.Name; VM.NameLabel.color = equipData.Quality.ToEquipNameColor(); } /// /// 装备的属性UI /// /// /// /// private void ShowAttrUi(EquipAttr equipData, EquipAttr wearEquip, bool bWear) { InitUI(); //装备的属性列表 //equipData.Attributes.GetAll(ref _allAttrTypeList, 0); equipData.Attributes.GetAll(ref _specialAttrTypeList, 2); if (_specialAttrTypeList.Count > 0) { _basicAttrItemMap.Add(_specialAttrTypeList[0], VM.SpecialAttrItem1); } if (_specialAttrTypeList.Count > 1) { _basicAttrItemMap.Add(_specialAttrTypeList[1], VM.SpecialAttrItem2); } foreach (var item in _basicAttrItemMap) { long attributeVal = equipData.Attributes.GetValue(item.Key); if (attributeVal > 0) { var compareType = GetCompareType(attributeVal, wearEquip == null ? 0 : wearEquip.Attributes.GetValue(item.Key)); item.Value.Ctrl.ShowUI(item.Key, attributeVal, compareType, true); } else { item.Value.Ctrl.ShowUI(item.Key, 0, eCompareType.None, false); } } } /// /// 新装备属性的比较标识 /// /// /// /// /// private eCompareType GetCompareType(long atrrVal, long wearAttrVal) { return atrrVal == wearAttrVal ? eCompareType.None : (atrrVal > wearAttrVal ? eCompareType.Higth : eCompareType.Low); } } }