private string BuildResultString() { string result = ""; for (int i = 0; i < likertQuestions.Count; i++) { LikertQuestion lq = likertQuestions[i]; result += lq.AnswerToString(); if (i != likertQuestions.Count - 1) { result += ":"; } } Debug.Log(result); return(result); }
public static List <LikertQuestion> ParseLikertFile(string text, char delimeter) { List <LikertQuestion> list = new List <LikertQuestion>(); // Assumes each questions is on a newline. string[] questions = text.Split('\n'); foreach (string question in questions) { // Question components are split with colons. string[] components = question.Split(delimeter); if (components.Length != 3) { DebugConsole.LogError("Poorly formatted likert file. Aborting with empty list. " + components.Length); return(new List <LikertQuestion>()); } // Choices are split with commas. string[] options = components[1].Split(','); SurveyQuestionType questionType; string type = components[2].Trim().ToLower(); switch (type) { case "yes": questionType = SurveyQuestionType.MultipleOptionSelect; break; case "no": questionType = SurveyQuestionType.SingleOptionSelect; break; case "text": questionType = SurveyQuestionType.ManualEntry; break; default: questionType = SurveyQuestionType.Invalid; break; } LikertQuestion lq = new LikertQuestion(components[0], options, questionType); list.Add(lq); } return(list); }
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); }
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(); } }