blob: 350a1cf21f64c1efb71eb9adb93508424b3f4105 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
using System.Collections;
using System.Collections.Generic;
using MoreMountains.Feedbacks;
using TMPro;
using UnityEngine;
public class CostDisplay : MonoBehaviour
{
public Coinslot coinslotPrefab;
public Coin coinPrefab;
public RectTransform gridParent;
public float horizontalSpacing;
public int maxElementsPerRow = 5;
public AnimationCurve yDistribution = new AnimationCurve();
public float peakYOffset = 50f;
public float rowYSpacing = 100f;
public Transform amountDisplayParent;
public TextMeshProUGUI amountDisplay;
public MMF_Player displayCostAmountShow;
public MMF_Player displayCostAmountHide;
private List<Coinslot> coinslotPool = new List<Coinslot>();
private List<Coinslot> currentlyActiveCoinslots = new List<Coinslot>();
private float elementWidth;
private float yCurveLeftAnchor;
private float yCurveRightAnchor;
private bool reUpdateBecauseFuckUnityCanvas;
private int currentAmount;
private int currentlyFilledCoins;
private float completeFillDuration = 1f;
private float minFillDurationPerCoin = 0.15f;
private bool denied;
private bool inDisappearAnimation;
private const float defaultScale = 0.01f;
private const float largeUIScale = 0.0125f;
public static int currentlyFilledCoinsFromLastActiveDisplay;
public bool CompletelyFilled => currentlyFilledCoins >= currentAmount;
public bool CompletelyEmpty => currentlyFilledCoins <= 0;
private void Start()
{
elementWidth = coinslotPrefab.GetComponent<RectTransform>().sizeDelta.x;
float num = (float)maxElementsPerRow * elementWidth + (float)(maxElementsPerRow - 1) * horizontalSpacing;
yCurveLeftAnchor = (0f - num) / 2f + elementWidth / 2f;
yCurveRightAnchor = num / 2f - elementWidth / 2f;
}
private void Update()
{
if (reUpdateBecauseFuckUnityCanvas)
{
UpdateDisplay(currentAmount, dirty: false);
}
}
public void UpdateDisplay(int amount, bool dirty = true)
{
if (SettingsManager.Instance.UseLargeInGameUI)
{
base.transform.localScale = Vector3.one * 0.0125f;
}
else
{
base.transform.localScale = Vector3.one * 0.01f;
}
inDisappearAnimation = false;
base.gameObject.SetActive(value: true);
StopAllCoroutines();
currentAmount = amount;
reUpdateBecauseFuckUnityCanvas = dirty;
currentlyActiveCoinslots.Clear();
currentlyFilledCoins = 0;
denied = false;
amountDisplayParent.gameObject.SetActive(value: false);
if (amount < 1)
{
foreach (Coinslot item in coinslotPool)
{
item.gameObject.SetActive(value: false);
}
return;
}
int num = amount - coinslotPool.Count;
for (int i = 0; i < num; i++)
{
coinslotPool.Add(Object.Instantiate(coinslotPrefab.gameObject, gridParent).GetComponent<Coinslot>());
}
int num2 = amount;
int num3 = num2;
if (num3 > maxElementsPerRow)
{
num3 = maxElementsPerRow;
}
int num4 = 0;
int num5 = 0;
float num6 = (0f - ((float)num3 * elementWidth + (float)(num3 - 1) * horizontalSpacing)) / 2f + elementWidth / 2f;
for (int j = 0; j < coinslotPool.Count; j++)
{
Coinslot coinslot = coinslotPool[j];
if (j < amount)
{
coinslot.gameObject.SetActive(value: true);
currentlyActiveCoinslots.Add(coinslot);
coinslot.transform.localScale = Vector3.zero;
float num7 = num6 + ((float)num4 * elementWidth + (float)num4 * horizontalSpacing);
float y = peakYOffset * yDistribution.Evaluate(Mathf.InverseLerp(yCurveLeftAnchor, yCurveRightAnchor, num7)) + rowYSpacing * (float)num5;
coinslotPool[j].GetComponent<RectTransform>().anchoredPosition = new Vector2(num7, y);
num4++;
num2--;
if (num4 >= maxElementsPerRow)
{
num3 = num2;
if (num3 > maxElementsPerRow)
{
num3 = maxElementsPerRow;
}
num4 = 0;
num5++;
num6 = (0f - ((float)num3 * elementWidth + (float)(num3 - 1) * horizontalSpacing)) / 2f + elementWidth / 2f;
}
}
else
{
coinslot.gameObject.SetActive(value: false);
}
}
foreach (Coinslot currentlyActiveCoinslot in currentlyActiveCoinslots)
{
currentlyActiveCoinslot.SetEmpty();
}
float num8 = (float)currentlyActiveCoinslots.Count * minFillDurationPerCoin;
if (num8 < completeFillDuration)
{
num8 = 1f;
}
ThronefallAudioManager.SetCoinDisplayFillTime(num8);
StartCoroutine(AnimateShowSlots());
}
public bool FillUp()
{
currentlyFilledCoinsFromLastActiveDisplay = currentlyFilledCoins;
if (currentlyActiveCoinslots.Count > currentlyFilledCoins && currentlyActiveCoinslots[currentlyFilledCoins].AddFill(Time.deltaTime * (1f / Mathf.Clamp(completeFillDuration / (float)currentAmount, minFillDurationPerCoin, completeFillDuration)), currentlyActiveCoinslots.Count - 1 == currentlyFilledCoins))
{
currentlyFilledCoins++;
currentlyFilledCoinsFromLastActiveDisplay = currentlyFilledCoins;
return true;
}
return false;
}
public void Deny()
{
if (!denied)
{
currentlyActiveCoinslots[currentlyFilledCoins].PlayDeny();
ThronefallAudioManager.Instance.MakeSureCoinFillSoundIsNotPlayingAnymore();
denied = true;
}
}
public void OnCompletion()
{
currentlyFilledCoins = 0;
currentlyFilledCoinsFromLastActiveDisplay = 0;
denied = false;
}
public void CancelFill(PlayerInteraction player)
{
foreach (Coinslot currentlyActiveCoinslot in currentlyActiveCoinslots)
{
if (currentlyActiveCoinslot.isFull)
{
Object.Instantiate(coinPrefab, currentlyActiveCoinslot.transform.position, currentlyActiveCoinslot.transform.rotation).SetTarget(player);
}
currentlyActiveCoinslot.SetEmpty();
}
ThronefallAudioManager.Oneshot(ThronefallAudioManager.AudioOneShot.CoinFillCancel);
currentlyFilledCoins = 0;
currentlyFilledCoinsFromLastActiveDisplay = 0;
denied = false;
}
private IEnumerator AnimateShowSlots()
{
float waitTime = 0.2f / (float)currentAmount;
if (currentAmount > maxElementsPerRow)
{
amountDisplayParent.gameObject.SetActive(value: true);
amountDisplay.text = "x" + currentAmount;
displayCostAmountShow.PlayFeedbacks();
yield return new WaitForSeconds(waitTime);
}
foreach (Coinslot currentlyActiveCoinslot in currentlyActiveCoinslots)
{
currentlyActiveCoinslot.Appear();
yield return new WaitForSeconds(waitTime);
}
}
public void Hide()
{
if (base.gameObject.activeSelf && !inDisappearAnimation)
{
inDisappearAnimation = true;
StopAllCoroutines();
StartCoroutine(AnimateHideSlots());
}
}
private IEnumerator AnimateHideSlots()
{
float waitTime = 0.2f / (float)currentAmount;
if (amountDisplay.gameObject.activeInHierarchy)
{
displayCostAmountHide.PlayFeedbacks();
yield return new WaitForSeconds(waitTime);
}
foreach (Coinslot currentlyActiveCoinslot in currentlyActiveCoinslots)
{
currentlyActiveCoinslot.Disappear();
yield return new WaitForSeconds(waitTime);
}
yield return new WaitForSeconds(1f);
inDisappearAnimation = false;
base.gameObject.SetActive(value: false);
}
}
|