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

122 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
using Cysharp.Threading.Tasks;
using PhxhSDK;
using cfg.ActorCfg;
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///
/// <summary>
/// 打开奖励获取界面
/// </summary>
public static async UniTask<UIWindow> Open(ItemCounts itemCounts)
{
return await UIManager.Instance.OpenWindow(UINameConst.UI_GetItemWindow, itemCounts);
}
/// <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;
}
}
/// <summary>
/// 道具列表
/// </summary>
private List<Item> listItem;
public override void OnInit()
{
UI_GetItemWindowBinder.GetComponents(this);
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);
}
protected override void OnShowWindow(object data = null)
{
mItems = data as ItemCounts;
RefreshMaterial(mItems);
}
private void RefreshMaterial(ItemCounts mItems)
{
for (int i = 0; i < listItem.Count; i++)
{
if (i < mItems.Ids.Count)
{
Item item = listItem[i];
item.SetInfo((int)mItems.Ids[i], (int)mItems.Counts[i]);
item.IsActive = true;
}
else
listItem[i].IsActive = false;
}
}
private void OnBgClick()
{
CloseWindow();
}
}