123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class EquipEquipItemNestedCtrl : UIController<EquipEquipItemNestedVM>
- {
- private Dictionary<EAttributeType, EquipAttrItemNestedView> _basicAttrItemMap;
- private List<EAttributeType> _allAttrTypeList; // 装备全部属性类型列表
- private List<EAttributeType> _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<EAttributeType, EquipAttrItemNestedView>();
- }
- 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<EAttributeType>();
- else
- _allAttrTypeList.Clear();
- if (_specialAttrTypeList == null)
- _specialAttrTypeList = new List<EAttributeType>();
- 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();
- }
- /// <summary>
- /// 装备的属性UI
- /// </summary>
- /// <param name="equipData"></param>
- /// <param name="wearEquip"></param>
- /// <param name="bWear"></param>
- 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);
- }
- }
- }
- /// <summary>
- /// 新装备属性的比较标识
- /// </summary>
- /// <param name="attributeType"></param>
- /// <param name="atrrVal"></param>
- /// <param name="wearEquip"></param>
- /// <returns></returns>
- private eCompareType GetCompareType(long atrrVal, long wearAttrVal)
- {
- return atrrVal == wearAttrVal ? eCompareType.None : (atrrVal > wearAttrVal ? eCompareType.Higth : eCompareType.Low);
- }
- }
- }
|