123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using FairyGUI;
- using FL.Data.Items;
- using XGame;
- 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;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class CommonItemBaseCtrl : UIController<CommonItemBaseVM>
- {
- private IItem data;
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- }
- #region UI事件
- private void AddUIListenres()
- {
- if (VM.ItemBtn != null)
- {
- VM.ItemBtn.onClick.Add(OnClickBtn);
- }
- }
- private void RemoveUIListenres()
- {
- if (VM.ItemBtn != null)
- {
- VM.ItemBtn.onClick.Remove(OnClickBtn);
- }
- }
- #endregion
- private void OnClickBtn(EventContext context)
- {
- if (data == null)
- {
- return;
- }
- else if (data?.ItemType == EItemType.Equip)
- {
- var _uiParam = new EquipParam();
- _uiParam.id = data.Id;
- _uiParam.equipType = (data as EquipItem).Table.Part;
- Context.UI.OpenAsync(UIKeys.DragonEggEquip, _uiParam);
- }
- else
- {
- Log.Debug($"显示道具:{data.Name}详情界面");
- }
- }
- /// <summary>
- /// UI显示数据
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- private Item GetItemUIData(int id)
- {
- ItemTable _itemTable = ItemTableRepo.Get(id);// 模拟
- Item _item = new Item();
- _item.Init(_itemTable, UIDDefine.New());
- return _item;
- }
- public void ShowUI(IItem item, UiParam uiParam)
- {
- data = item;
- if (VM.QualityImg != null)
- {
- VM.QualityImg.icon = AddressableDefine.ItemFrame(item.Quality);
- }
- if (VM.ItemIcon != null)
- {
- VM.ItemIcon.icon = item.Icon;
- }
- if (VM.NameLabel != null)
- {
- VM.NameLabel.visible = uiParam.bShowName;
- if (uiParam.bShowName)
- {
- VM.NameLabel.text = item.Name;
- }
- }
- if (VM.LvLabel != null)
- {
- VM.NameLabel.visible = uiParam.bShowLevel;
- if (uiParam.bShowLevel)
- {
- VM.LvLabel.text = $"lv.{item.Level}";
- }
- }
- if (VM.CountLabel != null)
- {
- VM.CountLabel.visible = uiParam.bShowCount;
- if (uiParam.bShowCount)
- {
- VM.CountLabel.text = item.Count;
- }
- }
- if (VM.MaskImg != null)
- {
- VM.MaskImg.visible = uiParam.bShowMask;
- }
- if (VM.ItemBtn != null)
- {
- VM.ItemBtn.visible = uiParam.bShowBtn;
- }
- }
- /// <summary>
- /// 模拟的道具数据展示
- /// </summary>
- /// <param name="tableId"></param>
- public void ShowAnalogData(int tableId, UiParam _uiParam)
- {
- ShowUI(GetItemUIData(tableId), _uiParam);
- }
- }
- }
|