145 lines
3.8 KiB
C#
145 lines
3.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIFishInfo : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private ModelViewerManager _modelViewer;
|
|
|
|
[SerializeField]
|
|
private UIManageAquarium _manageAquarium;
|
|
|
|
[SerializeField]
|
|
private RectTransform _rect;
|
|
|
|
[SerializeField]
|
|
private Text _fishNameText;
|
|
|
|
[SerializeField]
|
|
private Text _fishWeightText;
|
|
|
|
[SerializeField]
|
|
private Text _fishLengthText;
|
|
|
|
[SerializeField]
|
|
private Text _fisheryText;
|
|
|
|
[SerializeField]
|
|
private Text _habitatText;
|
|
|
|
[SerializeField]
|
|
private Text _sellPriceText;
|
|
|
|
[SerializeField]
|
|
private GameObject _inPanel;
|
|
|
|
[SerializeField]
|
|
private GameObject _outPanel;
|
|
|
|
[SerializeField]
|
|
private GameObject _canNotInsertPanel;
|
|
|
|
[SerializeField]
|
|
private Text _canNotInsertText;
|
|
|
|
[SerializeField]
|
|
private Button _insertButton;
|
|
|
|
[SerializeField]
|
|
private float _canInsertSize = 330f;
|
|
|
|
[SerializeField]
|
|
private float _canNotInsertSize = 370f;
|
|
|
|
private UIFish _currentFish;
|
|
|
|
public void ShowFish(UIFish fish, AquariumController aquarium)
|
|
{
|
|
if (_currentFish != null)
|
|
{
|
|
_currentFish.SetSelected(false);
|
|
}
|
|
_currentFish = fish;
|
|
FishManager.FishDefinition fishDefinition = fish.FishKept.GetFishDefinition();
|
|
_modelViewer.InstantiateObject(fishDefinition.fishPrefab.GetComponent<ModelViewerObject>(), fishDefinition.fishPrefab.fishName);
|
|
_fishNameText.text = Utilities.GetTranslation(fishDefinition.fishPrefab.fishName);
|
|
_fishWeightText.text = UtilitiesUnits.GetWeightString(fish.FishKept.weight);
|
|
_fishLengthText.text = UtilitiesUnits.GetLengthString(fish.FishKept.length);
|
|
_fisheryText.text = Utilities.GetTranslation(fish.FishKept.fishery);
|
|
_habitatText.text = Utilities.GetTranslation((!fish.FishKept.isSaltwater) ? "GUI/AQUARIUM/FRESHWATER" : "GUI/AQUARIUM/SALTWATER");
|
|
_inPanel.SetActive(fish.FishKept.aquarium != -1);
|
|
_outPanel.SetActive(fish.FishKept.aquarium == -1);
|
|
bool flag = !aquarium.Settings.IsMaxCapacityReached();
|
|
bool flag2 = fish.FishKept.weight <= (float)aquarium.Settings.fishLimitWeight;
|
|
bool flag3 = ((!fish.FishKept.isSaltwater) ? (aquarium.Settings.waterType == AquariumWaterType.Freshwater) : (aquarium.Settings.waterType == AquariumWaterType.Saltwater));
|
|
bool flag4 = flag && flag2 && flag3;
|
|
_canNotInsertPanel.SetActive(!flag4);
|
|
if (!flag4)
|
|
{
|
|
_canNotInsertText.text = GetCanNotInsertMessage(flag, flag2, flag3);
|
|
}
|
|
_insertButton.interactable = flag4;
|
|
int num = Mathf.RoundToInt(fish.FishKept.weight);
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
num = GlobalSettings.Instance.playerSettings.GetFishToMoney(fish.FishKept.weight, fishDefinition.fishPrefab.moneyFactor);
|
|
}
|
|
_sellPriceText.text = num.ToString("0 $");
|
|
_rect.sizeDelta = new Vector2(_rect.sizeDelta.x, (!flag4) ? _canNotInsertSize : _canInsertSize);
|
|
fish.SetSelected(true);
|
|
base.gameObject.SetActive(true);
|
|
}
|
|
|
|
private string GetCanNotInsertMessage(bool hasSpaceCapacity, bool fishSizeEnough, bool waterMatch)
|
|
{
|
|
if (!waterMatch)
|
|
{
|
|
return Utilities.GetTranslation("GUI/AQUARIUM/CANT_INSERT_HABITAT");
|
|
}
|
|
if (!hasSpaceCapacity)
|
|
{
|
|
return Utilities.GetTranslation("GUI/AQUARIUM/CANT_INSERT_CAPACITY");
|
|
}
|
|
if (!fishSizeEnough)
|
|
{
|
|
return Utilities.GetTranslation("GUI/AQUARIUM/CANT_INSERT_SIZE");
|
|
}
|
|
return Utilities.GetTranslation("GUI/AQUARIUM/CANT_INSERT_AQUARIUM");
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
if ((bool)_modelViewer.currentObject)
|
|
{
|
|
Object.Destroy(_modelViewer.currentObject.gameObject);
|
|
}
|
|
if (_currentFish != null)
|
|
{
|
|
_currentFish.SetSelected(false);
|
|
}
|
|
_currentFish = null;
|
|
base.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void OnPutInAquarium()
|
|
{
|
|
_manageAquarium.OnPutInAquariumFish(_currentFish);
|
|
}
|
|
|
|
public void OnRemoveFromAquarium()
|
|
{
|
|
_manageAquarium.OnRemoveFish(_currentFish);
|
|
}
|
|
|
|
public void OnInspect()
|
|
{
|
|
_manageAquarium.OnInspectFish(_currentFish);
|
|
}
|
|
|
|
public void OnSell()
|
|
{
|
|
_manageAquarium.OnSellFish(_currentFish);
|
|
Hide();
|
|
}
|
|
}
|