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

163 lines
4.4 KiB
C#
Raw Normal View History

2024-06-17 15:25:04 +08:00
using TMPro;
using System;
2024-01-31 19:16:16 +08:00
using PhxhSDK;
2024-06-17 15:25:04 +08:00
using Gameplay;
2024-01-24 13:30:17 +08:00
using UnityEngine;
2024-06-17 15:25:04 +08:00
using cfg.ChargeCfg;
2024-04-01 12:26:42 +08:00
using UnityEngine.UI;
2024-06-17 15:25:04 +08:00
using Cysharp.Threading.Tasks;
2024-01-24 13:30:17 +08:00
using Image = UnityEngine.UI.Image;
2024-06-17 15:25:04 +08:00
using Button = UnityEngine.UI.Button;
2024-07-25 12:34:16 +08:00
using Gameplay.Net;
using NLDPB;
2024-01-24 13:30:17 +08:00
public class UI_BuyDiamondController : UIWindow
{
2024-06-17 15:25:04 +08:00
private class IapItem : UIGameObjectWrapper
{
private TMP_Text textName;
2024-08-06 18:38:03 +08:00
2024-06-17 15:25:04 +08:00
private TMP_Text textPrice;
2024-08-06 18:38:03 +08:00
2024-06-17 15:25:04 +08:00
private Image imageIcon;
private Button iapItemBtn;
private DataCurrencyShopCfg cfg;
2024-08-06 18:38:03 +08:00
private const string Currency = "¥ {0}";
2024-06-17 15:25:04 +08:00
public IapItem(DataCurrencyShopCfg cfg, GameObject root) : base(root)
{
if (cfg == null) return;
2024-08-06 18:38:03 +08:00
2024-06-17 15:25:04 +08:00
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);
2024-08-06 18:38:03 +08:00
var stringKey = cfg.NameLocal;
textName.text = StringManager.Instance.GetTextByKey(stringKey);
textPrice.text = string.Format(Currency, cfg.NowPriceRMB);
2024-06-17 15:25:04 +08:00
imageIcon.sprite = await LoadAssetAsync<Sprite>(cfg.IconPath);
}
}
2024-08-06 18:38:03 +08:00
2024-05-14 13:40:27 +08:00
//UI GameObj
///Auto Gen Start///
public Button Button_Close;
2024-01-30 12:38:54 +08:00
2024-07-25 12:34:16 +08:00
GameObject UI_ShortTip;
2024-04-01 12:26:42 +08:00
/// <summary>
2024-06-17 15:25:04 +08:00
/// 打开购买钻石界面
2024-04-01 12:26:42 +08:00
/// </summary>
public static async UniTask<UIWindow> Open()
{
2024-08-13 14:29:50 +08:00
await CommonUtils.CaptureScreenshot();
2024-04-01 12:26:42 +08:00
2024-05-16 12:40:15 +08:00
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_BuyDiamond);
2024-04-01 12:26:42 +08:00
}
/// <summary>
/// 高斯模糊遮罩
/// </summary>
private RawImage rawImageGaussianBlurMask;
2024-08-06 18:38:03 +08:00
2024-06-17 15:25:04 +08:00
private GameObject mCurrentScrollViewContentObj;
private PhxhScrollView _mCurrentScrollView;
2024-05-14 13:40:27 +08:00
2024-01-24 13:30:17 +08:00
public override void OnInit()
{
UI_BuyDiamondBinder.GetComponents(this);
2024-04-01 12:26:42 +08:00
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
rawImageGaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
2024-01-24 13:30:17 +08:00
mCurrentScrollViewContentObj = FindObj("Image_BG/PhxhScrollView/Viewport/Content");
_mCurrentScrollView = GetComponent<PhxhScrollView>("Image_BG/PhxhScrollView");
2024-07-25 12:34:16 +08:00
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);
2024-06-17 15:25:04 +08:00
CreateScrollView();
2024-05-27 15:28:19 +08:00
}
2024-08-06 18:38:03 +08:00
protected override void OnShowWindow(object data = null)
2024-05-14 13:40:27 +08:00
{
2024-01-24 13:30:17 +08:00
RefreshAllShopItems();
}
2024-05-14 13:40:27 +08:00
2024-01-24 13:30:17 +08:00
private void CreateScrollView()
{
if (null != mCurrentScrollViewContentObj)
{
CommonUtils.DestoryAllChildGameObject(mCurrentScrollViewContentObj);
}
2024-08-06 18:38:03 +08:00
2024-01-24 13:30:17 +08:00
SetScrollView();
}
2024-05-14 13:40:27 +08:00
2024-01-24 13:30:17 +08:00
private void RefreshItem(int index, RectTransform item)
{
2024-06-17 15:25:04 +08:00
if (IAPManager.Instance.IapDataDic.TryGetValue(index + 1, out var iapItemUI))
2024-01-24 13:30:17 +08:00
{
2024-06-17 15:25:04 +08:00
var iapItem = new IapItem(iapItemUI, item.gameObject);
if (index < 0 || index >= IAPManager.Instance.IapDataDic.Count)
{
iapItem.IsScaleShow = false;
return;
}
2024-08-06 18:38:03 +08:00
2024-06-17 15:25:04 +08:00
iapItem.SetInfo(() => { OnShopItemClick(index + 1); });
2024-01-24 13:30:17 +08:00
}
}
2024-01-30 12:38:54 +08:00
2024-06-17 15:25:04 +08:00
private void OnShopItemClick(int id)
{
2024-08-06 18:38:03 +08:00
//TODO 审核包暂时关闭内购功能
UITipsManager.ShowTips("充值未开放");
//IAPManager.Instance.IAPBuyGoods(id);
2024-06-17 15:25:04 +08:00
//TODO 打开二次确认购买界面
}
2024-01-30 12:38:54 +08:00
private void RefreshAllShopItems()
{
_mCurrentScrollView.UpdateData(false);
}
2024-05-14 13:40:27 +08:00
2024-01-24 13:30:17 +08:00
private int GetCountFunc()
{
2024-06-17 15:25:04 +08:00
return IAPManager.Instance.IapDataDic.Count;
2024-01-24 13:30:17 +08:00
}
2024-05-14 13:40:27 +08:00
2024-01-24 13:30:17 +08:00
private void SetScrollView()
{
_mCurrentScrollView.SetUpdateFunc(RefreshItem);
_mCurrentScrollView.SetItemCountFunc(GetCountFunc);
}
private void _OnClickClose()
{
2024-05-14 13:40:27 +08:00
CloseWindow();
}
2024-05-14 13:40:27 +08:00
protected override void OnReloadWindow(object data = null)
{
}
protected override void OnHideWindow()
{
}
2024-01-24 13:30:17 +08:00
}