using System;
using UnityEngine;
using UnityEngine.UI;

namespace MyRoomCustom
{
	public class CreativeRoomUISaveLoad : MonoBehaviour
	{
		private void Start()
		{
		}

		public void OpenSavePanel()
		{
			if (this.m_IsOpenSave)
			{
				base.gameObject.SetActive(false);
				this.m_IsOpenSave = false;
				return;
			}
			this.m_IsOpenSave = true;
			this.m_IsOpenLoad = false;
			this.m_UITextTitle.text = "セーブ";
			NDebug.Assert(this.m_Manager, "部屋作成シーンのマネージャが見つかりませんでした");
			base.gameObject.SetActive(true);
			GameObject uiparentButtonArea = this.m_UIParentButtonArea;
			Transform transform = uiparentButtonArea.transform;
			int childCount = transform.childCount;
			for (int i = 0; i < childCount; i++)
			{
				int number = i;
				Transform child = transform.GetChild(number);
				Button componentInChildren = child.GetComponentInChildren<Button>();
				Text textDate = child.GetComponentInChildren<Text>();
				uGUIInputField componentInChildren2 = child.GetComponentInChildren<uGUIInputField>();
				CreativeRoomManager.CreativeRoomHeader saveDataHeader = this.m_Manager.GetSaveDataHeader(number);
				if (saveDataHeader != null)
				{
					componentInChildren.interactable = true;
					componentInChildren2.interactable = true;
					textDate.text = this.m_Manager.DateTimeParse(saveDataHeader.lastWriteTime);
					componentInChildren2.text = saveDataHeader.comment;
				}
				else
				{
					componentInChildren.interactable = true;
					componentInChildren2.interactable = false;
					textDate.text = string.Empty;
					componentInChildren2.text = string.Empty;
				}
				componentInChildren.onClick.RemoveAllListeners();
				componentInChildren.onClick.AddListener(delegate()
				{
					if (!GameMain.Instance.SysDlg.IsDecided)
					{
						return;
					}
					GameMain.Instance.SysDlg.Show("上書きしますか？", SystemDialog.TYPE.OK_CANCEL, delegate
					{
						CreativeRoomManager.CreativeRoomHeader creativeRoomHeader = this.m_Manager.Save(number);
						textDate.text = this.m_Manager.DateTimeParse(creativeRoomHeader.lastWriteTime);
						GameMain.Instance.SysDlg.Close();
					}, delegate
					{
						GameMain.Instance.SysDlg.Close();
					});
				});
				componentInChildren2.onEndEdit.RemoveAllListeners();
				componentInChildren2.onEndEdit.AddListener(delegate(string value)
				{
					this.m_Manager.SaveComment(number, value);
				});
			}
		}

		public void OpenLoadPanel()
		{
			if (this.m_IsOpenLoad)
			{
				base.gameObject.SetActive(false);
				this.m_IsOpenLoad = false;
				return;
			}
			this.m_IsOpenSave = false;
			this.m_IsOpenLoad = true;
			this.m_UITextTitle.text = "ロード";
			NDebug.Assert(this.m_Manager, "[CreativeRoom] 部屋作成シーンのマネージャクラスが見つかりませんでした");
			base.gameObject.SetActive(true);
			GameObject uiparentButtonArea = this.m_UIParentButtonArea;
			Transform transform = uiparentButtonArea.transform;
			int childCount = transform.childCount;
			for (int i = 0; i < childCount; i++)
			{
				int number = i;
				Transform child = transform.GetChild(number);
				Button componentInChildren = child.GetComponentInChildren<Button>();
				Text componentInChildren2 = child.GetComponentInChildren<Text>();
				uGUIInputField componentInChildren3 = child.GetComponentInChildren<uGUIInputField>();
				CreativeRoomManager.CreativeRoomHeader head = this.m_Manager.GetSaveDataHeader(number);
				if (head != null)
				{
					componentInChildren.interactable = true;
					componentInChildren3.interactable = true;
					componentInChildren2.text = this.m_Manager.DateTimeParse(head.lastWriteTime);
					componentInChildren3.text = head.comment;
				}
				else
				{
					componentInChildren.interactable = false;
					componentInChildren3.interactable = false;
					componentInChildren2.text = string.Empty;
					componentInChildren3.text = string.Empty;
				}
				componentInChildren.onClick.RemoveAllListeners();
				componentInChildren.onClick.AddListener(delegate()
				{
					if (head == null)
					{
						return;
					}
					if (!GameMain.Instance.SysDlg.IsDecided)
					{
						return;
					}
					GameMain.Instance.SysDlg.Show("ロードしますか？", SystemDialog.TYPE.OK_CANCEL, delegate
					{
						this.m_Manager.Load(number);
						GameMain.Instance.SysDlg.Close();
						this.gameObject.SetActive(false);
					}, delegate
					{
						GameMain.Instance.SysDlg.Close();
					});
				});
				componentInChildren3.onEndEdit.RemoveAllListeners();
				componentInChildren3.onEndEdit.AddListener(delegate(string value)
				{
					this.m_Manager.SaveComment(number, value);
				});
			}
		}

		private void OnDisable()
		{
			if (this.m_IsQuittingApplication)
			{
				return;
			}
			this.m_IsOpenSave = false;
			this.m_IsOpenLoad = false;
		}

		private void OnApplicationQuit()
		{
			this.m_IsQuittingApplication = (true && Application.isEditor);
		}

		[SerializeField]
		[Tooltip("セーブ、ロードを行うウィンドウのタイトルテキスト")]
		private Text m_UITextTitle;

		[SerializeField]
		[Tooltip("セーブ用のボタンを並べる親オブジェクト")]
		private GameObject m_UIParentButtonArea;

		[SerializeField]
		[Tooltip("部屋作成シーンのマネージャクラス")]
		private CreativeRoomManager m_Manager;

		private bool m_IsOpenSave;

		private bool m_IsOpenLoad;

		private bool m_IsQuittingApplication;
	}
}
