using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; // ЗАДАНИЯ: две вкладки -- основная цепочка и ежедневные (сброс в полночь). // Прогресс считается сам из игры: сбор ресурсов, стройка, Ратуша, бои, войска, герой, арена. public class QuestsPanel : BasePanel { int tab; TextMeshProUGUI resetTimer; protected override void Build(RectTransform root) { var col = UIKit.Card(root, new Color(0, 0, 0, 0), 0, 12); UIKit.Stretch(col); UIKit.Tabs(col, new[] { "Основные", "Ежедневные" }, tab, i => { tab = i; RequestRebuild(); }); bool daily = tab == 1; resetTimer = null; if (daily) { resetTimer = UIKit.Text(col, "", 26, UIKit.Theme.TextDim, TextAlignmentOptions.Center, 40); Tick(); } var holder = UIKit.Make("ListHolder", col); UIKit.Size(holder, -1, -1).flexibleHeight = 1; var list = ScrollList(holder); var source = daily ? GameData.DailyQuests : GameData.MainQuests; var shown = new List(); int claimedCount = 0; // Сначала готовые к получению, потом в процессе. В основных -- не больше 6 активных. foreach (var q in source) if (!GP.IsQuestClaimed(q, daily) && GP.IsQuestDone(q, daily)) shown.Add(q); foreach (var q in source) { if (GP.IsQuestClaimed(q, daily)) { claimedCount++; continue; } if (GP.IsQuestDone(q, daily)) continue; if (!daily && shown.Count >= 6) continue; shown.Add(q); } foreach (var q in shown) QuestCard(list, q, daily); if (shown.Count == 0) UIKit.Text(list, daily ? "Все ежедневные задания выполнены! Приходите завтра." : "Все задания выполнены! Скоро будут новые.", 30, UIKit.Theme.Gold, TextAlignmentOptions.Center, 120); UIKit.Text(list, "Выполнено: " + claimedCount + " из " + source.Count, 26, UIKit.Theme.TextDim, TextAlignmentOptions.Center, 50); } void QuestCard(Transform parent, QuestDef q, bool daily) { bool done = GP.IsQuestDone(q, daily); int progress = Mathf.Min(GP.QuestProgress(q, daily), q.target); var card = UIKit.Card(parent, done ? UIKit.Theme.CardDone : UIKit.Theme.Card); var title = UIKit.Text(card, q.title, 32); title.fontStyle = FontStyles.Bold; UIKit.Bar(card, (float)progress / q.target, done ? UIKit.Theme.Green : UIKit.Theme.Gold, 30, progress + " / " + q.target); var row = UIKit.Row(card, 80, 12); var reward = UIKit.Text(row, "Награда: " + GameData.RewardsText(q.rewards) + ", " + q.xp + " опыта", 24, UIKit.Theme.TextDim); UIKit.Size(reward, -1, -1, 1); var b = UIKit.Button(row, done ? "Забрать" : "В процессе", done ? UIKit.Theme.Green : UIKit.Theme.Gray, () => GP.ClaimQuest(q, daily), 220, 80); b.interactable = done; } protected override void Tick() { if (resetTimer != null) resetTimer.text = "Обновление через " + GameData.FormatTime(GameProgress.SecondsToNextDay); } }