using System; using System.Collections; using System.Collections.Generic; using MaidStatus; using Schedule; using UnityEngine; using UnityEngine.UI; using wf; public class ScheduleTaskViewer : MonoBehaviour { private void Awake() { Func func = delegate(GameObject parent, string name) { GameObject gameObject = Utility.CreatePrefab(parent, "SceneShop/Prefab/CategoryButton", true); UICenterOnClick2 componentInChildren = gameObject.GetComponentInChildren(); if (componentInChildren != null) { UnityEngine.Object.Destroy(componentInChildren); } gameObject.name = name; UILabel component = UTY.GetChildObject(gameObject, "Label", false).GetComponent(); component.text = gameObject.name; component.width -= 10; int m = component.width; component.width = 0; component.MakePixelPerfect(); while (m < component.width) { component.fontSize--; component.width = 0; component.MakePixelPerfect(); } return UTY.GetChildObject(gameObject, "Button", false).GetComponent(); }; foreach (KeyValuePair keyValuePair in ScheduleCSVData.TaskCategoryNameMap) { string value = keyValuePair.Value; UIButton uibutton = func(this.CategoryGrid.gameObject, value); uibutton.name = keyValuePair.Key.ToString(); this.category_button_dic_.Add(keyValuePair.Key, uibutton); } Dictionary dictionary = new Dictionary(); foreach (KeyValuePair keyValuePair2 in ScheduleCSVData.AllData) { int categoryID = keyValuePair2.Value.categoryID; if (!dictionary.ContainsKey(categoryID)) { dictionary.Add(categoryID, 0); } dictionary[categoryID]++; } int num = 0; foreach (KeyValuePair keyValuePair3 in dictionary) { num = System.Math.Max(num, keyValuePair3.Value); } for (int i = 0; i < 3; i++) { ScheduleTaskCtrl.TaskType key = (ScheduleTaskCtrl.TaskType)i; this.tmpData.Add(key, new ScheduleTaskViewer.TemporaryData()); this.tmpData[key].place = new GameObject(); this.tmpData[key].place.transform.SetParent(base.transform, false); this.tmpData[key].place.name = "tmp_" + key.ToString(); this.tmpData[key].place.SetActive(false); } for (int j = 0; j < num; j++) { NightTaskUnit nightTaskUnit = Utility.CreatePrefab(this.tmpData[ScheduleTaskCtrl.TaskType.Yotogi].place, "SceneDaily/Schedule/Prefab/NightTaskUnit", true).AddComponent(); nightTaskUnit.Init(this); nightTaskUnit.removePrarent = this.tmpData[ScheduleTaskCtrl.TaskType.Yotogi].place; } for (int k = 0; k < num; k++) { TrainingTaskUnit trainingTaskUnit = Utility.CreatePrefab(this.tmpData[ScheduleTaskCtrl.TaskType.Training].place, "SceneDaily/Schedule/Prefab/DaytimeTaskUnit", true).AddComponent(); trainingTaskUnit.Init(this); trainingTaskUnit.removePrarent = this.tmpData[ScheduleTaskCtrl.TaskType.Training].place; } for (int l = 0; l < num; l++) { WorkTaskUnit workTaskUnit = Utility.CreatePrefab(this.tmpData[ScheduleTaskCtrl.TaskType.Work].place, "SceneDaily/Schedule/Prefab/WorkTaskUnit", true).AddComponent(); workTaskUnit.Init(this); workTaskUnit.removePrarent = this.tmpData[ScheduleTaskCtrl.TaskType.Work].place; } } private void OnDestroy() { foreach (KeyValuePair keyValuePair in this.tmpData) { UnityEngine.Object.Destroy(keyValuePair.Value.place); foreach (KeyValuePair keyValuePair2 in keyValuePair.Value.icons) { UnityEngine.Object.DestroyImmediate(keyValuePair2.Value); } keyValuePair.Value.icons.Clear(); } } public void Call(Maid maid, ScheduleMgr.ScheduleTime scheduleTime, Dictionary> viewDic, Dictionary currentSetWorkDic) { if (this.category_button_dic_ == null) { this.Awake(); } ScheduleTaskViewer.scheduleTime = scheduleTime; HashSet hashSet = new HashSet(); int maxValue = int.MaxValue; UIWFTabButton uiwftabButton = null; UIWFTabButton uiwftabButton2 = null; foreach (KeyValuePair> keyValuePair in viewDic) { this.CallEnableButton(maid, keyValuePair.Key, keyValuePair.Value, ref hashSet, ref maxValue); } this.currentWorkDic = currentSetWorkDic; int num = maxValue; ScheduleCSVData.ScheduleBase work_data = null; foreach (KeyValuePair keyValuePair2 in this.category_button_dic_) { keyValuePair2.Value.onClick.Clear(); bool flag = hashSet.Contains(keyValuePair2.Key); keyValuePair2.Value.transform.parent.gameObject.SetActive(flag); if (flag) { EventDelegate.Add(keyValuePair2.Value.onClick, new EventDelegate.Callback(this.OnClickFromMainCategoryButton)); if (uiwftabButton2 == null && num == keyValuePair2.Key) { uiwftabButton2 = keyValuePair2.Value.gameObject.GetComponent(); } ScheduleCSVData.ScheduleBase scheduleBase = currentSetWorkDic[scheduleTime]; if (uiwftabButton == null && scheduleBase != null && scheduleBase.categoryID == keyValuePair2.Key) { work_data = scheduleBase; uiwftabButton = keyValuePair2.Value.gameObject.GetComponent(); } } } if (uiwftabButton == null) { uiwftabButton = uiwftabButton2; } Utility.ResetNGUI(this.CategoryGrid); Utility.ResetNGUI(this.CategoryScrollView); UIWFTabPanel componentInChildren = this.CategoryGrid.GetComponentInChildren(); componentInChildren.ResetSelect(); componentInChildren.UpdateChildren(); if (uiwftabButton != null) { componentInChildren.Select(uiwftabButton); } if (this.descDic == null) { DescScheduleYotogi component = UTY.GetChildObject(base.gameObject, "DescScheduleYotogi", false).GetComponent(); component.Init(this.taskCtrl); DescScheduleTraining component2 = UTY.GetChildObject(base.gameObject, "DescScheduleTraining", false).GetComponent(); component2.Init(this.taskCtrl); DescScheduleWork component3 = UTY.GetChildObject(base.gameObject, "DescScheduleWork", false).GetComponent(); component3.Init(this.taskCtrl); this.descDic = new Dictionary(); this.descDic.Add(ScheduleTaskCtrl.TaskType.Yotogi, component); this.descDic.Add(ScheduleTaskCtrl.TaskType.Training, component2); this.descDic.Add(ScheduleTaskCtrl.TaskType.Work, component3); } this.UpdateForDescriptionViewer(work_data); } private void CallEnableButton(Maid maid, ScheduleTaskCtrl.TaskType type, List viewList, ref HashSet enabled_category, ref int min_category_id) { this.tmpData[type].views = new List(viewList); for (int i = 0; i < this.tmpData[type].views.Count; i++) { if (!enabled_category.Contains(this.tmpData[type].views[i].schedule.categoryID)) { ScheduleCSVData.ScheduleBase schedule = this.tmpData[type].views[i].schedule; int categoryID = schedule.categoryID; if (DailyMgr.IsLegacy || schedule.mode != ScheduleCSVData.ScheduleBase.Mode.CM3D2) { if (!DailyMgr.IsLegacy || schedule.mode != ScheduleCSVData.ScheduleBase.Mode.COM3D) { if (DailyMgr.IsLegacy) { if (ScheduleTaskViewer.scheduleTime == ScheduleMgr.ScheduleTime.DayTime) { if (categoryID != 51) { goto IL_135; } } else if (ScheduleTaskViewer.scheduleTime == ScheduleMgr.ScheduleTime.Night && (categoryID == 51 || categoryID == 52)) { goto IL_135; } } if (maid.status.heroineType != HeroineType.Sub || (categoryID != 51 && categoryID != 100)) { enabled_category.Add(categoryID); min_category_id = System.Math.Min(min_category_id, categoryID); } } } } IL_135:; } } private void AddButtonEvent(Button button, int num) { button.onClick.AddListener(delegate { this.DoSomething(num); }); } private void DoSomething(int num) { MonoBehaviour.print(num); } public void onHoverOverEvent(ScheduleCSVData.ScheduleBase data) { this.UpdateForDescriptionViewer(data); } public void onHoverOutEvent(ScheduleCSVData.ScheduleBase data) { if (this.currentWorkDic[ScheduleTaskViewer.scheduleTime] != null && data != null && this.currentWorkDic[ScheduleTaskViewer.scheduleTime].categoryID == data.categoryID) { this.UpdateForDescriptionViewer(this.currentWorkDic[ScheduleTaskViewer.scheduleTime]); } else { this.UpdateForDescriptionViewer(null); } } public void OnClickTaskUnit(TaskUnit select_unit) { ScheduleTaskCtrl.TaskType taskType = select_unit.taskType; for (int i = 0; i < this.UnitGrid.transform.childCount; i++) { TaskUnit component = this.UnitGrid.transform.GetChild(i).GetComponent(); bool flag = component == select_unit; component.SetSelect(flag); if (flag) { this.currentWorkDic[ScheduleTaskViewer.scheduleTime] = component.schedule; if (component.schedule.type == ScheduleTaskCtrl.TaskType.Training) { ScheduleAPI.AddTrainingFacility(this.taskCtrl.ScheduleCtrl.SelectedMaid, component.schedule.id, ScheduleTaskViewer.scheduleTime); } } } this.description_viewer_out_draw_ = true; this.UpdateForDescriptionViewer(this.currentWorkDic[ScheduleTaskViewer.scheduleTime]); if (this.onClickWorkUnitEvent != null) { this.onClickWorkUnitEvent(select_unit.schedule); } } public TaskUnit GetSelectedTaskUnit() { for (int i = 0; i < this.UnitGrid.transform.childCount; i++) { TaskUnit component = this.UnitGrid.transform.GetChild(i).GetComponent(); if (component.isSelected) { return component; } } return null; } public void OnClickTaskUnit_Work(TaskUnit select_unit) { WorkTaskUnit workTaskUnit = (WorkTaskUnit)select_unit; if (workTaskUnit.work.workTyp == ScheduleCSVData.WorkType.Basic) { DescScheduleWork descScheduleWork = (DescScheduleWork)this.descDic[ScheduleTaskCtrl.TaskType.Work]; descScheduleWork.TaskUnit = workTaskUnit; descScheduleWork.EnableFacillityPanel(); } else { this.OnClickTaskUnit(select_unit); } } private void OnClickFromMainCategoryButton() { UIButton current = UIButton.current; int num = int.Parse(current.name); this.selectedCategoryID = num; ScheduleTaskCtrl.TaskType type = ScheduleTaskCtrl.TaskType.Yotogi; if (num == 51) { type = ScheduleTaskCtrl.TaskType.Training; } else if (num == 52) { type = ScheduleTaskCtrl.TaskType.Work; } this.CreateTaskUnit(type, current, num); } private void CreateTaskUnit(ScheduleTaskCtrl.TaskType type, UIButton current, int select_category_id) { if (type == ScheduleTaskCtrl.TaskType.Yotogi) { this.description_viewer_out_draw_ = (this.currentWorkDic[ScheduleTaskViewer.scheduleTime] != null && this.currentWorkDic[ScheduleTaskViewer.scheduleTime].categoryID == select_category_id); if (this.description_viewer_out_draw_ || this.AlwaysDrawDescriptionViewer) { this.UpdateForDescriptionViewer(this.currentWorkDic[ScheduleTaskViewer.scheduleTime]); } else { this.UpdateForDescriptionViewer(null); } } else if (type == ScheduleTaskCtrl.TaskType.Training) { if (this.currentWorkDic[ScheduleTaskViewer.scheduleTime].type == ScheduleTaskCtrl.TaskType.Training) { this.UpdateForDescriptionViewer(this.currentWorkDic[ScheduleTaskViewer.scheduleTime]); } else { this.UpdateForDescriptionViewer(null); } } else if (type == ScheduleTaskCtrl.TaskType.Work) { if (this.currentWorkDic[ScheduleTaskViewer.scheduleTime].type == ScheduleTaskCtrl.TaskType.Work) { this.UpdateForDescriptionViewer(this.currentWorkDic[ScheduleTaskViewer.scheduleTime]); } else { this.UpdateForDescriptionViewer(null); } } this.RemoveTaskUnitAll(); for (int i = 0; i < this.tmpData[type].views.Count; i++) { ScheduleTaskViewer.ViewData view_data = this.tmpData[type].views[i]; if (view_data.schedule.categoryID == this.selectedCategoryID) { if (view_data.schedule.IsCommon || !view_data.schedule.IsLegacy != DailyMgr.IsLegacy) { if (type == ScheduleTaskCtrl.TaskType.Training) { if (this.AddTaskUnitCheck(ScheduleTaskCtrl.TaskType.Training, view_data)) { this.AddTrainingTaskUnit(view_data); } } else if (type == ScheduleTaskCtrl.TaskType.Yotogi) { if (this.AddTaskUnitCheck(ScheduleTaskCtrl.TaskType.Yotogi, view_data)) { this.AddYotogiTaskUnit(view_data); } } else if (type == ScheduleTaskCtrl.TaskType.Work && this.AddTaskUnitCheck(ScheduleTaskCtrl.TaskType.Work, view_data)) { this.AddWorkTaskUnit(view_data); } } } } Utility.ResetNGUI(this.UnitGrid); Utility.ResetNGUI(this.UnitScrollView); GameObject childObject = UTY.GetChildObject(this.CategoryScrollView.transform.parent.gameObject, "Arrow", true); if (childObject != null) { Vector3 position = current.transform.TransformPoint(new Vector3(0f, 0f, 0f)); Vector3 local_pos = childObject.transform.parent.InverseTransformPoint(position); local_pos.x = childObject.transform.localPosition.x; local_pos.y += 18f; Hashtable args = TweenHash.EaseOutQuint(TweenHash.Type.Position, local_pos, 0.3f); iTween.MoveTo(childObject, args); } } private bool AddTaskUnitCheck(ScheduleTaskCtrl.TaskType type, ScheduleTaskViewer.ViewData view_data) { if (this.tmpData[type].place.transform.childCount <= 0) { return false; } ScheduleCSVData.ScheduleBase schedule = view_data.schedule; if (!this.tmpData[type].icons.ContainsKey(schedule.icon)) { string text = schedule.icon; if (!text.Contains(".tex")) { text += ".tex"; } if (!GameUty.FileSystem.IsExistentFile(text)) { Debug.LogError("スケジュール" + type.ToString() + "のアイコン画像が見つかりませんでした\n" + text); this.tmpData[type].icons.Add(schedule.icon, null); } else { Texture2D value = ImportCM.CreateTexture(text); this.tmpData[type].icons.Add(schedule.icon, value); } } return true; } private void AddTrainingTaskUnit(ScheduleTaskViewer.ViewData view_data) { ScheduleCSVData.Training training = (ScheduleCSVData.Training)view_data.schedule; if (training.trainingType == ScheduleCSVData.TrainingType.Trainee && !ScheduleAPI.CanTrainee(this.taskCtrl.ScheduleCtrl.SelectedMaid)) { return; } TrainingTaskUnit component = this.tmpData[ScheduleTaskCtrl.TaskType.Training].place.transform.GetChild(0).gameObject.GetComponent(); component.SetData(this, view_data); component.transform.SetParent(this.UnitGrid.transform, false); component.transform.localPosition = new Vector3(0f, (float)(this.UnitGrid.transform.childCount * 10), 0f); component.SetSelect(component.schedule == this.currentWorkDic[ScheduleTaskViewer.scheduleTime]); component.isEnabled = view_data.is_enabled; } private void AddYotogiTaskUnit(ScheduleTaskViewer.ViewData view_data) { if (GameMain.Instance.CharacterMgr.status.lockNTRPlay) { ScheduleCSVData.ScheduleBase schedule = view_data.schedule; ScheduleCSVData.Yotogi yotogi = (ScheduleCSVData.Yotogi)schedule; if (ScheduleCSVData.NetorareFlag.Contains(yotogi.id)) { return; } } NightTaskUnit component = this.tmpData[ScheduleTaskCtrl.TaskType.Yotogi].place.transform.GetChild(0).gameObject.GetComponent(); component.SetData(this, view_data); component.transform.SetParent(this.UnitGrid.transform, false); component.transform.localPosition = new Vector3(0f, (float)(this.UnitGrid.transform.childCount * 10), 0f); component.SetSelect(component.schedule == this.currentWorkDic[ScheduleTaskViewer.scheduleTime]); component.isEnabled = view_data.is_enabled; } private void AddWorkTaskUnit(ScheduleTaskViewer.ViewData view_data) { ScheduleCSVData.Work work = (ScheduleCSVData.Work)view_data.schedule; if (!work.facility.isBusiness && work.workTyp != ScheduleCSVData.WorkType.PowerUp) { return; } if (work.workTyp == ScheduleCSVData.WorkType.Basic) { Facility[] facilityArray = GameMain.Instance.FacilityMgr.GetFacilityArray(); bool flag = false; foreach (Facility facility in facilityArray) { if (!(facility == null)) { if (facility.defaultData.ID == work.facility.ID) { flag = true; break; } } } if (!flag) { return; } } WorkTaskUnit component = this.tmpData[ScheduleTaskCtrl.TaskType.Work].place.transform.GetChild(0).gameObject.GetComponent(); component.SetData(this, view_data); component.transform.SetParent(this.UnitGrid.transform, false); component.transform.localPosition = new Vector3(0f, (float)(this.UnitGrid.transform.childCount * 10), 0f); component.SetSelect(component.schedule == this.currentWorkDic[ScheduleTaskViewer.scheduleTime]); component.isEnabled = view_data.is_enabled; } private void RemoveTaskUnitAll() { Transform transform = this.UnitGrid.transform; List list = new List(); for (int i = 0; i < transform.childCount; i++) { list.Add(transform.GetChild(i)); } for (int j = 0; j < list.Count; j++) { TaskUnit component = list[j].GetComponent(); component.isEnabled = true; component.SetSelect(false); list[j].SetParent(component.removePrarent.transform, false); } } private void UpdateForDescriptionViewer(ScheduleCSVData.ScheduleBase work_data) { if (this.descDic == null) { return; } foreach (KeyValuePair keyValuePair in this.descDic) { if (work_data != null && work_data.type == keyValuePair.Key) { keyValuePair.Value.UpdateViewCommon(work_data); } else { keyValuePair.Value.UpdateViewCommon(null); } } } public ScheduleTaskViewer.TemporaryData TmpData(ScheduleTaskCtrl.TaskType type) { return this.tmpData[type]; } public static ScheduleMgr.ScheduleTime ScheduleTime { get { return ScheduleTaskViewer.scheduleTime; } set { ScheduleTaskViewer.scheduleTime = value; } } public ScheduleTaskCtrl taskCtrl; public UIGrid CategoryGrid; public UIScrollView CategoryScrollView; public UIGrid UnitGrid; public UIScrollView UnitScrollView; public GameObject ParameterViewer; public Dictionary descDic; [SerializeField] private int selectedCategoryID; public bool AlwaysDrawDescriptionViewer; public Action onClickWorkUnitEvent; private Dictionary category_button_dic_ = new Dictionary(); private Dictionary tmpData = new Dictionary(); private Dictionary currentWorkDic = new Dictionary(); private static ScheduleMgr.ScheduleTime scheduleTime; private bool description_viewer_out_draw_; public struct ViewData { public ScheduleTaskCtrl.TaskButton taskButton; public ScheduleCSVData.ScheduleBase schedule; public bool is_enabled; } public class TemporaryData { public GameObject place; public List views; public Dictionary icons = new Dictionary(); } }