Files
JJBB/Assets/Project/Script/GUI/Guide/BtnFunc.cs
2024-08-23 15:49:34 +08:00

203 lines
5.7 KiB
C#

using UnityEngine;
using System.Collections;
using GCGame.Table;
using Module.Log;
using UnityEngine.UI;
public class BtnFunc : MonoBehaviour
{
public int _functionOpenId;
//如果需要在外部设置ID,这边便需要激活为true,在UIPrefab上处理
public bool _IsIgnoreSetFuncId = false;
public GameObject remainTimeStateIcon;
public Text remainTimeText;
public GameObject _ImageGO;
public BtnList _BtnList;
public GameObject _limitDescBG;
public Text _limitLevelDesc;
public GameObject _RedIcon;
private int _OpenGuide;
private int _OpenLevel;
private int _ShowLevel;
private int _OpenVIPLevel;
private int _OpenDays; //按开服天数开启
private void OnEnable()
{
if (remainTimeStateIcon)
{
remainTimeStateIcon.SetActive(false);
RedTipPoint redTipPoint = remainTimeStateIcon.GetComponent<RedTipPoint>();
if (redTipPoint != null)
redTipPoint.Init();
}
}
public void UpdateFuncState(int _funcId = -1)
{
if(_funcId != -1 && !_IsIgnoreSetFuncId)
_functionOpenId = _funcId;
if (_funcId == 104)
return; //不处理
var functionOpenTab = TableManager.GetFunctionOpenByID(_functionOpenId, 0);
if(functionOpenTab == null)
{
return;
}
_OpenGuide = functionOpenTab.ShowGUIDId;
_OpenLevel = functionOpenTab.OpenLevel;
_ShowLevel = functionOpenTab.ShowLevel;
_OpenVIPLevel = functionOpenTab.OpenVipLv;
_OpenDays = functionOpenTab.OpenServerDay;
if (_OpenDays > GlobalData.OpenServerDays)
{
gameObject.SetActive(false);
return;
}
else gameObject.SetActive(true);
if (_OpenGuide > 0)
{
if (_OpenGuide > Guide.Instance._FinishGuideID)
{
gameObject.SetActive(false);
return;
}
else
{
LogModule.DebugLog("Set fuc enable:" + gameObject.name + " " + (GameManager.gameManager.PlayerDataPool.VipCost >= _OpenVIPLevel).ToString());
gameObject.SetActive(GameManager.gameManager.PlayerDataPool.VipCost >= _OpenVIPLevel);
}
}else if(functionOpenTab.ShowLevel > 0)
{
gameObject.SetActive(GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level >= functionOpenTab.ShowLevel && GameManager.gameManager.PlayerDataPool.VipCost >= _OpenVIPLevel);
}
if(_OpenLevel > _ShowLevel)
{
if(IsBtnOpen())
{
if (_limitDescBG != null)
_limitDescBG.gameObject.SetActive(false); // 达到开启得就不显示文字
}
else
{
if (_limitDescBG != null && _limitLevelDesc != null)
{
_limitLevelDesc.text = StrDictionary.GetClientDictionaryString("#{46002}", functionOpenTab.OpenLevel);
_limitDescBG.gameObject.SetActive(true);
}
}
}
else
{
if(_limitDescBG != null)
_limitDescBG.gameObject.SetActive(false);
}
ShowRemainTimeStateIcon();
}
public bool IsBtnOpen()
{
if (_OpenGuide > 0)
{
if (_OpenGuide > Guide.Instance._FinishGuideID)
{
return false;
}
else
{
return GameManager.gameManager.PlayerDataPool.VipCost >= _OpenVIPLevel;
}
}
else if (_OpenLevel > 0)
{
if(GameManager.gameManager.PlayerDataPool.FunctionOpenState.ContainsKey(_functionOpenId)
&& GameManager.gameManager.PlayerDataPool.FunctionOpenState[_functionOpenId]
&& GameManager.gameManager.PlayerDataPool.VipCost >= _OpenVIPLevel)
{
return true;
}
else
{
return false;
}
}
return true;
}
public void HideImage()
{
_ImageGO.gameObject.SetActive(false);
}
public void ShowImage()
{
_ImageGO.gameObject.SetActive(true);
}
public void OnFunctionIconClick()
{
if(IsBtnOpen())
{
if(FunctionExLogic.Instance())
{
FunctionExLogic.Instance().OnFunctionBtnClick(_functionOpenId);
}
}else
{
//打开提示界面
UIManager.ShowUI(UIInfo.FunctionLimitRoot, delegate(bool bSucess, object param) {
if(bSucess)
{
FunctionLimitRoot.Instance.ShowFunctionLimitInfo(_functionOpenId);
}
});
}
}
public void ShowRemainTimeStateIcon(int remainTime = -1)
{
if (remainTimeStateIcon == null)
return;
if (remainTime == -1)
remainTime = GameManager.gameManager.PlayerDataPool.FunctionRemainTimeStateManager.GetopyRemainTime();
if (remainTime <= 0)
{
remainTimeStateIcon.SetActive(false);
return;
}
remainTimeStateIcon.SetActive(true);
if (remainTimeText != null)
{
remainTimeText.text = (remainTime >= 99 ? 99 : remainTime).ToString();
}
}
public void ShowRedIcon(bool isShow)
{
if (_RedIcon)
{
if(isShow)
{
if(!_RedIcon.gameObject.activeInHierarchy)
_RedIcon.gameObject.SetActive(true);
}else
_RedIcon.gameObject.SetActive(false);
}
}
}