备份CatanBuilding瘦身独立工程
This commit is contained in:
196
Assets/Scripts/UI/Shop/DiamondsShopPanel.cs
Normal file
196
Assets/Scripts/UI/Shop/DiamondsShopPanel.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using tysdk;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DiamondsShopPanel : MonoBehaviour
|
||||
{
|
||||
protected CompositeDisposable disposables = new CompositeDisposable();
|
||||
#region Field&&Property
|
||||
Tables _tables;
|
||||
|
||||
Animation anim;
|
||||
[Space(10)]
|
||||
public PanelScroll panelScroll;
|
||||
public GameObject giftItem;
|
||||
public RectTransform giftContent;
|
||||
[Space(10)]
|
||||
public RectTransform shopScrollView;
|
||||
public GameObject shopItem;
|
||||
public Transform shopItemParent;
|
||||
float itemWidth;
|
||||
List<PackData> packItemDatas = new List<PackData>();
|
||||
List<GameObject> packItemSelects = new List<GameObject>();
|
||||
PackData curPackData;
|
||||
|
||||
[Space(10)] public GameObject imageItem;
|
||||
public Transform imageItemParent;
|
||||
private GameObject curSelect;
|
||||
private Image RedPoint;
|
||||
private Image RedPointFade;
|
||||
private Image RedPointSelect;
|
||||
PackItem curPackItem;
|
||||
|
||||
bool isTopOpen = false;
|
||||
|
||||
|
||||
|
||||
[SerializeField]
|
||||
private DiamondShopSlot[] _diamondShopSlots;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Function
|
||||
private void Awake()
|
||||
{
|
||||
anim = transform.GetComponentInParent<Animation>();
|
||||
panelScroll = transform.Find("bg_gift/bg_gift").GetComponent<PanelScroll>();
|
||||
giftItem = transform.Find("bg_gift/bg_gift/Viewport/Content/item").gameObject;
|
||||
giftContent = transform.Find("bg_gift/bg_gift/Viewport/Content").GetComponent<RectTransform>();
|
||||
shopItem = transform.Find("ScrollView/Viewport/Content/Item").gameObject;
|
||||
shopItemParent = transform.Find("ScrollView/Viewport/Content").GetComponent<Transform>();
|
||||
shopScrollView = transform.Find("ScrollView").GetComponent<RectTransform>();
|
||||
imageItem = transform.Find("bg_gift/Sliding/ImageItem").gameObject;
|
||||
imageItemParent = transform.Find("bg_gift/Sliding").GetComponent<Transform>();
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
|
||||
#if AGG
|
||||
using (var e = GEvent.GameEvent("enter_shop")) { }
|
||||
#endif
|
||||
|
||||
|
||||
var shopTokens = GContext.container.Resolve<Tables>().TbShopToken.DataList;
|
||||
var diamondShopTokens = shopTokens.Where(x => x.Type == 3).ToArray();
|
||||
|
||||
for (int i = 0; i < diamondShopTokens.Length; i++)
|
||||
{
|
||||
if (i == _diamondShopSlots.Length)
|
||||
{
|
||||
Debug.LogError($"[DiamondsShopPanl::Awake]diamond Shop Slot Not Enough");
|
||||
break;
|
||||
}
|
||||
_diamondShopSlots[i].SetData(diamondShopTokens[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected void Start()
|
||||
{
|
||||
isTopOpen = GContext.container.Resolve<PlayerShopData>().IsShopTopOpen;
|
||||
panelScroll.transform.parent.gameObject.SetActive(isTopOpen);
|
||||
|
||||
shopScrollView.sizeDelta = isTopOpen ? new Vector2(0, -1156f) : new Vector2(0, -506f);
|
||||
itemWidth = giftItem.GetComponent<RectTransform>().rect.width;
|
||||
imageItem.SetActive(false);
|
||||
|
||||
InitGift();
|
||||
SetScroll();
|
||||
|
||||
GContext.OnEvent<RewardPanelClose>().Subscribe(RewardPanelClose).AddTo(disposables);
|
||||
|
||||
}
|
||||
|
||||
#region Old
|
||||
void RewardPanelClose(RewardPanelClose rewardPanelClose)
|
||||
{
|
||||
InitGift();
|
||||
//播动画
|
||||
SetScroll();
|
||||
anim.Play();
|
||||
}
|
||||
void InitGift()
|
||||
{
|
||||
GContext.container.Resolve<PlayerShopData>().InitShopPackData();
|
||||
//DayOfWeek week = ZZTimeHelper.UtcNow().UtcNowOffset().DayOfWeek;
|
||||
packItemDatas.Clear();
|
||||
var DailyGiftPackList = GContext.container.Resolve<PlayerData>().priceLevel.DailyPackList;
|
||||
for (int i = 0; i < DailyGiftPackList.Count; i++)
|
||||
{
|
||||
PackData data = GetPackData(DailyGiftPackList[i]);
|
||||
if (data == null) continue;
|
||||
packItemDatas.Add(data);
|
||||
}
|
||||
|
||||
for (int i = 0; i < packItemDatas.Count; i++)
|
||||
{
|
||||
PackData data = packItemDatas[i];
|
||||
if (i < packItemSelects.Count)
|
||||
{
|
||||
data.select = packItemSelects[i].transform.Find("Select").gameObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject go1 = Instantiate(imageItem, imageItemParent);
|
||||
go1.SetActive(true);
|
||||
packItemSelects.Add(go1);
|
||||
data.select = go1.transform.Find("Select").gameObject;
|
||||
}
|
||||
data.select.SetActive(false);
|
||||
}
|
||||
|
||||
RedPointSelect = packItemSelects[0].transform.Find("Select").GetComponent<Image>();
|
||||
RedPoint = packItemSelects[0].transform.GetComponent<Image>();
|
||||
RedPointFade = packItemSelects[0].transform.Find("RedPoint").GetComponent<Image>();
|
||||
}
|
||||
PackData GetPackData(int id)
|
||||
{
|
||||
ShopPackManager packM = GContext.container.Resolve<PlayerShopData>().TbPackManagerGetOrDefault(id);
|
||||
if (packM == null) return null;
|
||||
Pack pack = _tables.TbPack.GetOrDefault(packM.PackID[0]);
|
||||
if (pack == null) return null;
|
||||
return new PackData
|
||||
{
|
||||
packM = packM,
|
||||
pack = pack,
|
||||
num = GContext.container.Resolve<PlayerShopData>().GetShopPackBuyCount(packM.ID),
|
||||
OnCenter = SetPackData,
|
||||
};
|
||||
}
|
||||
void SetScroll()
|
||||
{
|
||||
if (isTopOpen)
|
||||
{
|
||||
SetPackData(packItemDatas[0]);
|
||||
panelScroll.loop = true;
|
||||
panelScroll.Init<PackItem, PackData>(itemWidth, giftItem, OnSelectGiftItem, packItemDatas, true, curPackItem == null ? 0 : curPackItem.index);
|
||||
panelScroll.enabled = packItemDatas.Count > 1;
|
||||
}
|
||||
}
|
||||
|
||||
void OnSelectGiftItem(PackItem item)
|
||||
{
|
||||
curPackItem = item;
|
||||
PackData data = item.data;
|
||||
|
||||
giftContent.DOAnchorPosX(-item.transform.localPosition.x, 0.2f).OnComplete(() => { SetPackData(data); });
|
||||
}
|
||||
|
||||
void SetPackData(PackData data)
|
||||
{
|
||||
curPackData?.select.SetActive(false);
|
||||
curPackData = data;
|
||||
if (curPackData != null)
|
||||
{
|
||||
curPackData.select.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnDestroy()
|
||||
{
|
||||
disposables?.Dispose();
|
||||
disposables = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user