57 lines
2.6 KiB
C#
57 lines
2.6 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
|
|
// НАГРАДЫ: ежедневный вход, календарь на 7 дней. Один раз в сутки -- забрать подарок дня.
|
|
public class RewardsPanel : BasePanel
|
|
{
|
|
TextMeshProUGUI timer;
|
|
|
|
protected override void Build(RectTransform root)
|
|
{
|
|
var d = GP.Data;
|
|
var list = ScrollList(root);
|
|
|
|
UIKit.Text(list, "Заходите каждый день и забирайте подарки. На 7-й день -- главный приз!",
|
|
28, UIKit.Theme.TextDim, TextAlignmentOptions.Center);
|
|
|
|
bool canClaim = GP.CanClaimLogin;
|
|
int total = GameData.LoginRewards.Length;
|
|
int claimedUpTo = d.loginRewardIndex; // сколько дней цикла уже забрано
|
|
if (!canClaim && claimedUpTo == 0 && d.lastLoginRewardDay >= 0) claimedUpTo = total; // только что забрали 7-й
|
|
|
|
RectTransform row = null;
|
|
for (int i = 0; i < total; i++)
|
|
{
|
|
if (i % 4 == 0) row = UIKit.Row(list, 230, 12);
|
|
bool claimed = i < claimedUpTo;
|
|
bool current = canClaim && i == d.loginRewardIndex;
|
|
|
|
Color bg = claimed ? UIKit.Theme.CardDone : (current ? new Color(0.45f, 0.36f, 0.12f) : UIKit.Theme.Card);
|
|
var cell = UIKit.Card(row, bg, 10, 6);
|
|
UIKit.Size(cell, -1, -1, 1);
|
|
var day = UIKit.Text(cell, (i == total - 1 ? "ДЕНЬ 7!" : "День " + (i + 1)), 28,
|
|
current ? UIKit.Theme.Gold : UIKit.Theme.Text, TextAlignmentOptions.Center);
|
|
day.fontStyle = FontStyles.Bold;
|
|
var r = GameData.LoginRewards[i];
|
|
UIKit.Box(cell, GameData.ResColor(r[0].type), 12);
|
|
UIKit.Text(cell, GameData.RewardsText(r), 22, UIKit.Theme.Text, TextAlignmentOptions.Center);
|
|
UIKit.Text(cell, claimed ? "Получено" : (current ? "Сегодня" : ""), 22,
|
|
claimed ? UIKit.Theme.Green : UIKit.Theme.Gold, TextAlignmentOptions.Center);
|
|
}
|
|
|
|
UIKit.Spacer(list, 10);
|
|
var b = UIKit.Button(list, canClaim ? "ЗАБРАТЬ ПОДАРОК" : "Подарок получен", canClaim ? UIKit.Theme.Green : UIKit.Theme.Gray,
|
|
() => GP.ClaimLogin(), -1, 110, 36);
|
|
b.interactable = canClaim;
|
|
|
|
timer = UIKit.Text(list, "", 26, UIKit.Theme.TextDim, TextAlignmentOptions.Center, 50);
|
|
Tick();
|
|
}
|
|
|
|
protected override void Tick()
|
|
{
|
|
if (timer == null) return;
|
|
timer.text = GP.CanClaimLogin ? "" : "Следующий подарок через " + GameData.FormatTime(GameProgress.SecondsToNextDay);
|
|
}
|
|
}
|