132 lines
3.4 KiB
C#
132 lines
3.4 KiB
C#
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using LE_LevelEditor.Core;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FisheryEditorFishDropdown : MonoBehaviour
|
|
{
|
|
public Dropdown dropdown;
|
|
|
|
public Text infoNoSpeciesText;
|
|
|
|
public Slider slider;
|
|
|
|
public Text sliderText;
|
|
|
|
private FishManager fishManager;
|
|
|
|
[ReadOnly]
|
|
public LE_Object le_Object;
|
|
|
|
public List<int> fishIds = new List<int>();
|
|
|
|
private void Start()
|
|
{
|
|
InitList();
|
|
}
|
|
|
|
public void Show(LE_Object leObject)
|
|
{
|
|
InitList();
|
|
le_Object = leObject;
|
|
base.gameObject.SetActive(leObject != null);
|
|
if ((bool)leObject)
|
|
{
|
|
slider.value = (int)le_Object.CustomProperties.y;
|
|
slider.value = Mathf.Clamp(slider.value, 1f, slider.maxValue);
|
|
UpdateSliderText();
|
|
if ((bool)fishManager && fishManager.GetTotalFishCount() == 0)
|
|
{
|
|
dropdown.gameObject.SetActive(false);
|
|
infoNoSpeciesText.gameObject.SetActive(true);
|
|
infoNoSpeciesText.text = Utilities.GetTranslation("EDITOR/SPAWNER_ANY_FISH");
|
|
}
|
|
else if ((bool)fishManager && fishManager.GetTotalFishCount() > 0 && (int)le_Object.CustomProperties.x == -1)
|
|
{
|
|
dropdown.gameObject.SetActive(true);
|
|
infoNoSpeciesText.gameObject.SetActive(false);
|
|
dropdown.value = 0;
|
|
dropdown.RefreshShownValue();
|
|
le_Object.CustomProperties.x = fishIds[dropdown.value];
|
|
le_Object.CustomProperties.y = slider.value;
|
|
Debug.LogError("Create/fix FishSpawner Editor");
|
|
}
|
|
else if ((bool)fishManager && !HasFishUnlocked((int)le_Object.CustomProperties.x))
|
|
{
|
|
dropdown.gameObject.SetActive(false);
|
|
infoNoSpeciesText.gameObject.SetActive(true);
|
|
infoNoSpeciesText.text = Utilities.GetTranslation("EDITOR/SPAWNER_LOCKED") + ":\n" + Utilities.GetTranslation(fishManager.GetFishName((Fish.Species)le_Object.CustomProperties.x));
|
|
}
|
|
else
|
|
{
|
|
dropdown.gameObject.SetActive(true);
|
|
infoNoSpeciesText.gameObject.SetActive(false);
|
|
dropdown.value = fishIds.BinarySearch((int)le_Object.CustomProperties.x);
|
|
dropdown.RefreshShownValue();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void InitList()
|
|
{
|
|
if (!GlobalSettings.Instance || !GlobalSettings.Instance.fishManager || fishManager != null)
|
|
{
|
|
return;
|
|
}
|
|
fishManager = GlobalSettings.Instance.fishManager;
|
|
dropdown.options.Clear();
|
|
dropdown.options.Capacity = 0;
|
|
for (int i = 0; i < fishManager.fishDefinitions.Count; i++)
|
|
{
|
|
if (fishManager.fishDefinitions[i].isAvailable && fishManager.fishDefinitions[i].isAvailableFromDLCs && HasFishUnlocked(i))
|
|
{
|
|
dropdown.options.Add(new Dropdown.OptionData(Utilities.GetTranslation(fishManager.fishDefinitions[i].fishPrefab.fishName)));
|
|
fishIds.Add(i);
|
|
}
|
|
}
|
|
dropdown.value = 0;
|
|
dropdown.RefreshShownValue();
|
|
}
|
|
|
|
public bool HasFishUnlocked(int fishId)
|
|
{
|
|
if (fishId >= fishManager.fishDefinitions.Count)
|
|
{
|
|
Debug.LogError("Editor fish not found " + fishId);
|
|
return false;
|
|
}
|
|
return fishManager.fishDefinitions[fishId].caughtCount > 0;
|
|
}
|
|
|
|
public void UpdateFishSpecies()
|
|
{
|
|
if ((bool)fishManager && (bool)le_Object && dropdown.value >= 0 && dropdown.value < fishManager.fishDefinitions.Count)
|
|
{
|
|
le_Object.CustomProperties.x = fishIds[dropdown.value];
|
|
}
|
|
}
|
|
|
|
public void UpdateFishAmount()
|
|
{
|
|
if (slider.value < 1f)
|
|
{
|
|
slider.value = 1f;
|
|
}
|
|
else if ((bool)le_Object)
|
|
{
|
|
le_Object.CustomProperties.y = (int)slider.value;
|
|
UpdateSliderText();
|
|
}
|
|
}
|
|
|
|
public void UpdateSliderText()
|
|
{
|
|
sliderText.text = "Fish Amount: " + slider.value;
|
|
}
|
|
|
|
public void LanguageChanged()
|
|
{
|
|
}
|
|
}
|