summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/TreasuryUI.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Thronefall_v1.0/Decompile/TreasuryUI.cs')
-rw-r--r--Thronefall_v1.0/Decompile/TreasuryUI.cs224
1 files changed, 224 insertions, 0 deletions
diff --git a/Thronefall_v1.0/Decompile/TreasuryUI.cs b/Thronefall_v1.0/Decompile/TreasuryUI.cs
new file mode 100644
index 0000000..e86b87d
--- /dev/null
+++ b/Thronefall_v1.0/Decompile/TreasuryUI.cs
@@ -0,0 +1,224 @@
+using System.Collections.Generic;
+using TMPro;
+using UnityEngine;
+
+public class TreasuryUI : MonoBehaviour, DayNightCycle.IDaytimeSensitive
+{
+ public enum AnimationState
+ {
+ Off,
+ ScaleIn,
+ On,
+ ScaleOut,
+ WaitToScaleOut
+ }
+
+ public Transform coinsParent;
+
+ public GameObject renderCamera;
+
+ public GameObject coinPrefab;
+
+ public Transform spawn;
+
+ public float removalInterval;
+
+ public float addInterval = 0.35f;
+
+ public float activationLifetime = 1f;
+
+ public AnimationCurve scaleCurve;
+
+ public float scaleAnimationSpeed;
+
+ private Transform scaleTarget;
+
+ public float waitTimeBeforeScaleOut = 0.3f;
+
+ private TextMeshProUGUI displayText;
+
+ public Animator treasureChestAnimator;
+
+ private List<GameObject> instantiatedCoins = new List<GameObject>();
+
+ private PlayerInteraction targetPlayer;
+
+ private int coinQeue;
+
+ private float addCounter;
+
+ private float removalCounter;
+
+ private float activationCounter;
+
+ private bool overrideActivation;
+
+ private AnimationState currentState;
+
+ private float scaleAnimationProgress;
+
+ private float scaleOutWaitClock;
+
+ private bool shouldBeActive
+ {
+ get
+ {
+ if (!(activationCounter > 0f))
+ {
+ return overrideActivation;
+ }
+ return true;
+ }
+ }
+
+ private void Start()
+ {
+ DayNightCycle.Instance.RegisterDaytimeSensitiveObject(this);
+ scaleTarget = UIFrameManager.instance.TreasureChest.scaleTarget;
+ displayText = UIFrameManager.instance.TreasureChest.balanceNumber;
+ targetPlayer = TagManager.instance.Players[0].GetComponent<PlayerInteraction>();
+ targetPlayer.onBalanceGain.AddListener(AddCoins);
+ targetPlayer.onBalanceSpend.AddListener(RemoveCoins);
+ targetPlayer.onFocusPaymentInteraction.AddListener(LockActivation);
+ targetPlayer.onUnfocusPaymentInteraction.AddListener(UnlockActivation);
+ AddCoins(targetPlayer.Balance);
+ SetState(currentState);
+ }
+
+ private void SetState(AnimationState newState)
+ {
+ switch (newState)
+ {
+ case AnimationState.Off:
+ scaleTarget.localScale = Vector3.one * scaleCurve.Evaluate(0f);
+ scaleAnimationProgress = 0f;
+ break;
+ case AnimationState.On:
+ scaleTarget.localScale = Vector3.one * scaleCurve.Evaluate(1f);
+ scaleAnimationProgress = 1f;
+ treasureChestAnimator.SetBool("Open", value: true);
+ break;
+ case AnimationState.WaitToScaleOut:
+ treasureChestAnimator.SetBool("Open", value: false);
+ scaleOutWaitClock = 0f;
+ break;
+ }
+ currentState = newState;
+ }
+
+ private void Update()
+ {
+ if (addCounter > 0f)
+ {
+ addCounter -= Time.deltaTime;
+ }
+ if (removalCounter > 0f)
+ {
+ removalCounter -= Time.deltaTime;
+ }
+ if (activationCounter > 0f)
+ {
+ activationCounter -= Time.deltaTime;
+ }
+ if (coinQeue > 0 && addCounter <= 0f)
+ {
+ GameObject item = Object.Instantiate(coinPrefab, spawn.position, Random.rotation, coinsParent);
+ instantiatedCoins.Add(item);
+ coinQeue--;
+ addCounter = addInterval;
+ activationCounter = activationLifetime;
+ }
+ if (coinQeue < 0 && addCounter <= 0f)
+ {
+ GameObject obj = instantiatedCoins[instantiatedCoins.Count - 1];
+ instantiatedCoins.RemoveAt(instantiatedCoins.Count - 1);
+ Object.Destroy(obj);
+ coinQeue++;
+ removalCounter = removalInterval;
+ activationCounter = activationLifetime;
+ }
+ switch (currentState)
+ {
+ case AnimationState.Off:
+ if (shouldBeActive)
+ {
+ SetState(AnimationState.ScaleIn);
+ }
+ break;
+ case AnimationState.On:
+ if (!shouldBeActive)
+ {
+ SetState(AnimationState.WaitToScaleOut);
+ }
+ break;
+ case AnimationState.WaitToScaleOut:
+ scaleOutWaitClock += Time.deltaTime;
+ if (scaleOutWaitClock >= waitTimeBeforeScaleOut)
+ {
+ SetState(AnimationState.ScaleOut);
+ }
+ break;
+ case AnimationState.ScaleOut:
+ scaleAnimationProgress -= Time.deltaTime * scaleAnimationSpeed;
+ scaleTarget.localScale = Vector3.one * scaleCurve.Evaluate(scaleAnimationProgress);
+ if (scaleAnimationProgress <= 0f)
+ {
+ SetState(AnimationState.Off);
+ }
+ else if (shouldBeActive)
+ {
+ SetState(AnimationState.ScaleIn);
+ }
+ break;
+ case AnimationState.ScaleIn:
+ scaleAnimationProgress += Time.deltaTime * scaleAnimationSpeed;
+ scaleTarget.localScale = Vector3.one * scaleCurve.Evaluate(scaleAnimationProgress);
+ if (scaleAnimationProgress >= 1f)
+ {
+ SetState(AnimationState.On);
+ }
+ else if (!shouldBeActive)
+ {
+ SetState(AnimationState.ScaleIn);
+ }
+ break;
+ }
+ }
+
+ private void AddCoins(int amount)
+ {
+ coinQeue += amount;
+ displayText.text = "<sprite name=\"coin\">" + targetPlayer.Balance;
+ }
+
+ private void RemoveCoins(int amount)
+ {
+ coinQeue -= amount;
+ displayText.text = "<sprite name=\"coin\">" + targetPlayer.Balance;
+ }
+
+ private void LockActivation()
+ {
+ overrideActivation = true;
+ }
+
+ private void UnlockActivation()
+ {
+ overrideActivation = false;
+ activationCounter = activationLifetime;
+ }
+
+ public void OnDusk()
+ {
+ renderCamera.SetActive(value: false);
+ }
+
+ public void OnDawn_AfterSunrise()
+ {
+ }
+
+ public void OnDawn_BeforeSunrise()
+ {
+ renderCamera.SetActive(value: true);
+ }
+}