163 lines
4.4 KiB
C#
163 lines
4.4 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;
|
|
using Gameplay.Net;
|
|
using NLDPB;
|
|
|
|
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;
|
|
|
|
private const string Currency = "¥ {0}";
|
|
|
|
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);
|
|
var stringKey = cfg.NameLocal;
|
|
textName.text = StringManager.Instance.GetTextByKey(stringKey);
|
|
textPrice.text = string.Format(Currency, cfg.NowPriceRMB);
|
|
imageIcon.sprite = await LoadAssetAsync<Sprite>(cfg.IconPath);
|
|
}
|
|
}
|
|
|
|
//UI GameObj
|
|
///Auto Gen Start///
|
|
public Button Button_Close;
|
|
|
|
GameObject UI_ShortTip;
|
|
|
|
/// <summary>
|
|
/// 打开购买钻石界面
|
|
/// </summary>
|
|
public static async UniTask<UIWindow> Open()
|
|
{
|
|
await 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.GetScreenTexture2D();
|
|
mCurrentScrollViewContentObj = FindObj("Image_BG/PhxhScrollView/Viewport/Content");
|
|
_mCurrentScrollView = GetComponent<PhxhScrollView>("Image_BG/PhxhScrollView");
|
|
UI_ShortTip = FindObj("Image_BG/UI_ShortTip");
|
|
var adultStatus = (int)Actor.Instance.Logic.GetCount((uint)LogicID.AdultAuthStatus);
|
|
if (adultStatus == (int)AAStatus.AasUnderEighteen)
|
|
{
|
|
DebugUtil.Log("未成年人限制购买提示");
|
|
UI_ShortTip.SetActive(true);
|
|
}
|
|
|
|
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)
|
|
{
|
|
//TODO 审核包暂时关闭内购功能
|
|
UITipsManager.ShowTips("充值未开放");
|
|
//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()
|
|
{
|
|
}
|
|
} |