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

public class DaytimeTaskCtrl : BaseCreateViewerCtrl
{
	public void Init(ScheduleMgr scheduleMgr, ScheduleCtrl scheduleCtrl, GameObject goPanel)
	{
		this.m_scheduleMgr = scheduleMgr;
		this.m_scheduleCtrl = scheduleCtrl;
		this.m_goDaytimeTaskViewer = UTY.GetChildObject(goPanel, "DaytimeTaskViewer", false);
	}

	private void InitViewer()
	{
		this.m_unitPrefabPath = "SceneDaily/Schedule/Prefab/DaytimeTaskUnit";
		GameObject childObject = UTY.GetChildObject(this.m_goDaytimeTaskViewer, "TaskViewer", false);
		this.m_goUnitParent = UTY.GetChildObject(childObject, "Contents/TaskUnitParent", false);
		this.m_content = UTY.GetChildObject(childObject, "Contents", false);
		this.m_contentPosY = this.m_content.transform.localPosition.y;
		this.m_taskScrollView = UTY.GetChildObject(childObject, "Contents", false).GetComponent<UIScrollView>();
		this.m_goParameterViewer = UTY.GetChildObject(this.m_goDaytimeTaskViewer, "ParameterViewer", false);
		this.m_goMaidParameterParent = UTY.GetChildObject(this.m_goDaytimeTaskViewer, "ParameterViewer/MaidParameter/ParameterParent", false);
		GameObject childObject2 = UTY.GetChildObject(this.m_goMaidParameterParent, "StudyRate", false);
		this.m_lStudyRate = UTY.GetChildObject(childObject2, "Value", false).GetComponent<UILabel>();
		this.m_lCurrentStudyRate = UTY.GetChildObject(childObject2, "CurrentValue", false).GetComponent<UILabel>();
		GameObject childObject3 = UTY.GetChildObject(this.m_goMaidParameterParent, "Reception", false);
		this.m_lReception = UTY.GetChildObject(childObject3, "Value", false).GetComponent<UILabel>();
		this.m_lCurrentReception = UTY.GetChildObject(childObject3, "CurrentValue", false).GetComponent<UILabel>();
		GameObject childObject4 = UTY.GetChildObject(this.m_goMaidParameterParent, "Care", false);
		this.m_lCare = UTY.GetChildObject(childObject4, "Value", false).GetComponent<UILabel>();
		this.m_lCurrentCare = UTY.GetChildObject(childObject4, "CurrentValue", false).GetComponent<UILabel>();
		GameObject childObject5 = UTY.GetChildObject(this.m_goMaidParameterParent, "Lovely", false);
		this.m_lLovely = UTY.GetChildObject(childObject5, "Value", false).GetComponent<UILabel>();
		this.m_lCurrentLovely = UTY.GetChildObject(childObject5, "CurrentValue", false).GetComponent<UILabel>();
		GameObject childObject6 = UTY.GetChildObject(this.m_goMaidParameterParent, "Elegance", false);
		this.m_lElegance = UTY.GetChildObject(childObject6, "Value", false).GetComponent<UILabel>();
		this.m_lCurrentElegance = UTY.GetChildObject(childObject6, "CurrentValue", false).GetComponent<UILabel>();
		GameObject childObject7 = UTY.GetChildObject(this.m_goMaidParameterParent, "Charm", false);
		this.m_lCharm = UTY.GetChildObject(childObject7, "Value", false).GetComponent<UILabel>();
		this.m_lCurrentCharm = UTY.GetChildObject(childObject7, "CurrentValue", false).GetComponent<UILabel>();
		GameObject childObject8 = UTY.GetChildObject(this.m_goMaidParameterParent, "TeachRate", false);
		this.m_lTeachRate = UTY.GetChildObject(childObject8, "Value", false).GetComponent<UILabel>();
		this.m_lCurrentTeachRate = UTY.GetChildObject(childObject8, "CurrentValue", false).GetComponent<UILabel>();
		GameObject childObject9 = UTY.GetChildObject(this.m_goMaidParameterParent, "MaidClassExp", false);
		this.m_lMaidClassExp = UTY.GetChildObject(childObject9, "Value", false).GetComponent<UILabel>();
		this.m_lCurrentMaidClassExp = UTY.GetChildObject(childObject9, "CurrentValue", false).GetComponent<UILabel>();
		this.m_listMaidParameter = new List<ScheduleCtrl.VariableItem>
		{
			new ScheduleCtrl.VariableItem(childObject2, this.m_lStudyRate),
			new ScheduleCtrl.VariableItem(childObject3, this.m_lReception),
			new ScheduleCtrl.VariableItem(childObject4, this.m_lCare),
			new ScheduleCtrl.VariableItem(childObject5, this.m_lLovely),
			new ScheduleCtrl.VariableItem(childObject6, this.m_lElegance),
			new ScheduleCtrl.VariableItem(childObject7, this.m_lCharm),
			new ScheduleCtrl.VariableItem(childObject8, this.m_lTeachRate),
			new ScheduleCtrl.VariableItem(childObject9, this.m_lMaidClassExp)
		};
		this.m_goSalonParameter = UTY.GetChildObject(this.m_goDaytimeTaskViewer, "ParameterViewer/SalonParameter", false);
		this.m_goSalonParameterParent = UTY.GetChildObject(this.m_goDaytimeTaskViewer, "ParameterViewer/SalonParameter/ParameterParent", false);
		GameObject childObject10 = UTY.GetChildObject(this.m_goSalonParameterParent, "Cleanliness", false);
		this.m_lCleanliness = UTY.GetChildObject(childObject10, "Value", false).GetComponent<UILabel>();
		GameObject childObject11 = UTY.GetChildObject(this.m_goSalonParameterParent, "Brilliant", false);
		this.m_lBrilliant = UTY.GetChildObject(childObject11, "Value", false).GetComponent<UILabel>();
		GameObject childObject12 = UTY.GetChildObject(this.m_goSalonParameterParent, "Income", false);
		this.m_lIncome = UTY.GetChildObject(childObject12, "Value", false).GetComponent<UILabel>();
		this.m_listSalonParameter = new List<ScheduleCtrl.VariableItem>
		{
			new ScheduleCtrl.VariableItem(childObject10, this.m_lCleanliness),
			new ScheduleCtrl.VariableItem(childObject11, this.m_lBrilliant),
			new ScheduleCtrl.VariableItem(childObject12, this.m_lIncome)
		};
		this.m_taskScrollBar = UTY.GetChildObject(childObject, "Scroll Bar", false).GetComponent<UIScrollBar>();
		this.m_spBGOfParameterViewer = UTY.GetChildObject(this.m_goDaytimeTaskViewer, "ParameterViewer/BG", false).GetComponent<UISprite>();
		this.m_goTitleOfMaidParameter = UTY.GetChildObject(this.m_goDaytimeTaskViewer, "ParameterViewer/MaidParameter/Title", false);
		this.m_heightOfMaidParameterTitle = this.m_goTitleOfMaidParameter.GetComponent<UISprite>().height;
		this.m_goTitleOfSalonParameter = UTY.GetChildObject(this.m_goDaytimeTaskViewer, "ParameterViewer/SalonParameter/Title", false);
		this.m_heightOfSalonParameterTitle = this.m_goTitleOfSalonParameter.GetComponent<UISprite>().height;
	}

