Files
MinFt/Client/Assets/Scripts/UI/RewardPopup/RewardNormal.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

343 lines
11 KiB
C#

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<GameObject> rows = new();
public bool IsShow;
List<RewardItemNew> rewardItemNews = new();
List<ItemData> 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<ItemData> 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<ItemData> 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<ItemData> 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<RewardItemNew>();
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<cfg.Tables>().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<ItemData> dropItems)
{
dropItemsFly.Clear();
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 == 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<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);
}
}
void InitHide(List<ItemData> 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<RewardItemNew>();
reward.SetRewardPopupData(item, false);
reward.canvasGroup.alpha = 0f;
reward.gameObject.SetActive(true);
rewardItemNews.Add(reward);
}
}
}
}
public async Task AllClose(List<ItemData> 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();
}
}