97 lines
2.4 KiB
C#
97 lines
2.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using game;
|
|
using RND.SDK;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class OfflineWindow : ParameterWindow<int>
|
|
{
|
|
[SerializeField] private TimerRewardButtonsSection _rewardButtons;
|
|
[SerializeField] private Text _coinsEarn;
|
|
|
|
private int _bonusAmount;
|
|
|
|
protected override void OnInit()
|
|
{
|
|
_rewardButtons.Begin();
|
|
_rewardButtons.SetCallback(OnRewardSectionResult);
|
|
}
|
|
|
|
protected override void OnShow(int argument)
|
|
{
|
|
_rewardButtons.Begin();
|
|
|
|
UI.ShowWindow<CoinsCounterWindow>();
|
|
|
|
_bonusAmount = argument;
|
|
_coinsEarn.text = argument.ToString();
|
|
}
|
|
|
|
private void AddCoins(int multiplier = 1)
|
|
{
|
|
ProductStatistics.ResourcesEvent(EnumProductResourcesFlow.SOURCES, "gold", _bonusAmount * multiplier, "offline",
|
|
EnumHelper.IdFromConsumableType(EnumConsumable.COIN).ToString());
|
|
|
|
Save.Inventory.AddConsumableItem(EnumConsumable.COIN, (uint)(_bonusAmount * multiplier));
|
|
}
|
|
|
|
private IEnumerator PreCloseRoutine()
|
|
{
|
|
_rewardButtons.Hide();
|
|
|
|
//constants?
|
|
var delayBeforeMove = 0.15f;
|
|
var delayAfterMove = 1f;
|
|
var coinsCount = 15;
|
|
|
|
var coins = gameObject.AddComponent<ScreenCoins>();
|
|
coins.Init(coinsCount);
|
|
|
|
yield return new WaitForSeconds(delayBeforeMove);
|
|
|
|
yield return StartCoroutine(coins.MoveCoins());
|
|
|
|
yield return new WaitForSeconds(delayAfterMove);
|
|
UI.ShowWindow<MainWindow>();
|
|
UI.ShowWindow<CoinsCounterWindow>();
|
|
Close();
|
|
}
|
|
|
|
|
|
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()
|
|
{
|
|
AddCoins();
|
|
StartCoroutine(PreCloseRoutine());
|
|
}
|
|
|
|
private void OnPlayerFailReward()
|
|
{
|
|
_rewardButtons.Begin();
|
|
}
|
|
|
|
private void OnPlayerNeedReward()
|
|
{
|
|
AddCoins(_rewardButtons.Power);
|
|
StartCoroutine(PreCloseRoutine());
|
|
}
|
|
}
|