lcy
2025-10-28 b7bad9b52d93aec7fe16d2b086af927a44533dee
Main/System/ChallengeTab/ChallengeTabButton.cs
@@ -11,31 +11,73 @@
    [SerializeField] TextEx txtLockInfo;
    [SerializeField] Transform transUnlock;
    [SerializeField] RedpointBehaviour redpointBehaviour;
    Action action;
    void Awake()
    private Action _onClickAction;
    public struct DisplayData
    {
        btnTab.SetListener(() =>
        {
            UIManager.Instance.CloseWindow<ChallengeTabWin>();
            string activeBattleName = BattleManager.Instance.GetActiveBattleName();
            if (activeBattleName != "" && activeBattleName != "StoryBattleField")
            {
                UIManager.Instance.GetUI<MainWin>().ClickFunc(0);
            }
            action?.Invoke();
        });
        public int Index;
        public int RedpointId;
        public int OpenState;//0 FuncID 1 活动
        public int FuncId;
        public string CountInfo;
        public Action OnClickAction; // 按钮点击时触发的具体逻辑
    }
    public void Display(int index, int redpointId, bool isLock, string countInfo, string lockInfo, Action action)
    void Awake()
    {
        redpointBehaviour.redpointId = redpointId;
        transUnlock.SetActive(!isLock);
        txtCount.SetActive(isLock);
        txtLockInfo.SetActive(!isLock);
        imgIcon.SetSprite(StringUtility.Contact("ChallengeTab", index));
        txtName.text = Language.Get(StringUtility.Contact("ChallengeTab", index));
        txtCount.text = countInfo;
        txtLockInfo.text = lockInfo;
        this.action = action;
        btnTab.SetListener(OnTabClicked);
    }
}
    /// <summary>
    /// 处理按钮点击事件
    /// </summary>
    private void OnTabClicked()
    {
        // --- 通用点击逻辑 ---
        UIManager.Instance.CloseWindow<ChallengeTabWin>();
        string activeBattleName = BattleManager.Instance.GetActiveBattleName();
        if (activeBattleName != "" && activeBattleName != "StoryBattleField")
        {
            UIManager.Instance.GetUI<MainWin>().ClickFunc(0);
        }
        // 执行传入的具体业务逻辑
        _onClickAction?.Invoke();
    }
    /// <summary>
    /// 使用 DisplayData 结构体来更新按钮显示
    /// </summary>
    /// <param name="data">包含所有显示和行为配置的数据</param>
    public void Display(DisplayData data)
    {
        redpointBehaviour.redpointId = data.RedpointId;
        bool isOpen;
        if (data.OpenState == 0)
        {
            isOpen = FuncOpen.Instance.IsFuncOpen(data.FuncId);
        }
        else
        {
            isOpen = false;
        }
        // 根据锁定状态设置显隐
        transUnlock.SetActive(!isOpen);
        txtCount.SetActive(isOpen);
        txtLockInfo.SetActive(!isOpen);
        // 设置图标和名称
        string spriteAndLangKey = StringUtility.Contact("ChallengeTab", data.Index);
        imgIcon.SetSprite(spriteAndLangKey);
        txtName.text = Language.Get(spriteAndLangKey);
        // 设置TIPS文本
        txtCount.text = data.CountInfo;
        txtLockInfo.text = !isOpen ? Language.Get("Challenge02") : string.Empty;
        // 存储点击回调
        this._onClickAction = data.OnClickAction;
    }
}