Beispiel #1
0
 private bool VerifyResults()
 {
     for (int i = 0; i < likertQuestions.Count; i++)
     {
         LikertQuestion lq = likertQuestions[i];
         if (!lq.ContainsAtLeastOneAnswer() && lq.QuestionType == SurveyQuestionType.SingleOptionSelect)
         {
             errorText = "Please select a choice for question " + (i + 1) + ". Thanks!";
             return(false);
         }
         if (lq.QuestionType == SurveyQuestionType.ManualEntry)
         {
             string answer = lq.GetManualText();
             if (answer == null || answer.Length < 2 || !ContainsOnlyNumbers(answer))
             {
                 errorText = "Looks like there was an error filling out the field in question " + (i + 1) + ". Thanks!";
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #2
0
    void OnGUI()
    {
        if (drawGUI)
        {
            if (boxStyle == null && toggleStyle == null)
            {
                boxStyle = new GUIStyle(GUI.skin.box);
                boxStyle.normal.background = GUIUtils.MakeBlankTexture(ComputeWidth(), (int)(Screen.height / 2.0f), fontBackground);
                toggleStyle                    = new GUIStyle(GUI.skin.toggle);
                toggleStyle.font               = font;
                toggleStyle.normal.textColor   = fontColor;
                toggleStyle.onNormal.textColor = fontColor;
                toggleStyle.onHover.textColor  = Color.gray;
                toggleStyle.fontSize           = fontSize;
            }

            // Draws the LIKERT STUFFIE
            GUI.depth = (int)GUIDepthLevels.INFO_WINDOW;
            GUILayout.BeginArea(new Rect((Screen.width - ComputeWidth()) / 2, 0, ComputeWidth(), Screen.height), GUI.skin.box);
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, boxStyle);

            // Header
            textStyle.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label(headerText, textStyle);

            if (printErrorText)
            {
                Color fontColor = textStyle.normal.textColor;
                textStyle.normal.textColor = Color.red;
                GUILayout.Label(errorText, textStyle);
                textStyle.normal.textColor = fontColor;
            }

            // Populates the questions
            textStyle.alignment = TextAnchor.MiddleLeft;
            for (int q = 0; q < likertQuestions.Count; q++)
            {
                LikertQuestion lq = likertQuestions[q];
                // TODO (add style)
                string questionText = (q + 1) + ".\t" + lq.Question;
                GUILayout.Label(questionText, textStyle);
                if (lq.QuestionType == SurveyQuestionType.MultipleOptionSelect)
                {
                    GUILayout.BeginHorizontal();
                    for (int i = 0; i < lq.GetNumOptions() / 2; i++)
                    {
                        bool toggled = GUILayout.Toggle(lq.IsSelected(i), lq.Options[i], toggleStyle);
                        lq.SetOption(i, toggled);
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    for (int i = lq.GetNumOptions() / 2; i < lq.GetNumOptions(); i++)
                    {
                        bool toggled = GUILayout.Toggle(lq.IsSelected(i), lq.Options[i], toggleStyle);
                        lq.SetOption(i, toggled);
                    }
                    GUILayout.EndHorizontal();
                }
                else if (lq.QuestionType == SurveyQuestionType.SingleOptionSelect)
                {
                    // We use a selection grid.
                    int currentlySelected = lq.GetSelected();
                    int index             = GUILayout.SelectionGrid(currentlySelected, lq.Options, lq.GetNumOptions(), toggleStyle);
                    if (currentlySelected != index)
                    {
                        lq.ToggleOption(index);
                    }
                }
                else if (lq.QuestionType == SurveyQuestionType.ManualEntry)
                {
                    string manualEntry = (lq.GetManualText() == null) ? "" : lq.GetManualText();
                    string newEntry    = GUILayout.TextField(manualEntry, 3);
                    lq.SetManualText(newEntry);
                }
                GUILayout.Space(10);
            }

            GUILayout.EndScrollView();

            // Draws the submission button.
            if (GUILayout.Button("Submit"))
            {
                if (VerifyResults())
                {
                    results        = BuildResultString();
                    drawGUI        = false;
                    printErrorText = false;
                    if (nextSceneName != null && nextSceneName.Length > 0)
                    {
                        Application.LoadLevel(nextSceneName);
                    }
                }
                else
                {
                    printErrorText = true;
                }
            }
            GUILayout.EndArea();
        }
    }