SubtitleDisplayManager.cs 8.8 KB

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