using System;
using System.Collections.Generic;

public class UserEditMgr : BaseCreatePanel
{
	public override void Init()
	{
		this.m_goPanel = base.GetPanel("UserEditPanel");
		this.m_ctrl = base.GetCtrl<UserEditCtrl>();
		this.m_api = new UserEditAPI();
		this.m_ctrl.Init(this, this.m_api, this.m_goPanel);
		this.m_goPanel.SetActive(false);
		this.m_api.Init(this, new UserEditAPI.dgOnCharaLoadedCallBack(this.OnCharaLoaded));
		this.m_init = true;
	}

	private void OnCharaLoaded()
	{
		this.OpenUserEditPanel();
	}

	public void OnDestroy()
	{
		if (this.m_api != null)
		{
			this.m_api.Uninit();
		}
	}

	public void OpenUserEditPanel()
	{
		base.BaseOpenPanel();
	}

	protected override void OpenPanel()
	{
		Dictionary<string, UserEditCtrl.HeadButton> dicHeadPreset = this.LoadData();
		this.m_ctrl.CreateViewer(dicHeadPreset);
	}

	public void CloseUserEditPanel()
	{
		base.BaseClosePanel();
	}

	protected override void BeforeClose()
	{
		this.m_ctrl.SaveAndLoadScene();
	}

	protected override void AfterClose()
	{
		if (this.sceneMgr != null)
		{
			this.m_api.EndNextScene(new CameraMain.dgOnCompleteFade(this.sceneMgr.CloseScene));
		}
	}

	public void ClickPreset()
	{
		string name = UIButton.current.name;
		if (name != this.m_currentActivePreset)
		{
			this.m_ctrl.SetPreset(name);
			this.m_currentActivePreset = name;
		}
	}

	public void OnAbdomenValueChange()
	{
		if (this.m_init)
		{
			this.m_ctrl.UpdateAbdomenValue();
		}
	}

	public void OnColorValueChange()
	{
		if (this.m_init)
		{
			this.m_ctrl.UpdateColorValue();
		}
	}

	public void OnChangeName()
	{
		string value = UIInput.current.value;
		this.m_ctrl.SetName(value);
	}

	protected override void SetFadeTargetPanel()
	{
		this.fadeTargetPanel = this.m_goPanel;
	}

	private Dictionary<string, UserEditCtrl.HeadButton> LoadData()
	{
		Dictionary<string, UserEditCtrl.HeadButton> dictionary = new Dictionary<string, UserEditCtrl.HeadButton>();
		List<SceneEdit.SMenuItem> menu = this.m_api.GetMenu(MPN.head);
		foreach (SceneEdit.SMenuItem smenuItem in menu)
		{
			if (smenuItem.m_bMan)
			{
				UserEditCtrl.HeadButton headButton = new UserEditCtrl.HeadButton();
				headButton.name = smenuItem.m_strMenuFileName;
				headButton.headIcon = smenuItem.m_texIcon;
				headButton.item = smenuItem;
				if (!dictionary.ContainsKey(headButton.name))
				{
					dictionary.Add(headButton.name, headButton);
				}
			}
		}
		return dictionary;
	}

	private UserEditCtrl m_ctrl;

	private string m_currentActivePreset;

	private bool m_init;

	private UserEditAPI m_api;
}
