using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using GCGame.Table; using System; public class PVPRoot : MonoBehaviour { public static PVPRoot Instance; void Awake() { Instance = this; } void OnDestroy() { Instance = null; } #region Icon public List _NumSpriteList; public Image _SegmentIcon; public Image _SegMentDescIcon; public Image _SegmentNumDescIcon; public GameObject _NextLevelDescPanel; public Text _NextLevelVal; public GameObject _RedIcon; #endregion #region left up public Text _SeasonTimeDesc; public Text _SeasonRemainTimeDesc; public Text _NextLevelCanGainRewDesc; //达到XXX可获取奖励: public UIContainerBase _RewContainer; #endregion private static PvpInfo _MySelfPvpInfo = null; private void OnEnable() { if (_MySelfPvpInfo == null) _MySelfPvpInfo = GameManager.gameManager.PlayerDataPool.pvpIfo; ReqPvpInfo(); //InitSeasonInfo(); } void ReqPvpInfo() { ReqHonorBattlefieldPlayerInfo req = new ReqHonorBattlefieldPlayerInfo(); req.Flag = 1; req.SendMsg(); } public void OnPacket() { InitSegmentLevelInfo(); //InitRewContainer(); } DateTime _EndTime; double _RemainTime = 0.0d; public void InitSeasonInfo() { var _CurServerTime = GCGame.Utils.GetServerDateTime(); var pvpConfigBase = TableManager.GetHonorBattlefieldBaseByID(1, 0); if (pvpConfigBase == null) return; DateTime _StartTime; if (_CurServerTime.Day > pvpConfigBase.GetSeasonEndbyIndex(0)) { _StartTime = new DateTime(_CurServerTime.Year, _CurServerTime.Month, pvpConfigBase.GetSeasonEndbyIndex(0), 23, 59, 59); var _TotalDays = DateTime.DaysInMonth(_CurServerTime.Year, _CurServerTime.Month); _EndTime = new DateTime(_CurServerTime.Year, _CurServerTime.Month, _TotalDays, 23, 59, 59); _RemainTime = (_EndTime - _CurServerTime).TotalSeconds; } else { _StartTime = new DateTime(_CurServerTime.Year, _CurServerTime.Month, 1); var _TotalDays = DateTime.DaysInMonth(_CurServerTime.Year, _CurServerTime.Month); _EndTime = new DateTime(_CurServerTime.Year, _CurServerTime.Month, pvpConfigBase.GetSeasonEndbyIndex(0), 23, 59, 59); _RemainTime = (_EndTime - _CurServerTime).TotalSeconds; } //赛季时间描述 _SeasonTimeDesc.text = StrDictionary.GetClientDictionaryString("#{81017}", _StartTime.Year, _StartTime.Month, _StartTime.Day, _EndTime.Year, _EndTime.Month, _EndTime.Day); //初始化剩余时间描述 InitRemainTimeDesc(_RemainTime); StartCoroutine(CountRemainTimeSync()); } public void InitSegmentLevelInfo() { _MySelfPvpInfo = GameManager.gameManager.PlayerDataPool.pvpIfo; //必做刷新 var honorTab = TableManager.GetHonorBattlefieldSegmentByID(_MySelfPvpInfo.PvpSegmentLevel, 0); if(honorTab == null) { return; } LoadAssetBundle.Instance.SetImageSprite(_SegmentIcon, honorTab.SegmentIcon); LoadAssetBundle.Instance.SetImageSprite(_SegMentDescIcon, honorTab.SegmentDescIcon, delegate(bool isSucess, GameObject obj) { //_SegMentDescIcon.SetNativeSize(); //这边是新UI的适配 //_SegMentDescIcon.rectTransform.sizeDelta = new Vector2(_SegMentDescIcon.rectTransform.sizeDelta.x * 0.3f, _SegMentDescIcon.rectTransform.sizeDelta.y * 0.3f); }); _SegmentNumDescIcon.overrideSprite = _NumSpriteList[honorTab.SegmentNumDescIconIndex]; if(_MySelfPvpInfo.IsMaxLevel()) { _NextLevelDescPanel.SetActive(false); } else { _NextLevelDescPanel.SetActive(true); _NextLevelVal.text = _MySelfPvpInfo.SelfPvpScore + "/" + _MySelfPvpInfo.GetNextLevelNeedScore(); } } //倒计时 IEnumerator CountRemainTimeSync() { while(true) { yield return new WaitForSeconds(1.0f); var remainTime = (_EndTime - GCGame.Utils.GetServerDateTime()).TotalSeconds; if (remainTime <= 0) { remainTime = 0; } InitRemainTimeDesc(remainTime); if (remainTime == 0) yield break; } } private const int _DayTime = 3600 * 24; private const int _HourTime = 3600; private const int _MinTime = 60; public void InitRemainTimeDesc(double remainTime) { int _RemainDay = (int)remainTime / _DayTime; int _RemainHour = ((int)remainTime - _RemainDay * _DayTime) / _HourTime; int _RemainMin = ((int)remainTime - _RemainDay * _DayTime - _RemainHour * _HourTime) / 60; int _RemainSec = ((int)remainTime - _RemainDay * _DayTime - _RemainHour * _HourTime - _RemainMin * _MinTime); _SeasonRemainTimeDesc.text = StrDictionary.GetClientDictionaryString("#{81018}", _RemainDay.ToString().PadLeft(2, '0'), _RemainHour.ToString().PadLeft(2, '0'), _RemainMin.ToString().PadLeft(2, '0'), _RemainSec.ToString().PadLeft(2, '0')); } public void InitRewContainer() { var curSegmentLevel = _MySelfPvpInfo.PvpSegmentLevel; var nextSegmentLevel = curSegmentLevel >= _MySelfPvpInfo.MaxSegmentLevel ? curSegmentLevel : curSegmentLevel + 1; if(curSegmentLevel == nextSegmentLevel) { _RewContainer.gameObject.SetActive(false); } else { _RewContainer.gameObject.SetActive(true); _NextLevelCanGainRewDesc.text = StrDictionary.GetClientDictionaryString("#{82046}", _MySelfPvpInfo.GetSegmentLevelDesc(nextSegmentLevel)); var honorSegmentTab = TableManager.GetHonorBattlefieldSegmentByID(nextSegmentLevel, 0); List rewList = new List(); for(int index = 0; index < honorSegmentTab.getAwardCountCount(); index++) { CaptainWelfareRoot.CaptainWelfareRewItemInfo rew = new CaptainWelfareRoot.CaptainWelfareRewItemInfo(honorSegmentTab.GetAwardSubIdbyIndex(index), honorSegmentTab.GetAwardCountbyIndex(index)); rewList.Add(rew); } _RewContainer.InitContentItem(rewList); } } public void OnRankBtn() { UIManager.ShowUI(UIInfo.PvpRankPanel); } public void OnRewListBtn() { UIManager.ShowUI(UIInfo.PvpRewPanel); } public void OnExitBtn() { UIManager.CloseUI(UIInfo.PVPRoot); } public void OnPartInBtn() { MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{81001}"), "" ,delegate() { CG_REQ_ENTER_COPY req = (CG_REQ_ENTER_COPY)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_ENTER_COPY); req.SetCopyid(_MySelfPvpInfo._PvpSceneId); req.SendPacket(); UIManager.CloseUI(UIInfo.MessageBox); }, delegate() { UIManager.CloseUI(UIInfo.MessageBox); }); if (SportsPanel.Instance) SportsPanel.Instance.OnCloseBtn(); } public void OnRuleBtn() { // UIManager.ShowUI(UIInfo.PvpRulePanel); MessageHelpLogic.ShowHelpMessage(57); } public void OnSegmentBtn() { UIManager.ShowUI(UIInfo.PvpRulePanel); } public void ShowRewRedIcon(bool isShow) { _RedIcon.SetActive(isShow); } public void OnIntergalShopBtn() { YuanBaoShopLogic.OpenShopForJiFenItem(10, -1); } }