备份CatanBuilding瘦身独立工程
This commit is contained in:
297
Assets/Scripts/UI/Shop/GiftPopupPanel_Base.cs
Normal file
297
Assets/Scripts/UI/Shop/GiftPopupPanel_Base.cs
Normal file
@@ -0,0 +1,297 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GiftPopupPanel_Base : MonoBehaviour
|
||||
{
|
||||
Tables _tables;
|
||||
//Button btn_mask;
|
||||
Button btn_close;
|
||||
Button btn_buy;
|
||||
TMP_Text text_buy;
|
||||
|
||||
TMP_Text text_time;
|
||||
GameObject tag_more;
|
||||
TMP_Text text_best;
|
||||
protected TMP_Text Remaining;
|
||||
|
||||
GameObject ImageItem;
|
||||
List<GameObject> ImageItemList = new List<GameObject>();
|
||||
List<GameObject> selectGos = new List<GameObject>();
|
||||
GameObject SlidingRoot;
|
||||
Button btn_left;
|
||||
Button btn_right;
|
||||
GameObject btn_left_icon;
|
||||
GameObject btn_left_icon_gray;
|
||||
GameObject btn_right_icon;
|
||||
GameObject btn_right_icon_gray;
|
||||
|
||||
protected TriggerPackManager packManager;
|
||||
Pack pack;
|
||||
IAPItemList iAPItemList;
|
||||
protected List<ItemData> itemDatas = new List<ItemData>();
|
||||
protected TriggerPackBuyData curTriggerPackState;
|
||||
|
||||
List<TriggerPackBuyData> triggerPackDic;
|
||||
int index = 0;
|
||||
int allCount = 0;
|
||||
int curRedirectID;
|
||||
protected virtual int Type { get; }
|
||||
private void Awake()
|
||||
{
|
||||
curRedirectID = GContext.container.Resolve<IFaceUIService>().curRedirectID;
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
//btn_mask = transform.Find("mask").GetComponent<Button>();
|
||||
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
|
||||
btn_buy = transform.Find("root/btn_buy/btn_green").GetComponent<Button>();
|
||||
text_buy = transform.Find("root/btn_buy/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
|
||||
text_time = transform.Find("root/text_time").GetComponent<TMP_Text>();
|
||||
|
||||
tag_more = transform.Find("root/tag_more").gameObject;
|
||||
text_best = transform.Find("root/tag_more/text_best").GetComponent<TMP_Text>();
|
||||
Remaining = transform.Find("root/text_remaining").GetComponent<TMP_Text>();
|
||||
|
||||
ImageItem = transform.Find("root/SlidingRoot/Sliding/ImageItem").gameObject;
|
||||
ImageItem.SetActive(false);
|
||||
|
||||
SlidingRoot = transform.Find("root/SlidingRoot").gameObject;
|
||||
btn_left = transform.Find("root/SlidingRoot/btn_arrow_left").GetComponent<Button>();
|
||||
btn_right = transform.Find("root/SlidingRoot/btn_arrow_right").GetComponent<Button>();
|
||||
btn_left_icon = transform.Find("root/SlidingRoot/btn_arrow_left/icon").gameObject;
|
||||
btn_left_icon_gray = transform.Find("root/SlidingRoot/btn_arrow_left/icon_gray").gameObject;
|
||||
btn_right_icon = transform.Find("root/SlidingRoot/btn_arrow_right/icon").gameObject;
|
||||
btn_right_icon_gray = transform.Find("root/SlidingRoot/btn_arrow_right/icon_gray").gameObject;
|
||||
InitPanel();
|
||||
}
|
||||
protected virtual void InitPanel()
|
||||
{
|
||||
}
|
||||
protected void Start()
|
||||
{
|
||||
triggerPackDic = GContext.container.Resolve<TriggerPackData>().GetTriggerPackList(Type);
|
||||
if (triggerPackDic.Count <= 0)
|
||||
{
|
||||
OnClickClose();
|
||||
return;
|
||||
}
|
||||
triggerPackDic.Sort((a, b) => a.time.CompareTo(b.time));
|
||||
index = triggerPackDic.Count - 1;
|
||||
if (curRedirectID > 0)
|
||||
{
|
||||
for (int i = 0; i < triggerPackDic.Count; i++)
|
||||
{
|
||||
if (triggerPackDic[i].ID == curRedirectID)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
btn_left.onClick.AddListener(OnLeftClick);
|
||||
btn_right.onClick.AddListener(OnRightClick);
|
||||
//btn_mask.onClick.AddListener(OnClickClose);
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
btn_buy.onClick.AddListener(OnBuy);
|
||||
SetTriggerPackTimer();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
allCount = triggerPackDic.Count;
|
||||
if (allCount <= 0)
|
||||
{
|
||||
OnClickClose();
|
||||
return;
|
||||
}
|
||||
if (index >= allCount)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
SlidingRoot.SetActive(allCount > 1);
|
||||
int curCount = ImageItemList.Count;
|
||||
if (curCount < allCount)
|
||||
{
|
||||
for (int i = curCount; i < allCount; i++)
|
||||
{
|
||||
GameObject go = Instantiate(ImageItem, ImageItem.transform.parent);
|
||||
go.SetActive(true);
|
||||
selectGos.Add(go.transform.Find("Select").gameObject);
|
||||
ImageItemList.Add(go);
|
||||
}
|
||||
}
|
||||
else if (curCount > allCount)
|
||||
{
|
||||
for (int i = allCount; i < curCount; i++)
|
||||
{
|
||||
ImageItemList[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
SetData();
|
||||
}
|
||||
void SetSelect()
|
||||
{
|
||||
for (int i = 0; i < selectGos.Count; i++)
|
||||
{
|
||||
selectGos[i].SetActive(i == index);
|
||||
}
|
||||
btn_left_icon.SetActive(index > 0);
|
||||
btn_left_icon_gray.SetActive(index <= 0);
|
||||
btn_right_icon.SetActive(index < allCount - 1);
|
||||
btn_right_icon_gray.SetActive(index >= allCount - 1);
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (allCount > 1)
|
||||
{
|
||||
//左右滑动屏幕一半距离触发OnLeftClick或OnRightClick
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
OnBeginDrag();
|
||||
}
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
OnEndDrag();
|
||||
}
|
||||
}
|
||||
}
|
||||
float beginDragPosX = 0;
|
||||
void OnBeginDrag()
|
||||
{
|
||||
beginDragPosX = Input.mousePosition.x;
|
||||
}
|
||||
void OnEndDrag()
|
||||
{
|
||||
//滑动屏幕一半距离触发OnLeftClick或OnRightClick
|
||||
if (Mathf.Abs(Input.mousePosition.x - beginDragPosX) > Screen.width / 4)
|
||||
{
|
||||
if (Input.mousePosition.x > beginDragPosX)
|
||||
{
|
||||
OnLeftClick();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnRightClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnLeftClick()
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
index--;
|
||||
SetData();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRightClick()
|
||||
{
|
||||
if (index < allCount - 1)
|
||||
{
|
||||
index++;
|
||||
SetData();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetData()
|
||||
{
|
||||
if (allCount > 1)
|
||||
{
|
||||
SetSelect();
|
||||
}
|
||||
curTriggerPackState = triggerPackDic[index];
|
||||
int id = curTriggerPackState.ID;
|
||||
packManager = _tables.TbTriggerPackManager.GetOrDefault(id);
|
||||
int vipLevel = curTriggerPackState.vipLevel;
|
||||
int count = packManager.VIPPackList[vipLevel].Count;
|
||||
int buyCount = curTriggerPackState.index;
|
||||
if (buyCount >= count)
|
||||
{
|
||||
buyCount = count - 1;
|
||||
}
|
||||
pack = _tables.TbPack.GetOrDefault(packManager.VIPPackList[vipLevel][buyCount]);
|
||||
iAPItemList = _tables.TbIAPItemList.GetOrDefault(pack.IAPID);
|
||||
itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(pack.DropID, curTriggerPackState.mapID);
|
||||
SetShowData();
|
||||
SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(iAPItemList);
|
||||
GContext.Publish(sKUDetailDataEvent);
|
||||
text_buy.text = sKUDetailDataEvent.price;
|
||||
tag_more.SetActive(pack.Rebate > 0.0001);
|
||||
text_best.text = LocalizationMgr.GetFormatTextValue("UI_FishingShopPanel_2", pack.Rebate * 100);
|
||||
//Remaining.gameObject.SetActive(false);
|
||||
TimeSpan now = GContext.container.Resolve<TriggerPackData>().GetCurTriggerPackEndTime(curTriggerPackState);
|
||||
if (now.TotalSeconds < 0)
|
||||
{
|
||||
triggerPackDic.Remove(curTriggerPackState);
|
||||
Init();
|
||||
}
|
||||
text_time.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds);
|
||||
}
|
||||
protected virtual void SetShowData()
|
||||
{
|
||||
}
|
||||
|
||||
async void OnBuy()
|
||||
{
|
||||
btn_buy.enabled = false;
|
||||
if (iAPItemList == null)
|
||||
{
|
||||
GContext.Publish(new ShowData(itemDatas, RewardType.Normal));
|
||||
GContext.container.Resolve<PlayerItemData>().AddItem(itemDatas);
|
||||
GContext.Publish(new ShowData());
|
||||
GContext.container.Resolve<TriggerPackData>().AddTriggerPackCount(packManager.ID);
|
||||
OnBuySuccess();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData();
|
||||
shopBuyTypeData.type = ShopBuyType.TriggerPack;
|
||||
shopBuyTypeData.ID = packManager.ID;
|
||||
bool Result = await GContext.container.Resolve<PlayerShopData>().OnBuy(pack.DropID, shopBuyTypeData, iAPItemList, itemDatas);
|
||||
if (Result)
|
||||
{
|
||||
OnBuySuccess();
|
||||
}
|
||||
}
|
||||
btn_buy.enabled = true;
|
||||
}
|
||||
void OnBuySuccess()
|
||||
{
|
||||
//GContext.container.Resolve<TriggerPackData>().AddTriggerPackCount(packManager.ID);
|
||||
triggerPackDic.Remove(curTriggerPackState);
|
||||
Init();
|
||||
}
|
||||
protected virtual void OnClickClose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async void SetTriggerPackTimer()
|
||||
{
|
||||
Init();
|
||||
DateTime dateTime = ZZTimeHelper.UtcNow().UtcNowOffset();
|
||||
DateTime dateTime1 = dateTime.AddDays(1).Date;
|
||||
while (this != null && dateTime.Ticks < dateTime1.Ticks)
|
||||
{
|
||||
TimeSpan now = GContext.container.Resolve<TriggerPackData>().GetCurTriggerPackEndTime(curTriggerPackState);
|
||||
if (now.TotalSeconds < 0)
|
||||
{
|
||||
triggerPackDic.Remove(curTriggerPackState);
|
||||
Init();
|
||||
}
|
||||
text_time.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds);
|
||||
await System.Threading.Tasks.Task.Delay(1000);
|
||||
dateTime.AddSeconds(1);
|
||||
}
|
||||
if (this != null && dateTime.Ticks >= dateTime1.Ticks)
|
||||
{
|
||||
SetTriggerPackTimer();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user