using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
[XLua.Hotfix]
|
public class SuperValueGiftBehaviour : MonoBehaviour
|
{
|
[SerializeField] Text m_Cost;
|
[SerializeField] RareItem[] m_Items;
|
[SerializeField] Button m_Buy;
|
[SerializeField] Image m_AreadyBuySign;
|
|
OSGiftModel model
|
{
|
get { return ModelCenter.Instance.GetModel<OSGiftModel>(); }
|
}
|
|
VipModel vipModel
|
{
|
get { return ModelCenter.Instance.GetModel<VipModel>(); }
|
}
|
|
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];
|
ItemAttrData attrData = new ItemAttrData(item.id, false, (ulong)item.count);
|
ModelCenter.Instance.GetModel<ItemTipsModel>().SetItemTipsModel(attrData);
|
}
|
}
|
}
|
}
|
|
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].gameObject.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].gameObject.SetActive(false);
|
}
|
}
|
|
var config = CTGConfig.Get(id);
|
if (config != null)
|
{
|
OrderInfoConfig orderInfoConfig;
|
if (vipModel.TryGetOrderInfo(id, out orderInfoConfig))
|
{
|
m_Cost.text = Language.Get("SuperValueGiftCost", orderInfoConfig.PayRMBNum);
|
}
|
}
|
|
VipModel.RechargeCount rechargeCount;
|
bool alreadyBuy = false;
|
if (vipModel.TryGetRechargeCount(id, out rechargeCount))
|
{
|
alreadyBuy = rechargeCount.totalCount >= 1;
|
}
|
m_Buy.gameObject.SetActive(!alreadyBuy);
|
m_AreadyBuySign.gameObject.SetActive(alreadyBuy);
|
}
|
}
|
}
|