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 string charaNameText
	{
		get
		{
			return this.charaNameText_;
		}
		set
		{
			this.Awake();
			if (this.charaNameText_ == value)
			{
				return;
			}
			this.charaNameText_ = ((!string.IsNullOrEmpty(value)) ? value : string.Empty);
			if (this.charaNameUILabel != null)
			{
				this.charaNameUILabel.text = this.charaNameText_;
				this.charaNameUILabel.gameObject.SetActive(!string.IsNullOrEmpty(this.charaNameText_));
			}
			if (this.singleCharaNameUILabel != null)
			{
				this.singleCharaNameUILabel.text = this.charaNameText_;
				this.singleCharaNameUILabel.gameObject.SetActive(!string.IsNullOrEmpty(this.charaNameText_));
			}
		}
	}

	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;
			}
		}
	}

	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 text = string.Empty;
		this.charaNameText = text;
		text = text;
		this.subtitlesText = text;
		this.originalText = text;
		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 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);
		}
	}
}
