217 lines
9.3 KiB
C#
217 lines
9.3 KiB
C#
using asap.core;
|
|
using GameCore;
|
|
using UnityEngine;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using game;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
using Game;
|
|
|
|
namespace Assets.Scripts.UI.SocialRush
|
|
{
|
|
public class SocialRushMainPanel : MonoBehaviour
|
|
{
|
|
[SerializeField] protected SocialRushTaskView taskView;
|
|
[SerializeField] protected ASocialRushRewardItemView[] socialRushRewardItemViews;
|
|
[SerializeField] protected Button btnClose, btnInfo;
|
|
[SerializeField] protected EventFishRaidAndBombTipView tipView;
|
|
[SerializeField] protected SocialRushFlyingItemView flyingSocialRushReward;
|
|
[SerializeField] protected GameObject bezierPivot;
|
|
[Header("Flying Item")]
|
|
[SerializeField] private float taskProgressIncreaseDuration = 0.5f;
|
|
protected const int RewardSlotCount = 6;
|
|
[SerializeField] private bool _animationOn = false;
|
|
|
|
private async void Start()
|
|
{
|
|
try
|
|
{
|
|
GContext.OnEvent<FishingTurnTableContinueMultiDraw>().Subscribe(_ => OnClickClose()).AddTo(this);
|
|
btnClose.onClick.AddListener(OnClickClose);
|
|
btnInfo.onClick.AddListener(OnClickInfo);
|
|
var arc = GContext.container.Resolve<SocialRushArchitecture>();
|
|
Init();
|
|
if (arc.NeedUpdate())
|
|
{
|
|
_animationOn = true;
|
|
TryPlayGrantRewards(arc.TableContext.GetGrantRewardProcessData(arc.Model.ProgressDisplay, arc.Model.ProgressActual, RewardSlotCount, arc.Model.InflationRate));
|
|
}
|
|
else
|
|
{
|
|
_animationOn = false;
|
|
await Task.Delay(System.TimeSpan.FromSeconds(20f / 60));//wait for panel open animation
|
|
// GContext.Publish(new EventUISound("audio_ui_socialrush_viking_show"));
|
|
}
|
|
arc.SetFirstTime();
|
|
RedPointManager.Instance.SetRedPointState(arc.RedPointKey, arc.IsFirstTime);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
var arc = GContext.container.Resolve<SocialRushArchitecture>();
|
|
taskView.Init(arc.TableContext.GetTaskViewData(arc.Model.ProgressDisplay, arc.Model.InflationRate), taskProgressIncreaseDuration);
|
|
(var rewardItemsData, var finalRewardData) = arc.TableContext.GetRewardViewData(arc.Model.ProgressDisplay, arc.Model.InflationRate);
|
|
for (int i = 0; i < rewardItemsData.Count; i++)
|
|
socialRushRewardItemViews[i].Set(rewardItemsData[i]);
|
|
for (int i = rewardItemsData.Count; i < RewardSlotCount; i++)
|
|
socialRushRewardItemViews[i].gameObject.SetActive(false);
|
|
socialRushRewardItemViews[^1].Set(finalRewardData);
|
|
tipView.Init(arc.TableContext);
|
|
}
|
|
|
|
private async void TryPlayGrantRewards(SocialRushGrantRewardProcessData data)
|
|
{
|
|
try
|
|
{
|
|
await Task.Delay(System.TimeSpan.FromSeconds(20f / 60));//wait for panel open animation
|
|
GContext.Publish(new EventUISound("audio_ui_socialrush_viking_show"));
|
|
await Task.Delay(System.TimeSpan.FromSeconds(25f / 60));//wait for panel open animation
|
|
await TryPlayGrantRewardsAsync(data);
|
|
_animationOn = false;
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
_animationOn = false;
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private async Task TryPlayGrantRewardsAsync(SocialRushGrantRewardProcessData data)
|
|
{
|
|
var arc = GContext.container.Resolve<SocialRushArchitecture>();
|
|
var playerItemData = GContext.container.Resolve<PlayerItemData>();
|
|
int idxReward = 0, idxProgress = 0;
|
|
while (idxProgress < data.EndProgressList.Count)
|
|
{
|
|
// not last task
|
|
if (idxProgress < data.EndProgressList.Count - 1)
|
|
{
|
|
await taskView.PlayProgressAsync(data.EndProgressList[idxProgress], data.EndProgressList[idxProgress]);
|
|
idxProgress++;
|
|
idxReward++;
|
|
taskView.Set(0, data.EndProgressList[idxProgress], data.TaskRewardList[idxReward]);
|
|
await socialRushRewardItemViews[(idxReward - 1) % RewardSlotCount].PlayClaimed();
|
|
if (idxProgress % RewardSlotCount == 0)
|
|
{
|
|
var count = Mathf.Min(RewardSlotCount, data.RoadMapRewardList.Count - idxReward);
|
|
await Refresh(data.RoadMapRewardList.GetRange(idxReward, count));
|
|
}
|
|
}
|
|
// last task
|
|
else
|
|
{
|
|
await taskView.PlayProgressAsync(data.LastPartialProgress, data.EndProgressList[idxProgress]);
|
|
if (data.LastPartialProgress >= data.EndProgressList[idxProgress])
|
|
await socialRushRewardItemViews[idxReward % RewardSlotCount].PlayClaimed();
|
|
idxProgress++;
|
|
}
|
|
}
|
|
if (data.RewardsToGive.Count > 0)
|
|
{
|
|
GContext.Publish(new ShowData(data.RewardsToGive));
|
|
ChangeSource changeSource = new ChangeSource(arc.TableContext.EventId, "Event_Minigame4", "Event_Minigame4_Rush", "TaskReward");
|
|
|
|
playerItemData.AddItem(data.RewardsToGive, changeSource);
|
|
GContext.Publish(new ShowData());
|
|
}
|
|
arc.Model.SyncProgress();
|
|
arc.SavePlayfab();
|
|
}
|
|
|
|
protected virtual async Task Refresh(List<ItemData> rewardList)
|
|
{
|
|
int idx = 0;
|
|
var itemViewDataList = new List<SocialRushRewardItemViewData>();
|
|
while (idx < rewardList.Count)
|
|
{
|
|
itemViewDataList.Add(new SocialRushRewardItemViewData
|
|
{
|
|
Reward = rewardList[idx],
|
|
IsDone = false,
|
|
Type = idx % 2 == 0 ? SocialRushRewardItemViewType.LeftSide : SocialRushRewardItemViewType.RightSide,
|
|
DoShow = true
|
|
});
|
|
idx++;
|
|
}
|
|
if (itemViewDataList.Count > 0)
|
|
itemViewDataList[^1].Type = SocialRushRewardItemViewType.Final;
|
|
while (idx < RewardSlotCount)
|
|
{
|
|
itemViewDataList.Add(new SocialRushRewardItemViewData { DoShow = false });
|
|
idx++;
|
|
}
|
|
for (int i = 0; i < socialRushRewardItemViews.Length - 1; i++)
|
|
socialRushRewardItemViews[i].Hide();
|
|
|
|
for (int i = 0; i < itemViewDataList.Count; i++)
|
|
{
|
|
if (itemViewDataList[i].DoShow)
|
|
{
|
|
GContext.Publish(new EventUISound("audio_ui_socialrush_viking_fly"));
|
|
await FlyItem(
|
|
flyingSocialRushReward.transform.position,
|
|
socialRushRewardItemViews[i].transform.position,
|
|
bezierPivot.transform.position,
|
|
0.5f,
|
|
socialRushRewardItemViews[i].transform.localScale.x,
|
|
itemViewDataList[i].Reward);
|
|
}
|
|
socialRushRewardItemViews[i].Set(itemViewDataList[i]);
|
|
}
|
|
}
|
|
|
|
private void OnClickClose()
|
|
{
|
|
if (_animationOn)
|
|
return;
|
|
UIManager.Instance.DestroyUI(UITypes.SocialRushPanel);
|
|
var arc = GContext.container.Resolve<SocialRushArchitecture>();
|
|
if (!arc.IsActive())
|
|
GContext.Publish(new SocialRushHideEntrance());
|
|
}
|
|
|
|
private void OnClickInfo()
|
|
{
|
|
tipView.gameObject.SetActive(true);
|
|
}
|
|
|
|
private async Task FlyItem(Vector2 startPos, Vector2 endPos, Vector2 pivot, float duration, float targetScale, ItemData item)
|
|
{
|
|
var flyingItem = Instantiate(flyingSocialRushReward.gameObject, transform);
|
|
await flyingItem.GetComponent<SocialRushFlyingItemView>().FlyAsync(startPos, endPos, pivot, duration, targetScale, item);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class SocialRushHideEntrance { }
|
|
|
|
public class SocialRushGrantRewardProcessData
|
|
{
|
|
/// <summary>
|
|
/// Rewards to be shown in the zig-zag road map slots. Will probably include rewards from unfinished tasks. Final reward may be included.
|
|
/// </summary>
|
|
public List<ItemData> RoadMapRewardList { get; set; }
|
|
/// <summary>
|
|
/// The number shown as the target progress of each task in task view. May include the progress of the final task, progress of which may or may not be finished.
|
|
/// </summary>
|
|
public List<int> EndProgressList { get; set; }
|
|
/// <summary>
|
|
/// The rewards that are to be given to the player. May include the final reward. May be empty.
|
|
/// </summary>
|
|
public List<ItemData> RewardsToGive { get; set; }
|
|
/// <summary>
|
|
/// The progress of the last task shown.
|
|
/// </summary>
|
|
public int LastPartialProgress { get; set; }
|
|
/// <summary>
|
|
/// Rewards to be shown in the task view. May include the final reward. May just be one piece of reward more than rewards to give.
|
|
/// </summary>
|
|
public List<ItemData> TaskRewardList { get; set; }
|
|
}
|