Browse Source

Frosting on answerline change

Axel Nordh 5 years ago
parent
commit
98223ab665

+ 12 - 0
Assets/AnswerLineInfoPlayerButton.cs

@@ -0,0 +1,12 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class AnswerLineInfoPlayerButton : MonoBehaviour
+{
+    string playerName;
+    string buttonText;
+
+    public string PlayerName { get => playerName; set => playerName = value; }
+    public string ButtonText { get => buttonText; set => buttonText = value; }
+}

+ 11 - 0
Assets/AnswerLineInfoPlayerButton.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6359c2345490ab142a0615d06d95fe22
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 78 - 9
Assets/AnswerLineInfoScript.cs

@@ -3,6 +3,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
+using System.Linq;
 
 public class AnswerLineInfoScript : MonoBehaviour
 {
@@ -12,21 +13,38 @@ public class AnswerLineInfoScript : MonoBehaviour
     [SerializeField] Text lockedQuestionsText;
     [SerializeField] Text unlockedQuestionsText;
     [SerializeField] GameObject scrollView;
+    [SerializeField] GameObject answerLine;
+    [SerializeField] GameObject newQuestion;
 
     [SerializeField] GameObject gameManager;
-    private void Start() {
-        nextPlayerButton.onClick.AddListener(ShowPrevPlayerAnswerLine);
-        prevPlayerButton.onClick.AddListener(ShoeNextPlayerAnswerLine);
+    private List<KeyValuePair<string, int>> players;
+    private string currentPlayerShown;
 
+    private void Start() {
+        nextPlayerButton.onClick.AddListener(ShowNextPlayerAnswerLine);
+        prevPlayerButton.onClick.AddListener(ShowPrevPlayerAnswerLine);
+        currentPlayerShown = GameManagerScript.GetCurrentPlayer();
     }
 
     private void Update() {
         UpdateLockedQuestionsText();
-        UpdateUnlockedQuestionsText();        
+        UpdateUnlockedQuestionsText();
+        UpdateButtonsText(); 
+        SetQuestionClickable();
+    }
+
+    private void SetQuestionClickable() {
+        if (GameManagerScript.GetCurrentPlayer().Equals(currentPlayerShown)) {
+            newQuestion.GetComponent<NewQuestionCardController>().BackClickable = true;
+        } else {
+            newQuestion.GetComponent<NewQuestionCardController>().BackClickable = false;
+        }
     }
 
     public void UpdateButtonsText() {
-        List<KeyValuePair<string, int>> players = gameManager.GetComponent<GameManagerScript>().GetPlayers();
+        if (players == null) {
+            players = gameManager.GetComponent<GameManagerScript>().GetPlayers();
+        }
 
         if (players.Count <= 1) {
             nextPlayerButton.gameObject.SetActive(false);
@@ -34,6 +52,36 @@ public class AnswerLineInfoScript : MonoBehaviour
         } else {
             nextPlayerButton.gameObject.SetActive(true);
             prevPlayerButton.gameObject.SetActive(true);
+
+            if (currentPlayerShown == null) {
+                currentPlayerShown = GameManagerScript.GetCurrentPlayer();
+            }
+
+            string playerBaseText = LocalizationManager.Instance.GetText("ANSWERLINE_OTHER_PLAYER");
+            for (int i = 0; i < players.Count; i++) {
+                if (players[i].Key.Equals(currentPlayerShown, StringComparison.InvariantCultureIgnoreCase)) {
+                    if (i + 1 < players.Count) {
+                        nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[i+1].Key;
+                        nextPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[i + 1].Key);
+                        if (i - 1 > 0) {
+                            
+                            prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[i-1].Key;
+                            prevPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[i - 1].Key);
+                        } else {
+                            prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[players.Count-1].Key;
+                            prevPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[players.Count - 1].Key);
+                        }
+                        break;
+                    } else {
+                        nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[0].Key;
+                        nextPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[0].Key);
+                        
+                        prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName = players[i-1].Key;
+                        prevPlayerButton.GetComponentInChildren<Text>().text = String.Format(playerBaseText ,players[i - 1].Key);
+                        break;
+                    }
+                }
+            }
         }
     }
 
@@ -60,13 +108,34 @@ public class AnswerLineInfoScript : MonoBehaviour
             lockedQuestionsCount);
     }
 
-    private void ShoeNextPlayerAnswerLine()
+    private void ShowNextPlayerAnswerLine()
     {
-        throw new NotImplementedException();
+        GameManagerScript gameManagerScript = gameManager.GetComponent<GameManagerScript>();
+        List<NewQuestionData> playerQuestions = Database.Instance.GetPlayerQuestions(gameManagerScript.GameId, nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName, gameManagerScript.GameMode);
+
+        currentPlayerShown = nextPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName;
+        setQuestionFrosting(playerQuestions);
+        UpdateButtonsText();
     }
 
     private void ShowPrevPlayerAnswerLine()
