备份CatanBuilding瘦身独立工程
This commit is contained in:
270
Assets/Scripts/UI/RewardPopup/RewardFishBox.cs
Normal file
270
Assets/Scripts/UI/RewardPopup/RewardFishBox.cs
Normal file
@@ -0,0 +1,270 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RewardFishBox : RewardPopupBar
|
||||
{
|
||||
public Button btn_skip;
|
||||
public Button btn_close;
|
||||
public Button btn_next;
|
||||
public Button btn_all;
|
||||
public RewardNormal rewardBoxShow;
|
||||
public TMP_Text text_title, txt_rewardInfo;
|
||||
public bool isFly = false;
|
||||
List<ItemData> dropItemsFly = new List<ItemData>();
|
||||
|
||||
bool isAllOpen;
|
||||
[SerializeField]
|
||||
private RewardItemNew rewardItem;
|
||||
[SerializeField]
|
||||
private Transform tran_rewardParent;
|
||||
[SerializeField]
|
||||
private GameObject go_row;
|
||||
[SerializeField] private PanelScroll ps;
|
||||
|
||||
private List<RewardItemNew> rewards = new();
|
||||
private List<GameObject> rows = new();
|
||||
bool IsShow;
|
||||
public Action<bool> OnClickClose;
|
||||
private void Awake()
|
||||
{
|
||||
btn_close.onClick.AddListener(OnClose);
|
||||
btn_next.onClick.AddListener(OnClose);
|
||||
btn_all.onClick.AddListener(() =>
|
||||
{
|
||||
isAllOpen = true;
|
||||
OnClose();
|
||||
});
|
||||
btn_skip.onClick.AddListener(OnClick);
|
||||
}
|
||||
public void Init(List<ItemData> dropItems, string rewardInfo, string title)
|
||||
{
|
||||
OnClickClose = (_) =>
|
||||
{
|
||||
GContext.Publish(new ShowData(RewardType.Destroy));
|
||||
};
|
||||
btn_close.gameObject.SetActive(true);
|
||||
btn_next.gameObject.SetActive(false);
|
||||
btn_all.gameObject.SetActive(false);
|
||||
InitAsync(dropItems);
|
||||
txt_rewardInfo.gameObject.SetActive(!string.IsNullOrEmpty(rewardInfo));
|
||||
txt_rewardInfo.text = rewardInfo;
|
||||
if (!string.IsNullOrEmpty(title))
|
||||
{
|
||||
text_title.text = title;
|
||||
}
|
||||
}
|
||||
public async void InitAsync(List<ItemData> dropItems)
|
||||
{
|
||||
txt_rewardInfo.text = "";
|
||||
text_title.text = LocalizationMgr.GetText("UI_FishingRewardPanel_101002");
|
||||
dropItemsFly.Clear();
|
||||
if (isFly)
|
||||
{
|
||||
ExchangeItem(dropItems);
|
||||
}
|
||||
receive.SetActive(true);
|
||||
var x = 3;
|
||||
var curParent = tran_rewardParent;
|
||||
btn_close.gameObject.SetActive(false);
|
||||
btn_skip.gameObject.SetActive(true);
|
||||
int parentCount = 0;
|
||||
int rewardCount = 0;
|
||||
IsShow = true;
|
||||
clickCount = 0;
|
||||
jump = false;
|
||||
for (int i = 0; i < dropItems.Count; i++)
|
||||
{
|
||||
var index = i % 3;
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
if (rows.Count > parentCount)
|
||||
{
|
||||
curParent = rows[parentCount].transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
curParent = Instantiate(go_row, tran_rewardParent).transform;
|
||||
rows.Add(curParent.gameObject);
|
||||
}
|
||||
parentCount++;
|
||||
curParent.gameObject.SetActive(true);
|
||||
var count = dropItems.Count - i;
|
||||
for (int j = 0; j < x; j++)
|
||||
{
|
||||
curParent.GetChild(j).gameObject.SetActive(j < count);
|
||||
}
|
||||
}
|
||||
|
||||
var item = dropItems[i];
|
||||
RewardItemNew reward;
|
||||
if (rewards.Count > rewardCount)
|
||||
{
|
||||
reward = rewards[rewardCount];
|
||||
}
|
||||
else
|
||||
{
|
||||
reward = Instantiate(rewardItem.gameObject, curParent.GetChild(index)).GetComponent<RewardItemNew>();
|
||||
rewards.Add(reward);
|
||||
}
|
||||
rewardCount++;
|
||||
reward.SetData(item, isCanClick: true);
|
||||
reward.gameObject.SetActive(true);
|
||||
reward.PlayOpen();
|
||||
if (jump)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
await Awaiters.NextFrame;
|
||||
ps.verticalNormalizedPosition = 0f;
|
||||
await new WaitForSeconds(0.1f);
|
||||
}
|
||||
}
|
||||
AutoClose();
|
||||
await Awaiters.NextFrame;
|
||||
ps.verticalNormalizedPosition = 0f;
|
||||
btn_skip.gameObject.SetActive(false);
|
||||
btn_close.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
void ExchangeItem(List<ItemData> dropItems)
|
||||
{
|
||||
var map = new Dictionary<int, int>();
|
||||
var mapCurCount = new Dictionary<int, ulong>();
|
||||
//itemDataList重复合并
|
||||
for (int i = dropItems.Count - 1; i >= 0; i--)
|
||||
{
|
||||
ItemData itemData = dropItems[i];
|
||||
if (itemData.exchangeItemData != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (map.ContainsKey(itemData.id))
|
||||
{
|
||||
map[itemData.id] += itemData.count;
|
||||
}
|
||||
else
|
||||
{
|
||||
map[itemData.id] = itemData.count;
|
||||
}
|
||||
mapCurCount[itemData.id] = itemData.curCount;
|
||||
}
|
||||
|
||||
var newData = new List<ItemData>();
|
||||
Tables tables = GContext.container.Resolve<Tables>();
|
||||
foreach (var item in map)
|
||||
{
|
||||
ItemData itemData1 = new ItemData()
|
||||
{
|
||||
id = item.Key,
|
||||
count = item.Value
|
||||
};
|
||||
itemData1.curCount = mapCurCount[itemData1.id];
|
||||
newData.Add(itemData1);
|
||||
Item itemTable = tables.TbItem.GetOrDefault(itemData1.id);
|
||||
if (itemTable.Type != 5 && itemTable.Type != 9 && !(itemTable.Type == 3 && itemTable.SubType == 1))
|
||||
{
|
||||
dropItemsFly.Add(itemData1);
|
||||
}
|
||||
}
|
||||
|
||||
if (dropItems != null)
|
||||
{
|
||||
//转换物品链处理
|
||||
dropItems = new List<ItemData>(dropItems);
|
||||
for (int i = 0; i < dropItems.Count; i++)
|
||||
{
|
||||
ItemData itemData = dropItems[i];
|
||||
ExchangeItemData nextExchangeItemData = GetExchangeItemData(itemData.exchangeItemData);
|
||||
itemData.exchangeItemData = nextExchangeItemData;
|
||||
if (nextExchangeItemData != null)
|
||||
{
|
||||
dropItemsFly.Add(itemData);
|
||||
ExchangeItemData exchangeItemData = GetExchangeItemData(nextExchangeItemData.nextExchangeItemData);
|
||||
nextExchangeItemData.nextExchangeItemData = null;
|
||||
if (exchangeItemData != null)
|
||||
{
|
||||
ItemData itemData1 = new ItemData();
|
||||
itemData1.id = itemData.id;
|
||||
itemData1.curCount = itemData.curCount;
|
||||
itemData1.count = itemData.count;
|
||||
itemData1.exchangeItemData = exchangeItemData;
|
||||
dropItems.Insert(i + 1, itemData1);
|
||||
dropItemsFly.Add(itemData1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ExchangeItemData GetExchangeItemData(ExchangeItemData exchangeItemData)
|
||||
{
|
||||
if (exchangeItemData == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (exchangeItemData.exchangeCount > 0)
|
||||
{
|
||||
return exchangeItemData;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetExchangeItemData(exchangeItemData.nextExchangeItemData);
|
||||
}
|
||||
}
|
||||
|
||||
private int clickCount;
|
||||
private bool jump;
|
||||
|
||||
private void OnClick()
|
||||
{
|
||||
if (IsShow)
|
||||
{
|
||||
clickCount++;
|
||||
if (clickCount == 2)
|
||||
{
|
||||
jump = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator AutoCloseCoroutine()
|
||||
{
|
||||
yield return new WaitForSeconds(3f);
|
||||
if (isAutoClose)
|
||||
{
|
||||
isAllOpen = true;
|
||||
OnClose();
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnClose()
|
||||
{
|
||||
receive.SetActive(false);
|
||||
StopCoroutine("AutoCloseCoroutine");
|
||||
rewards.ForEach(x => x.gameObject.SetActive(false));
|
||||
rows.ForEach(x => x.gameObject.SetActive(false));
|
||||
IsShow = false;
|
||||
gameObject.SetActive(false);
|
||||
|
||||
if (dropItemsFly.Count > 0)
|
||||
{
|
||||
var list = dropItemsFly.Take(9).ToList();
|
||||
rewardBoxShow.InitHide(list);
|
||||
await Awaiters.NextFrame;
|
||||
await rewardBoxShow.AllClose();
|
||||
rewardBoxShow.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
OnClickClose.Invoke(isAllOpen);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user