/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using FairyGUI; using FL.Data.Items; using XGame.Database; using XGame.Framework.UI; namespace FL.FGUI { public class UiParam { public bool bShowName; public bool bShowCount; public bool bShowBtn; // 是否可点击 public bool bShowMask; public bool bShowLevel; public bool bShowBaseInfo; // 点击道具是否只显示物品简易信息 } /// /// UI逻辑处理类 /// /// public partial class CommonItemBaseCtrl : UIController { private IItem _data; private bool _bShowBaseInfo; protected override void OnEnable(object intent) { AddUIListenres(); } protected override void OnDisable() { RemoveUIListenres(); } #region UI事件 private void AddUIListenres() { VM.ItemBtn.onClick.Add(OnClickBtn); } private void RemoveUIListenres() { VM.ItemBtn.onClick.Remove(OnClickBtn); } #endregion private void OnClickBtn(EventContext context) { if (_data == null) { return; } else if (_data?.ItemType == EItemType.Equip) { if (_data is EquipItem) { Context.UI.OpenAsync(UIKeys.EquipEquipPanel, _data); } else Context.UI.OpenAsync( UIKeys.EquipEquipPanel, EquipData.Instance.GetBagEquipItem(_data.Id) ); } else if (_bShowBaseInfo) { ShowItemInfoPanel(); } else { ShowSourceOfPropsPanel(); } } /// /// 简易的道具物品信息 /// private void ShowItemInfoPanel() { //Log.Debug($"显示道具:{data.Name}详情界面"); Context.UI.OpenAsync( UIKeys.ItemInformationPanel, new ItemInfoParam { itemInfo = ItemTableRepo.Get(_data.TableId), numDesc = _data?.ItemType == EItemType.Equip ? $"LV.{_data.Level}" : (int.Parse(_data.Count) > 1 ? _data.Count : string.Empty), } ); } /// /// 道具物品的来源信息界面 /// private void ShowSourceOfPropsPanel() { Context.UI.OpenAsync( UIKeys.BagSourceOfPropsPanel, new ItemInfoParam { itemInfo = ItemTableRepo.Get(_data.TableId), numDesc = (int.Parse(_data.Count) > 1 ? _data.Count : string.Empty), } ); } public void ShowEmptyUI() { _data = null; VM.QualityImg.icon = "daojukuang1"; } public void ShowUI(IItem item, UiParam uiParam) { _data = item; _bShowBaseInfo = uiParam.bShowBaseInfo; VM.QualityImg.icon = AddressableDefine.ItemFrame(item.Quality); VM.ItemIcon.icon = item.Icon; VM.LvLabel.visible = uiParam.bShowLevel; if (uiParam.bShowLevel) { VM.LvLabel.text = $"LV.{item.Level}"; } VM.CountLabel.visible = uiParam.bShowCount; if (uiParam.bShowCount) { VM.CountLabel.text = item.Count; } VM.MaskImg.visible = uiParam.bShowMask; VM.ItemBtn.visible = uiParam.bShowBtn; } /// /// 道具背包中的物品信息 /// /// /// public void OnRefresh(int index, Item itemData) { UiParam _uiParam = new UiParam(); _uiParam.bShowBtn = true; _uiParam.bShowName = false; _uiParam.bShowCount = true; _uiParam.bShowLevel = false; _uiParam.bShowBaseInfo = false; ShowUI(itemData, _uiParam); } } }