176 lines
7.2 KiB
C#
176 lines
7.2 KiB
C#
using UnityEngine;
|
|
using EnhancedUI.EnhancedScroller;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
|
|
public class EventOfferJourneyWheelScroller : AEventOfferJourneyScroller
|
|
{
|
|
[SerializeField] private EnhancedScroller scroller;
|
|
[SerializeField] private EventOfferJourneyScrollerScrollRect scrollRect;
|
|
[SerializeField] private EventOfferJourneyWheelCellLeftBottom leftBottomCell;
|
|
[SerializeField] private EventOfferJourneyWheelCellLeftTop leftTopCell;
|
|
[SerializeField] private EventOfferJourneyWheelCellRightBottom rightBottomCell;
|
|
[SerializeField] private EventOfferJourneyWheelCellRightTop rightTopCell;
|
|
[SerializeField] private EventOfferJourneyWheelCellTop topCell;
|
|
[SerializeField]
|
|
private float topCellHeight = 860f,
|
|
normalCellHeight = 500f,
|
|
cellOffset = 90f,
|
|
lookAhead = 200f,
|
|
fireworkDelay = 0.5f,
|
|
rewardScale = 0.9f;
|
|
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.lookAheadAfter = lookAhead;
|
|
scroller.lookAheadBefore = lookAhead;
|
|
// Debug.Log($"[EventOfferJourney] before: {scroller.lookAheadBefore}");
|
|
// Debug.Log($"[EventOfferJourney] after: {scroller.lookAheadAfter}");
|
|
scroller.ReloadData();
|
|
}
|
|
|
|
public override EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex)
|
|
{
|
|
// Debug.Log("GetCellView " + dataIndex);
|
|
// Handle special case for Grand Prize (index 0)
|
|
if (dataIndex == 0)
|
|
{
|
|
return CreateCellView(scroller, dataIndex, topCell);
|
|
}
|
|
|
|
// Determine cell position using clear boolean expressions
|
|
bool isTopCell = (dataIndex % 4 == 1) || (dataIndex % 4 == 2);
|
|
bool isRightCell = _startPosParam == dataIndex % 2;
|
|
|
|
// Select appropriate cell prefab based on position
|
|
if (isTopCell && isRightCell)
|
|
return CreateCellView(scroller, dataIndex, rightTopCell);
|
|
if (isTopCell && !isRightCell)
|
|
return CreateCellView(scroller, dataIndex, leftTopCell);
|
|
if (!isTopCell && isRightCell)
|
|
return CreateCellView(scroller, dataIndex, rightBottomCell);
|
|
else
|
|
return CreateCellView(scroller, dataIndex, leftBottomCell);
|
|
}
|
|
|
|
private EnhancedScrollerCellView CreateCellView(EnhancedScroller scroller, int dataIndex, EnhancedScrollerCellView cellPrefab)
|
|
{
|
|
var aniPara = new EventOfferJourneyWheelAnimationParams
|
|
{
|
|
fireworkDelay = fireworkDelay,
|
|
rewardScale = rewardScale
|
|
};
|
|
var cellView = scroller.GetCellView(cellPrefab);
|
|
|
|
if (cellView == null)
|
|
{
|
|
Debug.LogError($"<color=red>[EventOfferJourney] Cell view is null for {cellPrefab.GetType().Name}.</color>");
|
|
return null;
|
|
}
|
|
|
|
switch (cellView)
|
|
{
|
|
case EventOfferJourneyWheelCellTop topCellView:
|
|
topCellView.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara);
|
|
return topCellView;
|
|
case EventOfferJourneyWheelCellRightTop rightTopCellView:
|
|
rightTopCellView.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara, cellOffset: cellOffset, bgIdx: dataIndex);
|
|
return rightTopCellView;
|
|
case EventOfferJourneyWheelCellLeftTop leftTopCellView:
|
|
leftTopCellView.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara, cellOffset: cellOffset, bgIdx: dataIndex);
|
|
return leftTopCellView;
|
|
case EventOfferJourneyWheelCellRightBottom rightBottomCellView:
|
|
rightBottomCellView.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara, cellOffset: cellOffset, bgIdx: dataIndex);
|
|
return rightBottomCellView;
|
|
case EventOfferJourneyWheelCellLeftBottom leftBottomCellView:
|
|
leftBottomCellView.Init(_dataList[dataIndex], GetBlockState(dataIndex), scroller, aniPara, cellOffset: cellOffset, bgIdx: dataIndex);
|
|
return leftBottomCellView;
|
|
default:
|
|
Debug.LogError($"<color=red>[EventOfferJourney] Unknown cell view type: {cellView.GetType().Name}</color>");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public override float GetCellViewSize(EnhancedScroller scroller, int dataIndex)
|
|
{
|
|
if (dataIndex <= 0)
|
|
return topCellHeight;
|
|
else
|
|
return normalCellHeight;
|
|
}
|
|
|
|
public override int GetNumberOfCells(EnhancedScroller scroller)
|
|
{
|
|
return _dataList.Count;
|
|
}
|
|
|
|
private float GetCellOffset(int dataIndex)
|
|
{
|
|
if (dataIndex == 0)
|
|
return 0;
|
|
if (dataIndex % 4 == 1 || dataIndex % 4 == 2)
|
|
return 0.5f + cellOffset / normalCellHeight;
|
|
else
|
|
return 0.5f - cellOffset / normalCellHeight;
|
|
}
|
|
#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: GetCellOffset(dataIndex));
|
|
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);
|
|
}
|
|
// #if UNITY_EDITOR
|
|
// [SerializeField] private float normalizedScrollerPosition;
|
|
// private void LateUpdate()
|
|
// {
|
|
// normalizedScrollerPosition = scroller.NormalizedScrollPosition;
|
|
// }
|
|
// #endif
|
|
}
|
|
|
|
public class EventOfferJourneyWheelAnimationParams
|
|
{
|
|
// public float showDuration;
|
|
// public float gapDuration;
|
|
public float fireworkDelay;
|
|
public float rewardScale;
|
|
} |