185 lines
5.4 KiB
C#
185 lines
5.4 KiB
C#
using GameCore;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
using TMPro;
|
|
using game;
|
|
|
|
public class BattlePassBuyGradePopupPanel : BasePanel
|
|
{
|
|
#region Field 乂
|
|
[SerializeField]
|
|
private Button
|
|
btn_close;
|
|
|
|
[SerializeField]
|
|
Transform
|
|
tran_slotParent;
|
|
|
|
[SerializeField]
|
|
Slider
|
|
sld_changeLevel;
|
|
|
|
[SerializeField]
|
|
Button
|
|
btn_buy,
|
|
btn_downLevel,
|
|
btn_upLevel;
|
|
|
|
[SerializeField]
|
|
GameObject
|
|
go_vipSlot,
|
|
go_normalSlot;
|
|
|
|
[SerializeField]
|
|
TMP_Text
|
|
txt_targetLevel,
|
|
txt_diamondCost,
|
|
txt_upLevel;
|
|
|
|
//Data
|
|
List<BPItemSlot> normalSlot = new();
|
|
List<BPItemSlot> vipSlot = new();
|
|
int curUpLevel;
|
|
int maxUpLevel;
|
|
int expGet;
|
|
int diamondCost;
|
|
float levelUpDelta;
|
|
|
|
BattlePassDataProvider _dataProvider;
|
|
#endregion
|
|
|
|
|
|
#region Func
|
|
private void Awake()
|
|
{
|
|
_dataProvider = GContext.container.Resolve<BattlePassDataProvider>();
|
|
}
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
ResfreshPanel();
|
|
btn_close.OnClickAsObservable().Subscribe(_=>Close()).AddTo(disposables);
|
|
btn_downLevel.OnClickAsObservable().Subscribe(_=>OnChangeUpLevel(curUpLevel-1,true)).AddTo(disposables);
|
|
btn_upLevel.OnClickAsObservable().Subscribe(_=>OnChangeUpLevel(curUpLevel+1,true)).AddTo(disposables);
|
|
sld_changeLevel.OnValueChangedAsObservable().Subscribe(OnSliderMove).AddTo(disposables);
|
|
btn_buy.OnClickAsObservable().Subscribe(_=>OnBuy()).AddTo(disposables);
|
|
}
|
|
|
|
protected void Close()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.BattlePassBuyGradePopupPanel);
|
|
}
|
|
|
|
private void ResfreshPanel()
|
|
{
|
|
go_normalSlot.gameObject.SetActive(false);
|
|
go_vipSlot.gameObject.SetActive(false);
|
|
maxUpLevel=_dataProvider.BPMaxLevel-_dataProvider.GetBPCurLevel;
|
|
levelUpDelta=(float)1/(float)(maxUpLevel-curUpLevel);
|
|
|
|
for (int i = 2; i < tran_slotParent.childCount; i++)
|
|
{
|
|
Destroy(tran_slotParent.GetChild(i).gameObject);
|
|
}
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
vipSlot.Add( Instantiate(go_vipSlot, tran_slotParent).GetComponent<BPItemSlot>());
|
|
}
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
normalSlot.Add( Instantiate(go_normalSlot, tran_slotParent).GetComponent<BPItemSlot>());
|
|
}
|
|
|
|
OnChangeUpLevel(_dataProvider.DefaultBuyLevel,true);
|
|
}
|
|
|
|
private void OnChangeUpLevel(int upLevel,bool sliderMove=false)
|
|
{
|
|
if( upLevel < 1 )
|
|
upLevel = 1;
|
|
if(upLevel>maxUpLevel)
|
|
upLevel = maxUpLevel;
|
|
|
|
curUpLevel = upLevel;
|
|
txt_upLevel.text = LocalizationMgr.GetFormatTextValue("UI_BattlePassPanel_13", curUpLevel);
|
|
txt_targetLevel.text = LocalizationMgr.GetFormatTextValue("UI_BattlePassPanel_12", _dataProvider.GetBPCurLevel + curUpLevel);
|
|
diamondCost = _dataProvider.GetDiamondCostByUpLevel(upLevel);
|
|
var normalItemDatas = _dataProvider.GetRewardsByUpLevel(upLevel,true);
|
|
var vipItemDatas = _dataProvider.GetRewardsByUpLevel(upLevel,false);
|
|
expGet = diamondCost/_dataProvider.curPassMain.ExpPrice*100;
|
|
|
|
txt_diamondCost.text = diamondCost.ToString();
|
|
if ( sliderMove )
|
|
{
|
|
sld_changeLevel.value = curUpLevel * levelUpDelta-levelUpDelta/2f;
|
|
}
|
|
var isVipUnlock = _dataProvider.IsUnlockVip;
|
|
for (int i = 0; i<vipSlot.Count; i++)
|
|
{
|
|
if(i<vipItemDatas.Count)
|
|
{
|
|
vipSlot[i].SetData(false,BPRewardSlot.ESlotState.Normal,vipItemDatas[i]);
|
|
}
|
|
else
|
|
{
|
|
vipSlot[i].SetInactive();
|
|
}
|
|
}
|
|
for ( int i = 0; i < normalSlot.Count; i++ )
|
|
{
|
|
if ( i < normalItemDatas.Count )
|
|
{
|
|
normalSlot[i].SetData(true, BPRewardSlot.ESlotState.Normal, normalItemDatas[i]);
|
|
}
|
|
else
|
|
{
|
|
normalSlot[i].SetInactive();
|
|
}
|
|
}
|
|
|
|
// _dataProvider.DefaultBuyLevel = upLevel;
|
|
|
|
}
|
|
|
|
private void OnSliderMove(float value)
|
|
{
|
|
var upLevel = (int)(value*1000000f)/ (int)(levelUpDelta*1000000f) +1;
|
|
if(curUpLevel!=upLevel)
|
|
{
|
|
OnChangeUpLevel(upLevel);
|
|
}
|
|
}
|
|
|
|
private void OnBuy()
|
|
{
|
|
var curDiamond = GContext.container.Resolve<PlayerData>().diamond;
|
|
if ( curDiamond >= diamondCost)
|
|
{
|
|
GContext.container.Resolve<PlayerData>().AddDiamond(-diamondCost);
|
|
#if AGG
|
|
using ( var e = GEvent.GameEvent("bp_purchase_level") )
|
|
{
|
|
e.AddContent("bp_level", _dataProvider.GetBPCurLevel)
|
|
.AddContent("purchase_level", curUpLevel)
|
|
.AddContent("af_price", diamondCost);
|
|
}
|
|
#endif
|
|
_dataProvider.SetBPExp(expGet);
|
|
GContext.Publish(new BpGetExp());
|
|
GContext.Publish(new ResAddEvent(_dataProvider.curPassMain.ExpItem));
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_3"));
|
|
Close();
|
|
}
|
|
else
|
|
{
|
|
_ = UIManager.Instance.ShowUI(UITypes.LackOfResourceConfirmPopupPanel);
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_59"));
|
|
}
|
|
}
|
|
#endregion
|
|
}
|