NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/UI_GetItemWindowController.cs

141 lines
3.3 KiB
C#
Raw Normal View History

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-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;
private ItemCounts mItems;
///Auto Gen End///
2024-04-09 19:40:43 +08:00
/// <summary>
/// 打开奖励获取界面
/// </summary>
public static async UniTask<UIWindow> Open(ItemCounts itemCounts)
{
2024-05-16 12:40:15 +08:00
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_GetItemWindow, itemCounts);
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-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;
listItem = new(tsItemRoot.childCount);
for (int i = 0; i < tsItemRoot.childCount; ++i)
{
listItem.Add(new Item(tsItemRoot.GetChild(i).gameObject));
}
BindButton(GetComponent<Button>("Image_BG"), OnBgClick);
2024-01-08 13:13:35 +08:00
}
protected override void OnShowWindow(object data = null)
2024-01-08 13:13:35 +08:00
{
mItems = data as ItemCounts;
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-04-09 19:40:43 +08:00
private void RefreshMaterial(ItemCounts mItems)
2024-01-08 13:13:35 +08:00
{
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];
item.SetInfo((int)mItems.Ids[i], (int)mItems.Counts[i]);
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-04-09 19:40:43 +08:00
private void OnBgClick()
{
CloseWindow();
}
2024-01-08 13:13:35 +08:00
}