备份CatanBuilding瘦身独立工程
This commit is contained in:
199
Assets/Scripts/UI/Shop/CommerceNoviceGiftPopupPanel.cs
Normal file
199
Assets/Scripts/UI/Shop/CommerceNoviceGiftPopupPanel.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CommerceNoviceGiftPopupPanel : MonoBehaviour
|
||||
{
|
||||
public int rodID;
|
||||
public Rod rod;
|
||||
#region Field&&Property
|
||||
private RewardItemNew[] rewardItems;
|
||||
|
||||
[SerializeField]
|
||||
private TMP_Text
|
||||
//txt_detail,
|
||||
txt_title,
|
||||
txt_buy,
|
||||
txt_remainder,
|
||||
//txt_rebate,
|
||||
txt_timer;
|
||||
|
||||
[SerializeField]
|
||||
private Button
|
||||
btn_close,
|
||||
btn_buy;
|
||||
[SerializeField]
|
||||
private List<Perk> perkList = new List<Perk>();
|
||||
[SerializeField]
|
||||
List<Button> peark_btns = new List<Button>();
|
||||
|
||||
public IconRodRoot iconRod;
|
||||
public RawImage rawImageRod;
|
||||
private TriggerPackBuyData _noticeGift;
|
||||
private IAPItemList _iapItem;
|
||||
private Pack _pack;
|
||||
private List<ItemData> _itemDatas;
|
||||
#endregion
|
||||
RodData config;
|
||||
|
||||
#region Function
|
||||
protected void Start()
|
||||
{
|
||||
iconRod.SetRawImage(rawImageRod);
|
||||
rewardItems = transform.Find("root/reward").GetComponentsInChildren<RewardItemNew>();
|
||||
|
||||
btn_buy.onClick.AddListener(OnBuy);
|
||||
btn_close.onClick.AddListener(Close);
|
||||
RefreshView();
|
||||
SetRod();
|
||||
}
|
||||
void SetRod()
|
||||
{
|
||||
var tables = GContext.container.Resolve<Tables>();
|
||||
config = tables.TbRodData.GetOrDefault(rodID);
|
||||
RodSkinData skin = tables.TbRodSkinData.GetOrDefault(rodID);
|
||||
RodAscend curRodAscend = tables.TbRodAscend.GetOrDefault(config.AscendID);
|
||||
int perkIDListCount = curRodAscend.PerkIDList.Count;
|
||||
|
||||
for (int i = 0; i < perkList.Count; i++)
|
||||
{
|
||||
if (i < perkIDListCount)
|
||||
{
|
||||
perkList[i].gameObject.SetActive(true);
|
||||
perkList[i].SetData(curRodAscend.PerkIDList[i], 1, config.Quality);
|
||||
}
|
||||
else
|
||||
{
|
||||
perkList[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < peark_btns.Count; i++)
|
||||
{
|
||||
int index = i;
|
||||
peark_btns[i].onClick.AddListener(() =>
|
||||
{
|
||||
ShowPeark(index);
|
||||
});
|
||||
}
|
||||
//rod.transform.localPosition = new Vector3(skin.DisplayPosition[0], skin.DisplayPosition[1], skin.DisplayPosition[2]);
|
||||
rod.transform.localRotation = Quaternion.Euler(skin.DisplayRotation[0], skin.DisplayRotation[1], skin.DisplayRotation[2]);
|
||||
//rod.transform.localScale = Vector3.one * skin.DisplayScale;
|
||||
rod.rod.GetComponent<Animator>().Play("Show01");
|
||||
StartDoRotate();
|
||||
}
|
||||
async void ShowPeark(int index)
|
||||
{
|
||||
item_tips _item_tips = await item_tips.Show();
|
||||
if (_item_tips == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_item_tips.ShowPerk(config.ID, index, peark_btns[index].transform.position);
|
||||
}
|
||||
void RefreshView()
|
||||
{
|
||||
var triggerPackData = GContext.container.Resolve<TriggerPackData>();
|
||||
var noticeGifts = triggerPackData.GetTriggerPackList(2);
|
||||
if (noticeGifts == null || noticeGifts.Count == 0)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
_noticeGift = noticeGifts[0];
|
||||
var triggerPack = GContext.container.Resolve<Tables>().TbTriggerPackManager.GetOrDefault(_noticeGift.ID);
|
||||
int packID = triggerPack.VIPPackList[triggerPackData.GetVIPLevel(2)][_noticeGift.index];
|
||||
_pack = GContext.container.Resolve<Tables>().TbPack.DataMap[packID];
|
||||
//txt_rebate.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_2", _pack.Rebate * 100);
|
||||
_iapItem = GContext.container.Resolve<Tables>().TbIAPItemList.GetOrDefault(_pack.IAPID);
|
||||
_itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(_pack.DropID);
|
||||
txt_remainder.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_1", 1, 1);
|
||||
|
||||
for (int i = 0; i < rewardItems.Length; i++)
|
||||
{
|
||||
if (i < _itemDatas.Count)
|
||||
{
|
||||
rewardItems[i].SetData(_itemDatas[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
rewardItems[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
txt_title.text = LocalizationMgr.GetFormatTextValue(_pack.Title_l10n_key);
|
||||
//txt_detail.text = LocalizationMgr.GetFormatTextValue(_pack.Desc_l10n_key);
|
||||
// txt_rebate.text = LocalizationMgr.GetFormatTextValue("UI_CommerceWelfarePopupPanel_2", _pack.Value);
|
||||
SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(_iapItem);
|
||||
GContext.Publish(sKUDetailDataEvent);
|
||||
txt_buy.text = sKUDetailDataEvent.price;
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(SetTimer());
|
||||
}
|
||||
|
||||
async void OnBuy()
|
||||
{
|
||||
btn_buy.onClick.RemoveAllListeners();
|
||||
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData();
|
||||
shopBuyTypeData.type = ShopBuyType.TriggerPack;
|
||||
shopBuyTypeData.ID = _noticeGift.ID;
|
||||
bool Result = await GContext.container.Resolve<PlayerShopData>().OnBuy(_pack.DropID, shopBuyTypeData, _iapItem, _itemDatas);
|
||||
if (Result)
|
||||
{
|
||||
OnBuySuccess();
|
||||
Close();
|
||||
}
|
||||
|
||||
btn_buy.onClick.AddListener(OnBuy);
|
||||
}
|
||||
async void OnBuySuccess()
|
||||
{
|
||||
//GContext.container.Resolve<TriggerPackData>().AddTriggerPackCount(_noticeGift.ID);
|
||||
var triggerPackData = GContext.container.Resolve<TriggerPackData>();
|
||||
var noticeGifts = triggerPackData.GetTriggerPackList(2);
|
||||
if (noticeGifts == null || noticeGifts.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_noticeGift = noticeGifts[0];
|
||||
var triggerPack = GContext.container.Resolve<Tables>().TbTriggerPackManager.GetOrDefault(_noticeGift.ID);
|
||||
await new WaitForSeconds(1f);
|
||||
|
||||
GContext.container.Resolve<IFaceUIService>().AddGiftFaceUI(triggerPack.ID, UITypes.CommerceNoviceGiftPopupPanel, triggerPack.PackType, true);
|
||||
GContext.Publish(new TriggerPackEvent());
|
||||
}
|
||||
void Close()
|
||||
{
|
||||
UIManager.Instance.DestroyUI(UITypes.CommerceNoviceGiftPopupPanel);
|
||||
}
|
||||
|
||||
IEnumerator SetTimer()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var now = GContext.container.Resolve<TriggerPackData>().GetCurTriggerPackEndTime(_noticeGift);
|
||||
if (now.TotalSeconds < 0)
|
||||
{
|
||||
RefreshView();
|
||||
yield break;
|
||||
}
|
||||
txt_timer.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds);
|
||||
yield return new WaitForSeconds(1);
|
||||
}
|
||||
}
|
||||
public Transform rotateTarget;
|
||||
void StartDoRotate()
|
||||
{
|
||||
var endRotation = rotateTarget.localRotation.eulerAngles + new Vector3(0, 360, 0);
|
||||
rotateTarget.DOKill();
|
||||
rotateTarget.DOLocalRotate(endRotation, 10f, DG.Tweening.RotateMode.FastBeyond360).SetEase(Ease.Linear).SetLoops(-1);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user