using System;
using System.Collections;
using UnityEngine;
using wf;
using Yotogis;

public class YotogiOldSkillContainerViewer
{
	public YotogiOldSkillContainerViewer(GameObject root_obj, MonoBehaviour parent)
	{
		this.root_obj_ = root_obj;
		this.parent_obj_ = UTY.GetChildObject(this.root_obj_, "SkillContainerViewer", false);
		GameObject childObject = UTY.GetChildObject(this.parent_obj_, "HpGroup", false);
		this.setting_hp_gauge_transform_ = UTY.GetChildObject(childObject, "Gauge", false).GetComponent<Transform>();
		GameObject childObject2 = UTY.GetChildObject(childObject, "Values", false);
		this.setting_max_hp_ = UTY.GetChildObject(childObject2, "MaxHp", false).GetComponent<UILabel>();
		this.setting_cur_hp_ = UTY.GetChildObject(childObject2, "CurrentHp", false).GetComponent<UILabel>();
		GameObject childObject3 = UTY.GetChildObject(this.parent_obj_, "SkillParent", false);
		this.skill_parent_grid_ = childObject3.GetComponent<UIGrid>();
		this.select_object_array_ = new YotogiOldSkillContainerViewer.YotogiSkillSelectSlot[7];
		for (int i = 0; i < this.select_object_array_.Length; i++)
		{
			this.select_object_array_[i] = new YotogiOldSkillContainerViewer.YotogiSkillSelectSlot(UTY.GetChildObject(childObject3, "SkillIconUnit" + i, false), new YotogiOldSkillIconDrag.OnDragChangeCallback(this.OnDragChangeCallback));
			YotogiOldSkillIcon component = this.select_object_array_[i].skill_icon_obj.GetComponent<YotogiOldSkillIcon>();
			component.SetOnClickEvent(new YotogiOldSkillIcon.OnClickEvent(this.OnRightClickIcon));
		}
		EventDelegate.Add(UTY.GetChildObject(this.parent_obj_, "DeselectAll", false).GetComponent<UIButton>().onClick, new EventDelegate(parent, "OnClickAllReset"));
	}

	public void Init(Maid maid)
	{
		this.maid_ = maid;
		for (int i = 0; i < this.select_object_array_.Length; i++)
		{
			this.select_object_array_[i].SetMaid(this.maid_);
			this.select_object_array_[i].SetSkillData(null);
		}
	}

	public void SetOnSkillChangeEvent(Action<YotogiOldSkillContainerViewer> call_back)
	{
		this.on_change_call_back_ = call_back;
	}

	public void SetMaxHp(int max_hp)
	{
		this.setting_max_hp_.text = max_hp.ToString();
		int num = int.Parse(this.setting_cur_hp_.text);
		if (max_hp < num)
		{
			this.SetCurrentHp(max_hp);
		}
	}

	public void SetCurrentHp(int cur_hp)
	{
		int num = int.Parse(this.setting_max_hp_.text);
		if (num < cur_hp)
		{
			cur_hp = num;
		}
		if (cur_hp <= 0)
		{
			this.setting_cur_hp_.color = Color.red;
		}
		else
		{
			this.setting_cur_hp_.color = Color.white;
		}
		this.setting_cur_hp_.text = cur_hp.ToString();
		if (cur_hp < 0)
		{
			cur_hp = 0;
		}
		Hashtable args = TweenHash.EaseOutSine(TweenHash.Type.Scale, new Vector3((float)cur_hp / (float)num, 1f, 1f), 0.4f);
		iTween.ScaleTo(this.setting_hp_gauge_transform_.gameObject, args);
	}

	public bool AddSkill(Skill.Old.Data data)
	{
		for (int i = 0; i < this.select_object_array_.Length; i++)
		{
			if (this.select_object_array_[i].skill_data == null)
			{
				this.select_object_array_[i].SetSkillData(data);
				if (this.on_change_call_back_ != null)
				{
					this.on_change_call_back_(this);
				}
				return true;
			}
		}
		return false;
	}

	public void ResetAllSkill()
	{
		for (int i = 0; i < this.select_object_array_.Length; i++)
		{
			this.select_object_array_[i].SetSkillData(null);
		}
		if (this.on_change_call_back_ != null)
		{
			this.on_change_call_back_(this);
		}
	}

	public Skill.Old.Data[] GetSettingSkillArray()
	{
		int num = 0;
		for (int i = 0; i < this.select_object_array_.Length; i++)
		{
			if (this.select_object_array_[i].skill_data != null)
			{
				num++;
			}
		}
		Skill.Old.Data[] array = new Skill.Old.Data[num];
		int num2 = 0;
		for (int j = 0; j < this.select_object_array_.Length; j++)
		{
			if (this.select_object_array_[j].skill_data != null)
			{
				array[num2] = this.select_object_array_[j].skill_data;
				num2++;
			}
		}
		return array;
	}

