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()
|
{
|
// --- 通用点击逻辑 ---
|
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;
|
}
|
}
|