132 lines
3.4 KiB
C#
132 lines
3.4 KiB
C#
using asap.core;
|
|
using GameCore;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BPItemSlot : MonoBehaviour
|
|
{
|
|
|
|
#region Field 乂
|
|
protected RewardItemNew RewardItem;
|
|
// protected Image
|
|
// img_bg;
|
|
protected GameObject
|
|
go_claim,
|
|
go_levelLock,
|
|
go_vipLock,
|
|
go_hasGot;
|
|
protected Button
|
|
btn_click;
|
|
|
|
|
|
protected bool _isNormal;
|
|
protected int _level;
|
|
protected CompositeDisposable _disposables = new();
|
|
protected BattlePassDataProvider _dataProvider;
|
|
#endregion
|
|
|
|
|
|
#region Func
|
|
private void Init()
|
|
{
|
|
RewardItem = transform.GetComponentInChildren<RewardItemNew>();
|
|
|
|
go_claim = transform.Find("position/claim").gameObject;
|
|
go_vipLock = transform.Find("position/lock")?.gameObject;
|
|
go_levelLock = transform.Find("position/unlock")?.gameObject;
|
|
go_hasGot = transform.Find("position/reward/received").gameObject;
|
|
|
|
// img_bg = RewardItem.transform.Find("bg").GetComponent<Image>();
|
|
btn_click = go_claim?.GetComponent<Button>();
|
|
|
|
_dataProvider = GContext.container.Resolve<BattlePassDataProvider>();
|
|
}
|
|
protected virtual void Start()
|
|
{
|
|
}
|
|
|
|
public void SetData(bool isNomal, BPRewardSlot.ESlotState state, ItemData itemData)
|
|
{
|
|
Init();
|
|
if (itemData == null)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
gameObject.SetActive(true);
|
|
_level = -1;
|
|
_isNormal = isNomal;
|
|
|
|
|
|
// GContext.container.Resolve<IUIService>().SetImageSprite(img_bg, isNomal ? "bg_shop_gift_hook" : "bg_batttlepass_reward");
|
|
|
|
RewardItem.SetData(itemData, abbr: true);
|
|
ChangeState(state);
|
|
|
|
}
|
|
public void SetData(bool isNomal, int level)
|
|
{
|
|
Init();
|
|
_level = level;
|
|
_isNormal = isNomal;
|
|
|
|
var itemData = _dataProvider.GetSlotDropItem(level, isNomal);
|
|
|
|
// GContext.container.Resolve<IUIService>().SetImageSprite(img_bg, isNomal ? "bg_shop_gift_hook" : "bg_batttlepass_reward");
|
|
|
|
RewardItem.SetData(itemData, abbr: true);
|
|
RefreshSlot();
|
|
if (!isNomal)
|
|
{
|
|
var particle = transform.Find("position/particle");
|
|
particle.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
|
|
public void RefreshSlot()
|
|
{
|
|
if (_level != -1)
|
|
ChangeState(GContext.container.Resolve<BattlePassDataProvider>().GetSlotState(_level, _isNormal));
|
|
else
|
|
ChangeState(BPRewardSlot.ESlotState.Normal);
|
|
|
|
}
|
|
|
|
public void SetInactive()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public virtual void ChangeState(BPRewardSlot.ESlotState state)
|
|
{
|
|
go_claim.SetActive(false);
|
|
go_levelLock?.SetActive(state == BPRewardSlot.ESlotState.LevelLock);
|
|
go_hasGot?.SetActive(state == BPRewardSlot.ESlotState.HasGotReward);
|
|
|
|
switch (state)
|
|
{
|
|
case BPRewardSlot.ESlotState.CanGetReward:
|
|
if (!_isNormal && !_dataProvider.IsUnlockVip)
|
|
break;
|
|
if (btn_click)
|
|
btn_click.enabled = true;
|
|
go_claim.SetActive(true);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
go_vipLock?.SetActive(!_isNormal && (!_dataProvider.IsUnlockVip || _dataProvider.UILockVip));
|
|
|
|
}
|
|
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_disposables?.Dispose();
|
|
}
|
|
#endregion
|
|
}
|
|
|