123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using FairyGUI;
- using FL.Data;
- using FL.Data.Items;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- public class EquipParam
- {
- public long id; // 装备唯一id
- public EEquipType equipType;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class DragonEggEquipCtrl : UIController<DragonEggEquipVM>
- {
- private EquipItem _newEquip;
- private EquipItem _wearEquip;
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- ShowUI(intent as EquipParam);
- }
- protected override void OnDisable()
- {
- _newEquip = null;
- _wearEquip = null;
- RemoveUIListenres();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.SellBtn.onClick.Add(OnClickSellBtn);
- VM.WearBtn.onClick.Add(OnClickWearBtn);
- VM.DecomposeBtn.onClick.Add(OnClickDecomposeBtn);
- }
- private void RemoveUIListenres()
- {
- VM.SellBtn.onClick.Remove(OnClickSellBtn);
- VM.WearBtn.onClick.Remove(OnClickWearBtn);
- VM.DecomposeBtn.onClick.Remove(OnClickDecomposeBtn);
- }
- #endregion
- /// <summary>
- /// 出售按钮事件
- /// </summary>
- /// <param name="context"></param>
- private void OnClickSellBtn(EventContext context)
- {
- if (_newEquip == null) return;
- if (_newEquip.FightingPower > _wearEquip.FightingPower)
- {
- XGame.Log.Warn($"当前要出售的装备{_newEquip.FightingPower}战力高于身上穿戴的{_wearEquip.FightingPower}");
- ConfirmationBoxParam dialogParam = new ConfirmationBoxParam()
- {
- cnt = StringDefine.sellHightPowerEquip,
- tipsKey = EDayTipsKey.SellEquip,
- onPromiseCallback = () => { SellEquip(); },
- };
- Context.UI.OpenAsync(UIKeys.CommonConfirmationBox, dialogParam);
- return;
- }
- SellEquip();
- }
- private void SellEquip()
- {
- DragonEggService.Instance.SellEquip(_newEquip);
- ClosePanel();
- }
- /// <summary>
- /// 穿戴|替换按钮事件
- /// </summary>
- /// <param name="context"></param>
- private void OnClickWearBtn(EventContext context)
- {
- if (_newEquip == null) return;
- DragonEggService.Instance.OnChangeEquip(_newEquip.EquipType, _newEquip);
- ClosePanel();
- }
- /// <summary>
- /// 分解按钮事件
- /// </summary>
- /// <param name="context"></param>
- private void OnClickDecomposeBtn(EventContext context)
- {
- ClosePanel();
- }
- private void ClosePanel()
- {
- Context.ClosePanel();
- }
- private void ShowUI(EquipParam param)
- {
- if (param == null) return;
- var id = param.id;
- if (param?.equipType != null)
- {
- var wearPartEquip = ItemData.Instance.GetEquipData(param.equipType);
- if (wearPartEquip != null && wearPartEquip.Id == id)
- {
- ShowEquipInfo(wearPartEquip);
- return;
- }
- }
- _newEquip = ItemData.Instance.GetNewEquip(param.id);
- if (_newEquip == null) return;
- _wearEquip = ItemData.Instance.GetEquipData(_newEquip.EquipType);
- bool bShowWear = _wearEquip != null;
- if (bShowWear)
- {
- VM.WearEquipItem.Ctrl.ShowUI(_newEquip, _wearEquip, true);
- }
- VM.NewEquipItem.Ctrl.ShowUI(_newEquip, _wearEquip);
- ShowBtnUI(bShowWear);
- }
- private void ShowBtnUI(bool bWear)
- {
- if (bWear)
- {
- //1_替换和出售 2_【替换】、【出售】、【分解】三个按钮
- VM.BtnState.selectedIndex = DragonEggData.Instance.IsUnLockDecompose ? 2 : 1;
- }
- else
- {
- // 当前没有同位置的装备,可使用的功能按钮只有【穿戴】
- VM.BtnState.selectedIndex = 0;
- }
- }
- private void ShowEquipInfo(EquipItem equip)
- {
- // 展示装备属性详情
- VM.BtnState.selectedIndex = 3;
- VM.NewEquipItem.Ctrl.ShowUI(equip, equip, true);
- }
- }
- }
|