Procházet zdrojové kódy

Lägg till fråga efter popup som frågar om man vill svara x

Axel Nordh před 7 roky
rodič
revize
1a0879ca10

+ 3 - 3
Assets/Prefab/Modal Panel.prefab

@@ -113,7 +113,7 @@ GameObject:
   - component: {fileID: 4606992418533541355}
   - component: {fileID: 4606992418533541352}
   m_Layer: 5
-  m_Name: Text
+  m_Name: NoText
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -486,7 +486,7 @@ GameObject:
   - component: {fileID: 4606992418804682743}
   - component: {fileID: 4606992418804682740}
   m_Layer: 5
-  m_Name: Text
+  m_Name: YesText
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -640,7 +640,7 @@ GameObject:
   - component: {fileID: 4606992419171989499}
   - component: {fileID: 4606992419171989496}
   m_Layer: 5
-  m_Name: Text
+  m_Name: CancelText
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0

+ 4 - 0
Assets/Prefab/QuestionCard.prefab

@@ -117,6 +117,10 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   questionText: {fileID: 491313937380098038}
   answerText: {fileID: 8760622633323229486}
+  questionString: 
+  answerString: 
+  idString: 
+  categoryString: 
 --- !u!114 &3820892049407775847
 MonoBehaviour:
   m_ObjectHideFlags: 0

+ 7 - 14
Assets/Scripts/ModalPanel/DisplayManager.cs

