using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using wf;

public class SoundWindow : BaseMaidPhotoWindow
{
	public override void Awake()
	{
		base.Awake();
		PhotoSoundData.Create();
		this.scroll_view_ = NGUITools.FindInParents<UIScrollView>(this.Grid.transform);
		for (int i = 0; i < PhotoSoundData.data.Count; i++)
		{
			PhotoSoundData photoSoundData = PhotoSoundData.data[i];
			GameObject gameObject = Utility.CreatePrefab(this.Grid.gameObject, "ScenePhotoMode/WindowListItem", true);
			gameObject.name = photoSoundData.id.ToString();
			UILabel componentInChildren = gameObject.GetComponentInChildren<UILabel>();
			componentInChildren.fontSize = 15;
			componentInChildren.text = photoSoundData.name;
			EventDelegate.Add(gameObject.GetComponent<UIWFTabButton>().onSelect, new EventDelegate.Callback(this.OnSelectBtn));
		}
		this.tab_panel_ = this.Grid.GetComponent<UIWFTabPanel>();
		NGUITools.FindInParents<UIScrollView>(this.Grid.transform).ResetPosition();
		this.Grid.Reposition();
		this.tab_panel_.UpdateChildren();
		this.scroll_view_.ResetPosition();
		this.UpdateChildren();
	}

	public override void Start()
	{
		base.Start();
		this.Init();
	}

	public void Init()
	{
		Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
		if (!woldStoreData.ContainsKey("再生サウンド"))
		{
			woldStoreData["再生サウンド"] = new Dictionary<string, string>();
			woldStoreData["再生サウンド"]["id"] = PhotoSoundData.Get(Path.ChangeExtension(this.initBgmFileName, ".ogg")).id.ToString();
		}
		long num = long.Parse(woldStoreData["再生サウンド"]["id"]);
		if (PhotoSoundData.Get(num) == null)
		{
			num = PhotoSoundData.Get("BGM021.ogg").id;
		}
		UIWFTabButton uiwftabButton = null;
		List<Transform> childList = this.Grid.GetChildList();
		int num2 = 0;
		while (num2 < childList.Count && uiwftabButton == null)
		{
			if (long.Parse(childList[num2].name) == num)
			{
				uiwftabButton = childList[num2].GetComponent<UIWFTabButton>();
			}
			num2++;
		}
		this.tab_panel_.Select(uiwftabButton);
	}

	public void OnSelectBtn()
	{
		if (!UIWFSelectButton.current.isSelected)
		{
			return;
		}
		long id = long.Parse(UIWFSelectButton.current.name);
		PhotoSoundData photoSoundData = PhotoSoundData.Get(id);
		photoSoundData.Play();
		Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
		if (!woldStoreData.ContainsKey("再生サウンド"))
		{
			woldStoreData["再生サウンド"] = new Dictionary<string, string>();
		}
		woldStoreData["再生サウンド"]["id"] = id.ToString();
	}

	public override void OnFinishMaidDeserializeLoad()
	{
		base.OnFinishMaidDeserializeLoad();
		this.scroll_view_.ResetPosition();
		GameMain.Instance.SoundMgr.StopBGM(0f);
		this.Init();
	}

	public override void OnDeserializeEvent()
	{
		List<string> maidStoreGuidList = this.mgr.GetMaidStoreGuidList();
		if (maidStoreGuidList.Count == 0)
		{
			this.scroll_view_.ResetPosition();
			GameMain.Instance.SoundMgr.StopBGM(0f);
			this.Init();
		}
	}

	public new PhotoWindowManager mgr
	{
		get
		{
			return base.mgr;
		}
	}

	public UIGrid Grid;

	public string initBgmFileName;

	private UIWFTabPanel tab_panel_;

	private UIScrollView scroll_view_;
}
