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

184 lines
5.4 KiB
C#

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using GCGame.Table;
using Module.Log;
public class WelfareOnLineRewardItem : UIItemBase {
public Text _TimeText;
public Image _ItemQuality;
public Image _ItemIcon;
public Text _ItemNum;
public Text _BtnDesc;
private int _ItemId;
private int _ItemCount;
private int _SubNodeState;
private int _NodeId;
private int _SubNodeId;
private bool isStartCountTime = false;
private int _TotalTime;
private int _PassedTime;
private int _RemainTime;
public override void Show(Hashtable hash)
{
base.Show(hash);
WelfareOnLineItemInfo info = (WelfareOnLineItemInfo)hash["InitObj"];
if(info == null)
{
LogModule.ErrorLog("info is null");
return;
}
_ItemId = info._ItemId;
_ItemCount = info._ItemCount;
_SubNodeState = info._SubNodeState;
_NodeId = info._NodeId;
_SubNodeId = info._SubNodeId;
isStartCountTime = info._IsCountTime;
_TotalTime = info._TotalTime;
_PassedTime = info._PassedTime;
_RemainTime = _TotalTime - _PassedTime;
if (_SubNodeState == (int)WelfareRootCtr.WlfareRewardState.CanGetAgain
|| _SubNodeState == (int)WelfareRootCtr.WlfareRewardState.CanGet
|| _SubNodeState == (int)WelfareRootCtr.WlfareRewardState.HasGeted)
{
_RemainTime = 0;
isStartCountTime = false;
}
InitBtnStateAndDesc();
InitRemainTimeDesc(_RemainTime);
InitRewItem();
}
public void InitRewItem()
{
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(_ItemId, 0);
if(commonItem == null)
{
LogModule.ErrorLog("Common is null, item id is : " + _ItemId);
}
LoadAssetBundle.Instance.SetImageSprite(_ItemIcon, commonItem.Icon);
LoadAssetBundle.Instance.SetImageSprite(_ItemQuality, GCGame.Utils.GetItemQualityFrame(commonItem.Quality));
if (commonItem.QualityEffect > 0)
{
CommonItemContainerItem.ShowQualityEffect(true, commonItem.QualityEffect, _ItemIcon.transform);
}
else
{
CommonItemContainerItem.ShowQualityEffect(false, commonItem.QualityEffect, _ItemIcon.transform);
}
if (_ItemCount == 1)
{
_ItemNum.gameObject.SetActive(false);
}
else
{
_ItemNum.text = _ItemCount.ToString();
}
}
private string _RemainMin; //分
private string _RemainSec; //秒
//初始化显示
public void InitRemainTimeDesc(int _RemainTime)
{
if(_RemainTime <= 0)
{
_TimeText.text = "00:00";
}else
{
if (_RemainTime / 60 == 0)
{
_RemainMin = "00";
}
else
{
if (_RemainTime / 60 < 10)
{
_RemainMin = "0" + _RemainTime / 60;
}
else
{
_RemainMin = (_RemainTime / 60).ToString();
}
}
if (_RemainTime % 60 < 10)
{
_RemainSec = "0" + _RemainTime % 60;
}
else
{
_RemainSec = (_RemainTime % 60).ToString();
}
_TimeText.text = _RemainMin + ":" + _RemainSec;
}
}
private float _CountTime = 0.0f;
private void Update()
{
if(isStartCountTime)
{
if (_RemainTime >= 0)
{
_CountTime += Time.deltaTime;
if (_CountTime >= 1.0f)
{
_CountTime = 1 - _CountTime;
_RemainTime--;
InitRemainTimeDesc(_RemainTime);
}
}
}
}
readonly string _GrayColor = "<color=#515053>{0}</color>";
readonly string _CoffeColor = "<color=#745146>{0}</color>";
public void InitBtnStateAndDesc()
{
if (_SubNodeState == (int)WelfareRootCtr.WlfareRewardState.CanGetAgain)
{
_BtnDesc.text = string.Format(_CoffeColor, StrDictionary.GetClientDictionaryString("#{42705}")); //"再次领取";
}
else if (_SubNodeState == (int)WelfareRootCtr.WlfareRewardState.CanGet)
{
_BtnDesc.text = string.Format(_CoffeColor, StrDictionary.GetClientDictionaryString("#{42703}")); //"领取";
}
else if (_SubNodeState == (int)WelfareRootCtr.WlfareRewardState.HasGeted)
{
_BtnDesc.text = string.Format(_GrayColor, StrDictionary.GetClientDictionaryString("#{42704}")); //"已领取";
}
else
{
_BtnDesc.text = string.Format(_CoffeColor, StrDictionary.GetClientDictionaryString("#{42623}")); //"未达成";
}
}
public void OnItemIconClick()
{
ItemTooltipsLogic.ShowItemTooltip(_ItemId, ItemTooltipsLogic.ShowType.Info, _ItemIcon.transform.position);
}
public void OnRecBtnClick()
{
if (_SubNodeState == (int)WelfareRootCtr.WlfareRewardState.CanGetAgain
|| _SubNodeState == (int)WelfareRootCtr.WlfareRewardState.CanGet)
{
ReqGetWelfareRew req = new ReqGetWelfareRew();
req._NodeId = _NodeId;
req._SubNodeId = _SubNodeId;
req.SendMsg();
}
}
}