|
using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
public class ItemTipWayWin : UIBase
|
{
|
[SerializeField] ItemCell itemCell;
|
[SerializeField] Text nameText;
|
[SerializeField] Text descText;
|
[SerializeField] ScrollerController scroller;
|
|
int itemID;
|
|
|
|
protected override void OnPreOpen()
|
{
|
scroller.OnRefreshCell += OnRefreshCell;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
itemID = functionOrder;
|
|
itemCell.Init(new ItemCellModel(itemID, false, 0));
|
var itemConfig = ItemConfig.Get(itemID);
|
nameText.text = itemConfig.ItemName;
|
descText.text = itemConfig.Description;
|
|
CreateScroller();
|
}
|
|
protected override void OnPreClose()
|
{
|
scroller.OnRefreshCell -= OnRefreshCell;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
}
|
|
private void OnFuncStateChangeEvent(int obj)
|
{
|
CreateScroller();
|
}
|
|
List<int> GetWayList()
|
{
|
var itemConfig = ItemConfig.Get(itemID);
|
if (itemConfig.GetWay.IsNullOrEmpty())
|
return new List<int>();
|
List<int> resList = new List<int>();
|
for (int i = 0; i < itemConfig.GetWay.Length; i++)
|
{
|
int way = itemConfig.GetWay[i];
|
if (!GetItemWaysConfig.HasKey(way))
|
continue;
|
GetItemWaysConfig config = GetItemWaysConfig.Get(way);
|
int funcID = config.FuncID;
|
if (FuncOpenLVConfig.HasKey(funcID) && !FuncOpen.Instance.IsFuncOpen(funcID))
|
continue;
|
resList.Add(way);
|
}
|
return resList;
|
}
|
|
void CreateScroller()
|
{
|
var itemConfig = ItemConfig.Get(itemID);
|
scroller.Refresh();
|
List<int> wayList = GetWayList();
|
for (int i = 0; i < wayList.Count; i++)
|
{
|
scroller.AddCell(ScrollerDataType.Header, itemConfig.GetWay[i]);
|
}
|
scroller.Restart();
|
}
|
|
|
void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
var way = GetItemWaysConfig.Get(cell.index);
|
var nameText = cell.FindComponent("Text", "name") as Text;
|
nameText.text = way.Name;
|
|
var descText = cell.FindComponent("Text", "way") as Text;
|
descText.text = way.Text;
|
|
cell.GetComponent<Button>().AddListener(() =>
|
{
|
Run(way);
|
});
|
}
|
|
void Run(GetItemWaysConfig way)
|
{
|
if (way == null)
|
return;
|
int funcID = way.FuncID;
|
if (FuncOpenLVConfig.HasKey(funcID) && !FuncOpen.Instance.IsFuncOpen(funcID))
|
return;
|
switch (way.Type)
|
{
|
case 1:
|
int shopID = int.Parse(way.CustomValue);
|
if (StoreModel.Instance.CheckPopBuyWin(shopID))
|
{
|
StoreModel.Instance.buyShopID = shopID;
|
UIManager.Instance.OpenWindow<BuyItemWin>();
|
}
|
break;
|
case 0:
|
default:
|
if (WindowSearchConfig.HasKey(way.WinJumpID))
|
{
|
var config = WindowSearchConfig.Get(way.WinJumpID);
|
if (config.WinName == "MainWin")
|
{
|
UIManager.Instance.GetUI<MainWin>()?.CloseSubUI();
|
UIManager.Instance.GetUI<MainWin>()?.ClickFunc(0);
|
}
|
else
|
{
|
if (!UIManager.Instance.IsOpened(config.WinName))
|
{
|
UIJumpManager.Instance.OpenWindow(way.WinJumpID);
|
}
|
}
|
}
|
break;
|
}
|
|
if (GuideConfig.HasKey(way.GuideID))
|
{
|
NewBieCenter.Instance.StartNewBieGuide(way.GuideID);
|
}
|
|
}
|
}
|
|
|