using System;
using System.Collections.Generic;
using UnityEngine;

namespace Kasizuki
{
	public class MaidMiniManagementCtrl : WfScreenChildren
	{
		public override void Awake()
		{
			base.Awake();
			this.m_SwitchingWindowDic = new Dictionary<string, NGUIWindow>();
			this.m_SwitchingWindowDic.Add("ステータス", UTY.GetChildObject(base.root_obj, "MaidMiniStatusPanel", false).GetComponent<NGUIWindow>());
			this.m_SwitchingWindowDic.Add("性癖", UTY.GetChildObject(base.root_obj, "MaidSeihekiPanel", false).GetComponent<NGUIWindow>());
			this.m_SwitchingWindowDic.Add("好感度", UTY.GetChildObject(base.root_obj, "MaidLikabilityPanel", false).GetComponent<NGUIWindow>());
			this.m_SwitchingWindowDic.Add("持ち込みアイテム", UTY.GetChildObject(base.root_obj, "Window Select Item", false).GetComponent<NGUIWindow>());
			this.m_SwitchingWindowDic.Add("パラメータロック", UTY.GetChildObject(base.root_obj, "Window Parameter Lock", false).AddComponent<NGUIWindow>());
			this.m_CharaSelectMgr = UTY.GetChildObject(base.root_obj, "CharacterSelectPanel", false).GetComponent<KasizukiCharacterSelectCtrl>();
			this.m_ButtonDic.Add("エディット", UTY.GetChildObject(base.root_obj, "ButtonParent/エディット", false).GetComponent<UIButton>());
			this.m_ButtonDic.Add("OK", UTY.GetChildObject(base.root_obj, "ButtonParent/OK", false).GetComponent<UIButton>());
			this.m_ButtonDic.Add("Cancel", UTY.GetChildObject(base.root_obj, "ButtonParent/Cancel", false).GetComponent<UIButton>());
			foreach (KeyValuePair<string, UIButton> keyValuePair in this.m_ButtonDic)
			{
				EventDelegate.Add(keyValuePair.Value.onClick, new EventDelegate.Callback(this.OnClickButton));
			}
			this.SetUpParameterLockWindow();
		}

		public void OnEnable()
		{
			this.m_SelectMaid = null;
			this.UpdateMaidInfoButtonEnable(false, true);
		}

		public void Open()
		{
			if (GameMain.Instance.KasizukiMgr.GetNowManType() == 10)
			{
				this.m_SwitchingWindowDic["パラメータロック"].GetCache<WFCheckBox>("好感度").enabled = false;
				this.m_SwitchingWindowDic["パラメータロック"].GetCache<WFCheckBox>("好感度").check = true;
			}
			else
			{
				this.m_SwitchingWindowDic["パラメータロック"].GetCache<WFCheckBox>("好感度").enabled = true;
				this.m_SwitchingWindowDic["パラメータロック"].GetCache<WFCheckBox>("好感度").check = GameMain.Instance.KasizukiMgr.GetSystemData<bool>(SystemDataType.好感度ロック);
			}
			this.UpdateMaidInfoButtonEnable(false, true);
			this.m_CharaSelectMgr.SetData();
		}

		protected override void OnCall()
		{
			this.m_CharaMgr = GameMain.Instance.CharacterMgr;
			this.edit_label_ = (base.parent_mgr as SceneKasizukiMainMenu).strScriptReturnLabelEdit;
			this.SetUpCharacterSelectManager();
			(this.m_SwitchingWindowDic["持ち込みアイテム"] as KasizukiItemCtrl).SetData();
			this.m_SwitchingWindowDic["持ち込みアイテム"].Close(0f, null);
		}

		private void SetUpCharacterSelectManager()
		{
			this.m_CharaSelectMgr.callbackSelectItem = new Action<Maid>(this.OnSelectChara);
		}

		private void SetUpParameterLockWindow()
		{
			KasizukiManager kasizukiMgr = GameMain.Instance.KasizukiMgr;
			NGUIWindow nguiwindow = this.m_SwitchingWindowDic["パラメータロック"];
			WFCheckBox wfcheckBox = nguiwindow.CacheChildObject<WFCheckBox>("ParentToggle/LockLikability/好感度", "好感度");
			WFCheckBox wfcheckBox2 = nguiwindow.CacheChildObject<WFCheckBox>("ParentToggle/LockPlayCount/仕事回数", "仕事回数");
			wfcheckBox.check = kasizukiMgr.GetSystemData<bool>(SystemDataType.好感度ロック);
			wfcheckBox2.check = kasizukiMgr.GetSystemData<bool>(SystemDataType.仕事回数ロック);
			wfcheckBox.onClick.Add(new Action<WFCheckBox>(this.OnChangeLock));
			wfcheckBox2.onClick.Add(new Action<WFCheckBox>(this.OnChangeLock));
		}

		private void OnSelectChara(Maid select_maid)
		{
			this.m_SelectMaid = select_maid;
			this.UpdateMaidInfoButtonEnable(this.m_SelectMaid != null, false);
			this.m_ButtonDic["OK"].isEnabled = (this.m_SelectMaid != null);
			this.m_ButtonDic["エディット"].gameObject.SetActive(this.m_SelectMaid != null);
			this.m_CharaSelectMgr.bigThumbnail.Visible = (this.m_SelectMaid != null);
			this.m_CharaSelectMgr.bigThumbnail.SetMaid(this.m_SelectMaid);
			this.m_SwitchingWindowDic["ステータス"].GetComponent<IStatusCtrl<Maid>>().SetData(this.m_SelectMaid);
			this.m_SwitchingWindowDic["性癖"].GetComponent<IStatusCtrl<Maid>>().SetData(this.m_SelectMaid);
			this.m_SwitchingWindowDic["好感度"].GetComponent<IStatusCtrl<Maid>>().SetData(this.m_SelectMaid);
			this.m_SwitchingWindowDic["ステータス"].Open(0.25f, null);
			this.m_SwitchingWindowDic["性癖"].Open(0.25f, null);
			this.m_SwitchingWindowDic["好感度"].Open(0.25f, null);
			this.m_SwitchingWindowDic["パラメータロック"].Open(0.25f, null);
		}

		private void OnClickButton()
		{
			string text = string.Empty;
			foreach (KeyValuePair<string, UIButton> keyValuePair in this.m_ButtonDic)
			{
				if (keyValuePair.Value == UIButton.current)
				{
					text = keyValuePair.Key;
					break;
				}
			}
			if (string.IsNullOrEmpty(text))
			{
				Debug.LogWarning("押されたボタンの名前が見つかりませんでした");
				return;
			}
			Debug.LogFormat("ボタン「{0}」が押された", new object[]
			{
				text
			});
			if (text == "エディット")
			{
				if (this.m_SelectMaid == null)
				{
					Debug.LogWarning("メイドが選択されていません");
					return;
				}
				if (string.IsNullOrEmpty(this.edit_label_))
				{
					Debug.LogWarning("エディットの飛び先ラベルがありません");
					return;
				}
				this.m_CharaMgr.SetActiveMaid(this.m_SelectMaid, 0);
				(base.parent_mgr as SceneKasizukiMainMenu).moveScreen.SetNextLabel(this.edit_label_);
				this.Finish();
			}
			else if (text == "OK")
			{
				if (this.m_OnClickOK != null)
				{
					this.m_OnClickOK();
				}
				else
				{
					Debug.LogWarning("OKボタンを押したときのコールバックが未登録です");
				}
			}
			else if (text == "Cancel")
			{
				if (this.m_OnClickCancel != null)
				{
					this.m_OnClickCancel();
				}
				else
				{
					Debug.LogWarning("Cancelボタンを押したときのコールバックが未登録です");
				}
			}
			else if (this.m_SelectMaid == null)
			{
				Debug.LogWarningFormat("ボタン「{0}」を押しましたが、選択しているメイドがnullでした", new object[]
				{
					text
				});
			}
			else
			{
				Debug.LogWarningFormat("ボタン「{0}」の処理はありません", new object[]
				{
					text
				});
			}
		}

		private void OnChangeLock(WFCheckBox checkBox)
		{
			NGUIWindow nguiwindow = this.m_SwitchingWindowDic["パラメータロック"];
			List<UnityEngine.Object> values = nguiwindow.cachedObjectDic.Values;
			if (!values.Contains(checkBox))
			{
				NDebug.Warning(string.Format("クリックされたボタン名に対応するボタンがありません\n{0}", checkBox.name));
			}
			if (!checkBox.GetComponent<Collider>().enabled)
			{
				return;
			}
			string name = checkBox.name;
			bool check = checkBox.check;
			if (name == "好感度")
			{
				KasizukiManager kasizukiMgr = GameMain.Instance.KasizukiMgr;
				kasizukiMgr.SetSystemData<bool>(SystemDataType.好感度ロック, check, false);
				Debug.LogFormat("好感度ロック：{0}", new object[]
				{
					check
				});
			}
			else if (name == "仕事回数")
			{
				KasizukiManager kasizukiMgr2 = GameMain.Instance.KasizukiMgr;
				kasizukiMgr2.SetSystemData<bool>(SystemDataType.仕事回数ロック, check, false);
				Debug.LogFormat("仕事回数ロック：{0}", new object[]
				{
					check
				});
			}
		}

