SubtitleDisplayManager.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SubtitleDisplayManager : MonoBehaviour
  5. {
  6. public string charaNameText
  7. {
  8. get
  9. {
  10. return this.charaNameText_;
  11. }
  12. set
  13. {
  14. this.Awake();
  15. if (this.charaNameText_ == value)
  16. {
  17. return;
  18. }
  19. this.charaNameText_ = ((!string.IsNullOrEmpty(value)) ? value : string.Empty);
  20. if (this.charaNameUILabel != null)
  21. {
  22. this.charaNameUILabel.text = this.charaNameText_;
  23. this.charaNameUILabel.gameObject.SetActive(!string.IsNullOrEmpty(this.charaNameText_));
  24. }
  25. if (this.singleCharaNameUILabel != null)
  26. {
  27. this.singleCharaNameUILabel.text = this.charaNameText_;
  28. this.singleCharaNameUILabel.gameObject.SetActive(!string.IsNullOrEmpty(this.charaNameText_));
  29. }
  30. }
  31. }
  32. public string originalText
  33. {
  34. get
  35. {
  36. return this.originalUILabel.text;
  37. }
  38. set
  39. {
  40. this.Awake();
  41. if (this.originalText_ == value)
  42. {
  43. return;
  44. }
  45. this.originalUILabel.text = (this.originalText_ = ((!string.IsNullOrEmpty(value)) ? MessageClass.GetWrapString(this.originalUILabel, value) : string.Empty));
  46. if (this.displayType_ == SubtitleDisplayManager.DisplayType.Original)
  47. {
  48. this.singleUILabel.text = this.originalText_;
  49. }
  50. }
  51. }
  52. public string subtitlesText
  53. {
  54. get
  55. {
  56. return this.subtitlesUILabel.text;
  57. }
  58. set
  59. {
  60. this.Awake();
  61. if (this.subtitlesText_ == value)
  62. {
  63. return;
  64. }
  65. this.subtitlesUILabel.text = (this.subtitlesText_ = ((!string.IsNullOrEmpty(value)) ? value : string.Empty));
  66. if (this.displayType_ == SubtitleDisplayManager.DisplayType.Subtitle)
  67. {
  68. this.singleUILabel.text = this.subtitlesText_;
  69. }
  70. }
  71. }
  72. public SubtitleDisplayManager.DisplayType displayType
  73. {
  74. get
  75. {
  76. return this.displayType_;
  77. }
  78. set
  79. {
  80. this.Awake();
  81. this.displayType_ = value;
  82. this.twoTextAreaObject.SetActive(false);
  83. this.singleTextAreaObject.SetActive(false);
  84. if (this.displayType_ == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle)
  85. {
  86. this.twoTextAreaObject.SetActive(true);
  87. }
  88. else if (this.displayType_ == SubtitleDisplayManager.DisplayType.None)
  89. {
  90. if (this.hideTypeOverRide != SubtitleDisplayManager.DisplayType.None)
  91. {
  92. if (this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle)
  93. {
  94. this.twoTextAreaObject.SetActive(true);
  95. }
  96. else if (this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.Original || this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.Subtitle)
  97. {
  98. this.singleTextAreaObject.SetActive(true);
  99. this.singleUILabel.text = ((this.hideTypeOverRide != SubtitleDisplayManager.DisplayType.Subtitle) ? this.originalText_ : this.subtitlesText_);
  100. }
  101. }
  102. }
  103. else if (this.displayType_ == SubtitleDisplayManager.DisplayType.Original || this.displayType_ == SubtitleDisplayManager.DisplayType.Subtitle)
  104. {
  105. this.singleTextAreaObject.SetActive(true);
  106. this.singleUILabel.text = ((this.displayType_ != SubtitleDisplayManager.DisplayType.Subtitle) ? this.originalText_ : this.subtitlesText_);
  107. }
  108. }
  109. }
  110. public bool visible
  111. {
  112. get
  113. {
  114. return base.gameObject.activeInHierarchy;
  115. }
  116. set
  117. {
  118. base.gameObject.SetActive(value);
  119. }
  120. }
  121. public float messageBgAlpha
  122. {
  123. get
  124. {
  125. return (this.messageBgAlphaLinkWidgets == null || 0 >= this.messageBgAlphaLinkWidgets.Length) ? 0f : this.messageBgAlphaLinkWidgets[0].alpha;
  126. }
  127. set
  128. {
  129. if (this.messageBgAlphaLinkWidgets != null)
  130. {
  131. foreach (UIWidget uiwidget in this.messageBgAlphaLinkWidgets)
  132. {
  133. if (uiwidget != null && !Mathf.Approximately(uiwidget.alpha, value))
  134. {
  135. uiwidget.alpha = value;
  136. }
  137. }
  138. }
  139. }
  140. }
  141. private float configMessageAlpha
  142. {
  143. get
  144. {
  145. return (float)(100 - GameMain.Instance.CMSystem.MsgWndAlpha) / 100f;
  146. }
  147. }
  148. private SubtitleDisplayManager.DisplayType configDisplayType
  149. {
  150. get
  151. {
  152. return GameMain.Instance.CMSystem.SubtitleType;
  153. }
  154. set
  155. {
  156. GameMain.Instance.CMSystem.SubtitleType = value;
  157. }
  158. }
  159. private void Awake()
  160. {
  161. if (this.callAwake)
  162. {
  163. return;
  164. }
  165. this.callAwake = true;
  166. string text = string.Empty;
  167. this.charaNameText = text;
  168. text = text;
  169. this.subtitlesText = text;
  170. this.originalText = text;
  171. this.displayType = this.configDisplayType;
  172. this.messageBgAlpha = this.configMessageAlpha;
  173. }
  174. public void SetTextFromScriptStyle(string text)
  175. {
  176. if (string.IsNullOrEmpty(text))
  177. {
  178. string empty = string.Empty;
  179. this.subtitlesText = empty;
  180. this.originalText = empty;
  181. return;
  182. }
  183. KeyValuePair<string, string> translationText = MessageClass.GetTranslationText(text);
  184. this.originalText = translationText.Key;
  185. this.subtitlesText = translationText.Value;
  186. }
  187. public void Update()
  188. {
  189. if (this.messageBgAlpha != this.configMessageAlpha)
  190. {
  191. this.messageBgAlpha = this.configMessageAlpha;
  192. }
  193. if (this.displayType != this.configDisplayType)
  194. {
  195. this.displayType = this.configDisplayType;
  196. }
  197. }
  198. [Header("日本語と翻訳,2テキスト表示する時の設定")]
  199. [SerializeField]
  200. private GameObject twoTextAreaObject;
  201. [SerializeField]
  202. private UILabel charaNameUILabel;
  203. [SerializeField]
  204. private UILabel originalUILabel;
  205. [SerializeField]
  206. private UILabel subtitlesUILabel;
  207. [Header("日本語 or 翻訳の1テキストのみ表示する時の設定")]
  208. [SerializeField]
  209. private GameObject singleTextAreaObject;
  210. [SerializeField]
  211. private UILabel singleCharaNameUILabel;
  212. [SerializeField]
  213. private UILabel singleUILabel;
  214. [Header("メッセージ背景不透明度とリンクされるWidget")]
  215. [SerializeField]
  216. private UIWidget[] messageBgAlphaLinkWidgets;
  217. [Header("None指定の時、特定のタイプに動作をオーバーライドする設定")]
  218. [SerializeField]
  219. private SubtitleDisplayManager.DisplayType hideTypeOverRide;
  220. private bool callAwake;
  221. private string charaNameText_;
  222. private string originalText_;
  223. private string subtitlesText_;
  224. private SubtitleDisplayManager.DisplayType displayType_;
  225. public enum DisplayType
  226. {
  227. None,
  228. OriginalAndSubtitle,
  229. Subtitle,
  230. Original
  231. }
  232. public static class EnumConvert
  233. {
  234. public static string GetString(SubtitleDisplayManager.DisplayType displayType)
  235. {
  236. string result = "表示しない";
  237. if (displayType == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle)
  238. {
  239. result = "両方表示";
  240. }
  241. else if (displayType == SubtitleDisplayManager.DisplayType.Original)
  242. {
  243. result = "日本語のみ";
  244. }
  245. else if (displayType == SubtitleDisplayManager.DisplayType.Subtitle)
  246. {
  247. result = "英語のみ";
  248. }
  249. return result;
  250. }
  251. }
  252. }