Files
Main/Assets/GameAssets/Resources/GameUI/Form/UIComponents/Scripts/UIPlayerLevelLabel.cs
2025-01-25 04:38:09 +08:00

111 lines
3.5 KiB
C#

using Thousandto.Code.Logic;
using Thousandto.Plugins.Common;
using UnityEngine;
namespace Thousandto.GameUI.Form
{
/// <summary>
/// 玩家等级的标签组件
/// </summary>
public class UIPlayerLevelLabel : MonoCacheBase
{
#region //UI控件
private GameObject _levelGo;
private UILabel _levelLbl;
private UILabel _dflevelLbl;
private UISprite _dfLevelIcon;
private GameObject _dflevelGo;
#endregion
public void OnFirstShow()
{
//基础的等级展示
var trans = transform.Find("Level");
if (trans != null)
{
_levelGo = trans.gameObject;
_levelLbl = _levelGo.GetComponent<UILabel>();
}
//巅峰的等级展示
trans = transform.Find("DFLevel");
if (trans != null)
{
_dflevelGo = trans.gameObject;
var tmpTrans = _dflevelGo.transform.Find("Text");
if (tmpTrans != null)
{
_dflevelLbl = tmpTrans.GetComponent<UILabel>();
}
tmpTrans = _dflevelGo.transform.Find("Icon");
if (tmpTrans != null)
{
_dfLevelIcon = tmpTrans.GetComponent<UISprite>();
}
}
}
//直接设置文本--不显示标记.
public void SetLabelText(string text)
{
if (_levelGo != null && !_levelGo.activeSelf)
{
_levelGo.SetActive(true);
}
if (_dflevelGo != null && _dflevelGo.activeSelf)
{
_dflevelGo.SetActive(false);
}
if (_levelLbl != null) _levelLbl.text = text;
}
//设置等级到标签,显示巅峰标记
public void SetLevel(int level)
{
int dfLevel;
if (CommonUtils.TryGetDFLevel(level, out dfLevel))
{
if (_levelGo != null) _levelGo.SetActive(false);
if(_dflevelGo != null) _dflevelGo.SetActive(true);
if (_dflevelLbl != null) _dflevelLbl.text = dfLevel.ToString();
}
else
{
if(_levelGo != null) _levelGo.SetActive(true);
if (_dflevelGo != null) _dflevelGo.SetActive(false);
if (_levelLbl != null) _levelLbl.text = string.Format(Thousandto.Cfg.Data.DeclareMessageString.Get(Thousandto.Cfg.Data.DeclareMessageString.C_UI_LEVELLV), dfLevel);
}
}
//设置等级到标签,不过不带有任何巅峰的标记
public void SetLevelOutFlag(int level)
{
int dfLevel;
CommonUtils.TryGetDFLevel(level, out dfLevel);
if (_levelGo != null && !_levelGo.activeSelf)
{
_levelGo.SetActive(true);
}
if (_dflevelGo != null && _dflevelGo.activeSelf)
{
_dflevelGo.SetActive(false);
}
if (_levelLbl != null) _levelLbl.text = dfLevel.ToString();
}
public void SetColor(Color color)
{
if (_dflevelLbl != null) _dflevelLbl.color = color;
if (_levelLbl != null) _levelLbl.color = color;
}
public void SetIconIsGray(bool isGray)
{
if (_dfLevelIcon != null) _dfLevelIcon.IsGray = isGray;
}
}
}