using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class SuperValueGiftBehaviour : MonoBehaviour
|
{
|
[SerializeField] int m_PayType = 0;
|
[SerializeField] Text m_Cost;
|
[SerializeField] RareItem[] m_Items;
|
[SerializeField] Button m_Buy;
|
[SerializeField] Image m_AreadyBuySign;
|
[SerializeField] Text m_Remind;
|
|
public int payType
|
{
|
get { return m_PayType; }
|
}
|
|
OSGiftModel model
|
{
|
get { return ModelCenter.Instance.GetModel<OSGiftModel>(); }
|
}
|
|
VipModel vipModel
|
{
|
get { return ModelCenter.Instance.GetModel<VipModel>(); }
|
}
|
|
PetModel petModel
|
{
|
get { return ModelCenter.Instance.GetModel<PetModel>(); }
|
}
|
|
ReikiRootModel reikiRootModel
|
{
|
get { return ModelCenter.Instance.GetModel<ReikiRootModel>(); }
|
}
|
|
TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
|
int rechargeId = 0;
|
|
private void Awake()
|
{
|
m_Buy.onClick.AddListener(Buy);
|
for (int i = 0; i < m_Items.Length; i++)
|
{
|
var _index = i;
|
m_Items[i].button.onClick.AddListener(() =>
|
{
|
OnItemClick(_index);
|
});
|
}
|
}
|
|
private void OnEnable()
|
{
|
vipModel.rechargeCountEvent += RechargeCountEvent;
|
}
|
|
private void OnDisable()
|
{
|
vipModel.rechargeCountEvent -= RechargeCountEvent;
|
}
|
|
private void RechargeCountEvent(int id)
|
{
|
if (id == rechargeId)
|
{
|
Display(rechargeId);
|
}
|
}
|
|
private void OnItemClick(int index)
|
{
|
if (rechargeId != 0)
|
{
|
List<Item> items;
|
if (vipModel.TryGetRechargeItem(rechargeId, out items))
|
{
|
if (index < items.Count)
|
{
|
var item = items[index];
|
ItemTipUtility.Show(item.id);
|
}
|
}
|
}
|
}
|
|
private void Buy()
|
{
|
if (rechargeId != 0)
|
{
|
VipModel.RechargeCount rechargeCount;
|
if (vipModel.TryGetRechargeCount(rechargeId, out rechargeCount))
|
{
|
if (rechargeCount.totalCount >= 1)
|
{
|
return;
|
}
|
}
|
vipModel.CTG(rechargeId);
|
}
|
}
|
|
public void Display(int id)
|
{
|
rechargeId = id;
|
List<Item> items;
|
bool hasItem = vipModel.TryGetRechargeItem(id, out items);
|
for (int i = 0; i < m_Items.Length; i++)
|
{
|
if (hasItem && i < items.Count)
|
{
|
m_Items[i].SetActive(true);
|
var _item = items[i];
|
var _itemModel = new ItemCellModel(_item.id, false, (ulong)_item.count);
|
m_Items[i].SetItemRare(_itemModel, i == 0);
|
}
|
else
|
{
|
m_Items[i].SetActive(false);
|
}
|
}
|
|
var config = CTGConfig.Get(id);
|
if (config != null)
|
{
|
OrderInfoConfig orderInfoConfig;
|
if (vipModel.TryGetOrderInfo(id, out orderInfoConfig))
|
{
|
m_Cost.text = Language.Get("SuperValueGiftCost", UIHelper.GetMoneyFormat((int)orderInfoConfig.PayRMBNum));
|
}
|
}
|
|
VipModel.RechargeCount rechargeCount;
|
bool alreadyBuy = false;
|
if (vipModel.TryGetRechargeCount(id, out rechargeCount))
|
{
|
alreadyBuy = rechargeCount.totalCount >= config.TotalBuyCount;
|
}
|
m_Buy.SetActive(!alreadyBuy);
|
m_AreadyBuySign.SetActive(alreadyBuy);
|
|
if (m_Remind != null)
|
{
|
m_Remind.SetActive(config.PayType == 7
|
|| config.PayType == 11);
|
if (config.PayType == 7)
|
{
|
var petId = 0;
|
var level = 0;
|
model.GetPetInfo(out petId, out level);
|
var point = model.GetSkillActivePoint(PlayerDatas.Instance.baseData.LV);
|
var petConfig = PetInfoConfig.Get(petId);
|
m_Remind.text = Language.Get("OpenServerGiftRemind7", petConfig.Name, level, point);
|
}
|
else if (config.PayType == 11)
|
{
|
var totalPoint = 0;
|
if (PlayerDatas.Instance.baseData.LV >= reikiRootModel.reikiPointAutoAddLevel)
|
{
|
var level = PlayerDatas.Instance.baseData.LV - reikiRootModel.reikiPointAutoAddLevel + 1;
|
totalPoint = level * reikiRootModel.titleAddPoint.point;
|
}
|
m_Remind.text = Language.Get("OpenServerGiftRemind11", totalPoint);
|
}
|
}
|
}
|
}
|
}
|
|