143 lines
3.8 KiB
C#
143 lines
3.8 KiB
C#
using TMPro;
|
|
using System;
|
|
using PhxhSDK;
|
|
using Gameplay;
|
|
using UnityEngine;
|
|
using cfg.ChargeCfg;
|
|
using UnityEngine.UI;
|
|
using Cysharp.Threading.Tasks;
|
|
using Image = UnityEngine.UI.Image;
|
|
using Button = UnityEngine.UI.Button;
|
|
|
|
public class UI_BuyDiamondController : UIWindow
|
|
{
|
|
private class IapItem : UIGameObjectWrapper
|
|
{
|
|
private TMP_Text textName;
|
|
|
|
private TMP_Text textPrice;
|
|
|
|
private Image imageIcon;
|
|
|
|
private Button iapItemBtn;
|
|
|
|
private DataCurrencyShopCfg cfg;
|
|
|
|
public IapItem(DataCurrencyShopCfg cfg, GameObject root) : base(root)
|
|
{
|
|
if (cfg == null) return;
|
|
|
|
IsScaleShow = true;
|
|
this.cfg = cfg;
|
|
textName = GetComponent<TMP_Text>("Text_ItemName");
|
|
textPrice = GetComponent<TMP_Text>("Image_CoinBG/Text_ItemPrice");
|
|
imageIcon = GetComponent<Image>("Image_ItemPic");
|
|
iapItemBtn = GetComponent<Button>();
|
|
}
|
|
|
|
public async void SetInfo(Action btnCallBack)
|
|
{
|
|
iapItemBtn.onClick.RemoveAllListeners();
|
|
BindButton(iapItemBtn, btnCallBack);
|
|
textName.text = cfg.Name;
|
|
textPrice.text = cfg.NowPriceRMB.ToString();
|
|
imageIcon.sprite = await LoadAssetAsync<Sprite>(cfg.IconPath);
|
|
}
|
|
}
|
|
|
|
//UI GameObj
|
|
///Auto Gen Start///
|
|
public Button Button_Close;
|
|
|
|
/// <summary>
|
|
/// 打开购买钻石界面
|
|
/// </summary>
|
|
public static async UniTask<UIWindow> Open()
|
|
{
|
|
CommonUtils.CaptureScreenshot();
|
|
|
|
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_BuyDiamond);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 高斯模糊遮罩
|
|
/// </summary>
|
|
private RawImage rawImageGaussianBlurMask;
|
|
private GameObject mCurrentScrollViewContentObj;
|
|
private PhxhScrollView _mCurrentScrollView;
|
|
|
|
public override void OnInit()
|
|
{
|
|
UI_BuyDiamondBinder.GetComponents(this);
|
|
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
|
|
rawImageGaussianBlurMask.texture = CommonUtils.screenTexture;
|
|
mCurrentScrollViewContentObj = FindObj("Image_BG/PhxhScrollView/Viewport/Content");
|
|
_mCurrentScrollView = GetComponent<PhxhScrollView>("Image_BG/PhxhScrollView");
|
|
BindButton(Button_Close, _OnClickClose);
|
|
CreateScrollView();
|
|
}
|
|
|
|
protected override void OnShowWindow(object data = null)
|
|
{
|
|
RefreshAllShopItems();
|
|
}
|
|
|
|
private void CreateScrollView()
|
|
{
|
|
if (null != mCurrentScrollViewContentObj)
|
|
{
|
|
CommonUtils.DestoryAllChildGameObject(mCurrentScrollViewContentObj);
|
|
}
|
|
SetScrollView();
|
|
}
|
|
|
|
private void RefreshItem(int index, RectTransform item)
|
|
{
|
|
if (IAPManager.Instance.IapDataDic.TryGetValue(index + 1, out var iapItemUI))
|
|
{
|
|
var iapItem = new IapItem(iapItemUI, item.gameObject);
|
|
if (index < 0 || index >= IAPManager.Instance.IapDataDic.Count)
|
|
{
|
|
iapItem.IsScaleShow = false;
|
|
return;
|
|
}
|
|
iapItem.SetInfo(() => { OnShopItemClick(index + 1); });
|
|
}
|
|
}
|
|
|
|
private void OnShopItemClick(int id)
|
|
{
|
|
IAPManager.Instance.IAPBuyGoods(id);
|
|
//TODO 打开二次确认购买界面
|
|
}
|
|
|
|
private void RefreshAllShopItems()
|
|
{
|
|
_mCurrentScrollView.UpdateData(false);
|
|
}
|
|
|
|
private int GetCountFunc()
|
|
{
|
|
return IAPManager.Instance.IapDataDic.Count;
|
|
}
|
|
|
|
private void SetScrollView()
|
|
{
|
|
_mCurrentScrollView.SetUpdateFunc(RefreshItem);
|
|
_mCurrentScrollView.SetItemCountFunc(GetCountFunc);
|
|
}
|
|
|
|
|
|
private void _OnClickClose()
|
|
{
|
|
CloseWindow();
|
|
}
|
|
|
|
protected override void OnReloadWindow(object data = null)
|
|
{
|
|
}
|
|
|
|
protected override void OnHideWindow()
|
|
{
|
|
}
|
|
} |