-    {
-        throw new NotImplementedException();
+    {       
+        GameManagerScript gameManagerScript = gameManager.GetComponent<GameManagerScript>();
+        List<NewQuestionData> playerQuestions = Database.Instance.GetPlayerQuestions(gameManagerScript.GameId, prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName, gameManagerScript.GameMode);
+        
+        currentPlayerShown = prevPlayerButton.GetComponent<AnswerLineInfoPlayerButton>().PlayerName;
+        setQuestionFrosting(playerQuestions);
+        UpdateButtonsText();
+    }
+
+    private void setQuestionFrosting(List<NewQuestionData> questions) {
+        ScrollViewScript scrollViewScript = scrollView.GetComponent<ScrollViewScript>();
+        scrollViewScript.RemoveEverythingFromAnswerline();
+        scrollViewScript.SetQuestionsInAnswerLine(questions);
+        if (GameManagerScript.GetCurrentPlayer().Equals(currentPlayerShown)) {
+            scrollViewScript.SetQuestionsFrosted(false);
+        } else {
+            scrollViewScript.SetQuestionsFrosted(true);
+        }
     }
 }

+ 30 - 2
Assets/Scenes/narKampen.unity

@@ -662,6 +662,8 @@ MonoBehaviour:
   lockedQuestionsText: {fileID: 1835093814}
   unlockedQuestionsText: {fileID: 1312570246}
   scrollView: {fileID: 1776196329}
+  answerLine: {fileID: 189632753}
+  newQuestion: {fileID: 3144502739437957925}
   gameManager: {fileID: 225506176}
 --- !u!114 &210243976
 MonoBehaviour:
@@ -676,7 +678,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   m_Material: {fileID: 0}
-  m_Color: {r: 1, g: 1, b: 1, a: 0.392}
+  m_Color: {r: 1, g: 1, b: 1, a: 0.78431374}
   m_RaycastTarget: 1
   m_Maskable: 1
   m_OnCullStateChanged:
@@ -1015,6 +1017,7 @@ GameObject:
   - component: {fileID: 343030765}
   - component: {fileID: 343030764}
   - component: {fileID: 343030763}
+  - component: {fileID: 343030767}
   m_Layer: 5
   m_Name: PrevPlayerButton
   m_TagString: Untagged
@@ -1135,6 +1138,18 @@ CanvasRenderer:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 343030761}
   m_CullTransparentMesh: 0
+--- !u!114 &343030767
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 343030761}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 6359c2345490ab142a0615d06d95fe22, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
 --- !u!1 &347087711
 GameObject:
   m_ObjectHideFlags: 0
@@ -1696,7 +1711,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   m_Material: {fileID: 0}
-  m_Color: {r: 1, g: 1, b: 1, a: 0.392}
+  m_Color: {r: 1, g: 1, b: 1, a: 0}
   m_RaycastTarget: 1
   m_Maskable: 1
   m_OnCullStateChanged:
@@ -3375,6 +3390,7 @@ GameObject:
   - component: {fileID: 1572950266}
   - component: {fileID: 1572950265}
   - component: {fileID: 1572950264}
+  - component: {fileID: 1572950268}
   m_Layer: 5
   m_Name: NextPlayerButton
   m_TagString: Untagged
@@ -3495,6 +3511,18 @@ CanvasRenderer:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1572950262}
   m_CullTransparentMesh: 0
+--- !u!114 &1572950268
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1572950262}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 6359c2345490ab142a0615d06d95fe22, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
 --- !u!1 &1737439049
 GameObject:
   m_ObjectHideFlags: 0

+ 102 - 102
Assets/Scripts/MainGame/NewQuestionCardController.cs

