备份CatanBuilding瘦身独立工程
This commit is contained in:
127
Assets/Scripts/UI/BattlePass/BPItemSlot.cs
Normal file
127
Assets/Scripts/UI/BattlePass/BPItemSlot.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
_disposables?.Dispose();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user