93 lines
2.2 KiB
C#
93 lines
2.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIFish : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Text _nameText;
|
|
|
|
[SerializeField]
|
|
private Text _weightText;
|
|
|
|
[SerializeField]
|
|
private Text _lengthText;
|
|
|
|
[SerializeField]
|
|
private Image _fishIcon;
|
|
|
|
[SerializeField]
|
|
private Image _selectedImage;
|
|
|
|
[SerializeField]
|
|
private Image _backgroundImage;
|
|
|
|
[SerializeField]
|
|
private GameObject _inAquariumPanel;
|
|
|
|
[SerializeField]
|
|
private GameObject _saltwaterPanel;
|
|
|
|
[SerializeField]
|
|
private GameObject _freshwaterPanel;
|
|
|
|
[SerializeField]
|
|
private CanvasGroup _canvasGroup;
|
|
|
|
[SerializeField]
|
|
private float _invalidAlpha = 0.8f;
|
|
|
|
private Action<UIFish> _onClickCallback;
|
|
|
|
public FishManager.FishKept FishKept { get; private set; }
|
|
|
|
public bool isMatched { get; private set; }
|
|
|
|
private void OnEnable()
|
|
{
|
|
SetSelected(false);
|
|
}
|
|
|
|
public void Initialize(FishManager.FishKept fish, Action<UIFish> onClickCallback)
|
|
{
|
|
_onClickCallback = onClickCallback;
|
|
FishKept = fish;
|
|
FishManager.FishDefinition fishDefinition = fish.GetFishDefinition();
|
|
_fishIcon.sprite = fishDefinition.icon;
|
|
_nameText.text = Utilities.GetTranslation(fishDefinition.fishPrefab.fishName);
|
|
_weightText.text = UtilitiesUnits.GetWeightString(fish.weight);
|
|
_lengthText.text = UtilitiesUnits.GetLengthString(fish.length);
|
|
bool isSaltwater = fishDefinition.fishPrefab.GetComponent<Fish>().isSaltwater;
|
|
_saltwaterPanel.SetActive(isSaltwater);
|
|
_freshwaterPanel.SetActive(!isSaltwater);
|
|
UpdateState();
|
|
}
|
|
|
|
public void UpdateMatched(AquariumSettings aquariumSettings)
|
|
{
|
|
bool flag = ((!FishKept.isSaltwater) ? (aquariumSettings.waterType == AquariumWaterType.Freshwater) : (aquariumSettings.waterType == AquariumWaterType.Saltwater));
|
|
bool flag2 = FishKept.weight <= (float)aquariumSettings.fishLimitWeight;
|
|
isMatched = flag && flag2;
|
|
_backgroundImage.enabled = isMatched;
|
|
_canvasGroup.alpha = ((!isMatched) ? _invalidAlpha : 1f);
|
|
}
|
|
|
|
public void UpdateState()
|
|
{
|
|
_inAquariumPanel.SetActive(FishKept.aquarium != -1);
|
|
}
|
|
|
|
public void OnClicked()
|
|
{
|
|
if (_onClickCallback != null)
|
|
{
|
|
_onClickCallback(this);
|
|
}
|
|
}
|
|
|
|
public void SetSelected(bool value)
|
|
{
|
|
_selectedImage.enabled = value;
|
|
}
|
|
}
|