QuestionCard.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Networking;
  6. using UnityEngine.UI;
  7. public class QuestionCard : MonoBehaviour {
  8. public Text questionText;
  9. public Text answerText;
  10. public Text backCategoryText;
  11. public GameObject questionTextPanel;
  12. public string questionString = "";
  13. public string answerString = "";
  14. public string idString = "";
  15. public string categoryString = "";
  16. public Color32 unsafeColor;
  17. public Color32 safeColor;
  18. [SerializeField] CanvasGroup frosting;
  19. [SerializeField] GameObject frontCategoryPanel;
  20. [SerializeField] Text frontCategoryText;
  21. public void SetQuestionSafe() {
  22. this.GetComponent<Image>().color = safeColor;
  23. }
  24. internal void SetQuestionUnSafe() {
  25. this.GetComponent<Image>().color = unsafeColor;
  26. }
  27. public bool IsQuestionSafe() {
  28. if (this.GetComponent<Image>().color == safeColor) {
  29. return true;
  30. }
  31. return false;
  32. }
  33. public void SetQuestionCategoryColor(Color32 questionCategoryColor) {
  34. if (backCategoryText != null) {
  35. backCategoryText.transform.parent.GetComponent<Image>().color = questionCategoryColor;
  36. frontCategoryPanel.GetComponent<Image>().color = questionCategoryColor;
  37. }
  38. }
  39. public void SetQuestionText(string text) {
  40. if (questionText == null) {
  41. GameObject test = new GameObject("Text");
  42. questionText = test.AddComponent<Text>();
  43. }
  44. this.questionText.text = text;
  45. }
  46. public void SetAnswerText(string text) {
  47. if (answerText == null) {
  48. GameObject test = new GameObject("Text");
  49. answerText = test.AddComponent<Text>();
  50. }
  51. this.answerText.text = text;
  52. }
  53. public Text GetQuestionText() {
  54. return this.questionText;
  55. }
  56. public Text GetAnswerText() {
  57. return this.answerText;
  58. }
  59. public int GetCategoryId() {
  60. Int32.TryParse(categoryString, out int result);
  61. return result;
  62. }
  63. internal int GetId() {
  64. Int32.TryParse(idString, out int result);
  65. return result;
  66. }
  67. public void SetId(int value) {
  68. idString = value.ToString();
  69. }
  70. public void SetBackCategoryText(string value) {
  71. if (backCategoryText == null) {
  72. GameObject test = new GameObject("Text"); // TODO test??
  73. backCategoryText = test.AddComponent<Text>();
  74. }
  75. backCategoryText.text = value;
  76. frontCategoryText.text = value;
  77. }
  78. public string GetBackCategoryText() {
  79. if (backCategoryText == null) {
  80. return "Category";
  81. }
  82. return backCategoryText.text;
  83. }
  84. public void SetFrostingActive(Boolean value) {
  85. if (value) {
  86. frosting.alpha = 1f;
  87. } else {
  88. frosting.alpha = 0f;
  89. }
  90. }
  91. }