117 lines
2.9 KiB
C#
117 lines
2.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class WinWindow : ParameterlessWindow
|
|
{
|
|
[SerializeField] private Text _coinsCountText;
|
|
[SerializeField] private LevelRewardSection _levelReward;
|
|
[SerializeField] private TimerRewardButtonsSection _rewardButtons;
|
|
|
|
private bool _haveReward;
|
|
|
|
protected override void OnInit()
|
|
{
|
|
_rewardButtons.SetCallback(OnRewardSectionResult);
|
|
}
|
|
|
|
protected override void OnShowed()
|
|
{
|
|
Ads.ShowInterstitial("win");
|
|
|
|
UI.GetOrCreateWindow<CoinsCounterWindow>().SyncCoinsCounter();
|
|
SyncCoinsCountText();
|
|
|
|
_levelReward.Init("@level_rewards/level_reward");
|
|
if (Settings.LEVEL_REWARD_ENABLE && _levelReward.HasReward)
|
|
{
|
|
_levelReward.Show();
|
|
_levelReward.ChangeProgress(true);
|
|
_rewardButtons.Hide();
|
|
StartCoroutine(ActionAfterCondition(() => _levelReward.IsWorking));
|
|
}
|
|
else
|
|
{
|
|
_levelReward.Hide();
|
|
_rewardButtons.Show();
|
|
_rewardButtons.Begin();
|
|
}
|
|
}
|
|
|
|
private IEnumerator ActionAfterCondition(Func<bool> predicate)
|
|
{
|
|
while (predicate.Invoke())
|
|
yield return null;
|
|
|
|
_rewardButtons.Show();
|
|
_rewardButtons.Begin();
|
|
}
|
|
|
|
private void OnRewardSectionResult(EnumRewardResult result)
|
|
{
|
|
switch (result)
|
|
{
|
|
case EnumRewardResult.SKIP:
|
|
OnPlayerSkipReward();
|
|
break;
|
|
case EnumRewardResult.FAIL:
|
|
OnPlayerFailReward();
|
|
break;
|
|
case EnumRewardResult.NEED_REWARD:
|
|
OnPlayerNeedReward();
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(result), result, null);
|
|
}
|
|
}
|
|
|
|
private void OnPlayerSkipReward()
|
|
{
|
|
StartClosing();
|
|
}
|
|
|
|
private void OnPlayerFailReward()
|
|
{
|
|
_rewardButtons.Begin();
|
|
}
|
|
|
|
private void OnPlayerNeedReward()
|
|
{
|
|
G.Instance.Session.MultiplyEarnedCoins(_rewardButtons.Power);
|
|
_haveReward = true;
|
|
SyncCoinsCountText();
|
|
StartClosing();
|
|
}
|
|
|
|
private void StartClosing()
|
|
{
|
|
G.Instance.Session.SaveEarnedCoins();
|
|
StartCoroutine(ClosingRoutine());
|
|
}
|
|
|
|
private void SyncCoinsCountText()
|
|
{
|
|
SetCoinsCountText(G.Instance.Session.EarnedCoins);
|
|
}
|
|
|
|
private void SetCoinsCountText(int coinsValue)
|
|
{
|
|
_coinsCountText.text = $"+{coinsValue}";
|
|
}
|
|
|
|
private IEnumerator ClosingRoutine()
|
|
{
|
|
_rewardButtons.Hide();
|
|
|
|
var coinsCounter = UI.GetOrCreateWindow<CoinsCounterWindow>();
|
|
coinsCounter.Show();
|
|
coinsCounter.SyncCoinsCounter();
|
|
|
|
if(_haveReward)
|
|
yield return coinsCounter.ShowScreenCoins();
|
|
|
|
G.Instance.Session.BuildLevel();
|
|
}
|
|
}
|