AlignmentPresetWindow.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class AlignmentPresetWindow : BaseMaidPhotoWindow
  6. {
  7. public override void Awake()
  8. {
  9. base.Awake();
  10. PhotoAlignmentPreset.Create();
  11. this.noCharaActive = base.GetComponentInChildren<PhotoNoCharaActive>();
  12. }
  13. public override void Start()
  14. {
  15. base.Start();
  16. this.Init();
  17. }
  18. public void Init()
  19. {
  20. for (int i = 0; i < PhotoAlignmentPreset.datas.Count; i++)
  21. {
  22. this.CreateAlignmentPresetButton(this.contentGrid.gameObject, PhotoAlignmentPreset.datas[i]);
  23. }
  24. Utility.ResetNGUI(this.contentGrid);
  25. Utility.ResetNGUI(NGUITools.FindInParents<UIScrollView>(this.contentGrid.transform));
  26. Utility.ResetNGUI(this.maidListGrid);
  27. Utility.ResetNGUI(NGUITools.FindInParents<UIScrollView>(this.maidListGrid.transform));
  28. this.UpdateMaidList();
  29. this.noCharaActive.ChangeMode(true, true);
  30. UIButton[] componentsInChildren = this.contentGrid.GetComponentsInChildren<UIButton>();
  31. foreach (UIButton uibutton in componentsInChildren)
  32. {
  33. uibutton.isEnabled = false;
  34. }
  35. }
  36. public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
  37. {
  38. if (maid == null || maid.boMAN)
  39. {
  40. return;
  41. }
  42. this.activeMaidList.Add(maid);
  43. this.UpdateMaidList();
  44. this.noCharaActive.ChangeMode(false, true);
  45. }
  46. public void OnSelectMaid()
  47. {
  48. GameObject gameObject = UIButton.current.transform.parent.gameObject;
  49. MaidPlate component = gameObject.GetComponent<MaidPlate>();
  50. bool selected = UIWFSelectButton.selected;
  51. if (selected)
  52. {
  53. for (int i = 0; i < this.selectMaidList.Length; i++)
  54. {
  55. if (this.selectMaidList[i] == null)
  56. {
  57. this.selectMaidList[i] = component;
  58. this.selectMaidList[i].SetSelectNoVisible(i + 1, true);
  59. break;
  60. }
  61. }
  62. }
  63. else
  64. {
  65. for (int j = 0; j < this.selectMaidList.Length; j++)
  66. {
  67. if (this.selectMaidList[j] == component)
  68. {
  69. this.selectMaidList[j].SetSelectNoVisible(j + 1, false);
  70. this.selectMaidList[j] = null;
  71. break;
  72. }
  73. }
  74. }
  75. bool flag = false;
  76. int num = 0;
  77. while (num < this.selectMaidList.Length && !flag)
  78. {
  79. if (this.selectMaidList[num] != null)
  80. {
  81. flag = true;
  82. }
  83. num++;
  84. }
  85. UIButton[] componentsInChildren = this.contentGrid.GetComponentsInChildren<UIButton>();
  86. foreach (UIButton uibutton in componentsInChildren)
  87. {
  88. uibutton.isEnabled = flag;
  89. }
  90. }
  91. public override void OnMaidRemoveEvent(Maid maid)
  92. {
  93. if (maid == null || maid.boMAN)
  94. {
  95. return;
  96. }
  97. this.activeMaidList.Remove(maid);
  98. this.UpdateMaidList();
  99. if (this.activeMaidList.Count <= 0)
  100. {
  101. this.noCharaActive.ChangeMode(true, true);
  102. }
  103. }
  104. public override void OnDeserializeEvent()
  105. {
  106. AlignmentPresetWindow.SelectData = null;
  107. }
  108. public void UpdateMaidList()
  109. {
  110. Dictionary<Maid, int> dictionary = new Dictionary<Maid, int>();
  111. for (int i = 0; i < this.selectMaidList.Length; i++)
  112. {
  113. if (this.selectMaidList[i] != null)
  114. {
  115. this.selectMaidList[i].SetSelectNoVisibleAllOff();
  116. bool flag = this.activeMaidList.Contains(this.selectMaidList[i].maid);
  117. if (flag)
  118. {
  119. dictionary.Add(this.selectMaidList[i].maid, i);
  120. }
  121. }
  122. this.selectMaidList[i] = null;
  123. }
  124. MaidPlate[] array = new MaidPlate[this.selectMaidList.Length];
  125. List<Transform> childList = this.maidListGrid.GetChildList();
  126. for (int j = 0; j < childList.Count; j++)
  127. {
  128. UnityEngine.Object.DestroyImmediate(childList[j].gameObject);
  129. }
  130. this.maidListGrid.transform.DetachChildren();
  131. List<Maid> sortedActiveMaidList = this.GetSortedActiveMaidList();
  132. for (int k = 0; k < sortedActiveMaidList.Count; k++)
  133. {
  134. GameObject gameObject = Utility.CreatePrefab(this.maidListGrid.gameObject, "ScenePhotoMode/SimpleMaidPlate", true);
  135. gameObject.GetComponent<MaidPlate>().SetMaidData(sortedActiveMaidList[k]);
  136. UIWFSelectButton component = UTY.GetChildObject(gameObject, "Button", false).GetComponent<UIWFSelectButton>();
  137. UIWFTabButton component2 = UTY.GetChildObject(gameObject, "Button", false).GetComponent<UIWFTabButton>();
  138. UnityEngine.Object.Destroy(component2);
  139. component.enabled = true;
  140. EventDelegate.Add(component.onSelect, new EventDelegate.Callback(this.OnSelectMaid));
  141. if (dictionary.ContainsKey(sortedActiveMaidList[k]))
  142. {
  143. array[dictionary[sortedActiveMaidList[k]]] = gameObject.GetComponent<MaidPlate>();
  144. }
  145. }
  146. this.switchPanel.SetNumberOfSelected(5);
  147. this.switchPanel.UpdateChildren();
  148. Utility.ResetNGUI(this.maidListGrid);
  149. Utility.ResetNGUI(NGUITools.FindInParents<UIScrollView>(this.maidListGrid.transform));
  150. this.UpdateChildren();
  151. for (int l = 0; l < array.Length; l++)
  152. {
  153. if (!(array[l] == null))
  154. {
  155. UIWFSelectButton component3 = UTY.GetChildObject(array[l].gameObject, "Button", false).GetComponent<UIWFSelectButton>();
  156. this.switchPanel.Select(component3);
  157. }
  158. }
  159. bool isEnabled = false;
  160. this.selectMaidList = array;
  161. for (int m = 0; m < this.selectMaidList.Length; m++)
  162. {
  163. if (this.selectMaidList[m] != null)
  164. {
  165. this.selectMaidList[m].SetSelectNoVisibleAllOff();
  166. this.selectMaidList[m].SetSelectNoVisible(m + 1, true);
  167. isEnabled = true;
  168. }
  169. }
  170. UIButton[] componentsInChildren = this.contentGrid.GetComponentsInChildren<UIButton>();
  171. foreach (UIButton uibutton in componentsInChildren)
  172. {
  173. uibutton.isEnabled = isEnabled;
  174. }
  175. }
  176. public GameObject CreateAlignmentPresetButton(GameObject parentObject, PhotoAlignmentPreset.Data data)
  177. {
  178. GameObject gameObject = Utility.CreatePrefab(parentObject, "ScenePhotoMode/AlignmentPresetButton", true);
  179. gameObject.name = data.id.ToString();
  180. UI2DSprite component = UTY.GetChildObject(gameObject, "Plate/Plate/BG/ThumImage", false).GetComponent<UI2DSprite>();
  181. if (!string.IsNullOrEmpty(data.thumbnailName))
  182. {
  183. Texture2D texture2D = ImportCM.CreateTexture(data.thumbnailName + ".tex");
  184. Sprite sprite2D = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  185. if (component.sprite2D != null && component.sprite2D.texture != null)
  186. {
  187. UnityEngine.Object.DestroyImmediate(component.sprite2D.texture);
  188. }
  189. component.sprite2D = sprite2D;
  190. component.SetDimensions(texture2D.width, texture2D.height);
  191. }
  192. UIButton componentInChildren = gameObject.GetComponentInChildren<UIButton>();
  193. componentInChildren.name = data.id.ToString();
  194. EventDelegate.Add(componentInChildren.onClick, new EventDelegate.Callback(this.OnClickLoadBtn));
  195. return gameObject;
  196. }
  197. private void OnClickLoadBtn()
  198. {
  199. GameObject gameObject = UIButton.current.transform.parent.parent.gameObject;
  200. int id = int.Parse(gameObject.name);
  201. PhotoAlignmentPreset.Data data = PhotoAlignmentPreset.GetData(id);
  202. GameMain.Instance.SysDlg.Show("選択した配置に変更します。\n宜しいですか?", SystemDialog.TYPE.OK_CANCEL, delegate
  203. {
  204. GameMain.Instance.SysDlg.Close();
  205. this.ExecAlignmentPreset(data);
  206. }, null);
  207. }
  208. private void ExecAlignmentPreset(PhotoAlignmentPreset.Data data)
  209. {
  210. for (int i = 0; i < this.selectMaidList.Length; i++)
  211. {
  212. if (this.selectMaidList[i] != null)
  213. {
  214. this.selectMaidList[i].maid.transform.localPosition = data.positions[i];
  215. }
  216. }
  217. }
  218. private List<Maid> GetSortedActiveMaidList()
  219. {
  220. if (this.activeMaidList.Count <= 0)
  221. {
  222. return new List<Maid>();
  223. }
  224. if (this.placementWindow == null)
  225. {
  226. this.placementWindow = (base.mgr.GetWindow(PhotoWindowManager.WindowType.Placement) as PlacementWindow);
  227. }
  228. List<Maid> list = new List<Maid>();
  229. List<Maid> maid_list = this.placementWindow.maid_list;
  230. for (int i = 0; i < maid_list.Count; i++)
  231. {
  232. if (this.activeMaidList.Contains(maid_list[i]))
  233. {
  234. list.Add(maid_list[i]);
  235. }
  236. }
  237. return list;
  238. }
  239. [HideInInspector]
  240. public static PhotoAlignmentPreset.Data SelectData;
  241. [SerializeField]
  242. private UIGrid maidListGrid;
  243. [SerializeField]
  244. private UIWFSwitchPanel switchPanel;
  245. [SerializeField]
  246. private UIGrid contentGrid;
  247. private MaidPlate[] selectMaidList = new MaidPlate[5];
  248. private PhotoNoCharaActive noCharaActive;
  249. private HashSet<Maid> activeMaidList = new HashSet<Maid>();
  250. private PlacementWindow placementWindow;
  251. }