StoryUtil.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System.Text.RegularExpressions;
  2. using System.Collections;
  3. using System;
  4. using cfg.GfgCfg;
  5. using FairyGUI;
  6. using UnityEngine;
  7. namespace GFGGame
  8. {
  9. public class StoryUtil
  10. {
  11. public static ArrayList GetLettersList(string words)
  12. {
  13. Regex regex = new Regex("\\u005Bcolor.*?/color]");
  14. MatchCollection mc = regex.Matches(words);
  15. string[] splitResult = regex.Split(words);
  16. ArrayList colorList = HandleColorTextList(mc);
  17. ArrayList result = new ArrayList();
  18. for (int i = 0; i < splitResult.Length; i++)
  19. {
  20. string text = splitResult[i];
  21. char[] charArr = text.ToCharArray();
  22. foreach (char a in charArr)
  23. {
  24. result.Add(a.ToString());
  25. }
  26. if (i < colorList.Count)
  27. {
  28. string[] colorTextArr = (string[])colorList[i];
  29. foreach (string b in colorTextArr)
  30. {
  31. result.Add(b);
  32. }
  33. }
  34. }
  35. return result;
  36. }
  37. private static ArrayList HandleColorTextList(MatchCollection mc)
  38. {
  39. ArrayList colorList = new ArrayList();
  40. for (int i = 0; i < mc.Count; i++)
  41. {
  42. Match m = mc[i];
  43. string[] result = HandleColorText(m);
  44. colorList.Add(result);
  45. }
  46. return colorList;
  47. }
  48. private static string[] HandleColorText(Match m)
  49. {
  50. string value = m.Value;
  51. Regex regexColor = new Regex("\\u005B.*?]");
  52. string text = regexColor.Replace(value, "");
  53. string[] result = new string[text.Length];
  54. Regex regexText = new Regex(text);
  55. string colorTemp = regexText.Replace(value, "xx");
  56. Regex regexLetter = new Regex("xx");
  57. for (int i = 0; i < text.Length; i++)
  58. {
  59. string letter = text.Substring(i, 1);
  60. string colorLetter = regexLetter.Replace(colorTemp, letter);
  61. result[i] = colorLetter;
  62. }
  63. return result;
  64. }
  65. public static string GetChapterOrderText(int chapterID)
  66. {
  67. int order = GetChapterOrder(chapterID);
  68. return "第" + NumberUtil.GetChiniseNumberText(order) + "章";
  69. }
  70. /// <summary>
  71. /// 获得章节显示的序号
  72. /// </summary>
  73. /// <param name="chapterCfgId"></param>
  74. /// <returns></returns>
  75. public static int GetChapterOrder(int chapterCfgId)
  76. {
  77. StoryChapterCfg storyChapterCfg = CommonDataManager.Tables.TblStoryChapterCfg.GetOrDefault(chapterCfgId);
  78. return storyChapterCfg.Order;
  79. }
  80. public static void UpdateStar(int starCount, GComponent component)
  81. {
  82. if (component != null)
  83. {
  84. int num = component.numChildren;
  85. for (int i = 1; i <= 3; i++)
  86. {
  87. GObject obj = component.GetChild("f" + i);
  88. if (obj != null)
  89. {
  90. obj.visible = i <= starCount;
  91. }
  92. }
  93. }
  94. }
  95. public static void UpdateStar(int starCount, GComponent component, int currentIndex)
  96. {
  97. if (component != null)
  98. {
  99. int num = component.numChildren;
  100. for (int i = 1; i <= 3; i++)
  101. {
  102. GObject obj = component.GetChild("f" + i);
  103. if (obj != null)
  104. {
  105. obj.visible = i <= starCount;
  106. if (currentIndex == 1)
  107. {
  108. (obj as GLoader).url = "ui://Main/tb_zx_jy_star";
  109. }
  110. else
  111. {
  112. (obj as GLoader).url = "ui://Main/tb_zx_pt_star";
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }