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

116 lines
3.3 KiB
C#
Raw Normal View History

2024-01-18 13:57:01 +08:00
using Gameplay;
using PhxhSDK;
using System;
2024-01-15 13:36:39 +08:00
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class UI_PatioController : UIWindow
{
//UI GameObj
///Auto Gen Start///
///Auto Gen End///
// Use this for initialization
List<NormalShopItemData> mShopDataList;
PhxhScrollView _mCurrentScrollView = null;
private GameObject mCurrentScrollViewContentObj = null;
Dictionary<GameObject, NormalShopItemData> mShopItemGoDataDic;
2024-01-23 12:25:47 +08:00
public override void OnInit()
2024-01-15 13:36:39 +08:00
{
//bind UI GameObj
UI_PatioBinder.GetComponents(this);
mShopDataList = new List<NormalShopItemData>();
_mCurrentScrollView = GetComponent<PhxhScrollView>("Scroll View");
mCurrentScrollViewContentObj = FindObj("Scroll View/Viewport/Content");
}
//invoke when open window
protected override void OnShowWindow(object data)
2024-01-15 13:36:39 +08:00
{
NormalShopDataForGacha nowShopData = data as NormalShopDataForGacha;
mShopDataList = nowShopData.normalShopItemDatas;
2024-01-18 13:57:01 +08:00
CreateScrollView();
2024-01-15 13:36:39 +08:00
}
private void CreateScrollView()
{
if (null != mCurrentScrollViewContentObj)
{
CommonUtils.DestoryAllChildGameObject(mCurrentScrollViewContentObj);
}
SetScrollView();
2024-01-18 13:57:01 +08:00
RefreshScrollview();
2024-01-15 13:36:39 +08:00
}
private void SetScrollView()
{
_mCurrentScrollView.SetUpdateFunc(RefreshItem);
_mCurrentScrollView.SetItemCountFunc(GetCountFunc);
_mCurrentScrollView.SetButton(SetScrollviewItemButton);
}
2024-01-18 13:57:01 +08:00
private void RefreshScrollview()
{
_mCurrentScrollView.UpdateData(false);
}
2024-01-15 13:36:39 +08:00
private int GetCountFunc()
{
return mShopDataList.Count;
}
private void SetScrollviewItemButton(GameObject obj)
{
GameObject singleObj = CommonUtils.GetGameObject(obj, "ClickBtn");
ClearBind(singleObj);
BindButton<GameObject>(singleObj, OnShopItemClick, singleObj);
}
private void OnShopItemClick(GameObject obj)
{
NormalShopItemData info = mShopItemGoDataDic[obj];
//await UIManager.Instance.OpenWindow(UINameConst.UI_Purchase, shopItemContainPic);
}
private void RefreshItem(int index, RectTransform item)
{
item.gameObject.SetActive(true);
NormalShopItemData normalShopData = mShopDataList[index];
RefreshSingleItem(item.gameObject,normalShopData);
mShopItemGoDataDic[item.gameObject]= normalShopData;
}
private void RefreshSingleItem(GameObject gameObject, NormalShopItemData normalShopData)
{
2024-01-18 13:57:01 +08:00
var uiHeadInfo = new UIHeadInfo((uint)CommonUtils.GetItemCharacterCfgId(normalShopData.id), false)
{
// ClickCb = (Action<int>)OnClickItem,
IsShowBg = false
};
UIHeadItemNode headItemNode = CommonUtils.GetComponent<UIHeadItemNode>(gameObject, "Head/UIHeadItemNode");
headItemNode.GetComponents();
headItemNode.SetData(uiHeadInfo);
//headItemNode.SetClickCbParam(index);
headItemNode.Refresh(false);
CommonUtils.GetComponent<TMP_Text>(gameObject, "Price").text = normalShopData.price.ToString();
2024-01-15 13:36:39 +08:00
}
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
}
//invoke when close window
protected override void OnHideWindow()
2024-01-15 13:36:39 +08:00
{
}
}