using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
public class AlchemyScrollBehaviour : MonoBehaviour
|
{
|
[SerializeField] ScrollerController m_Controller;
|
|
int alchemyType = 0;
|
|
AlchemyModel model { get { return ModelCenter.Instance.GetModel<AlchemyModel>(); } }
|
|
private void Awake()
|
{
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
m_Controller.lockType = EnhanceLockType.KeepVertical;
|
}
|
|
public void Display(int type)
|
{
|
alchemyType = type;
|
|
DisplayRecipes();
|
|
var alchemies = new List<int>(AlchemyConfig.GetAlchemies(alchemyType));
|
var index = alchemies.IndexOf(model.selectAlchemy);
|
if (index != -1)
|
{
|
m_Controller.JumpIndex(index);
|
}
|
|
model.selectAlchemyRefresh += SelectAlchemyRefresh;
|
model.alchemyStateRefresh += AlchemyStateRefresh;
|
}
|
|
void DisplayRecipes()
|
{
|
m_Controller.Refresh();
|
var alchemies = AlchemyConfig.GetAlchemies(alchemyType);
|
foreach (var id in alchemies)
|
{
|
m_Controller.AddCell(ScrollerDataType.Normal, id);
|
}
|
m_Controller.Restart();
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
if (type == ScrollerDataType.Header)
|
{
|
var qualityCell = cell as AlchemyQualityCell;
|
qualityCell.Display(cell.index);
|
}
|
else if (type == ScrollerDataType.Normal)
|
{
|
var recipeCell = cell as AlchemyRecipeCell;
|
recipeCell.Display(cell.index);
|
}
|
}
|
|
private void SelectQualityRefresh()
|
{
|
DisplayRecipes();
|
}
|
|
private void SelectAlchemyRefresh()
|
{
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
private void AlchemyStateRefresh()
|
{
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
public void Dispose()
|
{
|
model.selectAlchemyRefresh -= SelectAlchemyRefresh;
|
model.alchemyStateRefresh -= AlchemyStateRefresh;
|
}
|
}
|
}
|