LoadReplaceMaid.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using I2.Loc;
  5. using UnityEngine;
  6. using wf;
  7. public class LoadReplaceMaid : MonoBehaviour
  8. {
  9. public void Awake()
  10. {
  11. this.chara_mgr_ = GameMain.Instance.CharacterMgr;
  12. EventDelegate.Add(this.OKButton.onClick, new EventDelegate.Callback(this.OnClickOK));
  13. this.ui_panel_ = base.gameObject.GetComponentInChildren<UIPanel>();
  14. this.positionBackup.Add(this.OKButton.transform, this.OKButton.transform.localPosition);
  15. this.bgBackupSize = new Vector2((float)this.bgWidget.width, (float)this.bgWidget.height);
  16. }
  17. public void OnEnable()
  18. {
  19. if (this.scroll_view_ != null)
  20. {
  21. return;
  22. }
  23. this.scroll_view_ = NGUITools.FindInParents<UIScrollView>(this.ContentGrid.transform);
  24. this.ui_panel_.alpha = 0f;
  25. }
  26. public bool CheckAndStart(List<KeyValuePair<string, string>> check_guid_maid_list)
  27. {
  28. if (!base.gameObject.activeSelf)
  29. {
  30. base.gameObject.SetActive(true);
  31. }
  32. this.not_exist_maid_list_.Clear();
  33. this.already_used_maid_list_.Clear();
  34. this.replace_result_dic_.Clear();
  35. for (int i = 0; i < check_guid_maid_list.Count; i++)
  36. {
  37. string key = check_guid_maid_list[i].Key;
  38. Maid stockMaid = this.chara_mgr_.GetStockMaid(key);
  39. if (stockMaid == null)
  40. {
  41. this.not_exist_maid_list_.Add(new KeyValuePair<string, string>(check_guid_maid_list[i].Key, check_guid_maid_list[i].Value));
  42. }
  43. else
  44. {
  45. this.already_used_maid_list_.Add(stockMaid);
  46. }
  47. }
  48. bool flag = 0 < this.not_exist_maid_list_.Count;
  49. if (flag)
  50. {
  51. this.ui_panel_.alpha = 1f;
  52. this.SelectReplaceMaid();
  53. }
  54. else
  55. {
  56. this.ui_panel_.alpha = 0f;
  57. base.gameObject.SetActive(false);
  58. if (this.OnReplaceEndEvent != null)
  59. {
  60. this.OnReplaceEndEvent(this.replace_result_dic_);
  61. }
  62. }
  63. return flag;
  64. }
  65. private void ChangeMode(int not_exist_maid_count, string maid_name)
  66. {
  67. if (ScenePresetWindow.SelectData != null)
  68. {
  69. this.bgWidget.SetDimensions(818, 500);
  70. Vector3 vector = this.positionBackup[this.OKButton.transform];
  71. this.OKButton.transform.localPosition = new Vector3(1140f, vector.y, vector.z);
  72. if (0 <= ScenePresetWindow.SelectData.charaFocusImages.Length - not_exist_maid_count && ScenePresetWindow.SelectData.charaFocusImages.Length - not_exist_maid_count < ScenePresetWindow.SelectData.charaFocusImages.Length)
  73. {
  74. this.ui2dSprite.gameObject.SetActive(true);
  75. int num = ScenePresetWindow.SelectData.charaFocusImages.Length - not_exist_maid_count;
  76. string str = ScenePresetWindow.SelectData.charaFocusImages[num];
  77. Texture2D texture2D = ImportCM.CreateTexture(str + ".tex");
  78. Sprite sprite2D = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  79. if (this.ui2dSprite.sprite2D != null && this.ui2dSprite.sprite2D.texture != null)
  80. {
  81. UnityEngine.Object.DestroyImmediate(this.ui2dSprite.sprite2D.texture);
  82. }
  83. this.ui2dSprite.sprite2D = sprite2D;
  84. this.ui2dSprite.SetDimensions(texture2D.width, texture2D.height);
  85. Localize component = this.TextLabel.GetComponent<Localize>();
  86. if (component != null)
  87. {
  88. component.TermArgs = new Localize.ArgsPair[]
  89. {
  90. Localize.ArgsPair.Create((num + 1).ToString())
  91. };
  92. Utility.SetLocalizeTerm(component, "ScenePhotoMode/シチュ/ダイアログ/ポジション{0}に読み込むメイドを選択してください。", true);
  93. }
  94. else
  95. {
  96. this.TextLabel.text = "ポジション" + (num + 1) + "に読み込むメイドを選択してください。";
  97. }
  98. }
  99. }
  100. else
  101. {
  102. this.bgWidget.SetDimensions((int)this.bgBackupSize.x, (int)this.bgBackupSize.y);
  103. this.OKButton.transform.localPosition = this.positionBackup[this.OKButton.transform];
  104. this.ui2dSprite.gameObject.SetActive(false);
  105. Localize component2 = this.TextLabel.GetComponent<Localize>();
  106. if (component2 != null)
  107. {
  108. component2.TermArgs = new Localize.ArgsPair[]
  109. {
  110. Localize.ArgsPair.Create(maid_name)
  111. };
  112. Utility.SetLocalizeTerm(component2, LoadReplaceMaid.kText, true);
  113. }
  114. else
  115. {
  116. this.TextLabel.text = string.Format(LoadReplaceMaid.kText, maid_name);
  117. }
  118. }
  119. }
  120. private bool SelectReplaceMaid()
  121. {
  122. this.select_maid_ = null;
  123. if (this.not_exist_maid_list_.Count <= 0)
  124. {
  125. return false;
  126. }
  127. this.ChangeMode(this.not_exist_maid_list_.Count, this.not_exist_maid_list_[0].Value);
  128. List<Maid> list = new List<Maid>();
  129. for (int i = 0; i < this.chara_mgr_.GetStockMaidCount(); i++)
  130. {
  131. Maid stockMaid = this.chara_mgr_.GetStockMaid(i);
  132. if (!this.already_used_maid_list_.Contains(stockMaid))
  133. {
  134. list.Add(stockMaid);
  135. }
  136. }
  137. List<Maid> list2 = list;
  138. if (LoadReplaceMaid.<>f__mg$cache0 == null)
  139. {
  140. LoadReplaceMaid.<>f__mg$cache0 = new Comparison<Maid>(CharacterSelectManager.SortMaidStandardNoSchedule);
  141. }
  142. list2.Sort(LoadReplaceMaid.<>f__mg$cache0);
  143. list.Insert(0, null);
  144. for (int j = 0; j < this.ContentGrid.transform.childCount; j++)
  145. {
  146. UnityEngine.Object.Destroy(this.ContentGrid.transform.GetChild(j).gameObject);
  147. }
  148. this.ContentGrid.gameObject.transform.DetachChildren();
  149. this.TabPanel.ResetSelect();
  150. UIWFTabButton uiwftabButton = null;
  151. for (int k = 0; k < list.Count; k++)
  152. {
  153. GameObject f_goParent;
  154. if (list[k] == null)
  155. {
  156. f_goParent = Utility.CreatePrefab(this.ContentGrid.gameObject, "ScenePhotoMode/SimpleMaidPlateSelectNot", true);
  157. }
  158. else
  159. {
  160. f_goParent = Utility.CreatePrefab(this.ContentGrid.gameObject, "ScenePhotoMode/SimpleMaidPlateSelect", true);
  161. }
  162. SimpleMaidPlate component = UTY.GetChildObject(f_goParent, "Plate", false).GetComponent<SimpleMaidPlate>();
  163. component.SetMaidData(list[k]);
  164. UIWFTabButton component2 = UTY.GetChildObject(f_goParent, "Plate/Button", false).GetComponent<UIWFTabButton>();
  165. EventDelegate.Add(component2.onSelect, new EventDelegate.Callback(this.OnSelectMaid));
  166. if (list[k] == null)
  167. {
  168. component2.gameObject.name = string.Empty;
  169. }
  170. else
  171. {
  172. component2.gameObject.name = list[k].status.guid;
  173. }
  174. if (uiwftabButton == null)
  175. {
  176. uiwftabButton = component2;
  177. }
  178. }
  179. this.ContentGrid.Reposition();
  180. this.scroll_view_.ResetPosition();
  181. this.TabPanel.UpdateChildren();
  182. this.TabPanel.Select(uiwftabButton);
  183. return true;
  184. }
  185. public void OnClickOK()
  186. {
  187. this.replace_result_dic_.Add(this.not_exist_maid_list_[0].Key, this.select_maid_);
  188. this.not_exist_maid_list_.RemoveAt(0);
  189. this.already_used_maid_list_.Add(this.select_maid_);
  190. this.select_maid_ = null;
  191. if (!this.SelectReplaceMaid())
  192. {
  193. this.ui_panel_.alpha = 0f;
  194. base.gameObject.SetActive(false);
  195. if (this.OnReplaceEndEvent != null)
  196. {
  197. this.OnReplaceEndEvent(this.replace_result_dic_);
  198. }
  199. }
  200. }
  201. public void OnSelectMaid()
  202. {
  203. if (!UIWFSelectButton.current.isSelected)
  204. {
  205. return;
  206. }
  207. if (string.IsNullOrEmpty(UIWFSelectButton.current.gameObject.name))
  208. {
  209. this.select_maid_ = null;
  210. }
  211. else
  212. {
  213. this.select_maid_ = this.chara_mgr_.GetStockMaid(UIWFSelectButton.current.gameObject.name);
  214. }
  215. }
  216. public UIWFTabPanel TabPanel;
  217. public UIGrid ContentGrid;
  218. public UILabel TextLabel;
  219. public UIButton OKButton;
  220. public UIWidget bgWidget;
  221. public UI2DSprite ui2dSprite;
  222. public Action<Dictionary<string, Maid>> OnReplaceEndEvent;
  223. private Dictionary<Transform, Vector3> positionBackup = new Dictionary<Transform, Vector3>();
  224. private Vector2 bgBackupSize;
  225. private static string kText = "ScenePhotoMode/シチュ/ダイアログ/メイド{0}が見つかりませんでした。";
  226. private CharacterMgr chara_mgr_;
  227. private List<KeyValuePair<string, string>> not_exist_maid_list_ = new List<KeyValuePair<string, string>>();
  228. private HashSet<Maid> already_used_maid_list_ = new HashSet<Maid>();
  229. private Dictionary<string, Maid> replace_result_dic_ = new Dictionary<string, Maid>();
  230. private Maid select_maid_;
  231. private UIScrollView scroll_view_;
  232. private UIPanel ui_panel_;
  233. [CompilerGenerated]
  234. private static Comparison<Maid> <>f__mg$cache0;
  235. }