460 lines
14 KiB
C#
460 lines
14 KiB
C#
using cfg.ActorCfg;
|
||
using Cysharp.Threading.Tasks;
|
||
using Framework;
|
||
using Gameplay;
|
||
using Gameplay.Effect;
|
||
using Gameplay.Level;
|
||
using Gameplay.Net;
|
||
using NLDPB;
|
||
using PhxhSDK;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using Gameplay.Net;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Button = UnityEngine.UI.Button;
|
||
using Image = UnityEngine.UI.Image;
|
||
|
||
public class UI_GetItemWindowController : UIWindow
|
||
{
|
||
//UI GameObj
|
||
///Auto Gen Start///
|
||
public Image Image_BG;
|
||
public Image Image_ItemPic;
|
||
public Image Image_Bar;
|
||
public TMP_Text Text_ItemNum;
|
||
public TMP_Text Text_IteamName;
|
||
public TMP_Text Text_Continue;
|
||
|
||
|
||
///Auto Gen End///
|
||
|
||
private List<ListItem> mItems;
|
||
//分布展示奖励内容
|
||
private int stepIndex = 0;
|
||
//用于表示不同奖励列表的类型
|
||
private List<ItemSource> itemsType;
|
||
|
||
private EShowType _showType;
|
||
|
||
private GameObject _itemTemp;
|
||
private GameObject _scrollView;
|
||
private GameObject _scrollContent;
|
||
private GameObject _goMaskBg;
|
||
|
||
private Action _callBackFunc;
|
||
|
||
public enum EShowType
|
||
{
|
||
Normal,
|
||
StorySettle
|
||
}
|
||
|
||
private struct Param
|
||
{
|
||
public EShowType type;
|
||
public List<ListItem> listItem;
|
||
public List<ItemSource> itemType;
|
||
public Action cb;
|
||
|
||
public Param(EShowType Etype, List<ListItem> list, List<ItemSource> itemType, Action callBack = null)
|
||
{
|
||
type = Etype;
|
||
listItem = list;
|
||
this.itemType = itemType;
|
||
cb = callBack;
|
||
}
|
||
}
|
||
|
||
#region API
|
||
/// <summary>
|
||
/// 打开奖励获取界面,通用方法,用于单个道具
|
||
/// </summary>
|
||
public static async UniTask<UIWindow> Open(ItemCounts itemCounts, EShowType type = EShowType.Normal, Action cb = null)
|
||
{
|
||
List<ListItem> list = new();
|
||
ListItem itemList = new(itemCounts);
|
||
list.Add(itemList);
|
||
|
||
List<ItemSource> source = new();
|
||
source.Add(ItemSource.Max);//Max不显示奖励类型
|
||
|
||
int rewardCnt = 0;
|
||
foreach(var itemL in list)
|
||
{
|
||
for(int i = 0; i < itemL.Counts.Count; i++)
|
||
{
|
||
rewardCnt += itemL.Counts[i];
|
||
}
|
||
}
|
||
if(rewardCnt == 0)
|
||
{
|
||
DebugUtil.LogError("奖励数量为0,不显示奖励界面");
|
||
Actor.Instance.RewardItems.Clear();
|
||
cb?.Invoke();
|
||
return null;
|
||
}
|
||
CommonUtils.CaptureScreenshot();
|
||
UIManager.Instance.HideAllUI();
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_GetItemWindow, new Param(type, list, source, cb));
|
||
}
|
||
/// <summary>
|
||
/// 多个道具的奖励领取,此时不显示奖励类型
|
||
/// </summary>
|
||
/// <param name="itemList"></param>
|
||
/// <param name="type"></param>
|
||
/// <param name="cb"></param>
|
||
/// <returns></returns>
|
||
public static async UniTask<UIWindow> Open(ListItem itemList, EShowType type = EShowType.Normal, Action cb = null)
|
||
{
|
||
List<ListItem> list = new();
|
||
list.Add(itemList);
|
||
|
||
List<ItemSource> source = new();
|
||
source.Add(ItemSource.Max);//Max不显示奖励类型
|
||
|
||
int rewardCnt = 0;
|
||
foreach (var itemL in list)
|
||
{
|
||
for (int i = 0; i < itemL.Counts.Count; i++)
|
||
{
|
||
rewardCnt += itemL.Counts[i];
|
||
}
|
||
}
|
||
if (rewardCnt == 0)
|
||
{
|
||
DebugUtil.LogError("奖励数量为0,不显示奖励界面");
|
||
Actor.Instance.RewardItems.Clear();
|
||
cb?.Invoke();
|
||
return null;
|
||
}
|
||
CommonUtils.CaptureScreenshot();
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_GetItemWindow, new Param(type, list, source, cb));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 多个道具的奖励领取,允许分布显示奖励内容 ;
|
||
/// 此时传入EShowType.StorySettle,可以显示奖励类型
|
||
/// </summary>
|
||
/// <param name="itemList"></param>
|
||
/// <param name="type"></param>
|
||
/// <param name="cb"></param>
|
||
/// <returns></returns>
|
||
public static async UniTask<UIWindow> Open(ItemList itemList, EShowType type = EShowType.Normal, Action cb = null)
|
||
{
|
||
GetRewardsItems(itemList, out List<ListItem> list, out List<ItemSource> source);
|
||
|
||
int rewardCnt = 0;
|
||
foreach (var itemL in list)
|
||
{
|
||
for (int i = 0; i < itemL.Counts.Count; i++)
|
||
{
|
||
rewardCnt += itemL.Counts[i];
|
||
}
|
||
}
|
||
if (rewardCnt == 0)
|
||
{
|
||
DebugUtil.LogError("奖励数量为0,不显示奖励界面");
|
||
Actor.Instance.RewardItems.Clear();
|
||
cb?.Invoke();
|
||
return null;
|
||
}
|
||
|
||
CommonUtils.CaptureScreenshot();
|
||
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_GetItemWindow, new Param(type, list, source, cb));
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 奖励分类
|
||
/// </summary>
|
||
/// <param name="itemList"></param>
|
||
/// <param name="list"></param>
|
||
/// <param name="source"></param>
|
||
static void GetRewardsItems(ItemList itemList,out List<ListItem> list,out List<ItemSource> source)
|
||
{
|
||
DebugUtil.Log("显示奖励种类数目:" + itemList.Lists.Length);
|
||
list = new();
|
||
source = new();
|
||
var lists = itemList.Lists;
|
||
|
||
//首次奖励
|
||
var itemFirstList = CommonUtils.GetItemBySource(ItemSource.LevelPassFirst, lists);
|
||
if (itemFirstList != null && itemFirstList.Count > 0)
|
||
{
|
||
var itemFirst = new ListItem(CommonUtils.GetFilterRewardItemList(itemFirstList));
|
||
#if DEVELOPMENT_BUILD || DEBUG
|
||
DebugUtil.Log("显示首次奖励种类数目:" + itemFirstList.Count);
|
||
foreach (var it in itemFirstList)
|
||
{
|
||
DebugUtil.Log("首次奖励:" + it.ID + " " + it.Count);
|
||
}
|
||
#endif
|
||
list.Add(itemFirst);
|
||
source.Add(ItemSource.LevelPassFirst);
|
||
}
|
||
|
||
//常规奖励
|
||
var itemFixed = CommonUtils.GetItemBySource(ItemSource.LevelPassNormal, lists);
|
||
if (itemFixed != null && itemFixed.Count > 0)
|
||
{
|
||
var itemFix = new ListItem(CommonUtils.GetFilterRewardItemList(itemFixed));
|
||
#if DEVELOPMENT_BUILD || DEBUG
|
||
DebugUtil.Log("显示常规奖励种类数目:" + itemFixed.Count);
|
||
foreach (var it in itemFixed)
|
||
{
|
||
DebugUtil.Log("常规奖励:" + it.ID + " " + it.Count);
|
||
}
|
||
#endif
|
||
list.Add(itemFix);
|
||
source.Add(ItemSource.LevelPassNormal);
|
||
}
|
||
|
||
var itemPvPFixed = CommonUtils.GetItemBySource(ItemSource.PvpBattle, lists);
|
||
if (itemPvPFixed != null && itemPvPFixed.Count > 0)
|
||
{
|
||
var itemPvP = new ListItem(CommonUtils.GetFilterRewardItemList(itemPvPFixed));
|
||
list.Add(itemPvP);
|
||
source.Add(ItemSource.PvpBattle);
|
||
}
|
||
|
||
//星级奖励
|
||
var itemStarRewards = new List<Item>();
|
||
var itemStar1 = CommonUtils.GetItemBySource(ItemSource.LevelPassStar1, lists);
|
||
if (itemStar1 != null && itemStar1.Count > 0)
|
||
{
|
||
CommonUtils.CombineListItem(itemStarRewards, CommonUtils.GetFilterRewardItemList(itemStar1));
|
||
}
|
||
var itemStar2 = CommonUtils.GetItemBySource(ItemSource.LevelPassStar2, lists);
|
||
if (itemStar2 != null && itemStar2.Count > 0)
|
||
{
|
||
CommonUtils.CombineListItem(itemStarRewards, CommonUtils.GetFilterRewardItemList(itemStar2));
|
||
}
|
||
var itemStar3 = CommonUtils.GetItemBySource(ItemSource.LevelPassStar3, lists);
|
||
if (itemStar3 != null && itemStar3.Count > 0)
|
||
{
|
||
CommonUtils.CombineListItem(itemStarRewards, CommonUtils.GetFilterRewardItemList(itemStar3));
|
||
}
|
||
if (itemStarRewards.Count > 0)
|
||
{
|
||
var itemStar = new ListItem(itemStarRewards);
|
||
#if DEVELOPMENT_BUILD || DEBUG
|
||
DebugUtil.Log("显示星级奖励种类数目:" + itemStarRewards.Count);
|
||
foreach (var it in itemStarRewards)
|
||
{
|
||
DebugUtil.Log("星级奖励:" + it.ID + " " + it.Count);
|
||
}
|
||
#endif
|
||
list.Add(itemStar);
|
||
source.Add(ItemSource.LevelPassStar1);
|
||
}
|
||
|
||
//章节星级奖励
|
||
var itemChapterStar = CommonUtils.GetItemBySource(ItemSource.ChapterStar, lists);
|
||
if (itemChapterStar != null && itemChapterStar.Count > 0)
|
||
{
|
||
var itemChapter = new ListItem(CommonUtils.GetFilterRewardItemList(itemChapterStar));
|
||
#if DEVELOPMENT_BUILD || DEBUG
|
||
DebugUtil.Log("显示章节星级奖励种类数目:" + itemChapterStar.Count);
|
||
foreach (var it in itemChapterStar)
|
||
{
|
||
DebugUtil.Log("章节星级奖励:" + it.ID + " " + it.Count);
|
||
}
|
||
#endif
|
||
list.Add(itemChapter);
|
||
source.Add(ItemSource.ChapterStar);
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 道具UI图标
|
||
/// </summary>
|
||
private class ItemCell : UIGameObjectWrapper
|
||
{
|
||
/// <summary>
|
||
/// 道具名
|
||
/// </summary>
|
||
private TMP_Text textName;
|
||
|
||
/// <summary>
|
||
/// 固定掉落标识
|
||
/// </summary>
|
||
private GameObject FixedDrop;
|
||
/// <summary>
|
||
/// 首次掉落标识
|
||
/// </summary>
|
||
private GameObject FirstClearDrop;
|
||
/// <summary>
|
||
/// 星级掉落标识
|
||
/// </summary>
|
||
private GameObject AchievementReward;
|
||
|
||
|
||
/// <summary>
|
||
/// 通用道具类
|
||
/// </summary>
|
||
private GenericItem genericItem;
|
||
|
||
public ItemCell(GameObject root) : base(root)
|
||
{
|
||
textName = GetComponent<TMP_Text>("Text_IteamName");
|
||
FixedDrop = FindObj("ImageBlue");
|
||
FirstClearDrop = FindObj("ImageYellow");
|
||
AchievementReward = FindObj("ImageYellow2");
|
||
|
||
genericItem = new GenericItem(FindObj("GenericItem"));
|
||
}
|
||
|
||
public void SetInfo(int itemId, int count, ItemSource itemSource)
|
||
{
|
||
DataItem dataItem = TableManager.Instance.Tables.Item.Get(itemId);
|
||
if (dataItem == null)
|
||
{
|
||
DebugUtil.LogError($"获取配置错误 id:{itemId}");
|
||
return;
|
||
}
|
||
|
||
textName.text = CommonUtils.GetLocalizeText(dataItem.NameLocal);
|
||
|
||
genericItem.SetInfo(dataItem, count);
|
||
|
||
FixedDrop.SetActive(itemSource == ItemSource.LevelPassNormal);
|
||
FirstClearDrop.SetActive(itemSource == ItemSource.LevelPassFirst);
|
||
AchievementReward.SetActive(itemSource == ItemSource.LevelPassStar1);
|
||
|
||
IsScaleShow = true;
|
||
}
|
||
|
||
public override void Dispose()
|
||
{
|
||
genericItem.Dispose();
|
||
genericItem = null;
|
||
|
||
base.Dispose();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 道具列表
|
||
/// </summary>
|
||
private List<ItemCell> listItem;
|
||
|
||
public override void PreLoad(object data = null)
|
||
{
|
||
if (data != null)
|
||
{
|
||
var param = (Param)data;
|
||
mItems = param.listItem;
|
||
itemsType = param.itemType;
|
||
_showType = param.type;
|
||
_callBackFunc = param.cb;
|
||
|
||
stepIndex = 0;
|
||
}
|
||
}
|
||
|
||
public override void OnInit()
|
||
{
|
||
UI_GetItemWindowBinder.GetComponents(this);
|
||
|
||
Transform tsItemRoot = FindObj("Image_BG/Goods").transform;
|
||
_scrollView = FindObj("Image_BG/ScrollView");
|
||
_itemTemp = FindObj("Image_BG/Item");
|
||
_scrollContent = FindObj("Image_BG/ScrollView/Viewport/Content");
|
||
_goMaskBg = FindObj("Image_BG/ImageMaskBg");
|
||
|
||
var rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
|
||
rawImageGaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
|
||
|
||
BindButton(GetComponent<Button>("Image_BG"), OnBgClick);
|
||
|
||
AddBgClose(OnBgClick);
|
||
}
|
||
|
||
protected override void OnShowWindow(object data = null)
|
||
{
|
||
if (stepIndex < mItems.Count && stepIndex < itemsType.Count)
|
||
RefreshMaterial(mItems[stepIndex], itemsType[stepIndex]);
|
||
else
|
||
DebugUtil.LogError(mItems.Count + "," + itemsType.Count + ",stepIndex: " + stepIndex + "——奖励列表为空");
|
||
}
|
||
|
||
public override void OnRelease()
|
||
{
|
||
foreach (ItemCell item in listItem)
|
||
{
|
||
item.Dispose();
|
||
}
|
||
listItem.Clear();
|
||
|
||
base.OnRelease();
|
||
}
|
||
|
||
protected override void OnHideWindow()
|
||
{
|
||
base.OnHideWindow();
|
||
}
|
||
|
||
private void RefreshMaterial(ListItem mItems, ItemSource type)
|
||
{
|
||
AudioManager.Instance.PlayAudio(Framework.Constants.Sound.COMMON_CLAIM);
|
||
|
||
_scrollContent.transform.ClearChilds();
|
||
listItem = new(mItems.List.Count);
|
||
for (int i = 0; i < mItems.List.Count; ++i)
|
||
{
|
||
var item = Instantiate(_itemTemp, _scrollContent.transform);
|
||
listItem.Add(new ItemCell(item));
|
||
}
|
||
for (int i = 0; i < listItem.Count; i++)
|
||
{
|
||
if (i < mItems.Ids.Count)
|
||
{
|
||
ItemCell item = listItem[i];
|
||
item.SetInfo(mItems.Ids[i], mItems.Counts[i], type);
|
||
item.IsActive = true;
|
||
}
|
||
else
|
||
listItem[i].IsActive = false;
|
||
}
|
||
|
||
//_goMaskBg.SetActive(_showType == EShowType.StorySettle);
|
||
|
||
}
|
||
|
||
private async void OnBgClick()
|
||
{
|
||
UIManager.Instance.ShowAllUI();
|
||
if (_showType == EShowType.StorySettle)
|
||
{
|
||
if (stepIndex < mItems.Count - 1)//有未展示完的奖励
|
||
{
|
||
stepIndex++;
|
||
RefreshMaterial(mItems[stepIndex], itemsType[stepIndex]);
|
||
return;
|
||
}
|
||
}
|
||
_callBackFunc?.Invoke();
|
||
Actor.Instance.RewardItems.Clear(); // 清理奖励道具
|
||
CommonUtils.ScreenshotReset();
|
||
|
||
await UniTask.WaitForSeconds(0.3f); // 保证先进入加载后关闭该界面,否则可能会闪
|
||
|
||
UIManager.Instance.CloseWindow(UINameConst.UI_Purchase); // 关闭商店二次购买界面
|
||
|
||
if (null == gameObject)
|
||
return;
|
||
CloseWindow();
|
||
}
|
||
|
||
public override UniTask<bool> OnBack(object data = null)
|
||
{
|
||
Actor.Instance.RewardItems.Clear();
|
||
_callBackFunc?.Invoke();
|
||
CommonUtils.ScreenshotReset();
|
||
|
||
return base.OnBack(data);
|
||
}
|
||
} |