hch
5 天以前 23c416e43615b956f9b685b2184e9b18bf9cb665
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using UnityEngine;
using UnityEngine.UI;
 
public class ChallengeTabButton : MonoBehaviour
{
    [SerializeField] Button btnTab;
    [SerializeField] ImageEx imgIcon;
    [SerializeField] TextEx txtName;
    [SerializeField] TextEx txtCount;
    [SerializeField] TextEx txtLockInfo;
    [SerializeField] Transform transUnlock;
    [SerializeField] RedpointBehaviour redpointBehaviour;
 
    private Action _onClickAction;
 
    public struct DisplayData
    {
        public int Index;
        public int RedpointId;
        public int OpenState;//0 FuncID 1 活动
        public int FuncId;
        public string CountInfo;
        public Action OnClickAction; // 按钮点击时触发的具体逻辑
    }
 
    void Awake()
    {
        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;
    }
}