	private void OnRightClickIcon(GameObject my, YotogiOldSkillIcon click_obj)
	{
		if (UICamera.currentKey != KeyCode.Mouse1)
		{
			return;
		}
		YotogiOldSkillContainerViewer.YotogiSkillSelectSlot yotogiSkillSelectSlot = null;
		for (int i = 0; i < this.select_object_array_.Length; i++)
		{
			if (this.select_object_array_[i].skill_icon_obj == my)
			{
				yotogiSkillSelectSlot = this.select_object_array_[i];
				break;
			}
		}
		NDebug.AssertNull(yotogiSkillSelectSlot != null);
		yotogiSkillSelectSlot.SetSkillData(null);
		for (int j = 0; j < this.select_object_array_.Length; j++)
		{
			if (this.select_object_array_[j].skill_data == null && j + 1 < this.select_object_array_.Length && this.select_object_array_[j + 1].skill_data != null)
			{
				this.select_object_array_[j].Swap(this.select_object_array_[j + 1]);
				this.select_object_array_[j].skill_icon_obj.GetComponent<YotogiOldSkillIconDrag>().MoveReset();
				this.select_object_array_[j + 1].skill_icon_obj.transform.localPosition = Vector3.zero;
			}
		}
		if (this.on_change_call_back_ != null)
		{
			this.on_change_call_back_(this);
		}
	}

	private void OnDragChangeCallback(GameObject my_obj, GameObject change_obj)
	{
		YotogiOldSkillContainerViewer.YotogiSkillSelectSlot yotogiSkillSelectSlot = null;
		YotogiOldSkillContainerViewer.YotogiSkillSelectSlot yotogiSkillSelectSlot2 = null;
		for (int i = 0; i < this.select_object_array_.Length; i++)
		{
			if (this.select_object_array_[i].skill_icon_obj == my_obj)
			{
				yotogiSkillSelectSlot = this.select_object_array_[i];
			}
			else if (this.select_object_array_[i].skill_icon_obj == change_obj)
			{
				yotogiSkillSelectSlot2 = this.select_object_array_[i];
			}
			if (yotogiSkillSelectSlot != null && yotogiSkillSelectSlot2 != null)
			{
				break;
			}
		}
		yotogiSkillSelectSlot.Swap(yotogiSkillSelectSlot2);
	}

	private Maid maid_;

	private GameObject root_obj_;

	private GameObject parent_obj_;

	private UIGrid skill_parent_grid_;

	private Transform setting_hp_gauge_transform_;

	private UILabel setting_cur_hp_;

	private UILabel setting_max_hp_;

	private YotogiOldSkillContainerViewer.YotogiSkillSelectSlot[] select_object_array_;

	private Action<YotogiOldSkillContainerViewer> on_change_call_back_;

	private class YotogiSkillSelectSlot
	{
		public YotogiSkillSelectSlot(GameObject skill_icon_parent, YotogiOldSkillIconDrag.OnDragChangeCallback event_call_back)
		{
			this.skill_icon_obj = UTY.GetChildObject(skill_icon_parent, "SkillIconDrag", false);
			this.skill_icon_collider_ = this.skill_icon_obj.GetComponent<BoxCollider>();
			this.icon_btn_obj_ = this.skill_icon_obj.GetComponent<UIButton>();
			this.skill_icon_scripts_ = this.skill_icon_obj.GetComponent<YotogiOldSkillIcon>();
			this.btn_event_trigger_ = this.skill_icon_obj.gameObject.GetComponent<UIEventTrigger>();
			EventDelegate.Add(this.btn_event_trigger_.onHoverOver, delegate()
			{
				this.VisibleSkillName(true);
			});
			EventDelegate.Add(this.btn_event_trigger_.onHoverOut, delegate()
			{
				this.VisibleSkillName(false);
			});
			EventDelegate.Add(this.btn_event_trigger_.onDragStart, delegate()
			{
				this.VisibleSkillName(false);
			});
			this.skill_name_bg_ = UTY.GetChildObject(skill_icon_parent, "SkillName", false).GetComponent<UISprite>();
			this.skill_name_label_ = UTY.GetChildObject(this.skill_name_bg_.gameObject, "Val", false).GetComponent<UILabel>();
			GameObject childObject = UTY.GetChildObject(skill_icon_parent, "StarGroup", false);
			this.star_obj = new GameObject[3];
			for (int i = 0; i < this.star_obj.Length; i++)
			{
				this.star_obj[i] = UTY.GetChildObject(childObject, "Star" + i, false);
			}
			if (event_call_back != null)
			{
				this.skill_icon_obj.GetComponent<YotogiOldSkillIconDrag>().SetOnOnDragChangeCallback(event_call_back);
			}
		}

		public void VisibleSkillName(bool val)
		{
			if (!this.skill_icon_collider_.enabled || this.skill_data_ == null)
			{
				val = false;
			}
			float alpha = 0f;
			if (val)
			{
				alpha = 1f;
			}
			this.skill_name_bg_.alpha = alpha;
			this.skill_name_label_.alpha = alpha;
		}

