|
@@ -10,6 +10,8 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
|
|
|
private bool placeQuestion;
|
|
private bool placeQuestion;
|
|
|
NewQuestion nq;
|
|
NewQuestion nq;
|
|
|
private int newQuestionSiblingIndex;
|
|
private int newQuestionSiblingIndex;
|
|
|
|
|
+ ModalPanel modalPanel;
|
|
|
|
|
+ private bool answeredCorrectly;
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
// Start is called before the first frame update
|
|
|
void Start() {
|
|
void Start() {
|
|
@@ -28,6 +30,17 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
|
|
|
questionCard.transform.SetParent(contentPanel);
|
|
questionCard.transform.SetParent(contentPanel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public int GetUnlockedQuestionCount() {
|
|
|
|
|
+ int unlockedQuestionCount = 0;
|
|
|
|
|
+ for (int i = 0; i < contentPanel.childCount; i++) {
|
|
|
|
|
+ QuestionCard qc = contentPanel.GetChild(i).GetComponent<QuestionCard>();
|
|
|
|
|
+ if (!qc.IsQuestionSafe()) {
|
|
|
|
|
+ unlockedQuestionCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return unlockedQuestionCount;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void OnDrop(PointerEventData eventData) {
|
|
public void OnDrop(PointerEventData eventData) {
|
|
|
Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
|
|
Draggable d = eventData.pointerDrag.GetComponent<Draggable>();
|
|
|
if (d == null || !d.gameObject.name.Contains("NewQuestion")) {
|
|
if (d == null || !d.gameObject.name.Contains("NewQuestion")) {
|
|
@@ -37,15 +50,41 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
|
|
|
nq = d.GetComponent<NewQuestion>();
|
|
nq = d.GetComponent<NewQuestion>();
|
|
|
newQuestionSiblingIndex = d.placeholder.transform.GetSiblingIndex();
|
|
newQuestionSiblingIndex = d.placeholder.transform.GetSiblingIndex();
|
|
|
|
|
|
|
|
- ModalPanel 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);
|
|
|
|
|
|
|
+ GenericDialog dialog = GenericDialog.Instance();
|
|
|
|
|
+ dialog.SetTitle("Är du säker?");
|
|
|
|
|
+ dialog.SetMessage("Vill du svara att " + nq.GetQuestionText().text + " hände " + nq.GetAnswerText().text + "?");
|
|
|
|
|
+ dialog.SetOnAccept("Ja", () => {
|
|
|
|
|
+ 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.
|
|
|
|
|
+ } 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");
|
|
|
|
|
+ dialog.SetOnAccept("Ok", () => dialog.Hide());
|
|
|
|
|
+ dialog.SetOnDecline("", () => dialog.Hide());
|
|
|
|
|
+ }
|
|
|
|
|
+ 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);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
// 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() {
|
|
void YesFunction() {
|
|
|
|
|
+
|
|
|
int correctAnswer = Int32.Parse(nq.answerString);
|
|
int correctAnswer = Int32.Parse(nq.answerString);
|
|
|
Transform questionBefore = null;
|
|
Transform questionBefore = null;
|
|
|
Transform questionAfter = null;
|
|
Transform questionAfter = null;
|
|
@@ -65,7 +104,8 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
|
|
|
if (questionAfter != null) {
|
|
if (questionAfter != null) {
|
|
|
answerAfter = Int16.Parse(questionAfter.GetComponent<QuestionCard>().GetAnswerText().text);
|
|
answerAfter = Int16.Parse(questionAfter.GetComponent<QuestionCard>().GetAnswerText().text);
|
|
|
}
|
|
}
|
|
|
- if (answerBefore <= correctAnswer && answerAfter >= correctAnswer) { // korrect svar, spara frågan i tidslinjen och prompta ny modal för "Vill du ha en fråga till?" med meddelande om vad som står på spel (olåsta frågor)
|
|
|
|
|
|
|
+ if (answerBefore <= correctAnswer && answerAfter >= correctAnswer) {
|
|
|
|
|
+ // korrect svar, spara frågan i tidslinjen och prompta ny modal för "Vill du ha en fråga till?" med meddelande om vad som står på spel (olåsta frågor)
|
|
|
|
|
|
|
|
GameObject question = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
|
|
GameObject question = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
|
|
|
QuestionCard questionCard = question.GetComponent<QuestionCard>();
|
|
QuestionCard questionCard = question.GetComponent<QuestionCard>();
|
|
@@ -79,8 +119,10 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
|
|
|
|
|
|
|
|
questionCard.transform.SetParent(contentPanel);
|
|
questionCard.transform.SetParent(contentPanel);
|
|
|
questionCard.transform.SetSiblingIndex(newQuestionSiblingIndex);
|
|
questionCard.transform.SetSiblingIndex(newQuestionSiblingIndex);
|
|
|
- } else { // Visa modal för fel svar och meddela att man svarat fel och förlorat x olåsta frågor.
|
|
|
|
|
|
|
|
|
|
|
|
+ answeredCorrectly = true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ answeredCorrectly = false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|