Sfoglia il codice sorgente

Uppdaterat hur ny fråga fungerar, start på stats panelen

Axel Nordh 7 anni fa
parent
commit
4d3f1f69c4

+ 2 - 2
Assets/Prefab/QuestionCard.prefab

@@ -191,7 +191,7 @@ RectTransform:
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
   m_AnchoredPosition: {x: 0, y: 0.00071561}
-  m_SizeDelta: {x: 92, y: 125.3}
+  m_SizeDelta: {x: 90, y: 125.3}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!222 &7378609231691140005
 CanvasRenderer:
@@ -398,7 +398,7 @@ MonoBehaviour:
       Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
   m_FontData:
     m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
-    m_FontSize: 18
+    m_FontSize: 24
     m_FontStyle: 0
     m_BestFit: 0
     m_MinSize: 1

+ 0 - 8
Assets/Scripts/Draggable.cs

@@ -97,13 +97,5 @@ public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDra
 
         Destroy(placeholder);
         // Destroy(this); fungerar ej här om man ångrar vart man släpper frågan, då går den ej att dra igen.
-        // Show Modal and get yes/no confirm on placement, create new QuestionCard at newSiblingIndex.
-
-        //ModalPanel modalPanel = ModalPanel.Instance();
-        //ModalPanelDetails wrongAnswerDetail = new ModalPanelDetails { question = "Tyvärr fel svar, du förlorade olåsta frågor", iconImage = null };
-        //wrongAnswerDetail.button1Details = new EventButtonDetails { buttonTitle = "Ok" };
-        //wrongAnswerDetail.button2Details = null;
-        //wrongAnswerDetail.button3Details = null;
-        //modalPanel.NewChoice(wrongAnswerDetail);
     }
 }

+ 14 - 0
Assets/Scripts/NewQuestion.cs

@@ -14,6 +14,20 @@ public class NewQuestion : QuestionCard {
     public void SetQuestionData()
     {
         GetQuestion(false);
+        SetAnswerText("???? - ????");
+
+        // For testing only, remove when done
+        SetQuestionText(GetQuestionText().text + " " + GetAnswerText().text);
     }
 
+    private static NewQuestion instance;
+    public static NewQuestion Instance() {
+        if (!instance) {
+            instance = FindObjectOfType(typeof(NewQuestion)) as NewQuestion;
+            if (!instance) {
+                Debug.Log("There need to be at least one active GenericDialog on the screen");
+            }
+        }
+        return instance;
+    }
 }

+ 0 - 26
Assets/Scripts/NewQuestionScript.cs

@@ -1,26 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using UnityEngine.UI;
-using UnityEngine.EventSystems;
-
-public class NewQuestionScript : MonoBehaviour {
-
-    public GameObject prefab;
-    public Transform contentPanel;
-    // Start is called before the first frame update
-    void Start() {
-        NewQuestion newQuestion = GetNewQuestionData();
-
-        newQuestion.transform.SetParent(contentPanel);
-    }
-
-    private NewQuestion GetNewQuestionData() {
-        // if new game, create one question card to start with
-        GameObject question = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
-        NewQuestion questionCard = question.GetComponent<NewQuestion>();
-        questionCard.PrepareQuestion("NewQuestionText", "NewAnswerText");
-        questionCard.GetQuestion(false);
-        return questionCard;
-    }
-}

+ 0 - 11
Assets/Scripts/NewQuestionScript.cs.meta

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

+ 6 - 19
Assets/Scripts/QuestionCard.cs

@@ -17,6 +17,7 @@ public class QuestionCard : MonoBehaviour
 
     private Color32 unsafeColor = new Color32(255, 1, 1, 150);
     private Color32 safeColor = new Color32(1, 255, 1, 75);
+    private bool gettingQuestion;
 
     [Serializable]
     public class Question {
@@ -31,26 +32,11 @@ public class QuestionCard : MonoBehaviour
         public List<Question> questionsList = new List<Question>();
     }
 
-    // Start is called before the first frame update
-    void Start()
-    {
-    }
-
-    public QuestionCard() {
-
-    }
-
-    public QuestionCard(string answer, string question) {
-        answerText.text = answer;
-        questionText.text = question;
-    }
-
     public void PrepareQuestion() {
         questionText = GameObject.Find("QuestionText").GetComponent<Text>();
         answerText = GameObject.Find("AnswerText").GetComponent<Text>();
     }
 
