156 lines
3.8 KiB
C#
156 lines
3.8 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FloatParamWidget : MonoBehaviour
|
|
{
|
|
public bool isDepthWidget = true;
|
|
|
|
public Text text;
|
|
|
|
private Slider slider;
|
|
|
|
private EquipmentManager equipmentManager;
|
|
|
|
[HideInInspector]
|
|
public EquipmentGUI equipmentGUI;
|
|
|
|
[HideInInspector]
|
|
public EquipmentObject floatWeightObject;
|
|
|
|
public Image fillImage;
|
|
|
|
public List<Color> weightColors = new List<Color>();
|
|
|
|
private float lastInput;
|
|
|
|
private float inputDelay = 0.06f;
|
|
|
|
private void Start()
|
|
{
|
|
fillImage = slider.fillRect.GetComponent<Image>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Refresh();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isDepthWidget)
|
|
{
|
|
CheckInput();
|
|
}
|
|
if (!isDepthWidget && floatWeightObject != null && (bool)equipmentManager)
|
|
{
|
|
if (slider.maxValue != (float)floatWeightObject.amount)
|
|
{
|
|
slider.maxValue = floatWeightObject.amount;
|
|
}
|
|
EquipmentObject currentEquipment = equipmentManager.GetCurrentEquipment(EquipmentObject.EquipmentType.FLOAT);
|
|
if (currentEquipment != null)
|
|
{
|
|
FishingFloat component = currentEquipment.prefab.GetComponent<FishingFloat>();
|
|
if (slider.value >= component.optimalBurden * 2f)
|
|
{
|
|
fillImage.color = weightColors[3];
|
|
}
|
|
else
|
|
{
|
|
fillImage.color = weightColors[1];
|
|
}
|
|
}
|
|
}
|
|
fillImage.color = new Color(fillImage.color.r, fillImage.color.g, fillImage.color.b, (!slider.interactable) ? 0.5f : 1f);
|
|
}
|
|
|
|
private void CheckInput()
|
|
{
|
|
if (UtilitiesInput.GetButtonUp("FLOAT_LINE_INCREASE") || UtilitiesInput.GetButtonUp("FLOAT_LINE_DECREASE"))
|
|
{
|
|
lastInput = Time.realtimeSinceStartup;
|
|
}
|
|
if (!(Time.realtimeSinceStartup - lastInput < inputDelay))
|
|
{
|
|
if (UtilitiesInput.GetButton("FLOAT_LINE_INCREASE") && slider.value < slider.maxValue)
|
|
{
|
|
slider.value += 1f;
|
|
}
|
|
if (UtilitiesInput.GetButton("FLOAT_LINE_DECREASE") && slider.value > slider.minValue)
|
|
{
|
|
slider.value -= 1f;
|
|
}
|
|
lastInput = Time.realtimeSinceStartup;
|
|
}
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
equipmentManager = GlobalSettings.Instance.equipmentManager;
|
|
floatWeightObject = equipmentManager.FindEquipment(EquipmentObject.EquipmentType.OTHER, "FLOAT_WEIGHT_01");
|
|
}
|
|
slider = GetComponent<Slider>();
|
|
if ((bool)equipmentManager)
|
|
{
|
|
if (isDepthWidget)
|
|
{
|
|
if (slider.value != equipmentManager.currentSetSpecificParameters.currentFloatDepth)
|
|
{
|
|
slider.value = equipmentManager.currentSetSpecificParameters.currentFloatDepth;
|
|
}
|
|
}
|
|
else if (slider.value != equipmentManager.currentSetSpecificParameters.currentFloatWeight)
|
|
{
|
|
slider.value = equipmentManager.currentSetSpecificParameters.currentFloatWeight;
|
|
}
|
|
}
|
|
if ((bool)equipmentGUI)
|
|
{
|
|
slider.interactable = equipmentGUI.canEquipmentBeChanged;
|
|
}
|
|
LanguageChanged();
|
|
}
|
|
|
|
public void UpdateValue()
|
|
{
|
|
if ((bool)equipmentManager)
|
|
{
|
|
if (isDepthWidget)
|
|
{
|
|
equipmentManager.currentSetSpecificParameters.currentFloatDepth = slider.value;
|
|
}
|
|
else
|
|
{
|
|
equipmentManager.currentSetSpecificParameters.currentFloatWeight = slider.value;
|
|
}
|
|
}
|
|
if ((bool)equipmentGUI && equipmentGUI.isCurrentSet && equipmentGUI.canEquipmentBeChanged && (bool)equipmentManager)
|
|
{
|
|
equipmentManager.EquipmentChanged(EquipmentObject.EquipmentType.FLOAT);
|
|
}
|
|
LanguageChanged();
|
|
text.color = new Color(text.color.r, text.color.g, text.color.b, (!slider.interactable) ? slider.colors.disabledColor.a : 1f);
|
|
}
|
|
|
|
public void LanguageChanged()
|
|
{
|
|
string empty = string.Empty;
|
|
if (isDepthWidget)
|
|
{
|
|
text.text = string.Empty + slider.value + " cm";
|
|
if (GlobalSettings.Instance.playerSettings.imperialUnits)
|
|
{
|
|
Text obj = text;
|
|
obj.text = obj.text + "\n(" + UtilitiesUnits.GetLengthCmString(slider.value) + ")";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
text.text = string.Empty + slider.value + " / " + floatWeightObject.amount + " g";
|
|
}
|
|
}
|
|
}
|