Files
back_cantanBuilding/Assets/Scripts/UI/Potion/PotionScrollViewController.cs
2026-05-26 16:15:54 +08:00

120 lines
3.7 KiB
C#

using asap.core;
using EnhancedUI.EnhancedScroller;
using System.Collections;
using System.Collections.Generic;
namespace game
{
public class PotionScrollViewController : EnhancedScroller, IEnhancedScrollerDelegate
{
private EventPotionPanel m_Panel;
private EventPotionDataManager m_DataManager;
public void Init(EnhancedScroller scroller, EventPotionPanel potionPanel, EventPotionDataManager dataManager)
{
m_Scroller = scroller;
m_Panel = potionPanel;
m_DataManager = dataManager;
InitScrollerListData();
m_Scroller.Delegate = this;
m_Scroller.cellViewVisibilityChanged = CellViewVisibilityChanged;
m_Scroller.cellViewWillRecycle = CellViewWillRecycle;
m_Scroller.ReloadData();
}
#region
public void LockScrollView()
{
if (ScrollRect.vertical)
{
ScrollRect.vertical = false;
}
}
public void UnlockScrollView()
{
if (!ScrollRect.vertical)
{
ScrollRect.vertical = true;
}
}
public PotionItem GetOperationPotionItem()
{
if (Container == null) return null;
PotionItem[] items = Container.GetComponentsInChildren<PotionItem>();
if (items == null || items.Length < 1) return null;
foreach (var item in items)
{
if (item.Data.DataType == EventPotionDataType.Data_ItemAndOperation) return item;
}
return null;
}
#endregion
#region EnhancedScroller Handlers
private EnhancedScroller m_Scroller;
public PotionItem potionItem;
List<PotionItemData> scrollerDataList = new List<PotionItemData>();
void InitScrollerListData()
{
scrollerDataList = m_DataManager.ScrollerDataList;
}
public int GetTypeDataIndex(EventPotionDataType dataType, int index)
{
if (dataType == EventPotionDataType.Data_Wall)
{
return index;
}
else if (dataType == EventPotionDataType.Data_ItemAndOperation)
{
return 0;
}
int tmp = m_Panel.ScrollViewMinimumQuantity - 1;
return index - tmp;
}
public EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex)
{
PotionItem cellView = scroller.GetCellView(potionItem) as PotionItem;
var data = scrollerDataList[dataIndex];
cellView.gameObject.name = data.DataType + "-" + GetTypeDataIndex(data.DataType, dataIndex);
cellView.SetData(m_Panel, m_DataManager, data);
return cellView;
}
public float GetCellViewSize(EnhancedScroller scroller, int dataIndex)
{
return 200f;
}
public int GetNumberOfCells(EnhancedScroller scroller)
{
return scrollerDataList.Count;
}
private void CellViewVisibilityChanged(EnhancedScrollerCellView cellView)
{
}
private void CellViewWillRecycle(EnhancedScrollerCellView cellView)
{
PotionItem potionItem = cellView as PotionItem;
string name = "Recycle-";
if (potionItem != null)
{
if (potionItem.Data != null)
{
name += potionItem.Data.DataType + "-";
}
name += potionItem.dataIndex + "-" + potionItem.cellIndex;
}
cellView.gameObject.name = name;
}
#endregion
}
}