@@ -1,102 +1,102 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using UnityEngine.EventSystems;
-using UnityEngine.UI;
-
-
-public class NewQuestionCardController : MonoBehaviour, IPointerClickHandler {
-
-    public GameObject cardBack;
-    public GameObject cardFront;
-
-    public GameObject NewQuestionCard;
-
-    bool rotateDone = true;
-    bool backClickable = true;
-
-    [SerializeField] GameObject startParent;
-    [SerializeField] GameObject gameManager;
-
-    public bool BackClickable { get => backClickable; set => backClickable = value; }
-
-    public void OnPointerClick(PointerEventData eventData) {
-        if (cardBack.activeSelf && rotateDone && BackClickable)
-        {
-            RotateCard();
-        }
-    }
-
-    public void RotateCard()
-    {
-        StartCoroutine(Rotate(new Vector3(0, 90f, 0), 0.5f));
-        StartCoroutine(secondRotation());
-        StartCoroutine(startTimer());
-    }
-
-    private IEnumerator startTimer()
-    {
-        while (!rotateDone) {
-            yield return new WaitForSeconds(0.1f);
-        }
-        GameObject.Find("GameManager").GetComponent<GameManagerScript>().StartTimer();
-    }
-
-    public bool getRotationDone() {
-        return rotateDone;
-    }
-    private IEnumerator secondRotation() {
-        while (!rotateDone) {
-            yield return new WaitForSeconds(0.1f);
-        }
-        cardBack.SetActive(false);
-        cardFront.SetActive(true);
-        transform.Rotate(0, 180, 0);
-        StartCoroutine(Rotate(new Vector3(0, 90f,0 ), 0.5f));
-    }
-
-    private IEnumerator Rotate(Vector3 angle, float duration = 1.0f) {
-        rotateDone = false;
-        Quaternion from = transform.rotation;
-        Quaternion to = Quaternion.Euler(angle) * from;
-
-        float elapsed = 0.0f;
-        while (elapsed < duration) {
-            transform.rotation = Quaternion.Slerp(from, to, elapsed / duration);
-            elapsed += Time.deltaTime;
-            yield return null;
-        }
-        transform.rotation = to;
-        rotateDone = true;
-    }
-
-    private void ShowBackside() {
-        cardBack.SetActive(true);
-        cardFront.SetActive(false);
-    }
-
-    public void GenerateNewQuestion() {
-        KeyValuePair<int, string> SignedInUser = Database.Instance.GetSignedInUser();
-        string currentPlayer = GameManagerScript.GetCurrentPlayer();
-
-        resetPosition();
-        ShowBackside();
-        string gameMode = gameManager.GetComponent<GameManagerScript>().GetGameMode();
-        if (gameMode.Equals("Online")) {
-            if (currentPlayer.Equals(SignedInUser.Value, StringComparison.InvariantCultureIgnoreCase)) {
-                BackClickable = true;
-            } else {
-                BackClickable = false;
-            }
-        } else {
-            BackClickable =  true;
-        }
-        transform.parent.GetComponent<NewQuestionsPanel>().generateNewQuestion(BackClickable);
-    }
-
-    private void resetPosition() {
-        transform.SetParent(startParent.transform);
-        transform.localPosition = Vector3.zero;
-    }
-}
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.EventSystems;
+using UnityEngine.UI;
+
+
+public class NewQuestionCardController : MonoBehaviour, IPointerClickHandler {
+
+    public GameObject cardBack;
+    public GameObject cardFront;
+
+    public GameObject NewQuestionCard;
+
+    bool rotateDone = true;
+    bool backClickable = true;
+
+    [SerializeField] GameObject startParent;
+    [SerializeField] GameObject gameManager;
+
+    public bool BackClickable { get => backClickable; set => backClickable = value; }
+
+    public void OnPointerClick(PointerEventData eventData) {
+        if (cardBack.activeSelf && rotateDone && BackClickable)
+        {
+            RotateCard();
+        }
+    }
+
+    public void RotateCard()
+    {
+        StartCoroutine(Rotate(new Vector3(0, 90f, 0), 0.5f));
+        StartCoroutine(secondRotation());
+        StartCoroutine(startTimer());
+    }
+
+    private IEnumerator startTimer()
+    {
+        while (!rotateDone) {
+            yield return new WaitForSeconds(0.1f);
+        }
+        GameObject.Find("GameManager").GetComponent<GameManagerScript>().StartTimer();
+    }
+
+    public bool getRotationDone() {
+        return rotateDone;
+    }
+    private IEnumerator secondRotation() {
+        while (!rotateDone) {
+            yield return new WaitForSeconds(0.1f);
+        }
+        cardBack.SetActive(false);
+        cardFront.SetActive(true);
+        transform.Rotate(0, 180, 0);
+        StartCoroutine(Rotate(new Vector3(0, 90f,0 ), 0.5f));
+    }
+
+    private IEnumerator Rotate(Vector3 angle, float duration = 1.0f) {
+        rotateDone = false;
+        Quaternion from = transform.rotation;
+        Quaternion to = Quaternion.Euler(angle) * from;
+
+        float elapsed = 0.0f;
+        while (elapsed < duration) {
+            transform.rotation = Quaternion.Slerp(from, to, elapsed / duration);
+            elapsed += Time.deltaTime;
+            yield return null;
+        }
+        transform.rotation = to;
+        rotateDone = true;
+    }
+
+    private void ShowBackside() {
+        cardBack.SetActive(true);
+        cardFront.SetActive(false);
+    }
+
+    public void GenerateNewQuestion() {
+        KeyValuePair<int, string> SignedInUser = Database.Instance.GetSignedInUser();
+        string currentPlayer = GameManagerScript.GetCurrentPlayer();
+
+        resetPosition();
+        ShowBackside();
+        string gameMode = gameManager.GetComponent<GameManagerScript>().GetGameMode();
+        if (gameMode.Equals("Online")) {
+            if (currentPlayer.Equals(SignedInUser.Value, StringComparison.InvariantCultureIgnoreCase)) {
+                BackClickable = true;
+            } else {
+                BackClickable = false;
+            }
+        } else {
+            BackClickable =  true;
+        }
+        transform.parent.GetComponent<NewQuestionsPanel>().generateNewQuestion(BackClickable);
+    }
+
+    private void resetPosition() {
+        transform.SetParent(startParent.transform);
+        transform.localPosition = Vector3.zero;
+    }
+}

