159 lines
6.2 KiB
C#
159 lines
6.2 KiB
C#
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
/// <summary>
|
||
/// Контроллер карты боссов.
|
||
/// При активации читает currentBotLevel из GameManager и призы из PrizeSerializer.
|
||
///
|
||
/// Для каждого слота:
|
||
/// • побеждён (index < currentBotLevel) → серый аватар, фон «победы», оверлей с крестом
|
||
/// • есть приз → prizeContainer активен, спрайт и подпись подставляются
|
||
/// • приза нет → prizeContainer скрыт
|
||
/// </summary>
|
||
public class BossMapController : MonoBehaviour
|
||
{
|
||
// ─── Маппинг PrizeType → Sprite ──────────────────────────────
|
||
|
||
[System.Serializable]
|
||
public class PrizeEntry
|
||
{
|
||
public PrizeType type;
|
||
public Sprite sprite;
|
||
[Tooltip("Отображаемое имя (например «Жетоны»)")]
|
||
public string displayName;
|
||
}
|
||
|
||
[Header("Маппинг: тип приза → спрайт")]
|
||
[SerializeField] private PrizeEntry[] prizeSprites;
|
||
|
||
// ─── Слоты боссов ─────────────────────────────────────────────
|
||
|
||
[System.Serializable]
|
||
public class BossSlot
|
||
{
|
||
[Header("Аватар и фон")]
|
||
[Tooltip("Image аватара — станет серым при победе")]
|
||
public Image bossImage;
|
||
|
||
[Tooltip("Image фона — меняет спрайт при победе")]
|
||
public Image bossBackground;
|
||
|
||
[Tooltip("Спрайт фона когда босс не побеждён")]
|
||
public Sprite backgroundNormal;
|
||
|
||
[Tooltip("Спрайт фона когда босс побеждён")]
|
||
public Sprite backgroundDefeated;
|
||
|
||
[Header("Крест победы")]
|
||
[Tooltip("GO с картинкой креста — включается когда босс побеждён")]
|
||
public GameObject defeatedOverlay;
|
||
|
||
[Header("Приз")]
|
||
[Tooltip("Корневой GO блока приза — скрывается если приза нет")]
|
||
public GameObject prizeContainer;
|
||
|
||
[Tooltip("Image куда подставляется спрайт приза")]
|
||
public Image prizeImage;
|
||
|
||
[Tooltip("TMP_Text: название приза и количество (если > 1)")]
|
||
public TMP_Text prizeLabel;
|
||
}
|
||
|
||
[Header("Слоты боссов (0..4, порядок = индекс босса)")]
|
||
[SerializeField] private BossSlot[] bossSlots;
|
||
|
||
[Header("GameManager (для currentBotLevel и gameMode)")]
|
||
[SerializeField] private GameManager gameManager;
|
||
|
||
[Tooltip("Корневой GO с визуальным содержимым карты — скрывается в режиме PvP")]
|
||
[SerializeField] private GameObject contentRoot;
|
||
|
||
private static readonly Color DefeatedColor = new Color(0.35f, 0.35f, 0.35f, 1f);
|
||
|
||
// ─── Unity ────────────────────────────────────────────────────
|
||
|
||
private void OnEnable()
|
||
{
|
||
bool isBotMode = gameManager != null && gameManager.gameMode == GameMode.PlayerVsBot;
|
||
|
||
if (contentRoot != null)
|
||
contentRoot.SetActive(isBotMode);
|
||
|
||
if (isBotMode)
|
||
Refresh();
|
||
}
|
||
|
||
// ─── Logic ────────────────────────────────────────────────────
|
||
|
||
private void Refresh()
|
||
{
|
||
int currentLevel = gameManager != null ? gameManager.currentBotLevel : 0;
|
||
List<Prize> prizes = PrizeSerializer.GetPrizes();
|
||
|
||
for (int i = 0; i < bossSlots.Length; i++)
|
||
{
|
||
BossSlot slot = bossSlots[i];
|
||
if (slot == null) continue;
|
||
|
||
bool isDefeated = i < currentLevel;
|
||
|
||
// Аватар: серый если побеждён
|
||
if (slot.bossImage != null)
|
||
slot.bossImage.color = isDefeated ? DefeatedColor : Color.white;
|
||
|
||
// Фон: меняем спрайт
|
||
if (slot.bossBackground != null)
|
||
{
|
||
Sprite bg = isDefeated ? slot.backgroundDefeated : slot.backgroundNormal;
|
||
if (bg != null) slot.bossBackground.sprite = bg;
|
||
}
|
||
|
||
// Крест: активен только у побеждённых
|
||
if (slot.defeatedOverlay != null)
|
||
slot.defeatedOverlay.SetActive(isDefeated);
|
||
|
||
// Приз
|
||
if (slot.prizeContainer == null) continue;
|
||
|
||
// Приз показываем только если босс ещё не побеждён
|
||
bool hasPrize = !isDefeated && i < prizes.Count && prizes[i].PrizeType != PrizeType.None;
|
||
slot.prizeContainer.SetActive(hasPrize);
|
||
|
||
if (hasPrize)
|
||
{
|
||
Prize prize = prizes[i];
|
||
|
||
if (slot.prizeImage != null)
|
||
slot.prizeImage.sprite = FindSprite(prize.PrizeType);
|
||
|
||
if (slot.prizeLabel != null)
|
||
slot.prizeLabel.text = BuildLabel(prize);
|
||
}
|
||
}
|
||
}
|
||
|
||
// ─── Helpers ──────────────────────────────────────────────────
|
||
|
||
private string BuildLabel(Prize prize)
|
||
{
|
||
PrizeEntry entry = FindEntry(prize.PrizeType);
|
||
string label = entry != null && !string.IsNullOrWhiteSpace(entry.displayName)
|
||
? entry.displayName
|
||
: prize.PrizeType.ToString();
|
||
return prize.Amount > 1 ? $"{label} x{prize.Amount}" : label;
|
||
}
|
||
|
||
private Sprite FindSprite(PrizeType type) => FindEntry(type)?.sprite;
|
||
|
||
private PrizeEntry FindEntry(PrizeType type)
|
||
{
|
||
if (prizeSprites == null) return null;
|
||
foreach (var e in prizeSprites)
|
||
if (e.type == type) return e;
|
||
return null;
|
||
}
|
||
}
|
||
|