-
     public void PrepareQuestion(string questionTextName, string answerTextName)
     {
         questionText = GameObject.Find(questionTextName).GetComponent<Text>();
@@ -66,8 +52,10 @@ public class QuestionCard : MonoBehaviour
         if (www.isNetworkError || www.isHttpError)
         {
             Debug.Log(www.error);
-        } else
-        {
+        } else {
+            while (!www.isDone) {
+                yield return null;
+            }
             // Show result
             string jsonData = www.downloadHandler.text;
 
@@ -82,12 +70,11 @@ public class QuestionCard : MonoBehaviour
                     answerText.text = qe.questionsList[0].answer;
                 }
                 questionText.text = qe.questionsList[0].question;
-             }
+            }
             questionString = qe.questionsList[0].question;
             answerString = qe.questionsList[0].answer;
             idString = qe.questionsList[0].id;
             categoryString = qe.questionsList[0].category;
-
         }
     }
 

+ 30 - 11
Assets/Scripts/ScrollViewScript.cs

@@ -41,6 +41,13 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
         return unlockedQuestionCount;
     }
 
+    private void SetAllQuestionsLocked() {
+        for (int i = 0; i < contentPanel.childCount; i++) {
+            QuestionCard q = contentPanel.GetChild(i).GetComponent<QuestionCard>();
+            q.SetQuestionSafe();
+        }
+    }
+
     public void OnDrop(PointerEventData eventData) {
         Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
         if (d == null || !d.gameObject.name.Contains("NewQuestion")) {
@@ -57,42 +64,54 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
             YesFunction();
             dialog.Hide();
 
+
             if (answeredCorrectly) {
                 dialog.SetTitle("Korrekt svarat " + nq.answerString + "!");
                 dialog.SetMessage("Helt korrekt, vill du ha en ny fråga, du riskerar då " + GetUnlockedQuestionCount() + " om du svarar fel");
-                dialog.SetOnAccept("Ja", () => { dialog.Hide(); }); // generera ny fråga
-                dialog.SetOnDecline("Nej", () => { dialog.Hide(); }); // lås frågor som ej är låsta.
+                dialog.SetOnAccept("Ja", () => {
+                    dialog.Hide();
+                    nq.SetQuestionData();
+                }); // generera ny fråga
+                dialog.SetOnDecline("Nej", () => {
+                    dialog.Hide();
+                    SetAllQuestionsLocked();
+                }); // lås frågor som ej är låsta.
             } else {
                 dialog.SetTitle("Tyvärr fel svar, korrekt svar var " + nq.answerString);
                 dialog.SetMessage("Du förlorade " + GetUnlockedQuestionCount() + ", bättre lycka nästa gång");
+                RemoveUnlockedQuestions();
                 dialog.SetOnAccept("Ok", () => dialog.Hide());
                 dialog.SetOnDecline("", () => dialog.Hide());
+
+                nq.SetQuestionData();
             }
             dialog.Show();
 
         });
         dialog.SetOnDecline("Nej", () => dialog.Hide());
         dialog.Show();
+    }
 
-
-        //modalPanel = ModalPanel.Instance();
-        //ModalPanelDetails modalDetails = new ModalPanelDetails { question = "Vill du svara att " + nq.GetQuestionText().text + " hände " + nq.GetAnswerText().text + "?", iconImage = null };
-        //modalDetails.button1Details = new EventButtonDetails { buttonTitle = "Ja", action = YesFunction };
-        //modalDetails.button2Details = new EventButtonDetails { buttonTitle = "Nej", action = NoFunction };
-        //modalPanel.NewChoice(modalDetails);
+    private void RemoveUnlockedQuestions() {
+        for (int i = 0; i < contentPanel.childCount; i++) {
+            QuestionCard q = contentPanel.GetChild(i).GetComponent<QuestionCard>();
+            if (!q.IsQuestionSafe()) {
+                Destroy(q.gameObject);
+            }
+        }
     }
 
     // kontrollera om man svarat korrekt, om det är korrekt, visa ny modal med vill du ha ny fråga? om fel, meddela det och avsluta omgång.
     void YesFunction() {
-        
+
         int correctAnswer = Int32.Parse(nq.answerString);
         Transform questionBefore = null;
         Transform questionAfter = null;
         try {
-            questionBefore = contentPanel.GetChild(newQuestionSiblingIndex -1 );
+            questionBefore = contentPanel.GetChild(newQuestionSiblingIndex - 1);
         } catch (UnityException e) { }
         try {
-            questionAfter = contentPanel.GetChild(newQuestionSiblingIndex );
+            questionAfter = contentPanel.GetChild(newQuestionSiblingIndex);
         } catch (UnityException e) { }
 
         QuestionCard test = contentPanel.GetChild(0).GetComponent<QuestionCard>();

File diff suppressed because it is too large
+ 921 - 59
Assets/narKampen.unity


Some files were not shown because too many files changed in this diff