+ 256 - 251
Assets/Scripts/MainGame/ScrollViewScript.cs

@@ -1,251 +1,256 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using UnityEngine.EventSystems;
-using UnityEngine.UI;
-using System.Linq;
-
-public class ScrollViewScript : MonoBehaviour {
-    private const string newQuestionAnswerLineDefault = "???? - ????";
-    public GameObject answerlineQuestionPrefab;
-    public Transform contentPanel;
-    public Transform newQuestionsPanel;
-
-    private int newQuestionSiblingIndex;
-    private bool answeredCorrectly;
-    private List<KeyValuePair<string, int>> players;
-    private int gameId;
-    private string gameMode;
-
-    private bool sizeUpdated = false;
-    StatsScript statsScript;
-    GameManagerScript gameManagerScript;
-    TimerScript ts;
-
-    InformationPanelScript ips;
-
-    public string currentPlayer;
-
-    // Start is called before the first frame update
-    void Start() {
-        statsScript = GameObject.Find("StatsPanel").GetComponent<StatsScript>();
-        gameManagerScript = GameObject.Find("GameManager").GetComponent<GameManagerScript>();
-        ts = GameObject.Find("TimerCircle").GetComponent<TimerScript>();
-        players = gameManagerScript.GetPlayers();
-
-        EventManager.StartListening("TimerEvent", TimerRunOutEvent);
-        gameId = gameManagerScript.GameId;
-        currentPlayer = Database.Instance.GetCurrentPlayer(gameId, GetGameMode());
-
-        statsScript.MakeBold(currentPlayer);
-
-        List<NewQuestionData> answerlineQuestions = Database.Instance.GetPlayerQuestions(gameId, currentPlayer, GetGameMode());
-        if (Database.Instance.GetRoundValue(gameId, GetGameMode()) > 1) {
-            SetQuestionsInAnswerLine(answerlineQuestions);
-        }
-
-        statsScript.SetQuestionsLost(Database.Instance.GetQuestionsLost(gameId, currentPlayer, GetGameMode()));
-    }
-
-    private void Update() {
-        if (!sizeUpdated){
-            UpdateAnswerlineCardSize();
-        }
-    }
-
-    public string GetGameMode() {
-        if (gameMode == null) {
-            gameMode = PlayerPrefs.GetString("GameMode");
-        }
-        return gameMode;
-    }
-
-[SerializeField] GameObject leftDropZone;
-[SerializeField] GameObject rightDropZone;
-[SerializeField] GameObject middleDropZone;
-    public void SetQuestionsInAnswerLine(List<NewQuestionData> questions) {
-        int i = 0;
-
-        RectTransform newQuestionRect = GameObject.Find("NewQuestion").GetComponent<RectTransform>();
-        GameObject ldz = Instantiate(leftDropZone,Vector2.zero, Quaternion.identity);
-        GameObject rdz = Instantiate(rightDropZone,Vector2.zero, Quaternion.identity);
-        ldz.transform.SetParent(contentPanel);
-        ldz.transform.SetSiblingIndex(i++);
-        ldz.transform.localScale = new Vector3(1,1,1);
-        if (newQuestionRect.rect.width < 50f) {
-            ldz.GetComponent<LayoutElement>().preferredWidth = 50f;
-        } else {
-            ldz.GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
-        }
-
-        KeyValuePair<int, string> signedInUser = Database.Instance.GetSignedInUser();
-        foreach (NewQuestionData q in questions) {
-            GameObject answerLineQuestion = Instantiate(answerlineQuestionPrefab, Vector3.zero, Quaternion.identity);
-            answerLineQuestion.transform.SetParent(contentPanel, false);
-            answerLineQuestion.transform.SetSiblingIndex(i++);
-            answerLineQuestion.transform.localScale = new Vector3(1,1,1);
-            answerLineQuestion.GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
-            answerLineQuestion.GetComponent<LayoutElement>().preferredHeight = newQuestionRect.rect.height;
-
-            QuestionCard answerLineQuestionCard = answerLineQuestion.GetComponent<QuestionCard>();
-            answerLineQuestionCard.SetAnswerText(q.Answer);
-            answerLineQuestionCard.SetQuestionText(q.Question);
-            answerLineQuestionCard.SetId(q.Id);
-            answerLineQuestionCard.SetQuestionSafe();
-            answerLineQuestionCard.SetBackCategoryText(q.CategoryName);
-            answerLineQuestionCard.SetQuestionCategoryColor(q.CategoryColor);
-
-            if (gameMode.Equals("Online")) {
-                if (signedInUser.Value.Equals(GameManagerScript.GetCurrentPlayer(), StringComparison.InvariantCultureIgnoreCase)) {
-                    answerLineQuestionCard.SetFrostingActive(false);
-                } else {
-                    answerLineQuestionCard.SetFrostingActive(true);
-                }
-            }
-
-            GameObject mdz = Instantiate(middleDropZone, Vector3.zero, Quaternion.identity);
-            mdz.transform.SetParent(contentPanel);
-            mdz.transform.SetSiblingIndex(i++);
-            mdz.transform.localScale = new Vector3(1,1,1);
-        }
-
-        NewDropZoneScript newDropZoneScript = contentPanel.GetChild(i-1).GetComponent<NewDropZoneScript>();
-        Destroy(newDropZoneScript.gameObject);
-
-        rdz.transform.SetParent(contentPanel);
-        rdz.transform.SetSiblingIndex(i);
-        rdz.transform.localScale = new Vector3(1,1,1);
-        if (newQuestionRect.rect.width < 50f) {
-            rdz.GetComponent<LayoutElement>().preferredWidth = 50f;
-        } else {
-            rdz.GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
-        }
-        SetAllQuestionsLocked(false);
-    }
-
-    private void UpdateAnswerlineCardSize() {
-        RectTransform newQuestionRect = GameObject.Find("NewQuestion").GetComponent<RectTransform>();
-        List<QuestionCard> questions = contentPanel.GetComponentsInChildren<QuestionCard>().ToList();
-
-        foreach (QuestionCard q in questions) {
-            q.GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
-            q.GetComponent<LayoutElement>().preferredHeight = newQuestionRect.rect.height;
-        }
-
-        if (contentPanel.childCount > 0) {
-            contentPanel.GetChild(0).GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
-            contentPanel.GetChild(contentPanel.childCount -1).GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
-        }
-
-        if (questions.Count > 0 && questions[0].GetComponent<LayoutElement>().preferredWidth >= 0) {
-            sizeUpdated = true;
-        }
-    }
-
-    public int GetUnlockedQuestionCount() {
-        return contentPanel.GetComponentsInChildren<QuestionCard>().Where(q => !q.IsQuestionSafe()).ToArray().Length;;
-    }
-
-    public void SetAllQuestionsLocked(bool needsSave) {
-        List<int> saveQuestions = new List<int>();
-        AnswerLineQuestionCard[] answerLineQuestionCards = contentPanel.GetComponentsInChildren<AnswerLineQuestionCard>();
-        foreach (var questionCard in answerLineQuestionCards)
-        {
-            if (needsSave && !questionCard.IsQuestionSafe()) {
-                saveQuestions.Add(questionCard.GetId());
-                questionCard.SetQuestionSafe();
-            }
-        }
-
-        if (saveQuestions.Count > 0) {
-            Database.Instance.SavePlayersQuestion(saveQuestions, GameManagerScript.GetCurrentPlayer(), gameId, GetGameMode());
-        }
-    }
-
-     public List<int> GetQuestionIdsInAnswerLine() {
-        List<int> questionIds = new List<int>();
-
-        foreach (AnswerLineQuestionCard q in contentPanel.GetComponentsInChildren<AnswerLineQuestionCard>()) {
-            questionIds.Add(q.GetId());
-        }
-
-        return questionIds;
-    }
-
-    public void RemoveEverythingFromAnswerline() {
-        
-        foreach (Transform child in contentPanel.transform) {
-            Destroy(child.gameObject);
-        }
-    }
-
-    public void RemoveUnlockedQuestions() {
-        int lostQuestions = 0;
-        AnswerLineQuestionCard[] answerLineQuestionCards = contentPanel.GetComponentsInChildren<AnswerLineQuestionCard>();
-
-        foreach (AnswerLineQuestionCard aq in answerLineQuestionCards)
-        {
-            if (!aq.IsQuestionSafe()){
-                lostQuestions++;
-                aq.transform.SetParent(null);
-                Destroy(aq);
-                Destroy(aq.gameObject);
-            }
-        }
-        gameManagerScript.UpdateQuestiosLost(lostQuestions, currentPlayer);
-        statsScript.SetQuestionsInAnswerLine(currentPlayer, contentPanel.GetComponents<AnswerLineQuestionCard>().Length);
-    }
-
- 
-
-    void TimerRunOutEvent() { // Should be moved to some gameController
-        ts.StopTimer();
-        GenericDialog dialog = GenericDialog.Instance();
-        string message = LocalizationManager.Instance.GetText("TIMER_DIALOG_MESSAGE");
-        dialog.SetTitle(LocalizationManager.Instance.GetText("TIMER_DIALOG_TITLE"));
-        dialog.SetMessage(String.Format(message, GetUnlockedQuestionCount()));
-        dialog.SetOnAccept(LocalizationManager.Instance.GetText("OK"), () => {
-            RemoveUnlockedQuestions();
-            ts.ResetTimer();
-            dialog.Hide();
-            NextPlayer();
-        });
-        dialog.SetOnDecline("", () => dialog.Hide());
-        dialog.Show();
-
-    }
-
-    public void NextPlayer() {
-        for (int i = 0; i < players.Count; i++) {
-            if (players[i].Key.Equals(currentPlayer, StringComparison.InvariantCultureIgnoreCase)) {
-                if (i + 1 < players.Count) {
-                    currentPlayer = players[i + 1].Key;
-                    break;
-                } else {
-                    currentPlayer = players[0].Key;
-                    statsScript.IncreaseRoundValue();
-                    break;
-                }
-            }
-        }
-        
-        GenericDialog dialog = GenericDialog.Instance();
-        dialog.SetTitle(LocalizationManager.Instance.GetText("NEXT_PLAYER_DIALOG_TITLE"));
-        string message = LocalizationManager.Instance.GetText("NEXT_PLAYER_DIALOG_MESSAGE");
-        dialog.SetMessage(String.Format(message, currentPlayer));
-        dialog.SetOnAccept(LocalizationManager.Instance.GetText("OK"), () => {
-            RemoveEverythingFromAnswerline();
-            List<NewQuestionData> questions = Database.Instance.GetPlayerQuestions(gameId, currentPlayer, GetGameMode());
-            SetQuestionsInAnswerLine(questions);
-
-            statsScript.SetQuestionsLost(Database.Instance.GetQuestionsLost(gameManagerScript.GameId, currentPlayer, GetGameMode()));
-
-            statsScript.MakeBold(currentPlayer);
-            Database.Instance.SetCurrentPlayer(gameId, currentPlayer, GetGameMode());
-            dialog.Hide();
-        });
-        dialog.SetOnDecline("", () => dialog.Hide());
-        dialog.Show();
-    }
-}
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.EventSystems;
+using UnityEngine.UI;
+using System.Linq;
+
+public class ScrollViewScript : MonoBehaviour {
+    private const string newQuestionAnswerLineDefault = "???? - ????";
+    public GameObject answerlineQuestionPrefab;
+    public Transform contentPanel;
+    public Transform newQuestionsPanel;
+
+    private int newQuestionSiblingIndex;
+    private bool answeredCorrectly;
+    private List<KeyValuePair<string, int>> players;
+    private int gameId;
+    private string gameMode;
+
+    private bool sizeUpdated = false;
+    StatsScript statsScript;
+    GameManagerScript gameManagerScript;
+    TimerScript ts;
+
+    InformationPanelScript ips;
+
+    public string currentPlayer;
+
+    // Start is called before the first frame update
+    void Start() {
+        statsScript = GameObject.Find("StatsPanel").GetComponent<StatsScript>();
+        gameManagerScript = GameObject.Find("GameManager").GetComponent<GameManagerScript>();
+        ts = GameObject.Find("TimerCircle").GetComponent<TimerScript>();
+        players = gameManagerScript.GetPlayers();
+
+        EventManager.StartListening("TimerEvent", TimerRunOutEvent);
+        gameId = gameManagerScript.GameId;
+        currentPlayer = Database.Instance.GetCurrentPlayer(gameId, GetGameMode());
+
+        statsScript.MakeBold(currentPlayer);
+
+        List<NewQuestionData> answerlineQuestions = Database.Instance.GetPlayerQuestions(gameId, currentPlayer, GetGameMode());
+        if (Database.Instance.GetRoundValue(gameId, GetGameMode()) > 1) {
+            SetQuestionsInAnswerLine(answerlineQuestions);
+        }
+
+        statsScript.SetQuestionsLost(Database.Instance.GetQuestionsLost(gameId, currentPlayer, GetGameMode()));
+    }
+
+    private void Update() {
+        if (!sizeUpdated){
+            UpdateAnswerlineCardSize();
+        }
+    }
+
+    public string GetGameMode() {
+        if (gameMode == null) {
+            gameMode = PlayerPrefs.GetString("GameMode");
+        }
+        return gameMode;
+    }
+
+[SerializeField] GameObject leftDropZone;
+[SerializeField] GameObject rightDropZone;
+[SerializeField] GameObject middleDropZone;
+    public void SetQuestionsInAnswerLine(List<NewQuestionData> questions) {
+        int i = 0;
+
+        RectTransform newQuestionRect = GameObject.Find("NewQuestion").GetComponent<RectTransform>();
+        GameObject ldz = Instantiate(leftDropZone,Vector2.zero, Quaternion.identity);
+        GameObject rdz = Instantiate(rightDropZone,Vector2.zero, Quaternion.identity);
+        ldz.transform.SetParent(contentPanel);
+        ldz.transform.SetSiblingIndex(i++);
+        ldz.transform.localScale = new Vector3(1,1,1);
+        if (newQuestionRect.rect.width < 50f) {
+            ldz.GetComponent<LayoutElement>().preferredWidth = 50f;
+        } else {
+            ldz.GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
+        }
+
+        KeyValuePair<int, string> signedInUser = Database.Instance.GetSignedInUser();
+        foreach (NewQuestionData q in questions) {
+            GameObject answerLineQuestion = Instantiate(answerlineQuestionPrefab, Vector3.zero, Quaternion.identity);
+            answerLineQuestion.transform.SetParent(contentPanel, false);
+            answerLineQuestion.transform.SetSiblingIndex(i++);
+            answerLineQuestion.transform.localScale = new Vector3(1,1,1);
+            answerLineQuestion.GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
+            answerLineQuestion.GetComponent<LayoutElement>().preferredHeight = newQuestionRect.rect.height;
+
+            QuestionCard answerLineQuestionCard = answerLineQuestion.GetComponent<QuestionCard>();
+            answerLineQuestionCard.SetAnswerText(q.Answer);
+            answerLineQuestionCard.SetQuestionText(q.Question);
+            answerLineQuestionCard.SetId(q.Id);
+            answerLineQuestionCard.SetQuestionSafe();
+            answerLineQuestionCard.SetBackCategoryText(q.CategoryName);
+            answerLineQuestionCard.SetQuestionCategoryColor(q.CategoryColor);
+
+            if (gameMode.Equals("Online")) {
+                if (signedInUser.Value.Equals(GameManagerScript.GetCurrentPlayer(), StringComparison.InvariantCultureIgnoreCase)) {
+                    answerLineQuestionCard.SetFrostingActive(false);
+                } else {
+                    answerLineQuestionCard.SetFrostingActive(true);
+                }
+            }
+
+            GameObject mdz = Instantiate(middleDropZone, Vector3.zero, Quaternion.identity);
+            mdz.transform.SetParent(contentPanel);
+            mdz.transform.SetSiblingIndex(i++);
+            mdz.transform.localScale = new Vector3(1,1,1);
+        }
+
+        NewDropZoneScript newDropZoneScript = contentPanel.GetChild(i-1).GetComponent<NewDropZoneScript>();
+        Destroy(newDropZoneScript.gameObject);
+
+        rdz.transform.SetParent(contentPanel);
+        rdz.transform.SetSiblingIndex(i);
+        rdz.transform.localScale = new Vector3(1,1,1);
+        if (newQuestionRect.rect.width < 50f) {
+            rdz.GetComponent<LayoutElement>().preferredWidth = 50f;
+        } else {
+            rdz.GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
+        }
+        SetAllQuestionsLocked(false);
+    }
+
+    internal void SetQuestionsFrosted(bool frost) {
+        List<QuestionCard> questions = contentPanel.GetComponentsInChildren<QuestionCard>().ToList();
+        questions.ForEach(q => q.SetFrostingActive(frost));
+    }
+
+    private void UpdateAnswerlineCardSize() {
+        RectTransform newQuestionRect = GameObject.Find("NewQuestion").GetComponent<RectTransform>();
+        List<QuestionCard> questions = contentPanel.GetComponentsInChildren<QuestionCard>().ToList();
+
+        foreach (QuestionCard q in questions) {
+            q.GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
+            q.GetComponent<LayoutElement>().preferredHeight = newQuestionRect.rect.height;
+        }
+
+        if (contentPanel.childCount > 0) {
+            contentPanel.GetChild(0).GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
+            contentPanel.GetChild(contentPanel.childCount -1).GetComponent<LayoutElement>().preferredWidth = newQuestionRect.rect.width;
+        }
+
+        if (questions.Count > 0 && questions[0].GetComponent<LayoutElement>().preferredWidth >= 0) {
+            sizeUpdated = true;
+        }
+    }
+
+    public int GetUnlockedQuestionCount() {
+        return contentPanel.GetComponentsInChildren<QuestionCard>().Where(q => !q.IsQuestionSafe()).ToArray().Length;;
+    }
+
+    public void SetAllQuestionsLocked(bool needsSave) {
+        List<int> saveQuestions = new List<int>();
+        AnswerLineQuestionCard[] answerLineQuestionCards = contentPanel.GetComponentsInChildren<AnswerLineQuestionCard>();
+        foreach (var questionCard in answerLineQuestionCards)
+        {
+            if (needsSave && !questionCard.IsQuestionSafe()) {
+                saveQuestions.Add(questionCard.GetId());
+                questionCard.SetQuestionSafe();
+            }
+        }
+
+        if (saveQuestions.Count > 0) {
+            Database.Instance.SavePlayersQuestion(saveQuestions, GameManagerScript.GetCurrentPlayer(), gameId, GetGameMode());
+        }
+    }
+
+     public List<int> GetQuestionIdsInAnswerLine() {
+        List<int> questionIds = new List<int>();
+
+        foreach (AnswerLineQuestionCard q in contentPanel.GetComponentsInChildren<AnswerLineQuestionCard>()) {
+            questionIds.Add(q.GetId());
+        }
+
+        return questionIds;
+    }
+
+    public void RemoveEverythingFromAnswerline() {
+        
+        foreach (Transform child in contentPanel.transform) {
+            Destroy(child.gameObject);
+        }
+    }
+
+    public void RemoveUnlockedQuestions() {
+        int lostQuestions = 0;
+        AnswerLineQuestionCard[] answerLineQuestionCards = contentPanel.GetComponentsInChildren<AnswerLineQuestionCard>();
+
+        foreach (AnswerLineQuestionCard aq in answerLineQuestionCards)
+        {
+            if (!aq.IsQuestionSafe()){
+                lostQuestions++;
+                aq.transform.SetParent(null);
+                Destroy(aq);
+                Destroy(aq.gameObject);
+            }
+        }
+        gameManagerScript.UpdateQuestiosLost(lostQuestions, currentPlayer);
+        statsScript.SetQuestionsInAnswerLine(currentPlayer, contentPanel.GetComponents<AnswerLineQuestionCard>().Length);
+    }
+
+ 
+
+    void TimerRunOutEvent() { // Should be moved to some gameController
+        ts.StopTimer();
+        GenericDialog dialog = GenericDialog.Instance();
+        string message = LocalizationManager.Instance.GetText("TIMER_DIALOG_MESSAGE");
+        dialog.SetTitle(LocalizationManager.Instance.GetText("TIMER_DIALOG_TITLE"));
+        dialog.SetMessage(String.Format(message, GetUnlockedQuestionCount()));
+        dialog.SetOnAccept(LocalizationManager.Instance.GetText("OK"), () => {
+            RemoveUnlockedQuestions();
+            ts.ResetTimer();
+            dialog.Hide();
+            NextPlayer();
+        });
+        dialog.SetOnDecline("", () => dialog.Hide());
+        dialog.Show();
+
+    }
+
+    public void NextPlayer() {
+        for (int i = 0; i < players.Count; i++) {
+            if (players[i].Key.Equals(currentPlayer, StringComparison.InvariantCultureIgnoreCase)) {
+                if (i + 1 < players.Count) {
+                    currentPlayer = players[i + 1].Key;
+                    break;
+                } else {
+                    currentPlayer = players[0].Key;
+                    statsScript.IncreaseRoundValue();
+                    break;
+                }
+            }
+        }
+        
+        GenericDialog dialog = GenericDialog.Instance();
+        dialog.SetTitle(LocalizationManager.Instance.GetText("NEXT_PLAYER_DIALOG_TITLE"));
+        string message = LocalizationManager.Instance.GetText("NEXT_PLAYER_DIALOG_MESSAGE");
+        dialog.SetMessage(String.Format(message, currentPlayer));
+        dialog.SetOnAccept(LocalizationManager.Instance.GetText("OK"), () => {
+            RemoveEverythingFromAnswerline();
+            List<NewQuestionData> questions = Database.Instance.GetPlayerQuestions(gameId, currentPlayer, GetGameMode());
+            SetQuestionsInAnswerLine(questions);
+
+            statsScript.SetQuestionsLost(Database.Instance.GetQuestionsLost(gameManagerScript.GameId, currentPlayer, GetGameMode()));
+
+            statsScript.MakeBold(currentPlayer);
+            Database.Instance.SetCurrentPlayer(gameId, currentPlayer, GetGameMode());
+            dialog.Hide();
+        });
+        dialog.SetOnDecline("", () => dialog.Hide());
+        dialog.Show();
+    }
+}

