186 lines
7.4 KiB
C#
186 lines
7.4 KiB
C#
using UnityEngine;
|
|
using EnhancedUI.EnhancedScroller;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
|
|
public class EventOfferJourneyShellScroller : AEventOfferJourneyScroller
|
|
{
|
|
[SerializeField] private EnhancedScroller scroller;
|
|
[SerializeField] private EventOfferJourneyScrollerScrollRect scrollRect;
|
|
[SerializeField] private EventOfferJourneyScrollerCellShellLeft leftCell;
|
|
[SerializeField] private EventOfferJourneyScrollerCellShellRight rightCell;
|
|
[SerializeField]
|
|
private float normalCellHeight = 280f,
|
|
pointShowDuration = 0.1f,
|
|
pointGapDuration = 0.1f,
|
|
bubbleFxDelay = 0.5f,
|
|
rewardScale = 0.85f;
|
|
|
|
private List<EventOfferJourneyBlockData> _dataList;
|
|
private int _startPosParam;
|
|
|
|
#region EnhancedScrollerDelegate
|
|
public override void Init(List<EventOfferJourneyBlockData> dataList, int startPosParam)
|
|
{
|
|
_dataList = dataList;
|
|
_startPosParam = startPosParam % 2;
|
|
scroller.Delegate = this;
|
|
scroller.ReloadData();
|
|
}
|
|
|
|
public override EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex)
|
|
{
|
|
var aniPara = new EventOfferJourneyShellAnimationParams
|
|
{
|
|
showDuration = pointShowDuration,
|
|
gapDuration = pointGapDuration,
|
|
bubbleDelay = bubbleFxDelay,
|
|
rewardScale = rewardScale
|
|
};
|
|
var topBlockIsLeftLayout = _startPosParam == _dataList.Count % 2;
|
|
// Debug.Log("GetCellView " + dataIndex);
|
|
if (dataIndex == 0)
|
|
{
|
|
if (topBlockIsLeftLayout)
|
|
{
|
|
if (scroller.GetCellView(leftCell) is not EventOfferJourneyScrollerCellShellLeft cellViewFinal)
|
|
{
|
|
Debug.LogError($"<color=red>[EventOfferJourney] Cell view as final is null.</color>");
|
|
return null;
|
|
}
|
|
cellViewFinal.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara, true);
|
|
return cellViewFinal;
|
|
}
|
|
else
|
|
{
|
|
if (scroller.GetCellView(rightCell) is not EventOfferJourneyScrollerCellShellRight cellViewFinal)
|
|
{
|
|
Debug.LogError($"<color=red>[EventOfferJourney] Cell view as final is null.</color>");
|
|
return null;
|
|
}
|
|
cellViewFinal.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara, true);
|
|
return cellViewFinal;
|
|
}
|
|
}
|
|
else if (dataIndex % 2 == 0)
|
|
{
|
|
if (topBlockIsLeftLayout)
|
|
{
|
|
if (scroller.GetCellView(leftCell) is not EventOfferJourneyScrollerCellShellLeft cellViewLeft)
|
|
{
|
|
Debug.LogError("<color=red>[EventOfferJourney] Cell view as left is null.</color>");
|
|
return null;
|
|
}
|
|
cellViewLeft.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara);
|
|
return cellViewLeft;
|
|
}
|
|
else
|
|
{
|
|
if (scroller.GetCellView(rightCell) is not EventOfferJourneyScrollerCellShellRight cellViewRight)
|
|
{
|
|
Debug.LogError("<color=red>[EventOfferJourney] Cell view as right is null.</color>");
|
|
return null;
|
|
}
|
|
cellViewRight.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara);
|
|
return cellViewRight;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (topBlockIsLeftLayout)
|
|
{
|
|
if (scroller.GetCellView(rightCell) is not EventOfferJourneyScrollerCellShellRight cellViewRight)
|
|
{
|
|
Debug.LogError("<color=red>[EventOfferJourney] Cell view as right is null.</color>");
|
|
return null;
|
|
}
|
|
cellViewRight.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara);
|
|
return cellViewRight;
|
|
}
|
|
else
|
|
{
|
|
if (scroller.GetCellView(leftCell) is not EventOfferJourneyScrollerCellShellLeft cellViewLeft)
|
|
{
|
|
Debug.LogError("<color=red>[EventOfferJourney] Cell view as left is null.</color>");
|
|
return null;
|
|
}
|
|
cellViewLeft.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara);
|
|
return cellViewLeft;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override float GetCellViewSize(EnhancedScroller scroller, int dataIndex)
|
|
{
|
|
return normalCellHeight;
|
|
}
|
|
|
|
public override int GetNumberOfCells(EnhancedScroller scroller)
|
|
{
|
|
return _dataList.Count;
|
|
}
|
|
#endregion
|
|
|
|
public override async void JumpTo(int progress, float tweenTime = 0.5f)
|
|
{
|
|
var idx = _dataList.Count - progress - 1;
|
|
var dataIndex = idx % GetNumberOfCells(scroller);
|
|
scroller.JumpToDataIndex(
|
|
dataIndex: dataIndex,
|
|
tweenType: EnhancedScroller.TweenType.easeInOutCubic,
|
|
tweenTime: tweenTime,
|
|
scrollerOffset: 0.5f,
|
|
cellOffset: 0.5f);
|
|
scrollRect.BlockScroll();
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(0.5f));
|
|
scrollRect.UnblockScroll();
|
|
}
|
|
|
|
private EventOfferJourneyBlockView.EState GetBlockState(int dataIndex)
|
|
{
|
|
var idx = _dataList.Count - dataIndex - 1;
|
|
var progress = GContext.container.Resolve<IEventOfferJourneyData>().Progress;
|
|
if (idx == progress)
|
|
return EventOfferJourneyBlockView.EState.Active;
|
|
else if (idx < progress)
|
|
return EventOfferJourneyBlockView.EState.Bought;
|
|
else
|
|
return EventOfferJourneyBlockView.EState.Locked;
|
|
}
|
|
|
|
public override void Refresh(int progress)
|
|
{
|
|
var dataIndex = _dataList.Count - progress - 1;
|
|
var scrollViewCurrent = scroller.GetCellViewAtDataIndex(dataIndex) as EventOfferJourneyBlockView;
|
|
if (scrollViewCurrent != null)
|
|
scrollViewCurrent.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, dataIndex <= 0);
|
|
var scrollViewNext = scroller.GetCellViewAtDataIndex(dataIndex - 1) as EventOfferJourneyBlockView;
|
|
if (scrollViewNext != null)
|
|
scrollViewNext.Init(_dataList[dataIndex - 1], GetBlockState(dataIndex - 1), scroller, dataIndex - 1 <= 0);
|
|
}
|
|
}
|
|
|
|
public interface IEventOfferJourneyScroller
|
|
{
|
|
public void Init(List<EventOfferJourneyBlockData> dataList, int startPosParam);
|
|
public void JumpTo(int progress, float tweenTime);
|
|
public void Refresh(int progress);
|
|
}
|
|
|
|
public abstract class AEventOfferJourneyScroller : MonoBehaviour, IEventOfferJourneyScroller, IEnhancedScrollerDelegate
|
|
{
|
|
public abstract EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex);
|
|
public abstract float GetCellViewSize(EnhancedScroller scroller, int dataIndex);
|
|
public abstract int GetNumberOfCells(EnhancedScroller scroller);
|
|
public abstract void Init(List<EventOfferJourneyBlockData> dataList, int startPosParam);
|
|
public abstract void JumpTo(int progress, float tweenTime = 0.5f);
|
|
public abstract void Refresh(int progress);
|
|
}
|
|
|
|
public class EventOfferJourneyShellAnimationParams
|
|
{
|
|
public float showDuration;
|
|
public float gapDuration;
|
|
public float bubbleDelay;
|
|
public float rewardScale;
|
|
} |