140 lines
3.5 KiB
C#
140 lines
3.5 KiB
C#
using UFS2.Gameplay;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SpinningPointerUI : HUDCanvasGroupBase
|
|
{
|
|
private Animator animator;
|
|
|
|
public Text moveTypeText;
|
|
|
|
public Image PointerImage;
|
|
|
|
public GameObject moveTypeObject;
|
|
|
|
[HideInInspector]
|
|
public bool isTake;
|
|
|
|
private string lift_drop_text;
|
|
|
|
private string slow_lift_drop_text;
|
|
|
|
private string slow_straight_text;
|
|
|
|
private string straight_text;
|
|
|
|
private void SetCanvasVisibility(bool value, bool immediate = true)
|
|
{
|
|
canvasGroup = (canvasGroup ? canvasGroup : GetComponent<CanvasGroup>());
|
|
if (value)
|
|
{
|
|
SetOn(immediate ? 0f : 0.1f);
|
|
}
|
|
else
|
|
{
|
|
SetOff(immediate ? 0f : 0.4f);
|
|
}
|
|
canvasGroup.blocksRaycasts = false;
|
|
canvasGroup.ignoreParentGroups = false;
|
|
canvasGroup.interactable = false;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
animator = GetComponent<Animator>();
|
|
SetCanvasVisibility(value: false);
|
|
lift_drop_text = LanguageManager.Instance.GetText("LURE_METHOD_LIFT_DROP");
|
|
slow_lift_drop_text = LanguageManager.Instance.GetText("LURE_METHOD_SLOW_LIFT_DROP");
|
|
slow_straight_text = LanguageManager.Instance.GetText("LURE_METHOD_SLOW_STRAIGHT");
|
|
straight_text = LanguageManager.Instance.GetText("LURE_METHOD_STRAIGHT");
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
}
|
|
|
|
private bool LureIsInWater()
|
|
{
|
|
if (FScriptsHandler.Instance == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (FScriptsHandler.Instance.m_PlayerMain == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (!FScriptsHandler.Instance.m_PlayerMain.currentRod)
|
|
{
|
|
return false;
|
|
}
|
|
if (!FScriptsHandler.Instance.m_PlayerMain.currentRod.currentLure)
|
|
{
|
|
return false;
|
|
}
|
|
return FScriptsHandler.Instance.m_PlayerMain.currentRod.currentLure.waterDisplacement.IsInWater;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
bool value = LureIsInWater() && (!FishEntity.CurrentFishInFight || !FishEntity.CurrentFishInFight.IsHooked);
|
|
SetCanvasVisibility(value, immediate: false);
|
|
isTake = (bool)FishEntity.CurrentFishInFight && !FishEntity.CurrentFishInFight.IsHooked;
|
|
animator.SetBool("Take", isTake);
|
|
if (moveTypeText.text != "")
|
|
{
|
|
moveTypeObject.SetActive(value: true);
|
|
}
|
|
else
|
|
{
|
|
moveTypeObject.SetActive(value: false);
|
|
}
|
|
UpdateUIWidth();
|
|
if (isTake || !FScriptsHandler.Instance || !FScriptsHandler.Instance.m_PlayerMain || !FScriptsHandler.Instance.m_PlayerMain.currentRod || !FScriptsHandler.Instance.m_PlayerMain.currentRod.currentLure)
|
|
{
|
|
return;
|
|
}
|
|
GameWaterSystem.FindWaterLevelAtLocation(FScriptsHandler.Instance.m_PlayerMain.currentRod.currentLure.transform.position, out var waterLevel);
|
|
if (FScriptsHandler.Instance.m_PlayerMain.currentRod.currentLure.transform.position.y > waterLevel + 0.1f)
|
|
{
|
|
moveTypeText.text = "";
|
|
PointerImage.color = Color.white;
|
|
return;
|
|
}
|
|
switch (FScriptsHandler.Instance.m_PlayerMain.currentRod.currentLure.currentMoveType)
|
|
{
|
|
case FLure.MoveType.None:
|
|
moveTypeText.text = "";
|
|
break;
|
|
case FLure.MoveType.Opadający:
|
|
moveTypeText.text = lift_drop_text;
|
|
break;
|
|
case FLure.MoveType.PowolnyOpadający:
|
|
moveTypeText.text = slow_lift_drop_text;
|
|
break;
|
|
case FLure.MoveType.PowolnyWleczony:
|
|
moveTypeText.text = slow_straight_text;
|
|
break;
|
|
case FLure.MoveType.Wleczony:
|
|
moveTypeText.text = straight_text;
|
|
break;
|
|
}
|
|
PointerImage.color = Color.Lerp(Color.white, Color.green, FScriptsHandler.Instance.m_PlayerMain.currentRod.currentLure.percentEfficacy);
|
|
}
|
|
|
|
private void UpdateUIWidth()
|
|
{
|
|
if (canvasGroup.alpha > 0f)
|
|
{
|
|
rectTransform.sizeDelta = originalSizeDelta;
|
|
}
|
|
else
|
|
{
|
|
rectTransform.sizeDelta = new Vector2(0f, originalSizeDelta.y);
|
|
}
|
|
}
|
|
}
|