227 lines
8.3 KiB
C#
227 lines
8.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using GameCore;
|
|
using TMPro;
|
|
using asap.core;
|
|
using EnhancedUI.EnhancedScroller;
|
|
using game;
|
|
using DG.Tweening;
|
|
|
|
public class EventOfferJourneyBlockView : EnhancedScrollerCellView
|
|
{
|
|
[SerializeField] protected Button btnIap, btnTicket, btnIapGray, btnTicketGray;
|
|
[SerializeField] protected RewardItemNew reward;
|
|
[SerializeField] protected TMP_Text priceIap, priceTicket, priceIapGray, priceTicketGray;
|
|
[SerializeField] protected GameObject goLock, goGrandReward;
|
|
[SerializeField] protected Animation aniTick;
|
|
protected cfg.IAPItemList _iapItemList = null;
|
|
protected PlayerItemData _playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
private int _dropId, _cost;
|
|
protected EState _state = EState.Locked;
|
|
protected EnhancedScroller _scroller;
|
|
|
|
public virtual void Start()
|
|
{
|
|
btnIap.onClick.AddListener(OnClickIAP);
|
|
btnTicket.onClick.AddListener(OnClickTicket);
|
|
btnIapGray.onClick.AddListener(OnClickGrayBtn);
|
|
btnTicketGray.onClick.AddListener(OnClickGrayBtn);
|
|
}
|
|
|
|
public virtual void Init(EventOfferJourneyBlockData data, EState state, EnhancedScroller scroller, bool isGrandPrize = false)
|
|
{
|
|
// Debug.Log($"[EventOfferJourney] cell view: {data.DropId}, state: {state}, isGrandPrize: {isGrandPrize}");
|
|
_dropId = data.DropId;
|
|
if (reward != null && !isGrandPrize)
|
|
{
|
|
if (goGrandReward != null)
|
|
{
|
|
goGrandReward.SetActive(false);
|
|
goGrandReward.transform.localScale = Vector3.one;
|
|
}
|
|
reward.gameObject.SetActive(true);
|
|
reward.transform.localScale = Vector3.one;
|
|
reward.SetData(_playerItemData.GetItemDataOneLureInflation(null, data.DropId));
|
|
}
|
|
else if (reward != null)
|
|
{
|
|
if (goGrandReward != null)
|
|
{
|
|
goGrandReward.SetActive(true);
|
|
goGrandReward.transform.localScale = Vector3.one;
|
|
}
|
|
reward.gameObject.SetActive(false);
|
|
reward.transform.localScale = Vector3.one;
|
|
}
|
|
else if (goGrandReward != null)
|
|
{
|
|
goGrandReward.transform.localScale = Vector3.one;
|
|
goGrandReward.SetActive(true);
|
|
}
|
|
|
|
if (data.Type == EventOfferJourneyBlockData.EType.IAP)
|
|
InitByIapId(data.Price);
|
|
else
|
|
InitByTicketCost(data.Price);
|
|
|
|
btnIap.gameObject.SetActive(data.Type == EventOfferJourneyBlockData.EType.IAP);
|
|
btnIapGray.gameObject.SetActive(data.Type == EventOfferJourneyBlockData.EType.IAP);
|
|
btnTicket.gameObject.SetActive(data.Type == EventOfferJourneyBlockData.EType.Ticket);
|
|
btnTicketGray.gameObject.SetActive(data.Type == EventOfferJourneyBlockData.EType.Ticket);
|
|
|
|
if (state == EState.Bought)
|
|
{
|
|
if (aniTick != null)
|
|
{
|
|
aniTick.gameObject.SetActive(true);
|
|
reward.gameObject.SetActive(false);
|
|
}
|
|
goLock.SetActive(false);
|
|
btnIap.gameObject.SetActive(false);
|
|
btnTicket.gameObject.SetActive(false);
|
|
btnIapGray.gameObject.SetActive(false);
|
|
btnTicketGray.gameObject.SetActive(false);
|
|
}
|
|
else if (state == EState.Locked)
|
|
{
|
|
if (aniTick != null)
|
|
aniTick.gameObject.SetActive(false);
|
|
goLock.SetActive(true);
|
|
btnIap.gameObject.SetActive(false);
|
|
btnTicket.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
if (aniTick != null)
|
|
aniTick.gameObject.SetActive(false);
|
|
goLock.SetActive(false);
|
|
btnIapGray.gameObject.SetActive(false);
|
|
btnTicketGray.gameObject.SetActive(false);
|
|
}
|
|
_state = state;
|
|
_scroller = scroller;
|
|
}
|
|
|
|
private void InitByIapId(int IapId)
|
|
{
|
|
_playerItemData.ResolveIapId(IapId, out _iapItemList, out var textPrice);
|
|
priceIap.text = textPrice;
|
|
priceIapGray.text = textPrice;
|
|
}
|
|
|
|
private void InitByTicketCost(int TicketCost)
|
|
{
|
|
priceTicket.text = TicketCost.ToString();
|
|
priceTicketGray.text = TicketCost.ToString();
|
|
_iapItemList = null;
|
|
_cost = TicketCost;
|
|
}
|
|
|
|
protected async void OnClickIAP()
|
|
{
|
|
try
|
|
{
|
|
// var rewardItemList = _playerItemData.GetItemDataByDropId(_dropId);
|
|
var data = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
var shotBuyTypeData = new ShopBuyTypeData
|
|
{
|
|
type = data.BuyType,
|
|
ID = data.EventId,
|
|
NoShow = true
|
|
};
|
|
var res = await GContext.container.Resolve<PlayerShopData>()
|
|
.OnBuy(_dropId, shotBuyTypeData, _iapItemList, _playerItemData.GetItemDataByDropIdLureInflation(null, _dropId), RewardType.Normal);
|
|
if (res)
|
|
{
|
|
//TODO: success
|
|
OnPurchaseSuccessDisplay();
|
|
}
|
|
else
|
|
{
|
|
//TODO: fail
|
|
}
|
|
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
protected void OnClickTicket()
|
|
{
|
|
// var rewardItemList = _playerItemData.GetItemDataByDropId(_dropId);
|
|
var data = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
var ticketResult = data.AddTicket(-_cost);
|
|
if (!ticketResult)
|
|
{
|
|
Debug.Log("[EventOfferJourney] Insufficient tickets.");
|
|
ToastPanel.Show(LocalizationMgr.GetFormatTextValue("UI_OfferJourneyShellPanel_10", data.GetTicketName()));
|
|
}
|
|
else
|
|
{
|
|
_playerItemData.AddItemByDropLureInflation(null, _dropId, null);
|
|
data.ProgressUp();
|
|
OnPurchaseSuccessDisplay();
|
|
}
|
|
}
|
|
|
|
protected void Reset()
|
|
{
|
|
try
|
|
{
|
|
btnIap = transform.Find("OfferJourneyShell_Reward/btn_buy/btn_green_c").GetComponent<Button>();
|
|
btnTicket = transform.Find("OfferJourneyShell_Reward/btn_buy_item/btn_green_c").GetComponent<Button>();
|
|
btnIapGray = transform.Find("OfferJourneyShell_Reward/btn_buy_gray/btn_green_c").GetComponent<Button>();
|
|
btnTicketGray = transform.Find("OfferJourneyShell_Reward/btn_buy_item_gray/btn_green_c").GetComponent<Button>();
|
|
|
|
priceIap = transform.Find("OfferJourneyShell_Reward/btn_buy/btn_green_c/Ani_Container/p_text").GetComponent<TMP_Text>();
|
|
priceTicket = transform.Find("OfferJourneyShell_Reward/btn_buy_item/btn_green_c/Ani_Container/content_cost/cost/p_text_num").GetComponent<TMP_Text>();
|
|
priceIapGray = transform.Find("OfferJourneyShell_Reward/btn_buy_gray/btn_green_c/Ani_Container/p_text").GetComponent<TMP_Text>();
|
|
priceTicketGray = transform.Find("OfferJourneyShell_Reward/btn_buy_item_gray/btn_green_c/Ani_Container/content_cost/cost/p_text_num").GetComponent<TMP_Text>();
|
|
|
|
reward = transform.Find("OfferJourneyShell_Reward/reward").GetComponent<RewardItemNew>();
|
|
goGrandReward = transform.Find("OfferJourneyShell_Reward/grand_reward").gameObject;
|
|
goLock = transform.Find("OfferJourneyShell_Reward/locked").gameObject;
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.Log(e.ToString());
|
|
}
|
|
}
|
|
|
|
public virtual void OnPurchaseSuccessDisplay()
|
|
{
|
|
var data = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
RedPointManager.Instance.SetRedPointState(data.RedPointKey, data.ToEntranceData().DoNeedRedPoint);
|
|
GContext.Publish(new ShowData());
|
|
}
|
|
|
|
protected async System.Threading.Tasks.Task PlayFx(GameObject fx, float delay = 0)
|
|
{
|
|
fx.SetActive(false);
|
|
fx.SetActive(true);
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(delay));
|
|
}
|
|
|
|
protected async System.Threading.Tasks.Task PlayRewardDisappear(float delay = 0)
|
|
{
|
|
if (goGrandReward != null)
|
|
goGrandReward.transform.DOScale(0, delay);
|
|
await reward.transform.DOScale(0, delay).AsyncWaitForCompletion();
|
|
reward.gameObject.SetActive(false);
|
|
}
|
|
|
|
protected void OnClickGrayBtn()
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_30"));
|
|
}
|
|
|
|
public enum EState
|
|
{
|
|
Locked,
|
|
Active,
|
|
Bought
|
|
}
|
|
}
|