2024-01-08 13:13:35 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using TMPro;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
using Button = UnityEngine.UI.Button;
|
|
|
|
|
|
using Image = UnityEngine.UI.Image;
|
|
|
|
|
|
using Framework;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using Gameplay;
|
2024-04-09 19:40:43 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using PhxhSDK;
|
|
|
|
|
|
using cfg.ActorCfg;
|
2024-07-25 14:24:26 +08:00
|
|
|
|
using Gameplay.Level;
|
2024-01-08 13:13:35 +08:00
|
|
|
|
|
|
|
|
|
|
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///
|
2024-07-19 16:30:39 +08:00
|
|
|
|
private ListItem mItems;
|
|
|
|
|
|
|
2024-07-25 14:07:22 +08:00
|
|
|
|
private EShowType _showType;
|
|
|
|
|
|
|
2024-07-19 16:30:39 +08:00
|
|
|
|
private GameObject _itemTemp;
|
|
|
|
|
|
private GameObject _scrollView;
|
|
|
|
|
|
private GameObject _scrollContent;
|
2024-07-31 17:10:02 +08:00
|
|
|
|
private GameObject _goMaskBg;
|
2024-07-25 14:07:22 +08:00
|
|
|
|
|
|
|
|
|
|
public enum EShowType
|
|
|
|
|
|
{
|
|
|
|
|
|
Normal,
|
|
|
|
|
|
StorySettle
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private struct Param
|
|
|
|
|
|
{
|
|
|
|
|
|
public EShowType type;
|
|
|
|
|
|
public ListItem listItem;
|
|
|
|
|
|
|
|
|
|
|
|
public Param(EShowType Etype, ListItem list)
|
|
|
|
|
|
{
|
|
|
|
|
|
type = Etype;
|
|
|
|
|
|
listItem = list;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-08 13:13:35 +08:00
|
|
|
|
|
2024-04-09 19:40:43 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 打开奖励获取界面
|
|
|
|
|
|
/// </summary>
|
2024-07-25 14:07:22 +08:00
|
|
|
|
public static async UniTask<UIWindow> Open(ItemCounts itemCounts, EShowType type = EShowType.Normal)
|
2024-04-09 19:40:43 +08:00
|
|
|
|
{
|
2024-06-17 14:33:34 +08:00
|
|
|
|
ListItem itemList = new(itemCounts);
|
2024-07-25 14:07:22 +08:00
|
|
|
|
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_GetItemWindow, new Param(type, itemList));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static async UniTask<UIWindow> Open(ListItem itemList, EShowType type = EShowType.Normal)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_GetItemWindow, new Param(type, itemList));
|
2024-06-17 14:33:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-25 14:07:22 +08:00
|
|
|
|
public static async UniTask<UIWindow> Open(ItemList itemList, EShowType type = EShowType.Normal)
|
2024-06-17 14:33:34 +08:00
|
|
|
|
{
|
2024-07-25 14:07:22 +08:00
|
|
|
|
ListItem listItem = new(itemList);
|
|
|
|
|
|
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_GetItemWindow, new Param(type, listItem));
|
2024-04-09 19:40:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 道具
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private class Item : UIGameObjectWrapper
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 道具名
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private TMP_Text textName;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 通用道具
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private GenericItem genericItem;
|
|
|
|
|
|
|
|
|
|
|
|
public Item(GameObject root) : base(root)
|
|
|
|
|
|
{
|
|
|
|
|
|
textName = GetComponent<TMP_Text>("Text_IteamName");
|
|
|
|
|
|
|
|
|
|
|
|
genericItem = new GenericItem(FindObj("GenericItem"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetInfo(int itemId, int count)
|
|
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
IsScaleShow = true;
|
|
|
|
|
|
}
|
2024-05-08 13:59:40 +08:00
|
|
|
|
|
|
|
|
|
|
public override void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
genericItem.Dispose();
|
|
|
|
|
|
genericItem = null;
|
|
|
|
|
|
|
|
|
|
|
|
base.Dispose();
|
|
|
|
|
|
}
|
2024-04-09 19:40:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 道具列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private List<Item> listItem;
|
|
|
|
|
|
|
2024-06-17 14:33:34 +08:00
|
|
|
|
public override void PreLoad(object data = null)
|
|
|
|
|
|
{
|
2024-07-25 14:07:22 +08:00
|
|
|
|
if (data != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var param = (Param)data;
|
|
|
|
|
|
mItems = param.listItem;
|
|
|
|
|
|
_showType = param.type;
|
|
|
|
|
|
}
|
2024-06-17 14:33:34 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-23 12:25:47 +08:00
|
|
|
|
public override void OnInit()
|
2024-01-08 13:13:35 +08:00
|
|
|
|
{
|
|
|
|
|
|
UI_GetItemWindowBinder.GetComponents(this);
|
|
|
|
|
|
|
2024-04-09 19:40:43 +08:00
|
|
|
|
Transform tsItemRoot = FindObj("Image_BG/Goods").transform;
|
2024-07-19 16:30:39 +08:00
|
|
|
|
_scrollView = FindObj("Image_BG/ScrollView");
|
|
|
|
|
|
_itemTemp = FindObj("Image_BG/Item");
|
|
|
|
|
|
_scrollContent = FindObj("Image_BG/ScrollView/Viewport/Content");
|
2024-07-31 17:10:02 +08:00
|
|
|
|
_goMaskBg = FindObj("Image_BG/ImageMaskBg");
|
2024-04-09 19:40:43 +08:00
|
|
|
|
|
|
|
|
|
|
BindButton(GetComponent<Button>("Image_BG"), OnBgClick);
|
2024-01-08 13:13:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-24 16:32:38 +08:00
|
|
|
|
protected override void OnShowWindow(object data = null)
|
2024-01-08 13:13:35 +08:00
|
|
|
|
{
|
|
|
|
|
|
RefreshMaterial(mItems);
|
|
|
|
|
|
}
|
2024-04-09 19:40:43 +08:00
|
|
|
|
|
2024-05-08 13:59:40 +08:00
|
|
|
|
public override void OnRelease()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (Item item in listItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
listItem.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
base.OnRelease();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-17 14:33:34 +08:00
|
|
|
|
private void RefreshMaterial(ListItem mItems)
|
2024-01-08 13:13:35 +08:00
|
|
|
|
{
|
2024-07-19 16:30:39 +08:00
|
|
|
|
_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 Item(item));
|
|
|
|
|
|
}
|
2024-04-09 19:40:43 +08:00
|
|
|
|
for (int i = 0; i < listItem.Count; i++)
|
2024-01-08 13:13:35 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (i < mItems.Ids.Count)
|
|
|
|
|
|
{
|
2024-04-09 19:40:43 +08:00
|
|
|
|
Item item = listItem[i];
|
2024-06-17 14:33:34 +08:00
|
|
|
|
item.SetInfo(mItems.Ids[i], mItems.Counts[i]);
|
2024-04-09 19:40:43 +08:00
|
|
|
|
item.IsActive = true;
|
2024-01-08 13:13:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2024-04-09 19:40:43 +08:00
|
|
|
|
listItem[i].IsActive = false;
|
2024-01-08 13:13:35 +08:00
|
|
|
|
}
|
2024-07-31 17:10:02 +08:00
|
|
|
|
|
|
|
|
|
|
_goMaskBg.SetActive(_showType == EShowType.StorySettle);
|
|
|
|
|
|
|
2024-01-08 13:13:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-09 19:40:43 +08:00
|
|
|
|
private void OnBgClick()
|
|
|
|
|
|
{
|
2024-07-25 14:07:22 +08:00
|
|
|
|
if (_showType == EShowType.StorySettle)
|
|
|
|
|
|
{
|
2024-07-25 14:24:26 +08:00
|
|
|
|
LevelManager.Instance.ExitLevelDirectly();
|
2024-07-25 14:07:22 +08:00
|
|
|
|
}
|
2024-04-09 19:40:43 +08:00
|
|
|
|
CloseWindow();
|
|
|
|
|
|
}
|
2024-01-08 13:13:35 +08:00
|
|
|
|
}
|