81 lines
2.1 KiB
C#
81 lines
2.1 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;
|
|
|
|
public GameMode CachedGameMode { get; private set; }
|
|
|
|
public void Setup(GameMode gameMode)
|
|
{
|
|
CachedGameMode = gameMode;
|
|
|
|
NameLabel.text = gameMode.Alias;
|
|
DescriptionLabel.text = gameMode.Description;
|
|
IconImage.sprite = gameMode.Icon;
|
|
BackgroundImage.sprite = gameMode.Background;
|
|
|
|
Refresh();
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
PriceLabel.text = GetPriceText(WalletManager.Balance, CachedGameMode.Price);
|
|
bool available = WalletManager.Balance >= CachedGameMode.Price;
|
|
SetColorByInterativity(available);
|
|
}
|
|
|
|
public bool IsInteractable { get; private set; }
|
|
public void SetInteractable(bool interactable)
|
|
{
|
|
IsInteractable = interactable;
|
|
Refresh();
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnDeselect()
|
|
{
|
|
|
|
}
|
|
|
|
public void OnSelect()
|
|
{
|
|
|
|
}
|
|
|
|
private string GetPriceText(int balance, int required)
|
|
=> balance >= required ? $"{balance}/{required} Заходи!" : $"{balance}/{required}";
|
|
|
|
private void SetColorByInterativity(bool interactive)
|
|
{
|
|
if(AccessColoredGraphics == null) return;
|
|
|
|
Color targetColor = interactive ? InteractableColor : NonInteractableColor;
|
|
foreach(var g in AccessColoredGraphics)
|
|
{
|
|
g.color = targetColor;
|
|
}
|
|
}
|
|
}
|