	public void CreateTaskViewer(string buttonName)
	{
		if (!this.m_bInit)
		{
			this.InitViewer();
			this.m_bInit = true;
		}
		this.m_scheduleCtrl.SetMaidIdByButtonName(buttonName);
		this.m_scheduleCtrl.SetSelectedRowActive(buttonName);
		string maidId = this.m_scheduleCtrl.GetMaidId();
		this.m_currentActiveSlotNo = ScheduleCtrl.GetSlotNoByButtonName(buttonName);
		this.m_listDaytimeTask = this.LoadData(this.m_currentActiveSlotNo);
		base.CreateViewer<DaytimeTaskCtrl.DaytimeTaskButton>(this.m_listDaytimeTask);
		string daytimeTaskId = this.GetDaytimeTaskId();
		this.SetDaytimeTaskButtonActive(daytimeTaskId);
		this.m_scheduleMgr.SetCurrentDaytimeTaskActiveButton(daytimeTaskId);
		this.LoadDaytimeTaskData(daytimeTaskId);
		this.ResetPosition();
	}

	private void ResetPosition()
	{
		this.m_taskScrollView.ResetPosition();
		this.m_content.transform.localPosition = new Vector2(this.m_content.transform.localPosition.x, this.m_contentPosY);
	}

	protected override void SetDataForViewer()
	{
		this.m_dicDaytimeTask = new Dictionary<string, DaytimeTaskCtrl.DaytimeTaskButton>();
		int num = 0;
		foreach (DaytimeTaskCtrl.DaytimeTaskButton daytimeTaskButton in this.m_listDaytimeTask)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_goUnitPrefab);
			gameObject.name = daytimeTaskButton.id;
			GameObject childObject = UTY.GetChildObject(gameObject, "Main", false);
			childObject.name = daytimeTaskButton.id;
			base.SetTransformInfo(gameObject);
			UILabel component = UTY.GetChildObject(gameObject, "Title", false).GetComponent<UILabel>();
			component.text = daytimeTaskButton.name;
			UITexture component2 = childObject.GetComponent<UITexture>();
			component2.mainTexture = daytimeTaskButton.txtTaskIcon;
			this.SetDaytimeTaskRank(gameObject, daytimeTaskButton.rank);
			this.SetExpRatio(gameObject, daytimeTaskButton.expRatio);
			if (daytimeTaskButton.type == ScheduleCSVData.TrainingType.Travel)
			{
				UTY.GetChildObject(gameObject, "Stars", false).SetActive(false);
				UTY.GetChildObject(gameObject, "ExpRatio", false).SetActive(false);
				Transform transform = UTY.GetChildObject(gameObject, "Title", false).transform;
				Vector3 localPosition = transform.localPosition;
				localPosition.y = -55f;
				transform.localPosition = localPosition;
			}
			GameObject childObject2 = UTY.GetChildObject(childObject, "SelectCursor", false);
			childObject2.SetActive(false);
			daytimeTaskButton.selectCursor = childObject2;
			daytimeTaskButton.order = num;
			UIButton component3 = childObject.GetComponent<UIButton>();
			daytimeTaskButton.btnTask = component3;
			if (!daytimeTaskButton.enableTask)
			{
				Debug.Log(string.Format("選択できないタスクです。タスクID={0}, タスク名={1}", daytimeTaskButton.id, daytimeTaskButton.name));
			}
			this.m_dicDaytimeTask.Add(daytimeTaskButton.id, daytimeTaskButton);
			num++;
		}
	}

	private void LoadDaytimeTaskData(string taskId)
	{
		int num = int.Parse(taskId);
		foreach (ScheduleBase scheduleBase in this.worksData)
		{
			if (scheduleBase.workType == ScheduleType.Training)
			{
				ScheduleTraining scheduleTraining = (ScheduleTraining)scheduleBase;
				if (scheduleTraining.id == num)
				{
					MaidParams simulateeMaidParams = scheduleTraining.simulateeMaidParams;
					this.m_lStudyRate.text = this.Sign(simulateeMaidParams.study_rate, null);
					this.m_lReception.text = this.Sign(simulateeMaidParams.reception, null);
					this.m_lCare.text = this.Sign(simulateeMaidParams.care, null);
					this.m_lLovely.text = this.Sign(simulateeMaidParams.lovely, null);
					this.m_lElegance.text = this.Sign(simulateeMaidParams.elegance, null);
					this.m_lCharm.text = this.Sign(simulateeMaidParams.charm, null);
					this.m_lTeachRate.text = this.Sign(simulateeMaidParams.teach_rate, null);
					this.m_lMaidClassExp.text = this.Sign(simulateeMaidParams.exp, null);
					SalonParams simulateeSalonMaidParams = scheduleTraining.simulateeSalonMaidParams;
					this.m_lIncome.text = this.Sign(simulateeMaidParams.income, "#,0");
				}
			}
		}
		this.ExamineDisplayItem();
	}

	private string Sign(int input, string format = null)
	{
		if (input <= 0)
		{
			return input.ToString();
		}
		if (format != null)
		{
			return "+" + input.ToString(format);
		}
		return "+" + input.ToString();
	}

	private void ExamineDisplayItem()
	{
		int num = ScheduleCtrl.SetActiveExceptForNothing(this.m_listMaidParameter, "0");
		bool flag = num > 0;
		this.m_goTitleOfMaidParameter.SetActive(flag);
		int num2 = ScheduleCtrl.SetActiveExceptForNothing(this.m_listSalonParameter, "0");
		bool flag2 = num2 > 0;
		this.m_goTitleOfSalonParameter.SetActive(flag2);
		if (!flag && !flag2)
		{
			this.m_goParameterViewer.SetActive(false);
			return;
		}
		this.m_goParameterViewer.SetActive(true);
		BaseCreateViewerCtrl.Reposition(this.m_goMaidParameterParent);
		BaseCreateViewerCtrl.Reposition(this.m_goSalonParameterParent);
		this.AdjustParameterViewer(num, num2);
	}

	private void AdjustParameterViewer(int displayMaidParameterCount, int displaySalonParameterCount)
	{
		float num = 15f;
		float num2 = 25f;
		float num3 = 0f;
		if (displayMaidParameterCount > 0)
		{
			num3 += (float)this.m_heightOfMaidParameterTitle + num;
			float y = this.m_goMaidParameterParent.GetComponent<UITable>().padding.y;
			IEnumerator enumerator = this.m_goMaidParameterParent.transform.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object obj = enumerator.Current;
					Transform transform = (Transform)obj;
					if (transform.gameObject.activeSelf)
					{
						UILabel component = transform.GetComponent<UILabel>();
						num3 += (float)component.height + y * 2f;
					}
				}
			}
			finally
			{
				IDisposable disposable;
				if ((disposable = (enumerator as IDisposable)) != null)
				{
					disposable.Dispose();
				}
			}
			num3 += num2;
		}
		float num4 = 0f;
		if (displaySalonParameterCount > 0)
		{
			num4 += (float)this.m_heightOfSalonParameterTitle + num;
			float y = this.m_goSalonParameterParent.GetComponent<UITable>().padding.y;
			IEnumerator enumerator2 = this.m_goSalonParameterParent.transform.GetEnumerator();
			try
			{
				while (enumerator2.MoveNext())
				{
					object obj2 = enumerator2.Current;
					Transform transform2 = (Transform)obj2;
					if (transform2.gameObject.activeSelf)
					{
						UILabel component2 = transform2.GetComponent<UILabel>();
						num4 += (float)component2.height + y * 2f;
					}
				}
			}
			finally
			{
				IDisposable disposable2;
				if ((disposable2 = (enumerator2 as IDisposable)) != null)
				{
					disposable2.Dispose();
				}
			}
			num4 += num2;
		}
		if (num3 + num4 > 0f)
		{
			this.m_spBGOfParameterViewer.height = (int)(num3 + num4);
			float y2 = (num3 <= 0f) ? (-(num3 + num * 2f)) : (-(num3 + num));
			this.m_goSalonParameter.transform.localPosition = new Vector3(this.m_goSalonParameter.transform.localPosition.x, y2, 0f);
		}
	}

	private void SetDaytimeTaskRank(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);
			}
		}
	}

	private 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);
			}
		}
	}

	private string GetDaytimeTaskId()
	{
		ScheduleCtrl.MaidStatusAndTaskUnit maidStatusAndTaskUnit = null;
		Dictionary<string, ScheduleCtrl.MaidStatusAndTaskUnit> dicMaidStatusAndTask = this.m_scheduleCtrl.GetDicMaidStatusAndTask();
		if (dicMaidStatusAndTask.TryGetValue(this.m_scheduleCtrl.GetActiveSlotNo(), out maidStatusAndTaskUnit))
		{
			return maidStatusAndTaskUnit.daytimeTaskId;
		}
		return null;
	}

	public void UpdateTaskViewer(string taskId)
	{
		this.LoadDaytimeTaskData(taskId);
		this.SetDaytimeTaskButtonActive(taskId);
	}

	public void UpdateSelectedMaidTask(string taskId)
	{
		this.UpdatePersistentData(int.Parse(taskId));
		string currentActiveButton = this.m_scheduleMgr.CurrentActiveButton;
		this.m_scheduleMgr.UpdateMaidStatus();
		this.CreateTaskViewer(currentActiveButton);
		this.m_scheduleMgr.CurrentActiveButton = currentActiveButton;
	}

	private void UpdatePersistentData(int taskId)
	{
		this.m_scheduleApi.SetNoonWorkSlot_Safe(ScheduleMgr.ScheduleTime.DayTime, this.m_currentActiveSlotNo, taskId);
	}

	public void SetDaytimeTaskButtonActive(string taskId)
	{
		foreach (KeyValuePair<string, DaytimeTaskCtrl.DaytimeTaskButton> keyValuePair in this.m_dicDaytimeTask)
		{
			string key = keyValuePair.Key;
			DaytimeTaskCtrl.DaytimeTaskButton value = keyValuePair.Value;
			if (key == taskId)
			{
				if (value.enableTask)
				{
					value.btnTask.defaultColor = this.m_scheduleCtrl.GetActiveColor();
				}
				else
				{
					value.btnTask.defaultColor = this.m_scheduleCtrl.GetDisableColor();
				}
				value.selectCursor.SetActive(true);
			}
			else
			{
				value.selectCursor.SetActive(false);
				value.btnTask.defaultColor = this.m_scheduleCtrl.GetInActiveColor();
			}
		}
	}

	private List<DaytimeTaskCtrl.DaytimeTaskButton> LoadData(int slotNo)
	{
		this.m_scheduleApi = this.m_scheduleMgr.GetScheduleApi();
		this.worksData = this.m_scheduleApi.slot[slotNo].noonWorksData;
		this.m_currentSlotInfo = this.m_scheduleApi.slot[slotNo];
		List<DaytimeTaskCtrl.DaytimeTaskButton> list = new List<DaytimeTaskCtrl.DaytimeTaskButton>();
		foreach (ScheduleBase scheduleBase in this.worksData)
		{
			if (scheduleBase.workType == ScheduleType.Training)
			{
				ScheduleTraining scheduleTraining = (ScheduleTraining)scheduleBase;
				if (scheduleTraining.visible)
				{
					list.Add(new DaytimeTaskCtrl.DaytimeTaskButton
					{
						id = scheduleTraining.id.ToString(),
						name = scheduleTraining.name,
						rank = scheduleTraining.lv,
						expRatio = scheduleTraining.expRatioFrom0To10,
						txtTaskIcon = scheduleTraining.icon,
						enableTask = scheduleTraining.enabled,
						type = scheduleTraining.type
					});
				}
			}
		}
		return list;
	}

	private ScheduleMgr m_scheduleMgr;

	private ScheduleCtrl m_scheduleCtrl;

	private ScheduleScene m_scheduleApi;

	private Slot m_currentSlotInfo;

	private Dictionary<string, DaytimeTaskCtrl.DaytimeTaskButton> m_dicDaytimeTask;

	private List<ScheduleCtrl.VariableItem> m_listMaidParameter;

	private List<ScheduleCtrl.VariableItem> m_listSalonParameter;

	private List<DaytimeTaskCtrl.DaytimeTaskButton> m_listDaytimeTask;

	private List<ScheduleBase> worksData;

	private GameObject m_goDaytimeTaskViewer;

	private GameObject m_goParameterViewer;

	private GameObject m_goRoomViewer;

	private GameObject m_goMaidParameterParent;

	private GameObject m_goSalonParameter;

	private GameObject m_goSalonParameterParent;

	private GameObject m_goTitleOfMaidParameter;

	private GameObject m_goTitleOfSalonParameter;

	private GameObject m_content;

	private UISprite m_spBGOfParameterViewer;

	private UIScrollView m_taskScrollView;

	private UIScrollBar m_taskScrollBar;

	private UILabel m_lStudyRate;

	private UILabel m_lReception;

	private UILabel m_lCare;

	private UILabel m_lLovely;

	private UILabel m_lElegance;

	private UILabel m_lCharm;

	private UILabel m_lTeachRate;

	private UILabel m_lMaidClassExp;

	private UILabel m_lCleanliness;

	private UILabel m_lBrilliant;

	private UILabel m_lIncome;

	private UILabel m_lCurrentStudyRate;

	private UILabel m_lCurrentReception;

	private UILabel m_lCurrentCare;

	private UILabel m_lCurrentLovely;

	private UILabel m_lCurrentElegance;

	private UILabel m_lCurrentCharm;

	private UILabel m_lCurrentTeachRate;

	private UILabel m_lCurrentMaidClassExp;

	private UILabel m_lRoomName;

	private bool m_bInit;

	private float m_contentPosY;

	private int m_heightOfSalonParameterTitle;

	private int m_heightOfMaidParameterTitle;

	private int m_currentActiveSlotNo;

	private const string DAYTIME_TASK_UNIT_PATH = "SceneDaily/Schedule/Prefab/DaytimeTaskUnit";

	private const string NOTHING = "0";

	public class DaytimeTaskButton
	{
		public string id;

		public string name;

		public int rank;

		public int expRatio;

		public UIButton btnTask;

		public Texture2D txtTaskIcon;

		public GameObject selectCursor;

		public List<GameObject> listRank;

		public int order;

		public bool enableTask;

		public ScheduleCSVData.TrainingType type;
	}
}
