123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class BagUsePanelCtrl : UIController<BagUsePanelVM>
- {
- 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();
- }
- /// <summary>
- /// 增加|减少数量的按钮状态
- /// </summary>
- 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;
- }
- }
- }
|