67 lines
2.9 KiB
C#
67 lines
2.9 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
|
|
// МАГАЗИН: бесплатный сундук раз в день, пакеты ресурсов за кристаллы, обмен золота,
|
|
// витрина платных наборов (пока "скоро"). Лимиты покупок сбрасываются в полночь.
|
|
public class ShopPanel : BasePanel
|
|
{
|
|
TextMeshProUGUI timer;
|
|
|
|
protected override void Build(RectTransform root)
|
|
{
|
|
var list = ScrollList(root);
|
|
|
|
var wallet = UIKit.Row(list, 70, 20, UIKit.Theme.CardDark, 10);
|
|
WalletItem(wallet, ResourceType.Gems);
|
|
WalletItem(wallet, ResourceType.Gold);
|
|
|
|
timer = UIKit.Text(list, "", 24, UIKit.Theme.TextDim, TextAlignmentOptions.Center, 40);
|
|
Tick();
|
|
|
|
foreach (var item in GameData.ShopItems)
|
|
{
|
|
var it = item;
|
|
bool free = item.price == 0 && !item.comingSoon;
|
|
int bought = GP.BoughtToday(item.id);
|
|
bool canBuy = GP.CanBuy(item);
|
|
|
|
var card = UIKit.Card(list, free && canBuy ? UIKit.Theme.CardDone : UIKit.Theme.Card);
|
|
var row = UIKit.Row(card, 130, 16);
|
|
|
|
var iconColor = item.gives != null && item.gives.Length > 0 ? GameData.ResColor(item.gives[0].type) : UIKit.Theme.Gold;
|
|
UIKit.Icon(row, iconColor, item.id == "free_chest" ? "?" : "", 110);
|
|
|
|
var info = UIKit.Card(row, new Color(0, 0, 0, 0), 0, 4);
|
|
UIKit.Size(info, -1, -1, 1);
|
|
var title = UIKit.Text(info, item.title, 30);
|
|
title.fontStyle = FontStyles.Bold;
|
|
string gives = item.id == "free_chest" ? "Случайный набор ресурсов" : GameData.RewardsText(item.gives);
|
|
UIKit.Text(info, gives, 24, UIKit.Theme.TextDim);
|
|
if (item.dailyLimit > 0)
|
|
UIKit.Text(info, "Сегодня: " + bought + " / " + item.dailyLimit, 22, UIKit.Theme.TextDim);
|
|
|
|
string label;
|
|
Color color;
|
|
if (item.comingSoon) { label = item.priceLabel + "\nскоро"; color = UIKit.Theme.Gray; }
|
|
else if (!canBuy) { label = "Лимит"; color = UIKit.Theme.Gray; }
|
|
else if (free) { label = "Бесплатно"; color = UIKit.Theme.Green; }
|
|
else { label = item.price + " " + GameData.ResName(item.priceType); color = UIKit.Theme.Blue; }
|
|
|
|
var b = UIKit.Button(row, label, color, () => GP.Buy(it), 220, 100, 26);
|
|
b.interactable = canBuy;
|
|
}
|
|
}
|
|
|
|
static void WalletItem(Transform parent, ResourceType t)
|
|
{
|
|
UIKit.Icon(parent, GameData.ResColor(t), "", 40);
|
|
var txt = UIKit.Text(parent, GameData.ResName(t) + ": " + Mathf.FloorToInt(GameProgress.Instance.Res(t)).ToString("N0"), 28);
|
|
UIKit.Size(txt, -1, -1, 1);
|
|
}
|
|
|
|
protected override void Tick()
|
|
{
|
|
if (timer != null) timer.text = "Лимиты обновятся через " + GameData.FormatTime(GameProgress.SecondsToNextDay);
|
|
}
|
|
}
|