using System;
using System.Collections;
using MaidStatus;
using UnityEngine;
using wf;

public class AdditionalScenario : MonoBehaviour
{
	public void Init(string label)
	{
		this.m_MyPanel = base.GetComponent<UIPanel>();
		this.m_JumpLabel = label;
		base.StartCoroutine(this.Fade(true));
		ScenarioData[] addedScenario = GameMain.Instance.ScenarioSelectMgr.AddedScenario;
		if (addedScenario.Length <= 0)
		{
			Debug.Log("昨日から追加されたシナリオはもうありません");
			UnityEngine.Object.Destroy(base.gameObject);
			return;
		}
		this.m_FewVer.SetActive(false);
		this.m_ManyVer.SetActive(false);
		int num = 0;
		foreach (ScenarioData scenarioData in addedScenario)
		{
			if (!scenarioData.IsFixedMaid)
			{
				if (scenarioData.EventMaidCount > 0)
				{
					foreach (Maid maid in scenarioData.GetEventMaidList())
					{
						num++;
					}
				}
				else
				{
					num++;
				}
			}
			else if (!string.IsNullOrEmpty(scenarioData.Notification))
			{
				num++;
			}
			else if (scenarioData.EventMaidCount == 1)
			{
				if (scenarioData.GetEventMaid(0).status.heroineType == HeroineType.Sub)
				{
					num++;
				}
				else
				{
					num++;
				}
			}
			else
			{
				num++;
			}
		}
		GameObject gameObject = (num <= this.m_ManyModeCount) ? this.m_FewVer : this.m_ManyVer;
		gameObject.SetActive(true);
		this.m_UIScroll = gameObject.transform.Find("Contents").GetComponent<UIScrollView>();
		this.m_UIGrid = gameObject.transform.Find("Contents/Grid").GetComponent<UIGrid>();
		Action<string, string> action = delegate(string title, string chara)
		{
			GameObject gameObject2 = Utility.CreatePrefab(this.m_UIGrid.gameObject, "SceneScenarioSelect/Prefab/Additional", true);
			gameObject2.transform.Find("Title").GetComponent<UILabel>().text = title;
			gameObject2.transform.Find("Chara").GetComponent<UILabel>().text = chara;
		};
		foreach (ScenarioData scenarioData2 in addedScenario)
		{
			if (!scenarioData2.IsFixedMaid)
			{
				if (scenarioData2.EventMaidCount > 0)
				{
					foreach (Maid maid2 in scenarioData2.GetEventMaidList())
					{
						if (string.IsNullOrEmpty(scenarioData2.Notification))
						{
							action(scenarioData2.NotLineTitle, (!maid2.status.isFirstNameCall) ? maid2.status.lastName : maid2.status.firstName);
						}
						else
						{
							action(scenarioData2.NotLineTitle, scenarioData2.Notification);
						}
					}
				}
				else
				{
					action(scenarioData2.NotLineTitle, scenarioData2.Notification);
				}
			}
			else if (!string.IsNullOrEmpty(scenarioData2.Notification))
			{
				action(scenarioData2.NotLineTitle, scenarioData2.Notification);
			}
			else if (scenarioData2.EventMaidCount == 1)
			{
				if (scenarioData2.GetEventMaid(0).status.heroineType == HeroineType.Sub)
				{
					action(scenarioData2.NotLineTitle, "NPC");
				}
				else
				{
					action(scenarioData2.NotLineTitle, GameMain.Instance.ScenarioSelectMgr.GetConvertPersonal(scenarioData2.GetEventMaid(0)));
				}
			}
			else
			{
				action(scenarioData2.NotLineTitle, this.m_IdolNotice);
			}
		}
		if (this.m_UIGrid)
		{
			this.m_UIGrid.repositionNow = true;
		}
		if (this.m_UIScroll)
		{
			this.m_UIScroll.ResetPosition();
		}
		EventDelegate.Add(this.m_MyButton.onClick, new EventDelegate.Callback(this.FadeOut));
	}

	private void FadeOut()
	{
		if (this.m_MyPanel.alpha > 0.9f)
		{
			base.StartCoroutine(this.Fade(false));
		}
	}

	private IEnumerator Fade(bool is_fadein)
	{
		float timer = 0f;
		for (;;)
		{
			float rate = Mathf.Sin(Mathf.Clamp01(timer / this.m_FadeTime) * 90f * 0.0174532924f);
			if (!is_fadein)
			{
				rate = 1f - rate;
			}
			this.m_MyPanel.alpha = rate;
			timer += Time.deltaTime;
			if (timer >= this.m_FadeTime)
			{
				break;
			}
			yield return null;
		}
		if (!is_fadein)
		{
			UnityEngine.Object.Destroy(base.gameObject);
			if (!string.IsNullOrEmpty(this.m_JumpLabel))
			{
				GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_JumpLabel);
				GameMain.Instance.ScriptMgr.adv_kag.Exec();
			}
		}
		yield break;
		yield break;
	}

	[SerializeField]
	private float m_FadeTime = 0.5f;

	[SerializeField]
	private UIButton m_MyButton;

	[SerializeField]
	private GameObject m_FewVer;

	[SerializeField]
	private GameObject m_ManyVer;

	[SerializeField]
	[Header("この数以上で多数表示")]
	private int m_ManyModeCount = 8;

	private UIPanel m_MyPanel;

	private UIScrollView m_UIScroll;

	private UIGrid m_UIGrid;

	[SerializeField]
	[Header("固定3人イベントのときの呼称")]
	private string m_IdolNotice = "アイドルルート";

	private string m_JumpLabel = string.Empty;
}