		public void UpdateMaidInfoButtonEnable(bool isEnable, bool isImmediate = false)
		{
			float num = (!isImmediate) ? 0.25f : 0.01f;
			float num2 = (!isEnable) ? 0f : 1f;
			if (this.m_CharaSelectMgr && this.m_CharaSelectMgr.bigThumbnail)
			{
				this.m_CharaSelectMgr.bigThumbnail.Visible = isEnable;
			}
		}

		public void OpenSwitchingWindow(string name, bool isImmediate = false)
		{
			Dictionary<string, NGUIWindow> switchingWindowDic = this.m_SwitchingWindowDic;
			if (switchingWindowDic == null)
			{
				NDebug.Assert("ウィンドウの配列にnullが指定されました", false);
			}
			if (!switchingWindowDic.ContainsKey(name))
			{
				NDebug.Assert(string.Format("ウィンドウの配列には「{0}」のキーが存在しません", name), false);
			}
			foreach (KeyValuePair<string, NGUIWindow> keyValuePair in switchingWindowDic)
			{
				if (keyValuePair.Key == name)
				{
					if (isImmediate)
					{
						keyValuePair.Value.Open(0.01f, null);
					}
					else
					{
						keyValuePair.Value.Open(0.25f, null);
					}
				}
				else if (isImmediate)
				{
					keyValuePair.Value.Close(0.01f, null);
				}
				else
				{
					keyValuePair.Value.Close(0.25f, null);
				}
			}
		}

		public void CloseSwitchingWindowAll(bool isImmediate = false)
		{
			Dictionary<string, NGUIWindow> switchingWindowDic = this.m_SwitchingWindowDic;
			if (switchingWindowDic == null)
			{
				NDebug.Assert("ウィンドウの配列にnullが指定されました", false);
			}
			foreach (KeyValuePair<string, NGUIWindow> keyValuePair in switchingWindowDic)
			{
				if (isImmediate)
				{
					keyValuePair.Value.Close(0.01f, null);
				}
				else
				{
					keyValuePair.Value.Close(0.25f, null);
				}
			}
		}

		public T GetWindow<T>(string cachedName) where T : MonoBehaviour
		{
			if (!this.m_SwitchingWindowDic.ContainsKey(cachedName))
			{
				NDebug.Assert(string.Format("ウィンドウの配列には「{0}」\nというオブジェクトが存在しません", cachedName), false);
				Debug.LogError(string.Format("ウィンドウの配列には「{0}」\nというオブジェクトが存在しません", cachedName));
				return (T)((object)null);
			}
			NGUIWindow nguiwindow = this.m_SwitchingWindowDic[cachedName];
			T result;
			try
			{
				T t = nguiwindow as T;
				result = t;
			}
			catch (Exception ex)
			{
				NDebug.Assert(ex.ToString(), false);
				Debug.LogError(ex);
				result = (T)((object)null);
			}
			return result;
		}

		protected override void OnFinish()
		{
			SceneKasizukiMainMenu sceneKasizukiMainMenu = base.parent_mgr as SceneKasizukiMainMenu;
			if (sceneKasizukiMainMenu.moveScreen.next_label == this.edit_label_ && this.m_CharaMgr.GetMaid(0) != null)
			{
				this.m_CharaMgr.GetMaid(0).Visible = true;
			}
			if (!string.IsNullOrEmpty(sceneKasizukiMainMenu.moveScreen.next_label))
			{
				sceneKasizukiMainMenu.CallScreen("Move");
			}
		}

		public Action onClickOK
		{
			set
			{
				this.m_OnClickOK = value;
			}
		}

		public Action onClickCancel
		{
			set
			{
				this.m_OnClickCancel = value;
			}
		}

		public Maid selectMaid
		{
			get
			{
				return this.m_SelectMaid;
			}
			set
			{
				this.m_SelectMaid = value;
			}
		}

		public KasizukiCharacterSelectCtrl charaSelectMgr
		{
			get
			{
				return this.m_CharaSelectMgr;
			}
		}

		public Dictionary<string, UIButton> buttonDic
		{
			get
			{
				return this.m_ButtonDic;
			}
		}

		public static string BackUpSelectMaidGUID = string.Empty;

		public static float BackUpBarValue = 0f;

		private Action m_OnClickOK;

		private Action m_OnClickCancel;

		private Maid m_SelectMaid;

		private CharacterMgr m_CharaMgr;

		private KasizukiCharacterSelectCtrl m_CharaSelectMgr;

		private Dictionary<string, UIButton> m_ButtonDic = new Dictionary<string, UIButton>();

		private Dictionary<string, NGUIWindow> m_SwitchingWindowDic;

		private string edit_label_;
	}
}
