using System;
using UnityEngine;

[RequireComponent(typeof(WfFadeBasic))]
public class SceneEditNameSettingPanel : MonoBehaviour
{
	public Maid maid
	{
		get
		{
			return GameMain.Instance.CharacterMgr.GetMaid(0);
		}
	}

	public void Awake()
	{
		this.fadeBasic = base.GetComponent<WfFadeBasic>();
		EventDelegate.Add(this.lastNameInput.onChange, new EventDelegate.Callback(this.OnInputName));
		EventDelegate.Add(this.firstNameInput.onChange, new EventDelegate.Callback(this.OnInputName));
		EventDelegate.Add(this.enterButton.onClick, new EventDelegate.Callback(this.Close));
		EventDelegate.Add(this.cancelButton.onClick, new EventDelegate.Callback(this.Chancel));
		EventDelegate.Add(this.lastNameRandomButton.onClick, delegate()
		{
			this.lastNameInput.RemoveFocus();
			this.lastNameInput.value = MaidRandomName.GetLastName();
		});
		EventDelegate.Add(this.firstNameRandomButton.onClick, delegate()
		{
			this.firstNameInput.RemoveFocus();
			this.firstNameInput.value = MaidRandomName.GetFirstName();
		});
		this.fadeBasic.onCompleteFadeInAction = delegate(WfFadeBasic execFade)
		{
			this.lastNameInput.isSelected = true;
		};
	}

	public void Call()
	{
		this.backupLastName = this.maid.status.lastName;
		this.backupFirstName = this.maid.status.firstName;
		this.lastNameInput.value = this.backupLastName;
		this.firstNameInput.value = this.backupFirstName;
		this.fadeBasic.alpha = 0f;
		WfFadeJob.Create(this.fadeBasic, null, 0.3f, iTween.EaseType.linear);
	}

	public void Chancel()
	{
		if (this.fadeBasic.alpha != 1f)
		{
			return;
		}
		this.maid.status.lastName = this.backupLastName;
		this.maid.status.firstName = this.backupFirstName;
		this.Close();
	}

	public void Close()
	{
		this.lastNameInput.RemoveFocus();
		this.firstNameInput.RemoveFocus();
		this.fadeBasic.alpha = 1f;
		WfFadeJob.Create(null, this.fadeBasic, 0.3f, iTween.EaseType.linear);
	}

	private void OnInputName()
	{
		if (UIInput.current == this.lastNameInput)
		{
			this.maid.status.lastName = UIInput.current.value;
		}
		else
		{
			this.maid.status.firstName = UIInput.current.value;
		}
		UIInput.current.value = ((!(UIInput.current == this.lastNameInput)) ? this.maid.status.firstName : this.maid.status.lastName);
	}

	[SerializeField]
	private UIInput lastNameInput;

	[SerializeField]
	private UIButton lastNameRandomButton;

	[SerializeField]
	private UIInput firstNameInput;

	[SerializeField]
	private UIButton firstNameRandomButton;

	[SerializeField]
	private UIButton enterButton;

	[SerializeField]
	private UIButton cancelButton;

	private WfFadeBasic fadeBasic;

	private string backupLastName;

	private string backupFirstName;
}
