using asap.core; using cfg; using game; using Game; using GameCore; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using TMPro; using UnityEngine; using UnityEngine.UI; public class RewardNormal : RewardPopupBase { [SerializeField] private Transform tran_rewardParent; [SerializeField] private GameObject go_row; [SerializeField] private PanelScroll ps; [SerializeField] TMP_Text text_title, text_title_restored, txt_rewardInfo; [SerializeField] private Button btn_close, btn_skip; private List rows = new(); public bool IsShow; List rewardItemNews = new(); List dropItemsFly = new(); int childCount; //间隔时间 public float intervalTime = 0.166f; float maxWaitTime = 2.3f; private void Awake() { btn_close.onClick.AddListener(OnClose); btn_skip.onClick.AddListener(OnClick); go_row.SetActive(false); childCount = go_row.transform.childCount; } public void InitRestore(List dropItems) { text_title_restored.text = LocalizationMgr.GetText("Server_1003"); text_title_restored.gameObject.SetActive(true); text_title.gameObject.SetActive(false); Init(dropItems); ShowRewardInfo(LocalizationMgr.GetText("Server_1004")); } public void InitAsync(List dropItems, string rewardInfo) { text_title.text = LocalizationMgr.GetText("UI_FishingRewardPanel_101002"); text_title.gameObject.SetActive(true); text_title_restored.gameObject.SetActive(false); Init(dropItems); ShowRewardInfo(rewardInfo); } void ShowRewardInfo(string rewardInfo) { if (!string.IsNullOrEmpty(rewardInfo)) { txt_rewardInfo.gameObject.SetActive(true); txt_rewardInfo.text = rewardInfo; } else { txt_rewardInfo.gameObject.SetActive(false); } } async void Init(List dropItems) { receive.SetActive(true); InitResource(dropItems); ExchangeItem(dropItems); clickCount = 0; jump = false; IsShow = true; gameObject.SetActive(true); GameObject curParent; btn_skip.gameObject.SetActive(true); btn_close.gameObject.SetActive(false); for (int i = 0; i < dropItems.Count; i += childCount) { curParent = Instantiate(go_row, tran_rewardParent); curParent.SetActive(true); rows.Add(curParent.gameObject); var count = dropItems.Count - i; for (int j = 0; j < childCount; j++) { curParent.transform.GetChild(j).gameObject.SetActive(j < count); curParent.transform.GetChild(j).GetChild(0).gameObject.SetActive(false); } await Awaiters.NextFrame; ps.verticalNormalizedPosition = 0f; for (int j = 0; j < childCount; j++) { if (j < count) { var item = dropItems[i + j]; curParent.transform.GetChild(j).gameObject.SetActive(true); var reward = curParent.transform.GetChild(j).GetChild(0).GetComponent(); reward.SetRewardPopupData(item); reward.gameObject.SetActive(true); reward.PlayOpen(); rewardItemNews.Add(reward); GContext.Publish(new EventUISound("audio_ui_rewardpopup_5")); cfg.Item itemCfg = GContext.container.Resolve().TbItem.GetOrDefault(item.id); //GContext.Publish(new ResAddEvent(itemCfg.ID, itemCfg.Type, itemCfg.SubType)); if (jump) { } else { await new WaitForSeconds(0.1f); } } } } await Awaiters.NextFrame; ps.verticalNormalizedPosition = 0f; btn_skip.gameObject.SetActive(false); btn_close.gameObject.SetActive(true); AutoClose(); } IEnumerator AutoCloseCoroutine() { yield return new WaitForSeconds(3f); if (isAutoClose) { OnClose(); } } private int clickCount; private bool jump; private void OnClick() { if (IsShow) { clickCount++; if (clickCount == 2) { jump = true; } } } private async void OnClose() { StopCoroutine("AutoCloseCoroutine"); btn_close.gameObject.SetActive(false); CurRewardQCount curRewardQCount = new CurRewardQCount(); GContext.Publish(curRewardQCount); if (curRewardQCount.count <= 1) { GContext.Publish(new MaskFadeAlpha()); text_title.text = ""; text_title_restored.text = ""; txt_rewardInfo.gameObject.SetActive(false); } receive.SetActive(false); //bool isfly = false; //float waitTime = 0f; //for (int i = 0; i < rewardItemNews.Count; i++) //{ // isfly = rewardItemNews[i].ParticleAttractorCheck(); // await Awaiters.Seconds(intervalTime); // if (isfly) // { // waitTime = maxWaitTime; // } // else // { // waitTime -= intervalTime; // } //} //if (!isShowTop) // waitTime -= 0.8f; //if (waitTime > 0) // await Awaiters.Seconds(waitTime); rows.ForEach(x => Destroy(x.gameObject)); rows.Clear(); rewardItemNews.Clear(); await Awaiters.NextFrame; ps.verticalNormalizedPosition = 0f; if (dropItemsFly.Count > 0) { await AllClose(dropItemsFly); } IsShow = false; GContext.Publish(new ShowData(RewardType.Destroy)); } void ExchangeItem(List dropItems) { dropItemsFly.Clear(); var map = new Dictionary(); var mapCurCount = new Dictionary(); //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(); Tables tables = GContext.container.Resolve(); 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 == null) { Debug.LogError($"can not find item table, id = {itemData1.id}"); } else { if (itemTable.Type != 5 && itemTable.Type != 9 && itemTable.Type != 11 && !(itemTable.Type == 3 && itemTable.SubType == 1)) { dropItemsFly.Add(itemData1); } } } if (dropItems != null) { //转换物品链处理 dropItems = new List(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); } } void InitHide(List dropItems) { text_title_restored.gameObject.SetActive(false); text_title.gameObject.SetActive(false); ShowRewardInfo(""); InitResource(dropItems); receive.SetActive(false); btn_skip.gameObject.SetActive(false); btn_close.gameObject.SetActive(false); gameObject.SetActive(true); GameObject curParent; for (int i = 0; i < dropItems.Count; i += childCount) { curParent = Instantiate(go_row, tran_rewardParent); curParent.SetActive(true); rows.Add(curParent.gameObject); var count = dropItems.Count - i; for (int j = 0; j < childCount; j++) { curParent.transform.GetChild(j).gameObject.SetActive(j < count); curParent.transform.GetChild(j).GetChild(0).gameObject.SetActive(false); } for (int j = 0; j < childCount; j++) { if (j < count) { var item = dropItems[i + j]; curParent.transform.GetChild(j).gameObject.SetActive(true); var reward = curParent.transform.GetChild(j).GetChild(0).GetComponent(); reward.SetRewardPopupData(item, false); reward.canvasGroup.alpha = 0f; reward.gameObject.SetActive(true); rewardItemNews.Add(reward); } } } } public async Task AllClose(List dropItems) { InitHide(dropItems); await Awaiters.NextFrame; for (int i = 0; i < rewardItemNews.Count; i++) { rewardItemNews[i].ParticleAttractor(); } await Awaiters.Seconds(maxWaitTime); rows.ForEach(x => Destroy(x.gameObject)); rows.Clear(); rewardItemNews.Clear(); dropItemsFly.Clear(); } }