forked from nathan-zaloum/BucketCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextLimitCheck.cs
117 lines (91 loc) · 3.98 KB
/
TextLimitCheck.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Firebase;
using Firebase.Database;
public class TextLimitCheck : MonoBehaviour {
//----------------------------------------------------------------------------------------------------------------------------------------------//
[SerializeField]
private Text display;
[SerializeField]
private InputField input;
[SerializeField]
private Text alert;
[SerializeField]
private Color customRed, customGrey;
private bool nameTaken = false;
public bool validInput = false;
private List<string> takenCircleNames = new List<string> ();
//----------------------------------------------------------------------------------------------------------------------------------------------//
private void Start () {
CheckAbout ();
GetListOfCircles ();
}
//----------------------------------------------------------------------------------------------------------------------------------------------//
public void CheckName () {
GetListOfCircles ();
display.text = input.text.Length.ToString () + "/" + input.characterLimit;
if (input.text.Length == input.characterLimit || input.text.Length < 6) {
display.color = customRed;
} else {
display.color = customGrey;
}
if (input.text.Length < 6) {
alert.text = "Your name is too short, please make it at least 6 characters long.";
alert.color = customRed;
validInput = false;
} else {
if (takenCircleNames.Contains (input.text)) {
alert.text = "This name is already in use by another Circle. Please choose another.";
alert.color = customRed;
validInput = false;
} else {
if (input.text.Length == input.characterLimit) {
alert.text = "Character limit has been reached.";
alert.color = customGrey;
validInput = true;
} else {
alert.text = "";
validInput = true;
}
}
}
}
//----------------------------------------------------------------------------------------------------------------------------------------------//
public void CheckAbout () {
display.text = input.text.Length.ToString () + "/" + input.characterLimit;
if (input.text.Length == input.characterLimit || input.text.Length < 6) {
display.color = customRed;
} else {
display.color = customGrey;
}
if (input.text.Length < 6) {
alert.text = "Your description is too short, please make it at least 6 characters long.";
alert.color = customRed;
validInput = false;
} else {
if (input.text.Length == input.characterLimit) {
alert.text = "Character limit has been reached.";
alert.color = customGrey;
validInput = true;
} else {
alert.text = "";
validInput = true;
}
}
}
//----------------------------------------------------------------------------------------------------------------------------------------------//
private void GetListOfCircles () {
DataRef.AllCirlces ().GetValueAsync ().ContinueWith (async (task) => {
await new WaitForUpdate ();
DataSnapshot snapshot = task.Result;
foreach (DataSnapshot child in snapshot.Children) {
if (!takenCircleNames.Contains (child.Child("Name").Value.ToString ())) {
takenCircleNames.Add (child.Child ("Name").Value.ToString ());
}
}
});
}
//----------------------------------------------------------------------------------------------------------------------------------------------//
}