		public void Swap(YotogiOldSkillContainerViewer.YotogiSkillSelectSlot target)
		{
			GameObject gameObject = this.skill_icon_obj;
			this.skill_icon_obj = target.skill_icon_obj;
			target.skill_icon_obj = gameObject;
			this.skill_icon_collider_ = this.skill_icon_obj.GetComponent<BoxCollider>();
			this.icon_btn_obj_ = this.skill_icon_obj.GetComponent<UIButton>();
			this.skill_icon_scripts_ = this.skill_icon_obj.GetComponent<YotogiOldSkillIcon>();
			this.btn_event_trigger_ = this.skill_icon_obj.gameObject.GetComponent<UIEventTrigger>();
			this.btn_event_trigger_.onHoverOver.Clear();
			this.btn_event_trigger_.onHoverOut.Clear();
			this.btn_event_trigger_.onDragStart.Clear();
			EventDelegate.Add(this.btn_event_trigger_.onHoverOver, delegate()
			{
				this.VisibleSkillName(true);
			});
			EventDelegate.Add(this.btn_event_trigger_.onHoverOut, delegate()
			{
				this.VisibleSkillName(false);
			});
			EventDelegate.Add(this.btn_event_trigger_.onDragStart, delegate()
			{
				this.VisibleSkillName(false);
			});
			target.skill_icon_collider_ = target.skill_icon_obj.GetComponent<BoxCollider>();
			target.icon_btn_obj_ = target.skill_icon_obj.GetComponent<UIButton>();
			target.skill_icon_scripts_ = target.skill_icon_obj.GetComponent<YotogiOldSkillIcon>();
			target.btn_event_trigger_ = target.skill_icon_obj.gameObject.GetComponent<UIEventTrigger>();
			target.btn_event_trigger_.onHoverOver.Clear();
			target.btn_event_trigger_.onHoverOut.Clear();
			target.btn_event_trigger_.onDragStart.Clear();
			EventDelegate.Add(target.btn_event_trigger_.onHoverOver, delegate()
			{
				target.VisibleSkillName(true);
			});
			EventDelegate.Add(target.btn_event_trigger_.onHoverOut, delegate()
			{
				target.VisibleSkillName(false);
			});
			EventDelegate.Add(target.btn_event_trigger_.onDragStart, delegate()
			{
				target.VisibleSkillName(false);
			});
			Skill.Old.Data skill_data = this.skill_data;
			this.skill_data_ = target.skill_data;
			target.skill_data_ = skill_data;
			this.SetSkillData(this.skill_data);
			target.SetSkillData(target.skill_data);
			Transform parent = this.skill_icon_obj.transform.parent;
			this.skill_icon_obj.transform.parent = target.skill_icon_obj.transform.parent;
			target.skill_icon_obj.transform.parent = parent;
		}

		public void SetSkillData(Skill.Old.Data skill_data)
		{
			this.skill_data_ = skill_data;
			if (this.skill_data_ == null)
			{
				this.icon_btn_obj_.SetState(UIButtonColor.State.Normal, true);
				this.skill_icon_collider_.enabled = false;
			}
			else
			{
				this.skill_icon_collider_.enabled = true;
			}
			this.skill_icon_scripts_.SetSkillData(this.skill_data_);
			this.UpdateData();
		}

		public void UpdateData()
		{
			int num = 0;
			if (this.skill_data != null && this.maid_ != null)
			{
				num = this.maid_.status.yotogiSkill.Get(this.skill_data.id).level;
			}
			num = ((this.star_obj.Length >= num) ? num : this.star_obj.Length);
			for (int i = 0; i < this.star_obj.Length; i++)
			{
				this.star_obj[i].SetActive(i <= num - 1);
			}
			if (this.skill_data_ == null)
			{
				this.skill_name_label_.text = string.Empty;
				this.VisibleSkillName(false);
			}
			else
			{
				this.skill_name_label_.text = this.skill_data_.name;
				this.skill_name_label_.width = 0;
				this.skill_name_label_.MakePixelPerfect();
				this.skill_name_bg_.width = this.skill_name_label_.width + 20;
			}
		}

		public void SetMaid(Maid maid)
		{
			this.maid_ = maid;
		}

		public Skill.Old.Data skill_data
		{
			get
			{
				return this.skill_data_;
			}
		}

		public UIEventTrigger btn_event_trigger
		{
			get
			{
				return this.btn_event_trigger_;
			}
		}

		private Maid maid_;

		public GameObject skill_icon_obj;

		public GameObject[] star_obj;

		private UIEventTrigger btn_event_trigger_;

		private UISprite skill_name_bg_;

		private UILabel skill_name_label_;

		private UIButton icon_btn_obj_;

		private YotogiOldSkillIcon skill_icon_scripts_;

		private BoxCollider skill_icon_collider_;

		private Skill.Old.Data skill_data_;
	}
}
