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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChatController : MonoBehaviour
{
public bool IsOpen
{
get
{
return this.Content.activeInHierarchy;
}
}
public ObjectPoolBehavior chatBubPool;
public Transform TypingArea;
public SpriteRenderer TextBubble;
public TextBox TextArea;
public TextRenderer CharCount;
public int MaxChat = 15;
public Scroller scroller;
public GameObject Content;
public SpriteRenderer BackgroundImage;
public SpriteRenderer ChatNotifyDot;
public TextRenderer SendRateMessage;
public Vector3 SourcePos = new Vector3(0f, 0f, -10f);
public Vector3 TargetPos = new Vector3(-0.35f, 0.02f, -10f);
private const float MaxChatSendRate = 3f;
private float TimeSinceLastMessage = 3f;
public AudioClip MessageSound;
private bool animating;
private Coroutine notificationRoutine;
public BanMenu BanButton;
public void Toggle()
{
PlayerControl localPlayer = PlayerControl.LocalPlayer;
CustomNetworkTransform customNetworkTransform = (localPlayer != null) ? localPlayer.NetTransform : null;
if (this.animating || !customNetworkTransform)
{
return;
}
base.StopAllCoroutines();
if (this.IsOpen)
{
base.StartCoroutine(this.CoClose());
return;
}
this.Content.SetActive(true);
customNetworkTransform.Halt();
base.StartCoroutine(this.CoOpen());
}
public void SetVisible(bool visible)
{
Debug.Log("Chat is hidden: " + visible.ToString());
this.ForceClosed();
base.gameObject.SetActive(visible);
}
public void ForceClosed()
{
base.StopAllCoroutines();
this.Content.SetActive(false);
this.animating = false;
}
public IEnumerator CoOpen()
{
this.animating = true;
Vector3 scale = Vector3.one;
this.BanButton.Hide();
this.BanButton.SetVisible(true);
float targetScale = AspectSize.CalculateSize(base.transform.localPosition, this.BackgroundImage.sprite);
float timer = 0f;
while (timer < 0.15f)
{
timer += Time.deltaTime;
float num = Mathf.SmoothStep(0f, 1f, timer / 0.15f);
scale.y = (scale.x = Mathf.Lerp(0.1f, targetScale, num));
this.Content.transform.localScale = scale;
this.Content.transform.localPosition = Vector3.Lerp(this.SourcePos, this.TargetPos, num) * targetScale;
this.BanButton.transform.localPosition = new Vector3(0f, -num * 0.75f, -20f);
yield return null;
}
this.ChatNotifyDot.enabled = false;
this.animating = false;
this.GiveFocus();
yield break;
}
public IEnumerator CoClose()
{
this.animating = true;
this.BanButton.Hide();
Vector3 scale = Vector3.one;
float targetScale = AspectSize.CalculateSize(base.transform.localPosition, this.BackgroundImage.sprite);
for (float timer = 0f; timer < 0.15f; timer += Time.deltaTime)
{
float num = 1f - Mathf.SmoothStep(0f, 1f, timer / 0.15f);
scale.y = (scale.x = Mathf.Lerp(0.1f, targetScale, num));
this.Content.transform.localScale = scale;
this.Content.transform.localPosition = Vector3.Lerp(this.SourcePos, this.TargetPos, num) * targetScale;
this.BanButton.transform.localPosition = new Vector3(0f, -num * 0.75f, -20f);
yield return null;
}
this.BanButton.SetVisible(false);
this.Content.SetActive(false);
this.animating = false;
yield break;
}
public void SetPosition(MeetingHud meeting)
{
if (meeting)
{
base.transform.SetParent(meeting.transform);
base.transform.localPosition = new Vector3(3.1f, 2.2f, -10f);
return;
}
base.transform.SetParent(DestroyableSingleton<HudManager>.Instance.transform);
base.GetComponent<AspectPosition>().AdjustPosition();
}
public void UpdateCharCount()
{
Vector2 size = this.TextBubble.size;
size.y = Math.Max(0.62f, this.TextArea.TextHeight + 0.2f);
this.TextBubble.size = size;
Vector3 localPosition = this.TextBubble.transform.localPosition;
localPosition.y = (0.62f - size.y) / 2f;
this.TextBubble.transform.localPosition = localPosition;
Vector3 localPosition2 = this.TypingArea.localPosition;
localPosition2.y = -2.08f - localPosition.y * 2f;
this.TypingArea.localPosition = localPosition2;
int length = this.TextArea.text.Length;
this.CharCount.Text = length + "/100";
if (length < 75)
{
this.CharCount.Color = Color.black;
return;
}
if (length < 100)
{
this.CharCount.Color = new Color(1f, 1f, 0f, 1f);
return;
}
this.CharCount.Color = Color.red;
}
private void Update()
{
this.TimeSinceLastMessage += Time.deltaTime;
if (this.SendRateMessage.isActiveAndEnabled)
{
float num = 3f - this.TimeSinceLastMessage;
if (num < 0f)
{
this.SendRateMessage.gameObject.SetActive(false);
return;
}
this.SendRateMessage.Text = string.Format("Too fast. Wait {0} seconds", Mathf.CeilToInt(num));
}
}
public void SendChat()
{
float num = 3f - this.TimeSinceLastMessage;
if (num > 0f)
{
this.SendRateMessage.gameObject.SetActive(true);
this.SendRateMessage.Text = string.Format("Too fast. Wait {0} seconds", Mathf.CeilToInt(num));
return;
}
if (!PlayerControl.LocalPlayer.RpcSendChat(this.TextArea.text))
{
return;
}
this.TimeSinceLastMessage = 0f;
this.TextArea.Clear();
}
public void AddChatNote(GameData.PlayerInfo srcPlayer, ChatNoteTypes noteType)
{
if (srcPlayer == null)
{
return;
}
if (this.chatBubPool.NotInUse == 0)
{
this.chatBubPool.ReclaimOldest();
}
ChatBubble chatBubble = this.chatBubPool.Get<ChatBubble>();
PlayerControl.SetPlayerMaterialColors((int)srcPlayer.ColorId, chatBubble.ChatFace);
chatBubble.transform.SetParent(this.scroller.Inner);
chatBubble.transform.localScale = Vector3.one;
chatBubble.SetNotification();
if (noteType == ChatNoteTypes.DidVote)
{
int votesRemaining = MeetingHud.Instance.GetVotesRemaining();
chatBubble.SetName(string.Format("{0} has voted. {1} remaining.", srcPlayer.PlayerName, votesRemaining), false, true, Color.green);
}
chatBubble.TextArea.RefreshMesh();
chatBubble.Background.size = new Vector2(5.52f, 0.2f + chatBubble.NameText.Height);
Vector3 localPosition = chatBubble.Background.transform.localPosition;
localPosition.y = chatBubble.NameText.transform.localPosition.y - chatBubble.Background.size.y / 2f + 0.05f;
chatBubble.Background.transform.localPosition = localPosition;
this.AlignAllBubbles();
if (!this.IsOpen && this.notificationRoutine == null)
{
this.notificationRoutine = base.StartCoroutine(this.BounceDot());
}
if (srcPlayer.Object != PlayerControl.LocalPlayer)
{
SoundManager.Instance.PlaySound(this.MessageSound, false, 1f).pitch = 0.5f + (float)srcPlayer.PlayerId / 10f;
}
}
public void AddChat(PlayerControl sourcePlayer, string chatText)
{
if (!sourcePlayer || !PlayerControl.LocalPlayer)
{
return;
}
GameData.PlayerInfo data = PlayerControl.LocalPlayer.Data;
GameData.PlayerInfo data2 = sourcePlayer.Data;
if (data2 == null || data == null || (data2.IsDead && !data.IsDead))
{
return;
}
if (this.chatBubPool.NotInUse == 0)
{
this.chatBubPool.ReclaimOldest();
}
ChatBubble chatBubble = this.chatBubPool.Get<ChatBubble>();
try
{
chatBubble.transform.SetParent(this.scroller.Inner);
chatBubble.transform.localScale = Vector3.one;
bool flag = sourcePlayer == PlayerControl.LocalPlayer;
if (flag)
{
chatBubble.SetRight();
}
else
{
chatBubble.SetLeft();
}
bool flag2 = data.IsImpostor && data2.IsImpostor;
bool voted = MeetingHud.Instance && MeetingHud.Instance.DidVote(sourcePlayer.PlayerId);
PlayerControl.SetPlayerMaterialColors((int)data2.ColorId, chatBubble.ChatFace);
chatBubble.SetName(data2.PlayerName, data2.IsDead, voted, flag2 ? Palette.ImpostorRed : Color.white);
if (SaveManager.CensorChat)
{
chatText = BlockedWords.CensorWords(chatText);
}
chatBubble.TextArea.Text = chatText;
chatBubble.TextArea.RefreshMesh();
chatBubble.Background.size = new Vector2(5.52f, 0.2f + chatBubble.NameText.Height + chatBubble.TextArea.Height);
Vector3 localPosition = chatBubble.Background.transform.localPosition;
localPosition.y = chatBubble.NameText.transform.localPosition.y - chatBubble.Background.size.y / 2f + 0.05f;
chatBubble.Background.transform.localPosition = localPosition;
this.AlignAllBubbles();
if (!this.IsOpen && this.notificationRoutine == null)
{
this.notificationRoutine = base.StartCoroutine(this.BounceDot());
}
if (!flag)
{
SoundManager.Instance.PlaySound(this.MessageSound, false, 1f).pitch = 0.5f + (float)sourcePlayer.PlayerId / 10f;
}
}
catch
{
this.chatBubPool.Reclaim(chatBubble);
}
}
private void AlignAllBubbles()
{
float num = 0f;
List<PoolableBehavior> activeChildren = this.chatBubPool.activeChildren;
for (int i = activeChildren.Count - 1; i >= 0; i--)
{
ChatBubble chatBubble = activeChildren[i] as ChatBubble;
num += chatBubble.Background.size.y;
Vector3 localPosition = chatBubble.transform.localPosition;
localPosition.y = -1.85f + num;
chatBubble.transform.localPosition = localPosition;
num += 0.1f;
}
this.scroller.YBounds.min = Mathf.Min(0f, -num + this.scroller.HitBox.bounds.size.y);
}
private IEnumerator BounceDot()
{
this.ChatNotifyDot.enabled = true;
yield return Effects.Bounce(this.ChatNotifyDot.transform, 0.3f, 0.15f);
this.notificationRoutine = null;
yield break;
}
public void GiveFocus()
{
this.TextArea.GiveFocus();
}
}
|