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

public class WindowPartsEffectDepthBlur : WindowPartsEffectBase
{
	public override void Awake()
	{
		base.Awake();
		this.depth_field_ = GameMain.Instance.MainCamera.gameObject.AddComponent<DepthOfFieldScatter>();
		if (this.depth_field_.dofHdrShader == null)
		{
			this.depth_field_.dofHdrShader = Shader.Find("Hidden/Dof/DepthOfFieldHdr");
		}
		if (this.depth_field_.dx11BokehShader == null)
		{
			this.depth_field_.dx11BokehShader = Shader.Find("Hidden/Dof/DX11Dof");
		}
		if (this.depth_field_.dx11BokehTexture == null)
		{
			this.depth_field_.dx11BokehTexture = (Resources.Load("Textures/hexShape") as Texture2D);
		}
		this.depth_field_.enabled = false;
		this.backup_value_vector_ = new Vector4(this.depth_field_.focalLength, this.depth_field_.focalSize, this.depth_field_.aperture, this.depth_field_.maxBlurSize);
		this.SettingInput.onChangeValue.Add(new Action<WindowPartsInputSliderSet.SliderAndInputSet, float>(this.OnChangetValue));
		this.DebugDrawCheckBox.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBox));
	}

	public override void OnDestroy()
	{
		if (GameMain.Instance == null || GameMain.Instance.MainCamera == null || this.depth_field_ == null)
		{
			return;
		}
		UnityEngine.Object.DestroyImmediate(this.depth_field_);
		this.depth_field_ = null;
	}

	public override void OnChangeEffectEnabled(bool enabled)
	{
		WFCheckBox debugDrawCheckBox = this.DebugDrawCheckBox;
		this.SettingInput.enabled = enabled;
		debugDrawCheckBox.enabled = enabled;
	}

	public override void Init()
	{
		this.value_vector_ = this.backup_value_vector_;
		this.SettingInput.GetSliderAndInput("focalLength").ResetNum = this.backup_value_vector_.x;
		this.SettingInput.GetSliderAndInput("focalSize").ResetNum = this.backup_value_vector_.y;
		this.SettingInput.GetSliderAndInput("aperture").ResetNum = this.backup_value_vector_.z;
		this.SettingInput.GetSliderAndInput("maxBlurSize").ResetNum = this.backup_value_vector_.w;
		WFCheckBox enabledCheckBox = this.EnabledCheckBox;
		bool check = false;
		this.DebugDrawCheckBox.check = check;
		enabledCheckBox.check = check;
		this.UpdateGui();
	}

	public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
	{
		if (!maid.boMAN || is_deserialize_load || !base.effect_enabled || !this.depth_field_.visualizeFocus)
		{
			return;
		}
		this.DebugDrawCheckBox.check = false;
		this.OnClickCheckBox(this.DebugDrawCheckBox);
	}

	public override void OnClickEnabledCheckBox(WFCheckBox check_box)
	{
		base.OnClickEnabledCheckBox(check_box);
		this.CheckManPartVisible();
	}

	public void OnChangetValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
	{
		if (input_object.Name == "focalLength")
		{
			this.value_vector_.x = val;
		}
		else if (input_object.Name == "focalSize")
		{
			this.value_vector_.y = val;
		}
		else if (input_object.Name == "aperture")
		{
			this.value_vector_.z = val;
		}
		else if (input_object.Name == "maxBlurSize")
		{
			this.value_vector_.w = val;
		}
		this.depth_field_.focalLength = this.value_vector_.x;
		this.depth_field_.focalSize = this.value_vector_.y;
		this.depth_field_.aperture = this.value_vector_.z;
		this.depth_field_.maxBlurSize = this.value_vector_.w;
	}

	public void OnClickCheckBox(WFCheckBox check_box)
	{
		this.depth_field_.visualizeFocus = check_box.check;
		this.CheckManPartVisible();
	}

	private void CheckManPartVisible()
	{
		CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
		FaceWindow faceWindow = this.effect_window_.mgr.GetWindow(PhotoWindowManager.WindowType.Face) as FaceWindow;
		for (int i = 0; i < characterMgr.GetStockManCount(); i++)
		{
			Maid stockMan = characterMgr.GetStockMan(i);
			if (stockMan.Visible)
			{
				if (base.effect_enabled && this.depth_field_.visualizeFocus)
				{
					stockMan.body0.SetChinkoVisible(false);
					faceWindow.PartVisibleCheckBox.enabled = false;
				}
				else
				{
					Dictionary<string, string> maidStoreData = faceWindow.GetMaidStoreData(stockMan);
					stockMan.body0.SetChinkoVisible(bool.Parse(maidStoreData["parts_visible"]));
					faceWindow.PartVisibleCheckBox.enabled = true;
				}
			}
		}
	}

	public override void OnSerializeEvent()
	{
		Dictionary<string, Dictionary<string, string>> woldStoreData = this.effect_window_.GetWoldStoreData();
		woldStoreData["DepthBlur"] = new Dictionary<string, string>();
		Dictionary<string, string> dictionary = woldStoreData["DepthBlur"];
		dictionary.Add("value_vector", this.value_vector_.ToString("G9"));
		dictionary.Add("enabled", base.effect_enabled.ToString());
	}

	public override void OnDeserializeEvent()
	{
		Dictionary<string, Dictionary<string, string>> woldStoreData = this.effect_window_.GetWoldStoreData();
		if (!woldStoreData.ContainsKey("DepthBlur"))
		{
			this.ResetValue();
			this.value_vector_ = this.backup_value_vector_;
			this.EnabledCheckBox.check = base.effect_enabled;
			this.DebugDrawCheckBox.check = false;
		}
		else
		{
			Dictionary<string, string> dictionary = woldStoreData["DepthBlur"];
			this.value_vector_ = Parse.Vector4(dictionary["value_vector"]);
			base.effect_enabled = bool.Parse(dictionary["enabled"]);
			this.depth_field_.focalLength = this.value_vector_.x;
			this.depth_field_.focalSize = this.value_vector_.y;
			this.depth_field_.aperture = this.value_vector_.z;
			this.depth_field_.maxBlurSize = this.value_vector_.w;
		}
		this.depth_field_.visualizeFocus = false;
		this.UpdateGui();
	}

	public void ResetValue()
	{
		this.depth_field_.focalLength = this.backup_value_vector_.x;
		this.depth_field_.focalSize = this.backup_value_vector_.y;
		this.depth_field_.aperture = this.backup_value_vector_.z;
		this.depth_field_.maxBlurSize = this.backup_value_vector_.w;
		this.depth_field_.visualizeFocus = false;
		base.effect_enabled = false;
	}

	public void UpdateGui()
	{
		this.SettingInput.GetSliderAndInput("focalLength").value = this.value_vector_.x;
		this.SettingInput.GetSliderAndInput("focalSize").value = this.value_vector_.y;
		this.SettingInput.GetSliderAndInput("aperture").value = this.value_vector_.z;
		this.SettingInput.GetSliderAndInput("maxBlurSize").value = this.value_vector_.w;
		this.EnabledCheckBox.check = base.effect_enabled;
		this.DebugDrawCheckBox.check = this.depth_field_.visualizeFocus;
		this.OnChangeEffectEnabled(this.EnabledCheckBox.check);
		if (!this.EnabledCheckBox.check || !this.DebugDrawCheckBox.check)
		{
			FaceWindow faceWindow = this.effect_window_.mgr.GetWindow(PhotoWindowManager.WindowType.Face) as FaceWindow;
			faceWindow.PartVisibleCheckBox.enabled = true;
		}
	}

	protected override MonoBehaviour effect_object
	{
		get
		{
			return this.depth_field_;
		}
	}

	public WindowPartsInputSliderSet SettingInput;

	public WFCheckBox DebugDrawCheckBox;

	private DepthOfFieldScatter depth_field_;

	private Vector4 backup_value_vector_;

	private Vector4 value_vector_;
}
