/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using Codice.CM.Common; using FairyGUI; using FL.Data; using XGame.Database; using XGame.Framework.UI; using static Codice.CM.WorkspaceServer.WorkspaceTreeDataStore; namespace FL.FGUI { /// /// UI逻辑处理类 /// /// public partial class BagUsePanelCtrl : UIController { private int _useNum; // 要使用的数量 private int _maxNum; // 拥有的数量 protected override void OnEnable(object intent) { AddUIListenres(); ShowUI(intent as ItemTable); } protected override void OnDisable() { RemoveUIListenres(); } #region UI事件 private void AddUIListenres() { VM.UseBtn.onClick.Add(OnClickUseBtn); VM.ReduceOneBtn.onClick.Add(OnClickReduceOneBtn); VM.ReduceTenBtn.onClick.Add(OnClickReduceTenBtn); VM.AddOneBtn.onClick.Add(OnClickAddOneBtn); VM.AddTenBtn.onClick.Add(OnClickAddTenBtn); VM.MaxBtn.onClick.Add(OnClickMaxBtn); } private void RemoveUIListenres() { VM.UseBtn.onClick.Remove(OnClickUseBtn); VM.ReduceOneBtn.onClick.Remove(OnClickReduceOneBtn); VM.ReduceTenBtn.onClick.Remove(OnClickReduceTenBtn); VM.AddOneBtn.onClick.Remove(OnClickAddOneBtn); VM.AddTenBtn.onClick.Remove(OnClickAddTenBtn); VM.MaxBtn.onClick.Remove(OnClickMaxBtn); } private void OnClickUseBtn(EventContext context) { } private void OnClickReduceOneBtn(EventContext context) { ShowUseNum(_useNum - 1); } private void OnClickReduceTenBtn(EventContext context) { ShowUseNum(_useNum - 10); } private void OnClickAddOneBtn(EventContext context) { ShowUseNum(_useNum + 1); } private void OnClickAddTenBtn(EventContext context) { ShowUseNum(_useNum + 10); } private void OnClickMaxBtn(EventContext context) { ShowUseNum(_maxNum); } #endregion private void ShowUI(ItemTable itemInfo) { if (itemInfo != null) { _maxNum = (int)ItemData.Instance.GetItemNum(itemInfo.Id); VM.CountLabel.text = _maxNum.ToString(); VM.QualityIcon.icon = AddressableDefine.ItemFrame(itemInfo.Quality); VM.ItemIcon.icon = itemInfo.Icon; ShowUseNum(1); } } private void ShowUseNum(int count) { if (count < 0 || count > _maxNum) return; _useNum = count; VM.UseNumLabel.text = _useNum.ToString(); ShowBtnState(); } /// /// 增加|减少数量的按钮状态 /// private void ShowBtnState() { VM.ReduceOneBtn.enabled = _useNum != 0; VM.ReduceTenBtn.enabled = _useNum != 0; VM.UseBtn.enabled = _useNum != 0; VM.AddOneBtn.enabled = _useNum != _maxNum; VM.AddTenBtn.enabled = _useNum != _maxNum; } } }