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

public class TaskUnit : MonoBehaviour
{
	public ScheduleCSVData.ScheduleBase schedule { get; protected set; }

	public bool isSelected
	{
		get
		{
			return this.SelectCursor.alpha != 0f;
		}
	}

	public void Init(ScheduleTaskViewer taskViewer)
	{
		this.viewer = taskViewer;
		this.Icon = UTY.GetChildObject(base.gameObject, "Main", false).GetComponent<UITexture>();
		this.Button = this.Icon.GetComponent<UIButton>();
		this.SelectCursor = UTY.GetChildObject(base.gameObject, "Main/SelectCursor", false).GetComponent<UISprite>();
		this.TitleLabel = UTY.GetChildObject(base.gameObject, "Title", false).GetComponent<UILabel>();
		this.AddOnClickEvent();
		this.onHoverOverEvent = new Action<ScheduleCSVData.ScheduleBase>(this.viewer.onHoverOverEvent);
		this.onHoverOutEvent = new Action<ScheduleCSVData.ScheduleBase>(this.viewer.onHoverOutEvent);
		UIEventTrigger[] componentsInChildren = base.GetComponentsInChildren<UIEventTrigger>();
		foreach (UIEventTrigger uieventTrigger in componentsInChildren)
		{
			uieventTrigger.onHoverOut.Clear();
			EventDelegate.Add(uieventTrigger.onHoverOut, new EventDelegate.Callback(this.OnHoverOut));
			uieventTrigger.onHoverOver.Clear();
			EventDelegate.Add(uieventTrigger.onHoverOver, new EventDelegate.Callback(this.OnHoverOver));
		}
	}

	private void Update()
	{
		this.Monitor();
	}

	protected virtual void Monitor()
	{
	}

	protected virtual void AddOnClickEvent()
	{
		EventDelegate eventDelegate = new EventDelegate(this.viewer, "OnClickTaskUnit");
		eventDelegate.parameters[0].value = this;
		EventDelegate.Add(this.Button.onClick, eventDelegate);
	}

	public void SetData(ScheduleTaskCtrl.TaskType taskType, ScheduleTaskViewer viewer, ScheduleTaskViewer.ViewData viewData)
	{
		this.taskType = taskType;
		this.viewer = viewer;
		this.viewData = viewData;
		this.schedule = viewData.schedule;
		this.taskName = this.schedule.name;
		this.SelectCursor.alpha = 0f;
		this.TitleLabel.text = this.schedule.name;
		this.Icon.mainTexture = viewer.TmpData(taskType).icons[this.schedule.icon];
	}

	public bool isEnabled
	{
		get
		{
			return this.Button.isEnabled;
		}
		set
		{
			this.Button.isEnabled = value;
			this.TitleLabel.color = ((!this.Button.isEnabled) ? Color.gray : Color.white);
		}
	}

	public void SetSelect(bool is_select)
	{
		if (is_select && this.isEnabled)
		{
			this.SelectCursor.alpha = 1f;
			this.Button.defaultColor = Color.white;
			this.Button.SetState(UIButtonColor.State.Normal, false);
			BoxCollider component = this.Button.GetComponent<BoxCollider>();
			if (component != null)
			{
				component.size = Vector3.zero;
			}
		}
		else
		{
			this.SelectCursor.alpha = 0f;
			this.Button.defaultColor = this.backup_default_color_;
			BoxCollider component2 = this.Button.GetComponent<BoxCollider>();
			if (component2 != null)
			{
				UIWidget component3 = this.Button.GetComponent<UIWidget>();
				if (component3 != null)
				{
					Vector2 localSize = component3.localSize;
					component2.size = new Vector3(localSize.x, localSize.y, 0f);
				}
			}
		}
	}

	protected virtual void OnHoverOver()
	{
		if (this.onHoverOverEvent == null)
		{
			return;
		}
		this.onHoverOverEvent(this.schedule);
		this.isHover = true;
	}

	protected virtual void OnHoverOut()
	{
		if (this.onHoverOutEvent == null)
		{
			return;
		}
		this.onHoverOutEvent(this.schedule);
		this.isHover = false;
	}

	protected void SetTaskRank(GameObject go, int rank)
	{
		List<GameObject> list = new List<GameObject>();
		GameObject childObject = UTY.GetChildObject(go, "Stars/Icon", false);
		IEnumerator enumerator = childObject.transform.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				object obj = enumerator.Current;
				Transform transform = (Transform)obj;
				list.Add(transform.gameObject);
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		int count = list.Count;
		for (int i = 0; i < count; i++)
		{
			if (rank > i)
			{
				list[i].SetActive(true);
			}
			else
			{
				list[i].SetActive(false);
			}
		}
	}

	protected void SetExpRatio(GameObject go, int expRatio)
	{
		List<GameObject> list = new List<GameObject>();
		GameObject childObject = UTY.GetChildObject(go, "ExpRatio/ValueGroup", false);
		IEnumerator enumerator = childObject.transform.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				object obj = enumerator.Current;
				Transform transform = (Transform)obj;
				list.Add(transform.gameObject);
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		int count = list.Count;
		for (int i = 0; i < count; i++)
		{
			if (expRatio > i)
			{
				list[i].SetActive(true);
			}
			else
			{
				list[i].SetActive(false);
			}
		}
	}

	public void AdjustmentTitlePos(GameObject obj, ScheduleTaskCtrl.TaskButton taskButton, bool active = true)
	{
		UTY.GetChildObject(obj, "Stars", false).SetActive(active);
		UTY.GetChildObject(obj, "ExpRatio", false).SetActive(active);
		Transform transform = UTY.GetChildObject(obj, "Title", false).transform;
		Vector3 localPosition = transform.localPosition;
		localPosition.y = -27f;
		if (this.taskType == ScheduleTaskCtrl.TaskType.Training)
		{
			ScheduleTaskCtrl.TrainingTaskButton trainingTaskButton = (ScheduleTaskCtrl.TrainingTaskButton)taskButton;
			if (trainingTaskButton.type == ScheduleCSVData.TrainingType.Travel)
			{
				localPosition.y = -55f;
			}
		}
		if (this.taskType == ScheduleTaskCtrl.TaskType.Work && ScheduleCSVData.faclilityPowerUpWorkId == this.schedule.id)
		{
			localPosition.y = -51f;
		}
		transform.localPosition = localPosition;
	}

	protected ScheduleTaskViewer viewer;

	protected ScheduleTaskViewer.ViewData viewData;

	public GameObject removePrarent;

	[SerializeField]
	private bool isHover;

	public Action<ScheduleCSVData.ScheduleBase> onHoverOverEvent;

	public Action<ScheduleCSVData.ScheduleBase> onHoverOutEvent;

	[SerializeField]
	protected string taskName;

	public UITexture Icon;

	public UIButton Button;

	public UISprite SelectCursor;

	public UILabel TitleLabel;

	public ScheduleTaskCtrl.TaskType taskType;

	protected Color backup_default_color_ = new Color(1f, 1f, 1f, 0.6f);
}
