Files
JJBB/Assets/Project/Script/GUI/PVP/PvpRewInfoItem.cs

145 lines
5.9 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GCGame.Table;
public struct PvpRewInfoStruct
{
public PvpRewPanel.PvpRewType type;
public int id;
public PvpRewInfoStruct(PvpRewPanel.PvpRewType _Type, int _Id)
{
type = _Type;
id = _Id;
}
}
public class PvpRewInfoItem : UIItemBase {
public Text _ConditionDesc;
public Image _ConditionIcon;
public UIContainerBase _RewItemContainer;
public GameObject _RedIcon;
public GameObject _GetBtn; //赛季、段位奖励不能领取,需要服务器主动下发
public GameObject _GetedBtn; //已获取
public GameObject _CantBtn;
private int _CurRewType = -1;
private int _RewId;
public override void Show(Hashtable hash)
{
base.Show(hash);
PvpRewInfoStruct info = (PvpRewInfoStruct)hash["InitObj"];
_CurRewType = (int)info.type;
_RewId = info.id;
List<CaptainWelfareRoot.CaptainWelfareRewItemInfo> resList = new List<CaptainWelfareRoot.CaptainWelfareRewItemInfo>();
_GetBtn.SetActive(info.type != PvpRewPanel.PvpRewType.Rank && info.type != PvpRewPanel.PvpRewType.Segment);
_CantBtn.SetActive(info.type != PvpRewPanel.PvpRewType.Rank && info.type != PvpRewPanel.PvpRewType.Segment);
_GetedBtn.SetActive(info.type != PvpRewPanel.PvpRewType.Rank && info.type != PvpRewPanel.PvpRewType.Segment);
switch (info.type)
{
case PvpRewPanel.PvpRewType.Day:
{
var tab = TableManager.GetHonorBattlefieldAwardDayByID(info.id, 0);
for(int index = 0; index < tab.getAwardIdCount(); index++)
{
resList.Add(new CaptainWelfareRoot.CaptainWelfareRewItemInfo(tab.GetAwardSubIdbyIndex(index), tab.GetAwardCountbyIndex(index)));
}
_ConditionDesc.text = tab.ConditionDesc.Replace("#r", "\n");
LoadAssetBundle.Instance.SetImageSprite(_ConditionIcon, tab.ConditionIconPath);
}
break;
case PvpRewPanel.PvpRewType.Season:
{
var tab = TableManager.GetHonorBattlefieldAwardSeasonByID(info.id, 0);
for (int index = 0; index < tab.getAwardIdCount(); index++)
{
resList.Add(new CaptainWelfareRoot.CaptainWelfareRewItemInfo(tab.GetAwardSubIdbyIndex(index), tab.GetAwardCountbyIndex(index)));
}
_ConditionDesc.text = tab.ConditionDesc.Replace("#r", "\n");
LoadAssetBundle.Instance.SetImageSprite(_ConditionIcon, tab.ConditionIconPath);
}
break;
case PvpRewPanel.PvpRewType.Rank:
{
var tab = TableManager.GetHonorBattlefieldAwardRankByID(info.id, 0);
for (int index = 0; index < tab.getAwardIdCount(); index++)
{
resList.Add(new CaptainWelfareRoot.CaptainWelfareRewItemInfo(tab.GetAwardSubIdbyIndex(index), tab.GetAwardCountbyIndex(index)));
}
_ConditionDesc.text = tab.ConditionDesc.Replace("#r", "\n");
LoadAssetBundle.Instance.SetImageSprite(_ConditionIcon, tab.ConditionIconPath);
}
break;
case PvpRewPanel.PvpRewType.Segment:
{
var tab = TableManager.GetHonorBattlefieldSegmentByID(info.id, 0);
for (int index = 0; index < tab.getAwardIdCount(); index++)
{
resList.Add(new CaptainWelfareRoot.CaptainWelfareRewItemInfo(tab.GetAwardSubIdbyIndex(index), tab.GetAwardCountbyIndex(index)));
}
_ConditionDesc.text = tab.RewDesc.Replace("#r", "\n");
LoadAssetBundle.Instance.SetImageSprite(_ConditionIcon, tab.RewPath);
}
break;
}
_RewItemContainer.InitContentItem(resList);
var _ScrollRect = _RewItemContainer.GetComponentInChildren<ScrollRect>();
if(_ScrollRect)
_ScrollRect.horizontal = resList != null && resList.Count > 3;
RefreshRewState();
}
private bool _CanGet = false;
private bool _Geted = false;
public void RefreshRewState()
{
var _MySelfPvpInfo = GameManager.gameManager.PlayerDataPool.pvpIfo;
switch(_CurRewType)
{
case (int)PvpRewPanel.PvpRewType.Day:
{
if(_MySelfPvpInfo._DayRewStateDic.ContainsKey(_RewId))
{
_CanGet = _MySelfPvpInfo._DayRewStateDic[_RewId] == 1;
_Geted = _MySelfPvpInfo._DayRewStateDic[_RewId] == 2;
ShowRedIcon(_CanGet);
_GetedBtn.SetActive(_Geted);
_CantBtn.SetActive(!_CanGet && !_Geted);
}
}
break;
case (int)PvpRewPanel.PvpRewType.Season:
{
if (_MySelfPvpInfo._SeasonRewStateDic.ContainsKey(_RewId))
{
_CanGet = _MySelfPvpInfo._SeasonRewStateDic[_RewId] == 1;
_Geted = _MySelfPvpInfo._SeasonRewStateDic[_RewId] == 2;
ShowRedIcon(_CanGet);
_GetedBtn.SetActive(_Geted);
_CantBtn.SetActive(!_CanGet && !_Geted);
}
}
break;
}
}
public void ShowRedIcon(bool isShow)
{
_RedIcon.SetActive(isShow);
}
public void OnGetBtn()
{
ReqHonorBattlefieldGetAward req = new ReqHonorBattlefieldGetAward();
req.Type = _CurRewType + 1;
req.Id = _RewId;
req.SendMsg();
}
}