SubtitleDisplayManager.cs 7.8 KB

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