//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, April 22, 2019
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
using DG.Tweening;
|
using System;
|
using System.Collections.Generic;
|
|
namespace vnxbqy.UI
|
{
|
|
public class TipGetWaysWidget : MonoBehaviour
|
{
|
[SerializeField] ScrollRect m_ScrollRect;
|
[SerializeField] CanvasGroup m_AlphaTween;
|
|
string windowName;
|
List<WayCell> getWayBehaviours = new List<WayCell>();
|
|
[SerializeField] ItemBehaviour m_Item;
|
[SerializeField] Text m_Money;
|
[SerializeField] Button m_Buy;
|
[SerializeField] RectTransform m_Widget_Buy;
|
|
public void ShowItem()
|
{
|
if (m_Widget_Buy == null)
|
return;
|
var itemID = ItemTipUtility.mainTipData.itemId;
|
var shopConfig = StoreConfig.GetStoreCfg(itemID, 2, 5);
|
if (shopConfig == null)
|
{
|
m_Widget_Buy.SetActive(false);
|
return;
|
}
|
|
int curVipIndex = -1;
|
int nextVipIndex = -1;
|
bool isVipBuy = BuyItemController.Instance.CheckIsVipBuy(shopConfig, out curVipIndex, out nextVipIndex);
|
|
if ((isVipBuy && curVipIndex == -1) || PlayerDatas.Instance.baseData.LV < shopConfig.LV)
|
{
|
m_Widget_Buy.SetActive(false);
|
return;
|
}
|
|
m_Widget_Buy.SetActive(true);
|
m_Money.text = shopConfig.MoneyNumber.ToString();
|
m_Item.SetItem(itemID, 1);
|
m_Buy.RemoveAllListeners();
|
m_Buy.AddListener(() =>
|
{
|
BuyItem(shopConfig.ID);
|
});
|
}
|
|
|
private void BuyItem(int goodID)
|
{
|
ItemTipUtility.GoodOperate(ItemOperateType.buy, goodID, 1);
|
|
}
|
public void Display(ItemTipUtility.GetWay getWay)
|
{
|
CreateGetWayBehaviour(getWay.ways.Count);
|
for (var i = 0; i < getWayBehaviours.Count; i++)
|
{
|
var behaviour = getWayBehaviours[i];
|
if (i < getWay.ways.Count)
|
{
|
var way = getWay.ways[i];
|
behaviour.SetActive(true);
|
behaviour.Display(getWay.itemId, way);
|
behaviour.RemoveAllListeners();
|
behaviour.AddListener(OnGetWay);
|
}
|
else
|
{
|
behaviour.SetActive(false);
|
}
|
}
|
|
m_ScrollRect.verticalNormalizedPosition = 1f;
|
m_ScrollRect.AddMissingComponent<RayAccepter>();
|
this.SetActive(true);
|
m_AlphaTween.alpha = 0;
|
m_AlphaTween.DOFade(1, 0.5f);
|
|
ShowItem();
|
}
|
|
public void Bind(string windowName)
|
{
|
this.windowName = windowName;
|
}
|
|
private void OnGetWay()
|
{
|
if (!string.IsNullOrEmpty(windowName))
|
{
|
WindowCenter.Instance.Close(windowName);
|
}
|
}
|
|
public void Hide()
|
{
|
m_AlphaTween.alpha = 1;
|
m_AlphaTween.DOFade(0, 0.5f).OnComplete(() => { this.SetActive(false); });
|
}
|
|
private void CreateGetWayBehaviour(int count)
|
{
|
var nowCount = getWayBehaviours.Count;
|
var need = count - nowCount;
|
for (var i = 0; i < need; i++)
|
{
|
var instance = UIUtility.CreateWidget("GetWayCell", "GetWayCell");
|
|
instance.transform.SetParentEx(m_ScrollRect.content, Vector3.zero, Quaternion.identity, Vector3.one);
|
var getWellBehaviour = instance.GetComponent<WayCell>();
|
getWayBehaviours.Add(getWellBehaviour);
|
}
|
}
|
|
}
|
|
}
|