using System;
using System.Xml.Linq;
using UnityEngine;

public class PhotoModeMain : WfScreenChildren
{
	public static void ResetComebackData()
	{
		PhotoModeMain.editTargetMaid = null;
		PhotoModeMain.backupSaveData = null;
	}

	public override void Awake()
	{
		base.Awake();
	}

	protected override void OnCall()
	{
		this.photo_mgr_ = this.RootPanel.GetComponentInChildren<PhotoWindowManager>();
		EventDelegate.Add(this.photo_mgr_.EndButton.onClick, new EventDelegate.Callback(this.OnEnd));
		this.photo_mgr_.CallEditSceneFunction = new Action<Maid>(this.OnCallEdit);
		if (PhotoModeMain.backupSaveData != null)
		{
			base.SetFadeStatus(WfScreenChildren.FadeStatus.Wait);
			this.photo_mgr_.SaveAndLoadManager.ReadSave(PhotoModeMain.backupSaveData);
		}
	}

	protected override bool IsCallFadeIn()
	{
		return PhotoModeMain.backupSaveData == null;
	}

	public void OnDestroy()
	{
		if (GameMain.Instance.isQuitting)
		{
			return;
		}
		GizmoRender.global_control_lock = false;
		if (GameMain.Instance != null && GameMain.Instance.MainCamera != null && GameMain.Instance.MainCamera.camera != null)
		{
			GameMain.Instance.MainCamera.camera.backgroundColor = Color.black;
		}
		if (GameMain.Instance != null && GameMain.Instance.CharacterMgr != null && PhotoModeMain.editTargetMaid != null)
		{
			GameMain.Instance.CharacterMgr.SetActiveMaid(PhotoModeMain.editTargetMaid, 0);
			PhotoModeMain.editTargetMaid = null;
		}
		else
		{
			PhotoModeMain.ResetComebackData();
		}
	}

	public void OnEnd()
	{
		if (GameMain.Instance.SysDlg.IsDecided)
		{
			GameMain.Instance.SysDlg.Show("セーブしていないデータは失われます。\n終了しますか？", SystemDialog.TYPE.OK_CANCEL, new SystemDialog.OnClick(this.OnEndOk), null);
		}
	}

	public void OnEndOk()
	{
		GameMain.Instance.SysDlg.Close();
		this.Finish();
	}

	public void OnCallEdit(Maid maid)
	{
		PhotoModeMain.backupSaveData = this.photo_mgr_.SaveAndLoadManager.WriteSaveToXdocument(string.Empty, string.Empty);
		PhotoModeMain.editTargetMaid = maid;
		PhotoMode photoMode = base.parent_mgr as PhotoMode;
		this.photo_mgr_.OnEnd();
		photoMode.move_screen.SetNextLabel(photoMode.edit_label_name);
		base.parent_mgr.CallScreen("Move");
	}

	protected override void OnFinish()
	{
		this.photo_mgr_.OnEnd();
		base.parent_mgr.CallScreen("Move");
	}

	private static Maid editTargetMaid;

	private static XDocument backupSaveData;

	private PhotoWindowManager photo_mgr_;
}
