137 lines
4.5 KiB
C#
137 lines
4.5 KiB
C#
using Gameplay;
|
|
using PhxhSDK;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using Button = UnityEngine.UI.Button;
|
|
using Image = UnityEngine.UI.Image;
|
|
|
|
public class UI_BuyDiamondController : UIWindow
|
|
{
|
|
//UI GameObj
|
|
///Auto Gen Start///
|
|
public Image Image_BG;
|
|
public Button Button_Close;
|
|
public Image Image_RestartBG;
|
|
public TMP_Text Text_Restart;
|
|
public TMP_Text Text_Time;
|
|
public TMP_Text Text_Title;
|
|
public TMP_Text Text_Currency;
|
|
public Image Image_IteamTime;
|
|
public TMP_Text Text_ItemTime;
|
|
public Image Image_IteamMax;
|
|
public TMP_Text Text_ItemMax;
|
|
public TMP_Text Text_ItemName;
|
|
public Image Image_ItemPic;
|
|
public Image Image_CoinBG;
|
|
public Image Image_CoinLogo;
|
|
public TMP_Text Text_ItemPrice;
|
|
|
|
///Auto Gen End///
|
|
|
|
// Use this for initialization
|
|
|
|
ShopData nowShopData;
|
|
private GameObject mCurrentScrollViewContentObj = null;
|
|
PhxhScrollView _mCurrentScrollView = null;
|
|
Dictionary<GameObject, ShopItemForDisplay> mShopItemGoDataDic;
|
|
Dictionary<GameObject, int> mShopItemIndexGoDataDic;
|
|
public override void OnInit()
|
|
{
|
|
//bind UI GameObj
|
|
UI_BuyDiamondBinder.GetComponents(this);
|
|
mCurrentScrollViewContentObj = FindObj("Image_BG/PhxhScrollView/Viewport/Content");
|
|
_mCurrentScrollView = GetComponent<PhxhScrollView>("Image_BG/PhxhScrollView");
|
|
mShopItemGoDataDic = new Dictionary<GameObject, ShopItemForDisplay>();
|
|
mShopItemIndexGoDataDic = new Dictionary<GameObject, int>();
|
|
// BindButton(Button_Close, CloseOnClick);
|
|
}
|
|
|
|
//invoke when open window
|
|
protected override void OnShowWindow(object data = null)
|
|
{
|
|
GetData();
|
|
CreateScrollView();
|
|
RefreshAllShopItems();
|
|
}
|
|
private void CreateScrollView()
|
|
{
|
|
if (null != mCurrentScrollViewContentObj)
|
|
{
|
|
CommonUtils.DestoryAllChildGameObject(mCurrentScrollViewContentObj);
|
|
}
|
|
SetScrollView();
|
|
}
|
|
private void RefreshItem(int index, RectTransform item)
|
|
{
|
|
ShopItemForDisplay tempDataInfo = nowShopData.ItemList[index];
|
|
mShopItemGoDataDic[item.gameObject] = tempDataInfo;
|
|
mShopItemIndexGoDataDic[item.gameObject] = index;
|
|
|
|
RefreshSingleItem(item.gameObject, tempDataInfo);
|
|
}
|
|
|
|
private async void RefreshSingleItem(GameObject singleItem, ShopItemForDisplay tempDataInfo)
|
|
{
|
|
CommonUtils.GetComponent<TMP_Text>(singleItem, "Text_ItemName").text = tempDataInfo.Name;
|
|
CommonUtils.GetComponent<TMP_Text>(singleItem, "Image_ItemPic/Image_Bar/Text_ItemNum").text = tempDataInfo.shopItemCfg.ItemCount.ToString();
|
|
|
|
// CommonUtils.GetComponent<Image>(singleItem, "Image_ItemPic").sprite = await AssetManager.GetSingleton().LoadAssetAsync<Sprite>(Framework.Constants.UI_SHOP_ICON_PATH + nowShopData.Cfg.GoodsPathList[index]);
|
|
CommonUtils.GetComponent<TMP_Text>(singleItem, "Image_CoinPic/Text_Price").text = tempDataInfo.shopItemCfg.PriceCount.ToString();
|
|
|
|
CommonUtils.GetGameObject(singleItem, "Image_Day").SetActive(false);
|
|
CommonUtils.GetGameObject(singleItem, "Image_Num").SetActive(!tempDataInfo.IsNoLimit());
|
|
CommonUtils.GetGameObject(singleItem, "Image_NoMore").SetActive(tempDataInfo.RemainSoldTime() <= 0);
|
|
|
|
CommonUtils.GetComponent<TMP_Text>(singleItem, "Image_Num/Text_ItemMax").text = CommonUtils.GetLocalizeText("shop_remainNum", tempDataInfo.RemainSoldTime());
|
|
CommonUtils.GetComponent<Image>(singleItem, "Image_CoinPic").sprite = await AssetManager.GetSingleton().LoadAssetAsync<Sprite>(CommonUtils.GetItemPath(tempDataInfo.shopItemCfg.PriceID));
|
|
}
|
|
|
|
private void SetScrollviewItemButton(GameObject obj)
|
|
{
|
|
if (obj != null)
|
|
{
|
|
ClearBind(obj);
|
|
BindButton<GameObject>(obj, OnShopItemClick, obj);
|
|
}
|
|
}
|
|
|
|
private void OnShopItemClick(GameObject @object)
|
|
{
|
|
}
|
|
|
|
private void RefreshAllShopItems()
|
|
{
|
|
_mCurrentScrollView.UpdateData(false);
|
|
}
|
|
private int GetCountFunc()
|
|
{
|
|
return nowShopData.ItemList.Count;
|
|
}
|
|
private void SetScrollView()
|
|
{
|
|
_mCurrentScrollView.SetUpdateFunc(RefreshItem);
|
|
_mCurrentScrollView.SetItemCountFunc(GetCountFunc);
|
|
_mCurrentScrollView.SetButton(SetScrollviewItemButton);
|
|
}
|
|
|
|
private void GetData()
|
|
{
|
|
nowShopData = ShopManager.GetSingleton().GetShop(ShopManager.DiamondShopId);
|
|
|
|
}
|
|
//invoke when open window
|
|
|
|
|
|
//invoke when reload window
|
|
protected override void OnReloadWindow(object data = null)
|
|
{
|
|
|
|
}
|
|
|
|
//invoke when close window
|
|
protected override void OnHideWindow()
|
|
{
|
|
|
|
}
|
|
} |