@@ -12,10 +12,8 @@ public class DisplayManager : MonoBehaviour {
 
     private static DisplayManager displayManager;
 
-    public static DisplayManager Instance()
-    {
-        if (!displayManager)
-        {
+    public static DisplayManager Instance() {
+        if (!displayManager) {
             displayManager = FindObjectOfType(typeof(DisplayManager)) as DisplayManager;
             if (!displayManager)
                 Debug.LogError("There needs to be one active DisplayManager script on a GameObject in your scene.");
@@ -24,32 +22,27 @@ public class DisplayManager : MonoBehaviour {
         return displayManager;
     }
 
-    public void DisplayMessage(string message)
-    {
+    public void DisplayMessage(string message) {
         displayText.text = message;
         SetAlpha();
     }
 
-    void SetAlpha()
-    {
-        if (fadeAlpha != null)
-        {
+    void SetAlpha() {
+        if (fadeAlpha != null) {
             StopCoroutine(fadeAlpha);
         }
         fadeAlpha = FadeAlpha();
         StartCoroutine(fadeAlpha);
     }
 
-    IEnumerator FadeAlpha()
-    {
+    IEnumerator FadeAlpha() {
         Color resetColor = displayText.color;
         resetColor.a = 1;
         displayText.color = resetColor;
 
         yield return new WaitForSeconds(displayTime);
 
-        while (displayText.color.a > 0)
-        {
+        while (displayText.color.a > 0) {
             Color displayColor = displayText.color;
             displayColor.a -= Time.deltaTime / fadeTime;
             displayText.color = displayColor;

+ 176 - 27
Assets/Scripts/ModalPanel/ModalPanel.cs

@@ -3,22 +3,47 @@ using UnityEngine.UI;
 using UnityEngine.Events;
 using System.Collections;
 
-//  This script will be updated in Part 2 of this 2 part series.
+public class EventButtonDetails {
+    public string buttonTitle;
+    public Sprite buttonBackground;  // Not implemented
+    public UnityAction action;
+}
+
+public class EventSliderDetails {
+
+}
+
+public class ModalPanelDetails {
+    public string title; // Not implemented
+    public string question;
+    public Sprite iconImage;
+    public Sprite panelBackgroundImage; // Not implemented
+    public EventButtonDetails button1Details;
+    public EventButtonDetails button2Details;
+    public EventButtonDetails button3Details;
+    public EventButtonDetails button4Details;
+    public EventSliderDetails sliderDetails;
+}
+
+
 public class ModalPanel : MonoBehaviour {
 
     public Text question;
     public Image iconImage;
-    public Button yesButton;
-    public Button noButton;
-    public Button cancelButton;
+    public Button button1;
+    public Button button2;
+    public Button button3;
+
+    public Text button1Text;
+    public Text button2Text;
+    public Text button3Text;
+
     public GameObject modalPanelObject;
 
     private static ModalPanel modalPanel;
 
-    public static ModalPanel Instance()
-    {
-        if (!modalPanel)
-        {
+    public static ModalPanel Instance() {
+        if (!modalPanel) {
             modalPanel = FindObjectOfType(typeof(ModalPanel)) as ModalPanel;
             if (!modalPanel)
                 Debug.LogError("There needs to be one active ModalPanel script on a GameObject in your scene.");
@@ -27,33 +52,157 @@ public class ModalPanel : MonoBehaviour {
         return modalPanel;
     }
 
-    // Yes/No/Cancel: A string, a Yes event, a No event and Cancel event
-    public void Choice(string question, UnityAction yesEvent, UnityAction noEvent, UnityAction cancelEvent)
-    {
+
+    //  //  Announcement with Image:  A string, a Sprite and Cancel event;
+    //  public void Choice (string question, UnityAction cancelEvent, Sprite iconImage = null) {
+    //      modalPanelObject.SetActive (true);
+    //      
+    //      button3.onClick.RemoveAllListeners();
+    //      button3.onClick.AddListener (cancelEvent);
+    //      button3.onClick.AddListener (ClosePanel);
+    //      
+    //      this.question.text = question;
+    //      if (iconImage)
+    //          this.iconImage.sprite = iconImage;
+    //      
+    //      if (iconImage)
+    //          this.iconImage.gameObject.SetActive(true);
+    //      else
+    //          this.iconImage.gameObject.SetActive(false);
+    //      button1.gameObject.SetActive(false);
+    //      button2.gameObject.SetActive(false);
+    //      button3.gameObject.SetActive(true);
+    //  }
+
+    public void NewChoice(ModalPanelDetails details) {
         modalPanelObject.SetActive(true);
 
-        yesButton.onClick.RemoveAllListeners();
-        yesButton.onClick.AddListener(yesEvent);
-        yesButton.onClick.AddListener(ClosePanel);
+        this.iconImage.gameObject.SetActive(false);
+        button1.gameObject.SetActive(false);
+        button2.gameObject.SetActive(false);
+        button3.gameObject.SetActive(false);
 
-        noButton.onClick.RemoveAllListeners();
-        noButton.onClick.AddListener(noEvent);
-        noButton.onClick.AddListener(ClosePanel);
+        this.question.text = details.question;
 
-        cancelButton.onClick.RemoveAllListeners();
-        cancelButton.onClick.AddListener(cancelEvent);
-        cancelButton.onClick.AddListener(ClosePanel);
+        if (details.iconImage) {
+            this.iconImage.sprite = details.iconImage;
+            this.iconImage.gameObject.SetActive(true);
+        }
 
-        this.question.text = question;
+        button1.onClick.RemoveAllListeners();
+        button1.onClick.AddListener(details.button1Details.action);
+        button1.onClick.AddListener(ClosePanel);
+        button1Text.text = details.button1Details.buttonTitle;
+        button1.gameObject.SetActive(true);
 
-        this.iconImage.gameObject.SetActive(false);
-        yesButton.gameObject.SetActive(true);
-        noButton.gameObject.SetActive(true);
-        cancelButton.gameObject.SetActive(true);
+        if (details.button2Details != null) {
+            button2.onClick.RemoveAllListeners();
+            button2.onClick.AddListener(details.button2Details.action);
+            button2.onClick.AddListener(ClosePanel);
+            button2Text.text = details.button2Details.buttonTitle;
+            button2.gameObject.SetActive(true);
+        }
+
+        if (details.button3Details != null) {
+            button3.onClick.RemoveAllListeners();
+            button3.onClick.AddListener(details.button3Details.action);
+            button3.onClick.AddListener(ClosePanel);
+            button3Text.text = details.button3Details.buttonTitle;
+            button3.gameObject.SetActive(true);
+        }
     }
 
-    void ClosePanel()
-    {
+    //  //  Yes/No: A string, a Yes event, a No event (No Cancel Button);
+    //  public void Choice (string question, UnityAction yesEvent, UnityAction noEvent) {
+    //      modalPanelObject.SetActive (true);
+    //
+    //      button1.onClick.RemoveAllListeners();
+    //      button1.onClick.AddListener (yesEvent);
+    //      button1.onClick.AddListener (ClosePanel);
+    //
+    //      button2.onClick.RemoveAllListeners();
+    //      button2.onClick.AddListener (noEvent);
+    //      button2.onClick.AddListener (ClosePanel);
+    //
+    //      this.question.text = question;
+    //      
+    //      this.iconImage.gameObject.SetActive(false);
+    //      button1.gameObject.SetActive(true);
+    //      button2.gameObject.SetActive(true);
+    //      button3.gameObject.SetActive(false);
+    //  }
+    //  
+    //  //  Yes/No/Cancel: A string, a Yes event, a No event and Cancel event;
+    //  public void Choice (string question, UnityAction yesEvent, UnityAction noEvent, UnityAction cancelEvent) {
+    //      modalPanelObject.SetActive (true);
+    //      
+    //      button1.onClick.RemoveAllListeners();
+    //      button1.onClick.AddListener (yesEvent);
+    //      button1.onClick.AddListener (ClosePanel);
+    //      
+    //      button2.onClick.RemoveAllListeners();
+    //      button2.onClick.AddListener (noEvent);
+    //      button2.onClick.AddListener (ClosePanel);
+    //      
+    //      button3.onClick.RemoveAllListeners();
+    //      button3.onClick.AddListener (cancelEvent);
+    //      button3.onClick.AddListener (ClosePanel);
+    //      
+    //      this.question.text = question;
+    //      
+    //      this.iconImage.gameObject.SetActive(false);
+    //      button1.gameObject.SetActive(true);
+    //      button2.gameObject.SetActive(true);
+    //      button3.gameObject.SetActive(true);
+    //  }
+    //  
+    //  //  Yes/No with Image: A string, a Sprite, a Yes event, a No event (No Cancel Button);
+    //  public void Choice (string question, Sprite iconImage, UnityAction yesEvent, UnityAction noEvent) {
+    //      modalPanelObject.SetActive (true);
+    //      
+    //      button1.onClick.RemoveAllListeners();
+    //      button1.onClick.AddListener (yesEvent);
+    //      button1.onClick.AddListener (ClosePanel);
+    //      
+    //      button2.onClick.RemoveAllListeners();
+    //      button2.onClick.AddListener (noEvent);
+    //      button2.onClick.AddListener (ClosePanel);
+    //      
+    //      this.question.text = question;
+    //      this.iconImage.sprite = iconImage;
+    //      
+    //      this.iconImage.gameObject.SetActive(true);
+    //      button1.gameObject.SetActive(true);
+    //      button2.gameObject.SetActive(true);
+    //      button3.gameObject.SetActive(false);
+    //  }
+    //  
+    //  //  Yes/No/Cancel with Image: A string, a Sprite, a Yes event, a No event and Cancel event;
+    //  public void Choice (string question, Sprite iconImage, UnityAction yesEvent, UnityAction noEvent, UnityAction cancelEvent) {
+    //      modalPanelObject.SetActive (true);
+    //      
+    //      button1.onClick.RemoveAllListeners();
+    //      button1.onClick.AddListener (yesEvent);
+    //      button1.onClick.AddListener (ClosePanel);
+    //      
+    //      button2.onClick.RemoveAllListeners();
+    //      button2.onClick.AddListener (noEvent);
+    //      button2.onClick.AddListener (ClosePanel);
+    //      
+    //      button3.onClick.RemoveAllListeners();
+    //      button3.onClick.AddListener (cancelEvent);
+    //      button3.onClick.AddListener (ClosePanel);
+    //      
+    //      this.question.text = question;
+    //      this.iconImage.sprite = iconImage;
+    //      
+    //      this.iconImage.gameObject.SetActive(true);
+    //      button1.gameObject.SetActive(true);
+    //      button2.gameObject.SetActive(true);
+    //      button3.gameObject.SetActive(true);
+    //  }
+
+    void ClosePanel() {
         modalPanelObject.SetActive(false);
     }
 }

+ 6 - 6
Assets/Scripts/NewQuestionScript.cs

@@ -8,19 +8,19 @@ public class NewQuestionScript : MonoBehaviour {
 
     public GameObject prefab;
     public Transform contentPanel;
-    QuestionCard questionCard;
     // Start is called before the first frame update
     void Start() {
-        GetNewQuestionData();
+        NewQuestion newQuestion = GetNewQuestionData();
+
+        newQuestion.transform.SetParent(contentPanel);
     }
 
-    private void GetNewQuestionData() {
+    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;
-        questionCard = question.GetComponent<NewQuestion>();
+        NewQuestion questionCard = question.GetComponent<NewQuestion>();
         questionCard.PrepareQuestion("NewQuestionText", "NewAnswerText");
         questionCard.GetQuestion(false);
-
-        questionCard.transform.SetParent(contentPanel);
+        return questionCard;
     }
 }

+ 8 - 2
Assets/Scripts/QuestionCard.cs

@@ -7,8 +7,8 @@ using UnityEngine.UI;
 
 public class QuestionCard : MonoBehaviour
 {
-    private Text questionText;
-    private Text answerText;
+    public Text questionText;
+    public Text answerText;
 
     public string questionString = "";
     public string answerString = "";
@@ -45,6 +45,12 @@ public class QuestionCard : MonoBehaviour
         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>();

+ 25 - 12
Assets/Scripts/ScrollViewScript.cs

@@ -4,21 +4,21 @@ using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 
-public class ScrollViewScript : MonoBehaviour, IDropHandler
-{
+public class ScrollViewScript : MonoBehaviour, IDropHandler {
     public GameObject prefab;
     public Transform contentPanel;
+    private bool placeQuestion;
+    NewQuestion nq;
+    private int newQuestionSiblingIndex;
 
     // Start is called before the first frame update
-    void Start()
-    {
+    void Start() {
         SetGiventQuestion();
     }
 
-    public void SetGiventQuestion()
-    {
+    public void SetGiventQuestion() {
         // if new game, create one question card to start with
-        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.PrepareQuestion("QuestionText", "AnswerText");
         questionCard.GetQuestion(true);
@@ -33,12 +33,24 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler
         if (d == null || !d.gameObject.name.Contains("NewQuestion")) {
             return;
         }
+
+
         // Popup modal asking are you sure here or at onDragEnd?
+
+
+        nq = d.GetComponent<NewQuestion>();
+        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);
+    }
+
+    void YesFunction() {
         GameObject question = Instantiate(prefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
         QuestionCard questionCard = question.GetComponent<QuestionCard>();
-        questionCard.PrepareQuestion("QuestionText", "AnswerText");
-
-        NewQuestion nq = d.GetComponent<NewQuestion>();
 
         questionCard.SetAnswerText(nq.answerString);
         questionCard.SetQuestionText(nq.questionString);
@@ -47,9 +59,10 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler
         questionCard.categoryString = nq.categoryString;
         questionCard.idString = nq.idString;
 
-
         questionCard.transform.SetParent(contentPanel);
-        questionCard.transform.SetSiblingIndex(d.placeholder.transform.GetSiblingIndex());
+        questionCard.transform.SetSiblingIndex(newQuestionSiblingIndex);
     }
 
+    void NoFunction() {
+    }
 }

+ 60 - 13
Assets/narKampen.unity

@@ -208,6 +208,18 @@ MonoBehaviour:
   m_FlexibleWidth: -1
   m_FlexibleHeight: 1
   m_LayoutPriority: 1
+--- !u!114 &25919760 stripped
+MonoBehaviour:
+  m_CorrespondingSourceObject: {fileID: 4606992418533541352, guid: 952f6c50eed555c448854a8a8fdb799e,
+    type: 3}
+  m_PrefabInstance: {fileID: 4606992418052486849}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 0}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
 --- !u!114 &281669643 stripped
 MonoBehaviour:
   m_CorrespondingSourceObject: {fileID: 4606992418307720906, guid: 952f6c50eed555c448854a8a8fdb799e,
@@ -422,8 +434,8 @@ MonoBehaviour:
   m_TargetGraphic: {fileID: 1133529224}
   m_HandleRect: {fileID: 1133529223}
   m_Direction: 0
-  m_Value: 0
-  m_Size: 1
+  m_Value: 0.5
+  m_Size: 0.9999999
   m_NumberOfSteps: 0
   m_OnValueChanged:
     m_PersistentCalls:
@@ -473,6 +485,26 @@ GameObject:
     type: 3}
   m_PrefabInstance: {fileID: 4606992418052486849}
   m_PrefabAsset: {fileID: 0}
+--- !u!114 &1090354866
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1090354865}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 1679637790, guid: f70555f144d8491a825f0804e09c671c, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_IgnoreLayout: 1
+  m_MinWidth: -1
+  m_MinHeight: -1
+  m_PreferredWidth: -1
+  m_PreferredHeight: -1
+  m_FlexibleWidth: -1
+  m_FlexibleHeight: -1
+  m_LayoutPriority: 1
 --- !u!1 &1133529222
 GameObject:
   m_ObjectHideFlags: 0
@@ -1544,9 +1576,12 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   question: {fileID: 1423700018}
   iconImage: {fileID: 1299370472}
-  yesButton: {fileID: 281669643}
-  noButton: {fileID: 1682926880}
-  cancelButton: {fileID: 889577455}
+  button1: {fileID: 281669643}
+  button2: {fileID: 1682926880}
+  button3: {fileID: 889577455}
+  button1Text: {fileID: 757791029}
+  button2Text: {fileID: 25919760}
+  button3Text: {fileID: 2122362132}
   modalPanelObject: {fileID: 1090354865}
 --- !u!4 &2091956462
 Transform:
@@ -1562,6 +1597,18 @@ Transform:
   m_Father: {fileID: 0}
   m_RootOrder: 3
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!114 &2122362132 stripped
+MonoBehaviour:
+  m_CorrespondingSourceObject: {fileID: 4606992419171989496, guid: 952f6c50eed555c448854a8a8fdb799e,
+    type: 3}
+  m_PrefabInstance: {fileID: 4606992418052486849}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 0}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
 --- !u!1001 &4606992418052486849
 PrefabInstance:
   m_ObjectHideFlags: 0
@@ -1637,42 +1684,42 @@ PrefabInstance:
     - target: {fileID: 4606992419516846070, guid: 952f6c50eed555c448854a8a8fdb799e,
         type: 3}
       propertyPath: m_AnchoredPosition.x
-      value: 557.2581
+      value: -0.012331
       objectReference: {fileID: 0}
     - target: {fileID: 4606992419516846070, guid: 952f6c50eed555c448854a8a8fdb799e,
         type: 3}
       propertyPath: m_AnchoredPosition.y
-      value: -406.56677
+      value: 0.00053883
       objectReference: {fileID: 0}
     - target: {fileID: 4606992419516846070, guid: 952f6c50eed555c448854a8a8fdb799e,
         type: 3}
       propertyPath: m_SizeDelta.x
-      value: 1112.5162
+      value: 1126.4
       objectReference: {fileID: 0}
     - target: {fileID: 4606992419516846070, guid: 952f6c50eed555c448854a8a8fdb799e,
         type: 3}
       propertyPath: m_SizeDelta.y
-      value: 46.226715
+      value: -426.14
       objectReference: {fileID: 0}
     - target: {fileID: 4606992419516846070, guid: 952f6c50eed555c448854a8a8fdb799e,
         type: 3}
       propertyPath: m_AnchorMin.x
-      value: 0
+      value: 0.5
       objectReference: {fileID: 0}
     - target: {fileID: 4606992419516846070, guid: 952f6c50eed555c448854a8a8fdb799e,
         type: 3}
       propertyPath: m_AnchorMin.y
-      value: 1
+      value: 0.5
       objectReference: {fileID: 0}
     - target: {fileID: 4606992419516846070, guid: 952f6c50eed555c448854a8a8fdb799e,
         type: 3}
       propertyPath: m_AnchorMax.x
-      value: 0
+      value: 0.5
       objectReference: {fileID: 0}
     - target: {fileID: 4606992419516846070, guid: 952f6c50eed555c448854a8a8fdb799e,
         type: 3}
       propertyPath: m_AnchorMax.y
-      value: 0
+      value: 0.5
       objectReference: {fileID: 0}
     - target: {fileID: 4606992419516846070, guid: 952f6c50eed555c448854a8a8fdb799e,
         type: 3}