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

public class WindowPartsTransform : MonoBehaviour
{
	public virtual void Awake()
	{
		this.visible_setting_btn_dic_ = new Dictionary<string, UIWFTabButton>();
		if (this.VisibleSettingTab != null)
		{
			this.VisibleSettingTab.UpdateChildren();
			if (this.PosInput != null)
			{
				this.visible_setting_btn_dic_.Add("move", UTY.GetChildObject(this.VisibleSettingTab.gameObject, "MoveBtn/Btn", false).GetComponent<UIWFTabButton>());
				EventDelegate.Add(this.visible_setting_btn_dic_["move"].onClick, delegate()
				{
					this.axis_visible_type_ = WindowPartsTransform.AxisVisibleType.Position;
					this.OnChangeAxisVisibleType();
				});
			}
			else
			{
				UTY.GetChildObject(this.VisibleSettingTab.gameObject, "MoveBtn/Btn", false).SetActive(false);
			}
			if (this.RotateInput != null)
			{
				this.visible_setting_btn_dic_.Add("rotate", UTY.GetChildObject(this.VisibleSettingTab.gameObject, "RotateBtn/Btn", false).GetComponent<UIWFTabButton>());
				EventDelegate.Add(this.visible_setting_btn_dic_["rotate"].onClick, delegate()
				{
					this.axis_visible_type_ = WindowPartsTransform.AxisVisibleType.Rotate;
					this.OnChangeAxisVisibleType();
				});
			}
			else
			{
				UTY.GetChildObject(this.VisibleSettingTab.gameObject, "RotateBtn/Btn", false).SetActive(false);
			}
			if (this.PosInput != null || this.RotateInput != null)
			{
				this.visible_setting_btn_dic_.Add("unvisible", UTY.GetChildObject(this.VisibleSettingTab.gameObject, "UnVisibleBtn/Btn", false).GetComponent<UIWFTabButton>());
				EventDelegate.Add(this.visible_setting_btn_dic_["unvisible"].onClick, delegate()
				{
					this.axis_visible_type_ = WindowPartsTransform.AxisVisibleType.UnVisible;
					this.OnChangeAxisVisibleType();
				});
			}
			else
			{
				UTY.GetChildObject(this.VisibleSettingTab.gameObject, "UnVisibleBtn/Btn", false).SetActive(false);
			}
			if (this.visible_setting_btn_dic_.Count == 0)
			{
				this.VisibleSettingTab.gameObject.SetActive(false);
			}
			else
			{
				this.VisibleSettingTab.GetComponentInChildren<UIGrid>().Reposition();
			}
		}
		if (this.PosInput != null)
		{
			this.axis_visible_type = WindowPartsTransform.AxisVisibleType.Position;
		}
		else
		{
			this.axis_visible_type = WindowPartsTransform.AxisVisibleType.UnVisible;
		}
	}

	public virtual void Start()
	{
	}

	public virtual void SetObject(GameObject target_object)
	{
		this.target_object_ = target_object;
		Transform target_trans = null;
		if (this.target_object_ != null)
		{
			target_trans = this.target_object_.transform;
		}
		if (this.PosInput != null)
		{
			this.PosInput.SetTarget(target_trans, Vector3.zero);
		}
		if (this.RotateInput != null)
		{
			this.RotateInput.SetTarget(target_trans, Vector3.zero);
		}
		if (this.ScaleInput != null)
		{
			this.ScaleInput.SetTarget(target_trans, new Vector3(this.ScaleInput.SliderMin, this.ScaleInput.SliderMin, this.ScaleInput.SliderMin));
		}
	}

	public virtual void SetObject(GameObject target_object, Vector3 init_pos, Vector3 init_rotate, Vector3 init_scale)
	{
		this.target_object_ = target_object;
		Transform target_trans = null;
		if (this.target_object_ != null)
		{
			target_trans = this.target_object_.transform;
		}
		if (this.PosInput != null)
		{
			this.PosInput.SetTarget(target_trans, init_pos);
		}
		if (this.RotateInput != null)
		{
			this.RotateInput.SetTarget(target_trans, init_rotate);
		}
		if (this.ScaleInput != null)
		{
			this.ScaleInput.SetTarget(target_trans, init_scale);
		}
	}

	public void NextAxis()
	{
		if (this.axis_visible_type == WindowPartsTransform.AxisVisibleType.Position)
		{
			this.axis_visible_type = WindowPartsTransform.AxisVisibleType.Rotate;
		}
		else if (this.axis_visible_type == WindowPartsTransform.AxisVisibleType.Rotate)
		{
			this.axis_visible_type = WindowPartsTransform.AxisVisibleType.UnVisible;
		}
		else if (this.axis_visible_type == WindowPartsTransform.AxisVisibleType.UnVisible)
		{
			this.axis_visible_type = WindowPartsTransform.AxisVisibleType.Position;
		}
		this.OnChangeAxisVisibleType();
	}

	public void SetEnabledAxisButton(bool pos, bool rotate)
	{
		if (this.PosInput != null)
		{
			this.visible_setting_btn_dic_["move"].isEnabled = pos;
		}
		if (this.RotateInput != null)
		{
			this.visible_setting_btn_dic_["rotate"].isEnabled = rotate;
		}
	}

	public WindowPartsTransform.AxisVisibleType axis_visible_type
	{
		get
		{
			return this.axis_visible_type_;
		}
		set
		{
			if (this.visible_setting_btn_dic_.Count == 0)
			{
				this.axis_visible_type_ = WindowPartsTransform.AxisVisibleType.UnVisible;
				return;
			}
			this.axis_visible_type_ = value;
			if (value == WindowPartsTransform.AxisVisibleType.Position)
			{
				if (this.visible_setting_btn_dic_.ContainsKey("move"))
				{
					this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["move"]);
				}
				else
				{
					this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["unvisible"]);
				}
			}
			else if (value == WindowPartsTransform.AxisVisibleType.Rotate)
			{
				if (this.visible_setting_btn_dic_.ContainsKey("rotate"))
				{
					this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["rotate"]);
				}
				else
				{
					this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["unvisible"]);
				}
			}
			else
			{
				this.VisibleSettingTab.Select(this.visible_setting_btn_dic_["unvisible"]);
			}
		}
	}

	protected virtual void OnChangeAxisVisibleType()
	{
		if (this.onChangeAxisVisibleType == null)
		{
			return;
		}
		for (int i = 0; i < this.onChangeAxisVisibleType.Count; i++)
		{
			this.onChangeAxisVisibleType[i]();
		}
	}

	public PhotTransInput PosInput;

	public PhotTransInput RotateInput;

	public PhotTransInput ScaleInput;

	public UIWFTabPanel VisibleSettingTab;

	public List<Action> onChangeAxisVisibleType = new List<Action>();

	private WindowPartsTransform.AxisVisibleType axis_visible_type_;

	private GameObject target_object_;

	private Dictionary<string, UIWFTabButton> visible_setting_btn_dic_;

	public enum AxisVisibleType
	{
		Position,
		Rotate,
		UnVisible
	}
}