BIN
Assets/narKampenLocal.db


+ 7 - 7
ProjectSettings/GvhProjectSettings.xml

@@ -1,8 +1,8 @@
-<projectSettings>
-  <projectSetting name="Google.IOSResolver.VerboseLoggingEnabled" value="False" />
-  <projectSetting name="Google.PackageManagerResolver.VerboseLoggingEnabled" value="False" />
-  <projectSetting name="Google.VersionHandler.VerboseLoggingEnabled" value="False" />
-  <projectSetting name="GooglePlayServices.AutoResolverEnabled" value="False" />
-  <projectSetting name="GooglePlayServices.PromptBeforeAutoResolution" value="False" />
-  <projectSetting name="GooglePlayServices.UseJetifier" value="True" />
+<projectSettings>
+  <projectSetting name="Google.IOSResolver.VerboseLoggingEnabled" value="False" />
+  <projectSetting name="Google.PackageManagerResolver.VerboseLoggingEnabled" value="False" />
+  <projectSetting name="Google.VersionHandler.VerboseLoggingEnabled" value="False" />
+  <projectSetting name="GooglePlayServices.AutoResolverEnabled" value="False" />
+  <projectSetting name="GooglePlayServices.PromptBeforeAutoResolution" value="False" />
+  <projectSetting name="GooglePlayServices.UseJetifier" value="True" />
 </projectSettings>

+ 17 - 0
omnisharp.json

@@ -0,0 +1,17 @@
+
+{
+    "FormattingOptions": {
+        "NewLinesForBracesInLambdaExpressionBody": false,
+        "NewLinesForBracesInAnonymousMethods": false,
+        "NewLinesForBracesInAnonymousTypes": false,
+        "NewLinesForBracesInControlBlocks": false,
+        "NewLinesForBracesInTypes": false,
+        "NewLinesForBracesInMethods": false,
+        "NewLinesForBracesInProperties": false,
+        "NewLinesForBracesInObjectCollectionArrayInitializers": false,
+        "NewLinesForBracesInAccessors": false,
+        "NewLineForElse": false,
+        "NewLineForCatch": false,
+        "NewLineForFinally": false
+    }
+}