|
|
@@ -13,20 +13,23 @@ public class StatsScript : MonoBehaviour {
|
|
|
private Text[] statsTextNames;
|
|
|
private Text[] statsTextValues;
|
|
|
|
|
|
- private List<StatsLine> statLines;
|
|
|
+ private List<StatsLine> statLines = new List<StatsLine>();
|
|
|
|
|
|
GameManagerScript gms;
|
|
|
|
|
|
private void Start() {
|
|
|
- statLines = new List<StatsLine>();
|
|
|
gms = GameObject.Find("GameManager").GetComponent<GameManagerScript>();
|
|
|
CreateStandardStats();
|
|
|
+
|
|
|
+ AddPlayersToStats(gms.GetPlayers());
|
|
|
}
|
|
|
|
|
|
private void CreateStandardStats() {
|
|
|
StatsLine round = CreateStatLine();
|
|
|
round.SetStatName("Round");
|
|
|
- round.SetStatValue("1");
|
|
|
+ int roundValue = gms.GetDatabase().GetRoundValue(gms.GameId);
|
|
|
+
|
|
|
+ round.SetStatValue(roundValue.ToString());
|
|
|
round.name = "roundStat";
|
|
|
|
|
|
StatsLine lostQuestions = CreateStatLine();
|
|
|
@@ -54,7 +57,7 @@ public class StatsScript : MonoBehaviour {
|
|
|
|
|
|
public void AddPlayersToStats(List<KeyValuePair<string, int>> players) {
|
|
|
|
|
|
- foreach (KeyValuePair<string,int> player in players) {
|
|
|
+ foreach (KeyValuePair<string, int> player in players) {
|
|
|
StatsLine p = CreateStatLine();
|
|
|
p.SetStatName(player.Key);
|
|
|
p.SetStatValue(player.Value.ToString());
|
|
|
@@ -63,50 +66,34 @@ public class StatsScript : MonoBehaviour {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void AddTextComponent(GameObject parent, string text, bool alignCenter, int index) {
|
|
|
- GameObject playerHeaderGameObject = new GameObject();
|
|
|
- playerHeaderGameObject.transform.parent = parent.transform;
|
|
|
-
|
|
|
- Text newTextObject = playerHeaderGameObject.AddComponent<Text>();
|
|
|
- newTextObject.text = text;
|
|
|
- newTextObject.font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
|
|
|
- newTextObject.color = new Color32(50, 50, 50, 255);
|
|
|
-
|
|
|
- newTextObject.resizeTextForBestFit = true;
|
|
|
- newTextObject.resizeTextMinSize = 10;
|
|
|
- newTextObject.resizeTextMaxSize = 14;
|
|
|
-
|
|
|
- if (index >= 0) {
|
|
|
- newTextObject.name = "Player" + index;
|
|
|
- }
|
|
|
-
|
|
|
- if (alignCenter) {
|
|
|
- newTextObject.alignment = TextAnchor.MiddleCenter;
|
|
|
- }
|
|
|
-
|
|
|
- RectTransform rectTransform = newTextObject.GetComponent<RectTransform>();
|
|
|
- rectTransform.sizeDelta = new Vector2(0, 15);
|
|
|
- rectTransform.localPosition = new Vector3(0, 0, 0);
|
|
|
- rectTransform.localScale = new Vector3(1, 1, 1);
|
|
|
- }
|
|
|
-
|
|
|
public void IncreaseRoundValue() {
|
|
|
- foreach (Text text in statsTextValues) {
|
|
|
- if (text.name.Equals("Stats Value Round")) {
|
|
|
- Int32.TryParse(text.text, out int round);
|
|
|
+ foreach (StatsLine sl in statLines) {
|
|
|
+ if (sl.GetName().Equals("Round")) {
|
|
|
+ Int32.TryParse(sl.GetValue(), out int round);
|
|
|
round++;
|
|
|
- text.text = round.ToString();
|
|
|
- gms.GetDatabase().SetRoundValue(gms.GameId, round);
|
|
|
+ sl.SetStatValue(round.ToString());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void SetQuestionsInAnswerLine(string playerName, int count) {
|
|
|
- for (int i = 0; i < statsTextNames.Length; i++) {
|
|
|
- if (statsTextNames[i].text.Equals(playerName)) {
|
|
|
- statsTextValues[i].text = count.ToString();
|
|
|
+ public void MakeBold(string playerName) {
|
|
|
+ foreach (StatsLine sl in statLines) {
|
|
|
+ if (sl.GetName().Equals(playerName)) {
|
|
|
+ sl.MakeBold();
|
|
|
+ } else {
|
|
|
+ sl.UnBold();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void SetQuestionsInAnswerLine(string playerName, int count) {
|
|
|
+ foreach (StatsLine sl in statLines) {
|
|
|
+ if (sl.GetName().Equals(playerName)) {
|
|
|
+ sl.SetStatValue(count.ToString()) ;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|