188 lines
7.2 KiB
C#
188 lines
7.2 KiB
C#
using System.Collections.Generic;
|
|
using asap.core;
|
|
using game;
|
|
using Game;
|
|
using GameCore;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json.Linq;
|
|
using TMPro;
|
|
using UIScriptBase;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
namespace Assets.Scripts.UI.OfferSweep
|
|
{
|
|
public class OfferSweepPackCell : MonoBehaviour
|
|
{
|
|
#region UI_ELEMENTS
|
|
protected Button btn_purchase;
|
|
protected GameObject locked;
|
|
protected GameObject bg_done;
|
|
protected GameObject bg_reward;
|
|
protected GameObject fx_ui_offersweep_reward_loop;
|
|
protected RewardItemNew[] _rewardItemNews;
|
|
protected TextMeshProUGUI p_text;
|
|
protected Image frame_sweep_progress;
|
|
protected Animation fxAnimation;
|
|
#endregion
|
|
private int _index;
|
|
private OfferSweepManager _offerSweepManager;
|
|
private void Awake()
|
|
{
|
|
btn_purchase = this.transform.Find("RewardContent/btn_buy/btn_green_c").GetComponent<Button>();
|
|
btn_purchase.onClick.AddListener(OnClickPurchase);
|
|
_rewardItemNews = this.transform.Find("RewardContent/reward").GetComponentsInChildren<RewardItemNew>(true);
|
|
p_text = btn_purchase.transform.Find("Ani_Container/p_text").GetComponent<TextMeshProUGUI>();
|
|
frame_sweep_progress = this.transform.Find("ProgressContent/frame_sweep_progress_bg/frame_sweep_progress").GetComponent<Image>();
|
|
locked = this.transform.Find("RewardContent/locked").gameObject;
|
|
bg_done = this.transform.Find("RewardContent/bg_done").gameObject;
|
|
bg_reward = this.transform.Find("ProgressContent/bg_reward").gameObject;
|
|
fx_ui_offersweep_reward_loop = this.transform.Find("ProgressContent/fx_ui_offersweep_reward_loop").gameObject;
|
|
fxAnimation=this.GetComponent<Animation>();
|
|
InitUI();
|
|
}
|
|
protected void InitUI()
|
|
{
|
|
if (p_text)
|
|
p_text.text = string.Empty;
|
|
if (frame_sweep_progress)
|
|
frame_sweep_progress.fillAmount = 0;
|
|
for (int i = 0; i < _rewardItemNews.Length; i++)
|
|
_rewardItemNews[i].gameObject.SetActive(false);
|
|
fx_ui_offersweep_reward_loop?.SetActive(false);
|
|
}
|
|
public void SetData(int index, OfferSweepManager offerSweepManager)
|
|
{
|
|
this._index = index;
|
|
this._offerSweepManager = offerSweepManager;
|
|
}
|
|
public async Task PlayEffect(string name,bool isNeedShowUI=true)
|
|
{
|
|
//sound
|
|
if (name.Contains("Unlock")|| name.Contains("Final"))
|
|
{
|
|
GContext.Publish(new EventUISound($"audio_ui_offerjourneyshell_break"));
|
|
}
|
|
if (name.Contains("Final"))
|
|
{
|
|
GContext.Publish(new EventUISound($"audio_ui_offersweep_reward"));
|
|
}
|
|
|
|
fxAnimation?.Play(name);
|
|
var time = fxAnimation?[name]?.length??0.1f;
|
|
await Awaiters.SecondsRealtime(time);
|
|
if(isNeedShowUI)
|
|
ShowUI();
|
|
}
|
|
public void ShowUI()
|
|
{
|
|
var sweepPackData = _offerSweepManager.SweepPackData;
|
|
if (sweepPackData == null) return;
|
|
|
|
var isDone = sweepPackData?.PurchasePackDir.ContainsKey(_index) ?? false;
|
|
var isLocked = _index != 0 && !(sweepPackData?.PurchasePackDir.ContainsKey(_index - 1) ?? false);
|
|
var isCanPurchase = !isDone;
|
|
|
|
fx_ui_offersweep_reward_loop?.SetActive(isCanPurchase&&!isLocked);
|
|
bg_done.SetActive(isDone);
|
|
bg_reward.SetActive(isDone);
|
|
locked.SetActive(isLocked);
|
|
|
|
if (btn_purchase)
|
|
btn_purchase.gameObject.SetActive(isCanPurchase);
|
|
if (frame_sweep_progress)
|
|
frame_sweep_progress.fillAmount = isDone ? 1 : 0;
|
|
|
|
var isNotNull = _offerSweepManager.GetData(_index, out _, out _, out var itemDatas, out var iapItem, out _);
|
|
if (!isNotNull) return;
|
|
|
|
for (int i = 0; i < _rewardItemNews.Length && i < itemDatas.Count; i++)
|
|
{
|
|
_rewardItemNews[i].SetData(itemDatas[i]);
|
|
_rewardItemNews[i].gameObject.SetActive(true);
|
|
}
|
|
|
|
if (isDone) return;
|
|
|
|
SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(iapItem);
|
|
GContext.Publish(sKUDetailDataEvent);
|
|
if (p_text) p_text.text = sKUDetailDataEvent.price;
|
|
}
|
|
private bool isPurchaseing=false;
|
|
private void OnClickPurchase()
|
|
{
|
|
if(isPurchaseing) return;
|
|
isPurchaseing = true;
|
|
_ = Purchase();
|
|
}
|
|
public void SetPurchaseStatus(bool isPurchaseing)
|
|
{
|
|
this.isPurchaseing=isPurchaseing;
|
|
}
|
|
private async Task Purchase()
|
|
{
|
|
var sweepPackData = _offerSweepManager.SweepPackData;
|
|
if (sweepPackData == null)
|
|
{
|
|
isPurchaseing = false;
|
|
return;
|
|
}
|
|
|
|
var isLocked = _index != 0 && !(sweepPackData?.PurchasePackDir.ContainsKey(_index - 1) ?? false);
|
|
if (isLocked)
|
|
{
|
|
isPurchaseing = false;
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_30"));
|
|
return;
|
|
}
|
|
|
|
var isNotNull = _offerSweepManager.GetData(_index, out _, out var packConfig, out var itemDatas, out var iapItem, out var packId);
|
|
if (!isNotNull)
|
|
{
|
|
isPurchaseing = false;
|
|
return;
|
|
}
|
|
var data = _offerSweepManager.SweepPackData;
|
|
var allPackIds = new Dictionary<int,int>();
|
|
allPackIds.TryAdd(_index, packId);
|
|
if (_index == 4)
|
|
{
|
|
_offerSweepManager.GetData(5, out _, out _, out _, out _, out var packId6);
|
|
allPackIds.TryAdd(5, packId6);
|
|
}
|
|
|
|
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData
|
|
{
|
|
type = ShopBuyType.None,
|
|
extraPurcheData = new JObject
|
|
{
|
|
{ nameof(OfferSweepPackData), JToken.FromObject(allPackIds) },
|
|
{ nameof(data.FishingEventID), data.FishingEventID }
|
|
}
|
|
};
|
|
|
|
bool Result = await GContext.container.Resolve<PlayerShopData>().OnBuy(packConfig.DropID, shopBuyTypeData, iapItem, itemDatas);
|
|
if (Result)
|
|
{
|
|
if (data.PurchasePackDir.TryAdd(_index, packId))
|
|
_offerSweepManager.SaveData();
|
|
GContext.Publish(new ShowData());
|
|
if (_index != 4) return;
|
|
//5和免费奖励分开发
|
|
_offerSweepManager.GetData(5, out _, out _, out var freeItemDatas, out _, out var packId6);
|
|
GContext.Publish(new DeferredRewardStashService.EventStashItems() { Items = freeItemDatas });
|
|
|
|
if (data.PurchasePackDir.TryAdd(5, packId6))
|
|
{
|
|
data.PurchasedCount++;
|
|
_offerSweepManager.SaveData();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShowUI();
|
|
}
|
|
isPurchaseing = false;
|
|
}
|
|
}
|
|
} |