UIWFConditionList.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.Collections.Generic;
  3. using I2.Loc;
  4. using UnityEngine;
  5. using wf;
  6. [RequireComponent(typeof(UITable))]
  7. public class UIWFConditionList : MonoBehaviour
  8. {
  9. public int height { get; private set; }
  10. public int width { get; private set; }
  11. private void Awake()
  12. {
  13. if (this.condition_label_list_ != null)
  14. {
  15. return;
  16. }
  17. this.condition_label_list_ = new List<UILabel>();
  18. this.condition_label_localize_list_ = new List<Localize>();
  19. UITable component = base.GetComponent<UITable>();
  20. List<Transform> childList = component.GetChildList();
  21. foreach (Transform transform in childList)
  22. {
  23. UILabel component2 = UTY.GetChildObject(transform.gameObject, "Message", false).GetComponent<UILabel>();
  24. component2.overflowMethod = UILabel.Overflow.ShrinkContent;
  25. this.condition_label_list_.Add(component2);
  26. this.condition_label_localize_list_.Add(component2.GetComponent<Localize>());
  27. this.defaultFontSize = component2.fontSize;
  28. this.widthMargin = (int)(component2.transform.localPosition.x - (float)(UTY.GetChildObject(transform.gameObject, "No", false).GetComponent<UIWidget>().width / -2));
  29. transform.gameObject.SetActive(false);
  30. }
  31. }
  32. public void SetTexts(string[] texts, int limitTextWidth = -1)
  33. {
  34. KeyValuePair<string[], Color>[] array = new KeyValuePair<string[], Color>[texts.Length];
  35. for (int i = 0; i < texts.Length; i++)
  36. {
  37. array[i] = new KeyValuePair<string[], Color>(new string[]
  38. {
  39. texts[i]
  40. }, Color.white);
  41. }
  42. this.SetTexts(array, limitTextWidth);
  43. }
  44. public void SetTexts(KeyValuePair<string[], Color>[] texts, int limitTextWidth = -1)
  45. {
  46. if (this.condition_label_list_ == null)
  47. {
  48. this.Awake();
  49. }
  50. this.lastLimitTextWidth = limitTextWidth;
  51. float num = 0f;
  52. float num2 = 0f;
  53. Localize localize = null;
  54. for (int i = 0; i < this.condition_label_list_.Count; i++)
  55. {
  56. if (this.condition_label_localize_list_[i] != null)
  57. {
  58. this.condition_label_localize_list_[i].LocalizeEvent.RemoveAllListeners();
  59. }
  60. if (i < texts.Length)
  61. {
  62. Transform parent = this.condition_label_list_[i].transform.parent;
  63. if (i == 0)
  64. {
  65. num = Mathf.Abs(parent.localPosition.y);
  66. }
  67. this.condition_label_list_[i].transform.parent.gameObject.SetActive(true);
  68. if (texts[i].Key.Length == 1)
  69. {
  70. if (!Product.supportMultiLanguage || this.condition_label_localize_list_[i] == null)
  71. {
  72. this.condition_label_list_[i].text = Utility.GetTermLastWord(texts[i].Key[0]);
  73. }
  74. else
  75. {
  76. this.condition_label_localize_list_[i].TermArgs = null;
  77. this.condition_label_localize_list_[i].SetTerm(string.Empty);
  78. this.condition_label_localize_list_[i].SetTerm(texts[i].Key[0]);
  79. }
  80. }
  81. else if (!Product.supportMultiLanguage || this.condition_label_localize_list_[i] == null)
  82. {
  83. string[] array = new string[texts[i].Key.Length - 1];
  84. for (int j = 1; j < texts[i].Key.Length; j++)
  85. {
  86. array[j - 1] = Utility.GetTermLastWord(texts[i].Key[j]);
  87. }
  88. this.condition_label_list_[i].text = string.Format(Utility.GetTermLastWord(texts[i].Key[0]), array);
  89. }
  90. else
  91. {
  92. bool setIsTerm = false;
  93. if (texts[i].Key[0].Contains("性経験") || texts[i].Key[0].Contains("契約タイプ") || texts[i].Key[0].Contains("性癖") || texts[i].Key[0].Contains("ヒロインタイプ"))
  94. {
  95. setIsTerm = true;
  96. }
  97. Localize.ArgsPair[] array2 = new Localize.ArgsPair[texts[i].Key.Length - 1];
  98. for (int k = 1; k < texts[i].Key.Length; k++)
  99. {
  100. array2[k - 1] = Localize.ArgsPair.Create(texts[i].Key[k], setIsTerm);
  101. }
  102. this.condition_label_localize_list_[i].TermArgs = array2;
  103. this.condition_label_localize_list_[i].SetTerm(texts[i].Key[0]);
  104. localize = this.condition_label_localize_list_[i];
  105. }
  106. this.condition_label_list_[i].color = texts[i].Value;
  107. num2 = Mathf.Abs(parent.localPosition.y) + (float)parent.gameObject.GetComponent<UIWidget>().height;
  108. }
  109. else
  110. {
  111. this.condition_label_list_[i].transform.parent.gameObject.SetActive(false);
  112. }
  113. }
  114. this.height = (int)(num2 - num);
  115. this.ResizeUI(limitTextWidth);
  116. if (localize != null)
  117. {
  118. localize.LocalizeEvent.AddListener(delegate()
  119. {
  120. this.updateFlag = true;
  121. });
  122. }
  123. }
  124. private void Update()
  125. {
  126. if (!this.updateFlag)
  127. {
  128. return;
  129. }
  130. this.ResizeUI(this.lastLimitTextWidth);
  131. this.updateFlag = false;
  132. }
  133. public void ResizeUI(int limitTextWidth = -1)
  134. {
  135. this.width = 0;
  136. for (int i = 0; i < this.condition_label_list_.Count; i++)
  137. {
  138. if (this.condition_label_list_[i].transform.parent.gameObject.activeSelf)
  139. {
  140. if (limitTextWidth != -1)
  141. {
  142. this.condition_label_list_[i].width = limitTextWidth;
  143. }
  144. else
  145. {
  146. this.condition_label_list_[i].fontSize = this.defaultFontSize;
  147. this.condition_label_list_[i].width = 0;
  148. this.condition_label_list_[i].MakePixelPerfect();
  149. if (0 <= limitTextWidth)
  150. {
  151. Utility.ResizeUILabelFontSize(this.condition_label_list_[i], limitTextWidth);
  152. }
  153. this.width = Mathf.Max(this.width, this.condition_label_list_[i].width);
  154. }
  155. }
  156. }
  157. this.width += this.widthMargin;
  158. if (this.resizeUIEvent != null && this.resizeUIEvent.Count >= 1)
  159. {
  160. EventDelegate.Execute(this.resizeUIEvent);
  161. }
  162. }
  163. private int widthMargin;
  164. public List<EventDelegate> resizeUIEvent = new List<EventDelegate>();
  165. private int lastLimitTextWidth = -1;
  166. private bool updateFlag;
  167. private List<UILabel> condition_label_list_;
  168. private List<Localize> condition_label_localize_list_;
  169. private int defaultFontSize;
  170. }