using System; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; // Окно здания. Открывается тапом по зданию (подписей над зданиями больше нет -- всё здесь). // У каждого здания своё окно: // - добывающее (Лесопилка, Ферма, Каменоломня, Шахта, Рудник): рабочие этой профессии и кнопки "−" / "+", // добыча в час, сколько ресурса на складе и когда склад заполнится, что даст улучшение и его цена; // - Склад и Амбар: запас / лимит по их ресурсам, что даст улучшение и цена; // - Дом: сколько жилья даёт, население / предел, улучшение и цена; // - Ратуша: жильё, резерв для найма, что откроется на следующем уровне, цена улучшения; // - Кристалл: где добывается, запас / лимит; // - Казармы: очередь обучения, какие войска открыты и что нужно для остальных, улучшение (открывает войска), // кнопка "Нанять войска" (панель "Войска"). // - Стройка и улучшение идут по времени (BuildTimer, 01.11, ТЕСТ): полоска, сколько осталось, ускорение за кристаллы. // Пока здание строится, в окне только стройка; при улучшении здание работает на старом уровне. // - У построенных зданий (кроме Ратуши) -- кнопка "Перенести" (бесплатно, уровень и стройка сохраняются). Сноса нет (04.11). // Без здания (кнопка "Рабочие" в панели DEV и "Все рабочие" в окне) -- список рабочих по всем профессиям. // Окно -- только интерфейс: рабочих ставит модуль Населения, добычу считает модуль Экономики. // Пока окно открыто, цифры обновляются сами (раз в полсекунды). public static class BuildingWindow { static GameObject root; static GameObject focus; // здание, по которому тапнули (null -- список рабочих) static readonly List live = new List(); // что обновлять, пока окно открыто public static void OnWorkplaceTapped(ResourceCollector building) { Open(building != null ? building.gameObject : null); } public static void OnStorageTapped(StorageBuilding building) { Open(building != null ? building.gameObject : null); } public static void OnTownHallTapped(TownHall townHall) { Open(townHall != null ? townHall.gameObject : null); } public static void Open(GameObject building) { // В режиме стройки тап -- это выбор места, а не здания if (BuildModeController.Instance != null && BuildModeController.Instance.IsActive) return; focus = building; Rebuild(); } public static void Close() { if (root != null) UnityEngine.Object.Destroy(root); root = null; focus = null; live.Clear(); } static void Rebuild() { if (root != null) UnityEngine.Object.Destroy(root); live.Clear(); var modal = UIKit.Modal(TitleFor(focus), out root); root.AddComponent(); var card = ScrollBody(modal); // длинное окно прокручивается, "Закрыть" всегда видна внизу (05.11) var rc = focus != null ? focus.GetComponent() : null; var storage = focus != null ? focus.GetComponent() : null; var townHall = focus != null ? focus.GetComponent() : null; var barracks = focus != null ? focus.GetComponent() : null; var hospital = focus != null ? focus.GetComponent() : null; var heroCastle = focus != null ? focus.GetComponent() : null; bool constructing = focus != null && BuildTimer.IsConstructing(focus.transform); if (focus != null) TimerBlock(card, focus); if (focus == null) WorkersList(card); else if (constructing) UIKit.Text(card, "Пока здание строится, оно не работает.", 22, UIKit.Theme.TextDim, TextAlignmentOptions.Center); else if (townHall != null) TownHallSection(card, townHall); else if (barracks != null) BarracksSection(card, barracks); else if (hospital != null) HospitalSection(card, hospital); else if (heroCastle != null) HeroCastleSection(card); else if (rc != null && rc.IsWorkplace) WorkplaceSection(card, rc); else if (rc != null && rc.IsHouse) HouseSection(card, rc); else if (rc != null && rc.resourceType == ResourceType.Gems) CrystalSection(card); else if (storage != null) StorageSection(card, storage); if (focus != null) ActionsBlock(card, focus); UIKit.Button(modal, "Закрыть", UIKit.Theme.Gray, Close, -1, 80, 28); } // Окно не выше экрана: заголовок сверху, содержимое прокручивается, кнопка "Закрыть" -- внизу, вне прокрутки. // Закрыть можно и тапом по затемнению вокруг окна, и кнопкой "Назад" (Escape). static RectTransform ScrollBody(RectTransform modal) { var fit = modal.GetComponent(); if (fit != null) UnityEngine.Object.DestroyImmediate(fit); modal.anchorMin = new Vector2(0.06f, 0.05f); modal.anchorMax = new Vector2(0.94f, 0.95f); modal.offsetMin = Vector2.zero; modal.offsetMax = Vector2.zero; var dim = root.GetComponent(); if (dim != null) { var outside = root.AddComponent