ManaNotify.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6. public class ManaNotify
  7. {
  8. private class Content
  9. {
  10. public bool IsImage;
  11. public string text;
  12. public TextAnchor Alignment;
  13. public Content(bool isImage, string text, TextAnchor alignment)
  14. {
  15. this.text = text;
  16. this.IsImage = isImage;
  17. this.Alignment = alignment;
  18. }
  19. }
  20. public static bool Initialized;
  21. private static List<Text> TextList = new List<Text>();
  22. private static Dictionary<string, List<Content>> ContentsDic = new Dictionary<string, List<Content>>();
  23. public static void AddLine(bool isImage, string language, string content, TextAnchor alignment)
  24. {
  25. if (language == "null")
  26. {
  27. AddLine(isImage, "English", content, alignment);
  28. AddLine(isImage, "Chinese", content, alignment);
  29. AddLine(isImage, "ChineseTraditional", content, alignment);
  30. }
  31. if (!ContentsDic.ContainsKey(language))
  32. {
  33. ContentsDic.Add(language, new List<Content>());
  34. }
  35. ContentsDic[language].Add(new Content(isImage, content, alignment));
  36. }
  37. public static void Show()
  38. {
  39. if (!Initialized)
  40. {
  41. Initialize(GetLanguage());
  42. }
  43. else
  44. {
  45. SwitchLanguage(GetLanguage());
  46. }
  47. ManaAudio.PlayClip(Clip.BubbleClip);
  48. ManaReso.Get("R_Notify").TweenForCG();
  49. Auxiliary.Instance.DelayCall
  50. (
  51. () =>
  52. {
  53. ManaReso.Get<VerticalLayoutGroup>("R_Grid").CalculateLayoutInputVertical();
  54. ManaReso.Get<VerticalLayoutGroup>("R_Grid").SetLayoutVertical();
  55. },
  56. 1
  57. );
  58. }
  59. public static void Initialize(string language)
  60. {
  61. Initialized = true;
  62. List<Content> contents = ContentsDic[language];
  63. for (int i = 0; i < contents.Count; i++)
  64. {
  65. Transform transform = ManaReso.Get("NotifyItem", Folder.UI, false, ManaReso.Get("R_Grid"), false);
  66. if (contents[i].IsImage)
  67. {
  68. transform.GetComponent<Text>().fontSize = 300;
  69. transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
  70. transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
  71. transform.GetComponent<Text>().resizeTextForBestFit = false;
  72. transform.GetComponent<ContentSizeFitter>().enabled = true;
  73. transform.GetChild(0).GetComponent<Image>().sprite = ManaServer.NotificationSprite;
  74. }
  75. transform.GetComponent<Text>().text = contents[i].text;
  76. transform.GetComponent<Text>().alignment = contents[i].Alignment;
  77. TextList.Add(transform.GetComponent<Text>());
  78. }
  79. }
  80. public static void SwitchLanguage(string language)
  81. {
  82. for (int i = 0; i < TextList.Count; i++)
  83. {
  84. TextList[i].text = ContentsDic[language][i].text;
  85. }
  86. }
  87. public static string GetLanguage()
  88. {
  89. if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  90. {
  91. return "Chinese";
  92. }
  93. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  94. {
  95. return "ChineseTraditional";
  96. }
  97. else if (ManaLan.CurrentLan == Lan.English)
  98. {
  99. return "English";
  100. }
  101. else
  102. {
  103. throw new Exception();
  104. }
  105. }
  106. }