229 lines
6.0 KiB
C#
229 lines
6.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.UIElements;
|
|
using Button = UnityEngine.UI.Button;
|
|
using Image = UnityEngine.UI.Image;
|
|
using Toggle = UnityEngine.UI.Toggle;
|
|
using ScrollView = PhxhSDK.PhxhScrollView;
|
|
using Framework;
|
|
using Cysharp.Threading.Tasks;
|
|
using Gameplay;
|
|
using Gameplay.Common;
|
|
using Gameplay.Net;
|
|
|
|
public class UI_CreditPointExchangePanelController : UIWindow
|
|
{
|
|
//UI GameObj
|
|
///Auto Gen Start///
|
|
public Image Image_TopBar;
|
|
public Image Image_Bg;
|
|
//public Button Button_Back;
|
|
public Button Button_Close;
|
|
//public TMP_Text Text_Back;
|
|
//public Button Button_Home;
|
|
public Image Image_GoldBg;
|
|
public Image Image_GoldIconBg;
|
|
public Image Image_GoldIcon;
|
|
public TMP_Text Text_GoldNum;
|
|
public Image Image_DiamondBg;
|
|
public Image Image_DiamondIconBg;
|
|
public Image Image_DiamondIcon;
|
|
public TMP_Text Text_DiamondNum;
|
|
public Button Button_DiamondAdd;
|
|
public Image Image_CreditPointBg;
|
|
public Image Image_CreditPoint;
|
|
public TMP_Text Text_CreditPointNum;
|
|
public Image Image_Arrow;
|
|
public Image Image_StuffBg;
|
|
public Image Image_Stuff;
|
|
public TMP_Text Text_StuffNum;
|
|
public Button Button_Zero;
|
|
public TMP_Text Text_Zero;
|
|
public Button Button_Decrease;
|
|
//public TMP_Text Text_Decrease;
|
|
public Button Button_Add;
|
|
//public TMP_Text Text_Add;
|
|
public Button Button_Max;
|
|
public TMP_Text Text_Max;
|
|
public Image Image_NumBg;
|
|
public TMP_Text Text_Num;
|
|
public TMP_Text Text_Cost;
|
|
public Image Image_CostIcon;
|
|
public TMP_Text Text_CostNum;
|
|
public Button Button_ExchangeBtn;
|
|
|
|
///Auto Gen End///
|
|
|
|
private int UseCount = 0;
|
|
private int exchangeCount = 0;
|
|
|
|
private string creditPointLocalizeString;
|
|
private string stuffLocalizeString;
|
|
|
|
public async static UniTask<UIWindow> Open(int defaultCount = 0)
|
|
{
|
|
CommonUtils.CaptureScreenshot();
|
|
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_CreditPointExchangePanel, defaultCount);
|
|
}
|
|
|
|
// deal with input data
|
|
public override void PreLoad(object data = null)
|
|
{
|
|
UseCount = (int)data;
|
|
}
|
|
|
|
// Use this for initialization
|
|
public override void OnInit()
|
|
{
|
|
//bind UI GameObj
|
|
UI_CreditPointExchangePanelBinder.GetComponents(this);
|
|
|
|
var rawImage = GetComponent<RawImage>("GaussianBlurMask");
|
|
rawImage.texture = CommonUtils.GetScreenTexture2D();
|
|
|
|
var itemCfg = TableManager.Instance.Tables.Item.DataMap[GLConfig.Inst.data.PurchaseDiamondID];
|
|
exchangeCount = itemCfg.Param3;
|
|
var exchangeItemCfg = TableManager.Instance.Tables.Item.DataMap[itemCfg.Param2];
|
|
|
|
|
|
BindButton(Button_Close, OnBackClick);
|
|
BindButton(Button_Add, OnPlusClick);
|
|
BindButton(Button_Decrease, OnMinusClick);
|
|
BindButton(Button_Max, OnMaxClick);
|
|
BindButton(Button_Zero, OnZeroClick);
|
|
BindButton(Button_ExchangeBtn, OnConfirmClick);
|
|
BindButton(Button_DiamondAdd, OnButtonDiamondAddClick);
|
|
|
|
creditPointLocalizeString = CommonUtils.GetLocalizeText(itemCfg.NameLocal);
|
|
stuffLocalizeString = CommonUtils.GetLocalizeText(exchangeItemCfg.NameLocal);
|
|
|
|
EventManager.Instance.Register<uint>(EventManager.EventName.ItemChange, OnItemChange);
|
|
|
|
Text_CreditPointNum.text = creditPointLocalizeString + "*" + 1;
|
|
Text_StuffNum.text = stuffLocalizeString + "*" + exchangeCount;
|
|
|
|
UI_CurrencyList currenyList = GetComponent<UI_CurrencyList>("TopNode/UI_CurrencyList");
|
|
currenyList.SetData(new List<(bool, int)> { (false, GLConfig.Inst.data.DiamondItemId), (true, GLConfig.Inst.data.PurchaseDiamondID) });
|
|
}
|
|
|
|
//invoke when open window
|
|
protected override void OnShowWindow(object data = null)
|
|
{
|
|
//RefreshTopBar();
|
|
RefreshCountUI();
|
|
UI_CurrencyList currenyList = GetComponent<UI_CurrencyList>("TopNode/UI_CurrencyList");
|
|
currenyList.Refresh();
|
|
}
|
|
|
|
//invoke when reload window
|
|
protected override void OnReloadWindow(object data = null)
|
|
{
|
|
|
|
}
|
|
|
|
//invoke when close window
|
|
protected override void OnHideWindow()
|
|
{
|
|
|
|
}
|
|
|
|
//invoke when destroy
|
|
public override void OnRelease()
|
|
{
|
|
base.OnRelease();
|
|
EventManager.Instance.Unregister<uint>(EventManager.EventName.ItemChange, OnItemChange);
|
|
}
|
|
|
|
//void RefreshTopBar()
|
|
//{
|
|
// Text_GoldNum.text = CategoryManager.Instance.GetItemCount(GLConfig.Inst.data.DiamondItemId).ToString();
|
|
// Text_DiamondNum.text = CategoryManager.Instance.GetItemCount(GLConfig.Inst.data.PurchaseDiamondID).ToString();
|
|
//}
|
|
|
|
void RefreshCountUI()
|
|
{
|
|
var creditPoint = UseCount;
|
|
var getItemCount = exchangeCount * creditPoint;
|
|
|
|
//Text_CreditPointNum.text = creditPointLocalizeString + "*" + creditPoint;
|
|
//Text_StuffNum.text = stuffLocalizeString + "*" + getItemCount.ToString();
|
|
|
|
Text_Num.text = UseCount.ToString();
|
|
Text_CostNum.text = creditPoint.ToString();
|
|
|
|
if (UseCount > CategoryManager.Instance.GetItemCount(GLConfig.Inst.data.PurchaseDiamondID))
|
|
{
|
|
Text_CostNum.color = Color.red;
|
|
}
|
|
else
|
|
{
|
|
Text_CostNum.color = Color.white;
|
|
}
|
|
}
|
|
|
|
void OnBackClick()
|
|
{
|
|
CloseWindow();
|
|
}
|
|
|
|
void OnPlusClick()
|
|
{
|
|
UseCount++;
|
|
|
|
RefreshCountUI();
|
|
}
|
|
|
|
void OnMinusClick()
|
|
{
|
|
if (UseCount > 0)
|
|
{
|
|
UseCount--;
|
|
RefreshCountUI();
|
|
}
|
|
}
|
|
|
|
void OnMaxClick()
|
|
{
|
|
UseCount = (int)CategoryManager.Instance.GetItemCount(GLConfig.Inst.data.PurchaseDiamondID);
|
|
RefreshCountUI();
|
|
}
|
|
void OnZeroClick()
|
|
{
|
|
UseCount = 0;
|
|
RefreshCountUI();
|
|
}
|
|
|
|
void OnConfirmClick()
|
|
{
|
|
if (UseCount > 0)
|
|
{
|
|
var maxCount = CategoryManager.Instance.GetItemCount(GLConfig.Inst.data.PurchaseDiamondID);
|
|
if (UseCount > maxCount)
|
|
{
|
|
CommonUtils.ShowMessageTips("信用点数不足,无法进行兑换");
|
|
return;
|
|
}
|
|
//NetHelper.UseItem((uint)GLConfig.Inst.data.PurchaseDiamondID, (uint)UseCount);
|
|
UI_CreditPointExchangeTipController.Open(new int[] { UseCount, UseCount * exchangeCount }).Forget();
|
|
}
|
|
}
|
|
|
|
void OnButtonDiamondAddClick()
|
|
{
|
|
UI_BuyDiamondController.Open().Forget();
|
|
}
|
|
|
|
void OnItemChange(uint itemID)
|
|
{
|
|
if (itemID != GLConfig.Inst.data.PurchaseDiamondID)
|
|
return;
|
|
UseCount = 0;
|
|
//RefreshTopBar();
|
|
RefreshCountUI();
|
|
UI_CurrencyList currenyList = GetComponent<UI_CurrencyList>("TopNode/UI_CurrencyList");
|
|
currenyList.Refresh();
|
|
}
|
|
} |