Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/HUDWatchFish.cs
2026-02-21 16:45:37 +08:00

203 lines
6.5 KiB
C#

using UnityEngine;
using UnityEngine.UI;
public class HUDWatchFish : MonoBehaviour
{
public Text fishNameText;
public Text fishWeigthText;
public Text fishLengthText;
public Text fishExpText;
public Text playerMoneyText;
public Text newRecordText;
public Color newRecordStartColor = Color.white;
public Color newRecordFinishColor = Color.yellow;
public PlayerExperienceWidget playerExperienceWidget;
[Space(10f)]
public Text infoFishParams;
public Text infoJunkParams;
public Button watchTakeBtn;
public Button watchSellBtn;
public Button watchReleaseBtn;
public Text watchSellBtnText;
public Text watchReleaseBtnText;
public Button watchFilletBtn;
public Button watchYoungBaitBtn;
public Button watchMakeHookBtn;
[Space(10f)]
public Vector3 watchFishInfoPosHook = new Vector3(0f, -200f, 0f);
public Vector3 watchFishInfoPosHands = new Vector3(0f, 0f, 0f);
public Vector3 watchFishInfoPosBoat = new Vector3(0f, 0f, 0f);
private RectTransform rectTransform;
private int currentMoneyAmount;
private int currentExpAmount;
private int currentLevel;
private PlayerSettingsMy playerSettings;
private void Awake()
{
rectTransform = GetComponent<RectTransform>();
if ((bool)GlobalSettings.Instance)
{
playerSettings = GlobalSettings.Instance.playerSettings;
}
}
private void Start()
{
LeanTween.value(base.gameObject, newRecordStartColor, newRecordFinishColor, 1f).setLoopPingPong().setIgnoreTimeScale(true)
.setEaseInOutQuad()
.setOnUpdate(delegate(Color val)
{
newRecordText.color = val;
});
}
public void PlayerCaughtFish(Fish fish)
{
infoFishParams.gameObject.SetActive(false);
watchSellBtn.interactable = true;
watchReleaseBtn.interactable = true;
int expPrize = fish.GetExpPrize();
int moneyPrize = fish.GetMoneyPrize();
if ((bool)playerSettings)
{
currentMoneyAmount = playerSettings.playersMoney;
currentExpAmount = playerSettings.playersExperience;
currentLevel = playerSettings.playersLevel;
playerExperienceWidget.expEnergyBar.SetValueMin(playerSettings.GetThresholdExperience((int)playerSettings.playersLevel - 1));
playerExperienceWidget.expEnergyBar.SetValueMax(playerSettings.GetThresholdExperience(playerSettings.playersLevel));
}
else
{
currentMoneyAmount = 666;
currentExpAmount = 150;
currentLevel = 9;
playerExperienceWidget.expEnergyBar.SetValueMin(100);
playerExperienceWidget.expEnergyBar.SetValueMax(200);
}
playerExperienceWidget.expEnergyBar.SetValueCurrent(currentExpAmount);
playerExperienceWidget.levelValueText.text = currentLevel.ToString();
fishNameText.text = ((!fish.isYoung) ? string.Empty : (string.Empty + Utilities.GetTranslation("HUD_WATCH_FISH/YOUNG") + " ")) + Utilities.GetTranslation(fish.fishName);
fishWeigthText.text = UtilitiesUnits.GetWeightString(fish.Weight);
fishLengthText.text = UtilitiesUnits.GetLengthString(fish.Length);
fishExpText.text = "+ " + ((!playerSettings) ? expPrize : playerSettings.GetExpUpdated(expPrize)) + " " + Utilities.GetTranslation("HUD_WATCH_FISH/EXP");
playerMoneyText.text = currentMoneyAmount + " $";
watchSellBtnText.text = Utilities.GetTranslation("HUD_WATCH_FISH/SELL") + " +" + moneyPrize + " $";
watchReleaseBtnText.text = Utilities.GetTranslation("HUD_WATCH_FISH/RELEASE") + " +" + ((!playerSettings) ? expPrize : playerSettings.GetExpUpdated(Mathf.RoundToInt((float)expPrize * 0.2f))) + " " + Utilities.GetTranslation("HUD_WATCH_FISH/EXP");
watchYoungBaitBtn.gameObject.SetActive(false);
watchFilletBtn.gameObject.SetActive(false);
if ((bool)GlobalSettings.Instance)
{
newRecordText.enabled = GlobalSettings.Instance.fishManager.IsFishBigger(fish);
playerSettings.AddScore(expPrize);
playerSettings.AddExperience(playerSettings.GetExpUpdated(expPrize));
GlobalSettings.Instance.fishManager.ChangeFishBigger(fish, GlobalSettings.Instance.levelsManager.GetCurrentFishery().name);
GlobalSettings.Instance.levelsManager.PlayerCaughtFish(fish);
}
}
public void OnDecision(int decision, float delay)
{
watchSellBtn.interactable = false;
watchReleaseBtn.interactable = false;
switch (decision)
{
case 1:
LeanTween.value(currentMoneyAmount, (!playerSettings) ? 777f : ((float)(int)playerSettings.playersMoney), delay).setOnUpdate(delegate(float value)
{
playerMoneyText.text = (int)value/*cast due to .constrained prefix*/ + " $";
});
break;
case 2:
UpdateExpBer(delay);
break;
}
}
public void UpdateExpBer(float delay, float fakeValue = 250f)
{
LeanTween.value(currentExpAmount, (!playerSettings) ? fakeValue : ((float)(int)playerSettings.playersExperience), delay).setOnUpdate(delegate(float value)
{
if (playerExperienceWidget.expEnergyBar.valueCurrent >= playerExperienceWidget.expEnergyBar.valueMax && currentLevel < ((!playerSettings) ? 25 : ((int)playerSettings.maxPlayerLevel)))
{
currentLevel++;
playerExperienceWidget.levelValueText.text = currentLevel.ToString();
LeanTween.scale(playerExperienceWidget.levelValueText.rectTransform, Vector3.one * 1.4f, 0.2f).setLoopPingPong(1);
AudioController.Play("level_reached");
if ((bool)playerSettings)
{
if (currentLevel == (int)playerSettings.maxPlayerLevel)
{
playerExperienceWidget.expEnergyBar.SetValueMin(0);
playerExperienceWidget.expEnergyBar.SetValueMax(1);
playerExperienceWidget.expEnergyBar.SetValueCurrent(1);
}
else
{
playerExperienceWidget.expEnergyBar.SetValueMin(playerSettings.GetThresholdExperience(currentLevel - 1));
playerExperienceWidget.expEnergyBar.SetValueMax(playerSettings.GetThresholdExperience(currentLevel));
}
}
else
{
playerExperienceWidget.expEnergyBar.SetValueMin(200);
playerExperienceWidget.expEnergyBar.SetValueMax(300);
}
}
playerExperienceWidget.expEnergyBar.SetValueCurrent((int)value);
});
LeanTween.scale(playerExperienceWidget.gameObject, playerExperienceWidget.gameObject.transform.localScale * 1.1f, delay / 2f).setLoopPingPong(1);
}
public void PlayerCaughtJunk(Junk junk)
{
}
public void UpdateWatchFishPosition(Fish.WatchStyle watchStyle)
{
if (VRManager.IsVROn())
{
rectTransform.anchoredPosition = watchFishInfoPosHands;
return;
}
switch (watchStyle)
{
case Fish.WatchStyle.HOOK_LIGHT:
rectTransform.anchoredPosition = watchFishInfoPosHook;
break;
case Fish.WatchStyle.HANDS:
rectTransform.anchoredPosition = watchFishInfoPosHands;
break;
case Fish.WatchStyle.BOAT:
rectTransform.anchoredPosition = watchFishInfoPosBoat;
break;
}
}
}