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

165 lines
4.6 KiB
C#
Raw Normal View History

2024-06-17 15:25:04 +08:00
using TMPro;
using NLDPB;
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;
using Gameplay.Net;
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-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>();
}
2024-11-11 15:35:17 +08:00
public async void SetInfo()
2024-06-17 15:25:04 +08:00
{
iapItemBtn.onClick.RemoveAllListeners();
2024-11-11 15:35:17 +08:00
CommonUtils.BindButton(iapItemBtn, OnClick);
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-11-11 15:35:17 +08:00
private async void OnClick()
{
2024-12-26 15:08:06 +08:00
#if UNITY_IOS
// ios 只走苹果内购
IAPManager.Instance.SetCurrentPayChannel(IAPManager.PayChannel.Apple);
IAPManager.Instance.CheckAndBuyGoods(cfg.Id);
2025-01-02 14:18:26 +08:00
#elif SDK_BILIBILI
IAPManager.Instance.SetCurrentPayChannel(IAPManager.PayChannel.Bilibili);
2025-03-21 13:55:46 +08:00
IAPManager.Instance.CheckAndBuyGoods(cfg.Id);
2025-01-02 15:13:57 +08:00
#else
2024-11-11 15:35:17 +08:00
await UI_PayWindowController.Open(cfg);
2025-01-02 15:13:57 +08:00
#endif
2024-11-11 15:35:17 +08:00
}
2024-06-17 15:25:04 +08:00
}
2024-08-06 18:38:03 +08:00
/// <summary>
/// 高斯模糊遮罩
/// </summary>
private RawImage rawImageGaussianBlurMask;
2024-05-14 13:40:27 +08:00
public Button Button_Close;
2024-01-30 12:38:54 +08:00
private GameObject UI_ShortTip;
private GameObject mCurrentScrollViewContentObj;
private PhxhScrollView _mCurrentScrollView;
2024-07-25 12:34:16 +08:00
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-09-18 16:03:02 +08:00
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
}
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)
{
if (IAPManager.Instance.IapShopItem.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.IapShopItem.Count)
2024-06-17 15:25:04 +08:00
{
iapItem.IsScaleShow = false;
return;
}
2024-08-06 18:38:03 +08:00
2024-11-11 15:35:17 +08:00
iapItem.SetInfo();
2024-01-24 13:30:17 +08:00
}
}
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()
{
return IAPManager.Instance.IapShopItem.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
}