123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class SubtitleDisplayManager : MonoBehaviour
- {
- public static float configMessageAlpha
- {
- get
- {
- return (float)(100 - GameMain.Instance.CMSystem.MsgWndAlpha) / 100f;
- }
- }
- public static SubtitleDisplayManager.DisplayType configDisplayType
- {
- get
- {
- return GameMain.Instance.CMSystem.SubtitleType;
- }
- set
- {
- GameMain.Instance.CMSystem.SubtitleType = value;
- }
- }
- public KeyValuePair<string, string> charaNameText
- {
- get
- {
- return new KeyValuePair<string, string>(this.charaNameText_, this.translatedCharaNameText_);
- }
- set
- {
- this.Awake();
- this.charaNameText_ = ((!string.IsNullOrEmpty(value.Key)) ? value.Key : string.Empty);
- this.translatedCharaNameText_ = ((!string.IsNullOrEmpty(value.Value)) ? value.Value : this.charaNameText_);
- string text = this.charaNameText_;
- if (!string.IsNullOrEmpty(this.translatedCharaNameText_) && this.displayType_ != SubtitleDisplayManager.DisplayType.Original && (this.displayType_ != SubtitleDisplayManager.DisplayType.None || this.hideTypeOverRide != SubtitleDisplayManager.DisplayType.Original))
- {
- text = this.translatedCharaNameText_;
- if ((this.translatedCharaNameText_ != this.charaNameText_ && this.displayType_ == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle) || (this.displayType_ == SubtitleDisplayManager.DisplayType.None && this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle))
- {
- text = this.translatedCharaNameText_ + " / " + this.charaNameText_;
- }
- }
- if (this.charaNameUILabel != null)
- {
- this.charaNameUILabel.text = text;
- this.charaNameUILabel.gameObject.SetActive(!string.IsNullOrEmpty(text));
- }
- if (this.singleCharaNameUILabel != null)
- {
- this.singleCharaNameUILabel.text = text;
- this.singleCharaNameUILabel.gameObject.SetActive(!string.IsNullOrEmpty(text));
- }
- }
- }
- public string originalText
- {
- get
- {
- return this.originalUILabel.text;
- }
- set
- {
- this.Awake();
- if (this.originalText_ == value)
- {
- return;
- }
- this.originalUILabel.text = (this.originalText_ = ((!string.IsNullOrEmpty(value)) ? MessageClass.GetWrapString(this.originalUILabel, value) : string.Empty));
- if (this.displayType_ == SubtitleDisplayManager.DisplayType.Original || (this.displayType_ == SubtitleDisplayManager.DisplayType.None && this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.Original))
- {
- this.singleUILabel.text = this.originalText_;
- }
- }
- }
- public string subtitlesText
- {
- get
- {
- return this.subtitlesUILabel.text;
- }
- set
- {
- this.Awake();
- if (this.subtitlesText_ == value)
- {
- return;
- }
- this.subtitlesUILabel.text = (this.subtitlesText_ = ((!string.IsNullOrEmpty(value)) ? value : string.Empty));
- if (this.displayType_ == SubtitleDisplayManager.DisplayType.Subtitle || (this.displayType_ == SubtitleDisplayManager.DisplayType.None && this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.Subtitle))
- {
- this.singleUILabel.text = this.subtitlesText_;
- }
- }
- }
- public SubtitleDisplayManager.DisplayType displayType
- {
- get
- {
- return this.displayType_;
- }
- set
- {
- this.Awake();
- this.displayType_ = value;
- this.twoTextAreaObject.SetActive(false);
- this.singleTextAreaObject.SetActive(false);
- if (this.displayType_ == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle)
- {
- this.twoTextAreaObject.SetActive(true);
- }
- else if (this.displayType_ == SubtitleDisplayManager.DisplayType.None)
- {
- if (this.hideTypeOverRide != SubtitleDisplayManager.DisplayType.None)
- {
- if (this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle)
- {
- this.twoTextAreaObject.SetActive(true);
- }
- else if (this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.Original || this.hideTypeOverRide == SubtitleDisplayManager.DisplayType.Subtitle)
- {
- this.singleTextAreaObject.SetActive(true);
- this.singleUILabel.text = ((this.hideTypeOverRide != SubtitleDisplayManager.DisplayType.Subtitle) ? this.originalText_ : this.subtitlesText_);
- UILabel uilabel = (this.hideTypeOverRide != SubtitleDisplayManager.DisplayType.Original) ? this.subtitlesUILabel : this.originalUILabel;
- this.singleUILabel.effectDistance = uilabel.effectDistance;
- this.singleUILabel.spacingX = uilabel.spacingX;
- this.singleUILabel.spacingY = uilabel.spacingY;
- }
- }
- }
- else if (this.displayType_ == SubtitleDisplayManager.DisplayType.Original || this.displayType_ == SubtitleDisplayManager.DisplayType.Subtitle)
- {
- this.singleTextAreaObject.SetActive(true);
- this.singleUILabel.text = ((this.displayType_ != SubtitleDisplayManager.DisplayType.Subtitle) ? this.originalText_ : this.subtitlesText_);
- UILabel uilabel2 = (this.displayType_ != SubtitleDisplayManager.DisplayType.Subtitle) ? this.originalUILabel : this.subtitlesUILabel;
- this.singleUILabel.effectDistance = uilabel2.effectDistance;
- this.singleUILabel.spacingX = uilabel2.spacingX;
- this.singleUILabel.spacingY = uilabel2.spacingY;
- }
- this.charaNameText = this.charaNameText;
- }
- }
- public bool visible
- {
- get
- {
- return base.gameObject.activeInHierarchy;
- }
- set
- {
- base.gameObject.SetActive(value);
- }
- }
- public float messageBgAlpha
- {
- get
- {
- return this.setAlpha;
- }
- set
- {
- this.setAlpha = value;
- if (this.messageBgAlphaLinkWidgets != null)
- {
- foreach (UIWidget uiwidget in this.messageBgAlphaLinkWidgets)
- {
- float num = 0.7f * this.setAlpha;
- if (uiwidget != null && !Mathf.Approximately(uiwidget.alpha, num))
- {
- uiwidget.alpha = num;
- }
- }
- }
- }
- }
- private void Awake()
- {
- if (this.callAwake)
- {
- return;
- }
- this.callAwake = true;
- string empty = string.Empty;
- this.subtitlesText = empty;
- this.originalText = empty;
- this.charaNameText = new KeyValuePair<string, string>(string.Empty, string.Empty);
- this.displayType = SubtitleDisplayManager.configDisplayType;
- this.messageBgAlpha = SubtitleDisplayManager.configMessageAlpha;
- }
- public void SetTextFromScriptStyle(string text)
- {
- if (string.IsNullOrEmpty(text))
- {
- string empty = string.Empty;
- this.subtitlesText = empty;
- this.originalText = empty;
- return;
- }
- KeyValuePair<string, string> translationText = MessageClass.GetTranslationText(text);
- this.originalText = translationText.Key;
- this.subtitlesText = translationText.Value;
- }
- public void Update()
- {
- if (!this.autoDisplayTypeChange)
- {
- return;
- }
- if (this.messageBgAlpha != SubtitleDisplayManager.configMessageAlpha)
- {
- this.messageBgAlpha = SubtitleDisplayManager.configMessageAlpha;
- }
- if (this.displayType != SubtitleDisplayManager.configDisplayType)
- {
- this.displayType = SubtitleDisplayManager.configDisplayType;
- }
- }
- [Header("日本語と翻訳,2テキスト表示する時の設定")]
- [SerializeField]
- private GameObject twoTextAreaObject;
- [SerializeField]
- private UILabel charaNameUILabel;
- [SerializeField]
- private UILabel originalUILabel;
- [SerializeField]
- private UILabel subtitlesUILabel;
- [Header("日本語 or 翻訳の1テキストのみ表示する時の設定")]
- [SerializeField]
- private GameObject singleTextAreaObject;
- [SerializeField]
- private UILabel singleCharaNameUILabel;
- [SerializeField]
- private UILabel singleUILabel;
- [Header("メッセージ背景不透明度とリンクされるWidget")]
- [SerializeField]
- private UIWidget[] messageBgAlphaLinkWidgets;
- [Header("None指定の時、特定のタイプに動作をオーバーライドする設定")]
- [SerializeField]
- private SubtitleDisplayManager.DisplayType hideTypeOverRide;
- [Header("コンフィグの内容を読み取って表示タイプを自動更新する")]
- [SerializeField]
- private bool autoDisplayTypeChange = true;
- private bool callAwake;
- private string charaNameText_;
- private string translatedCharaNameText_;
- private string originalText_;
- private string subtitlesText_;
- private SubtitleDisplayManager.DisplayType displayType_;
- private float setAlpha = -1f;
- public enum DisplayType
- {
- None,
- OriginalAndSubtitle,
- Subtitle,
- Original
- }
- public static class EnumConvert
- {
- public static string GetString(SubtitleDisplayManager.DisplayType displayType)
- {
- string result = "表示しない";
- if (displayType == SubtitleDisplayManager.DisplayType.OriginalAndSubtitle)
- {
- result = "両方表示";
- }
- else if (displayType == SubtitleDisplayManager.DisplayType.Original)
- {
- result = "日本語のみ";
- }
- else if (displayType == SubtitleDisplayManager.DisplayType.Subtitle)
- {
- result = "英語のみ";
- }
- return result;
- }
- public static string GetTerm(SubtitleDisplayManager.DisplayType displayType)
- {
- return "Config/字幕タイプ/" + SubtitleDisplayManager.EnumConvert.GetString(displayType);
- }
- }
- }
|