77 lines
2.0 KiB
C#
77 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameModeView : MonoBehaviour, ISelectable, IActivable
|
|
{
|
|
public static event Action<GameMode> OnGameModeChosen;
|
|
|
|
//Данные для заполнения
|
|
[SerializeField] private TextMeshProUGUI NameLabel;
|
|
[SerializeField] private TextMeshProUGUI DescriptionLabel;
|
|
[SerializeField] private Image IconImage;
|
|
[SerializeField] private TextMeshProUGUI PriceLabel;
|
|
|
|
[SerializeField] private Image BackgroundImage;
|
|
|
|
//Отображение доступности
|
|
[SerializeField] private List<Graphic> AccessColoredGraphics;
|
|
[SerializeField] private Color InteractableColor;
|
|
[SerializeField] private Color NonInteractableColor;
|
|
|
|
private GameMode CachedGameMode;
|
|
|
|
public void Setup(GameMode gameMode, bool available)
|
|
{
|
|
CachedGameMode = gameMode;
|
|
|
|
NameLabel.text = gameMode.Alias;
|
|
DescriptionLabel.text = gameMode.Description;
|
|
IconImage.sprite = gameMode.Icon;
|
|
BackgroundImage.sprite = gameMode.Background;
|
|
|
|
Refresh(gameMode, available);
|
|
}
|
|
|
|
public void Refresh(GameMode gameMode, bool available)
|
|
{
|
|
PriceLabel.text = GetPriceText(WalletManager.Balance, gameMode.Price);
|
|
SetInteractable(available);
|
|
SetColorByInterativity(available);
|
|
}
|
|
|
|
public bool IsInteractable { get; private set; }
|
|
public void SetInteractable(bool interactable)
|
|
{
|
|
IsInteractable = interactable;
|
|
Refresh(CachedGameMode, interactable);
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnDeselect()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnSelect()
|
|
{
|
|
|
|
}
|
|
|
|
private string GetPriceText(int balance, int required)
|
|
=> balance >= required ? "Готово" : $"{balance}/{required}";
|
|
|
|
private void SetColorByInterativity(bool interactive)
|
|
{
|
|
Color targetColor = interactive ? InteractableColor : NonInteractableColor;
|
|
foreach(var g in AccessColoredGraphics) g.color = targetColor;
|
|
}
|
|
|
|
}
|