LoadReplaceMaid.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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, false);
  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. if (!this.already_used_maid_list_.Contains(this.chara_mgr_.GetStockMaid(i)))
  132. {
  133. list.Add(this.chara_mgr_.GetStockMaid(i));
  134. }
  135. }
  136. List<Maid> list2 = list;
  137. if (LoadReplaceMaid.<>f__mg$cache0 == null)
  138. {
  139. LoadReplaceMaid.<>f__mg$cache0 = new Comparison<Maid>(CharacterSelectManager.SortMaidStandardNoSchedule);
  140. }
  141. list2.Sort(LoadReplaceMaid.<>f__mg$cache0);
  142. list.Insert(0, null);
  143. for (int j = 0; j < this.ContentGrid.transform.childCount; j++)
  144. {
  145. UnityEngine.Object.Destroy(this.ContentGrid.transform.GetChild(j).gameObject);
  146. }
  147. this.ContentGrid.gameObject.transform.DetachChildren();
  148. this.TabPanel.ResetSelect();
  149. UIWFTabButton uiwftabButton = null;
  150. for (int k = 0; k < list.Count; k++)
  151. {
  152. GameObject f_goParent;
  153. if (list[k] == null)
  154. {
  155. f_goParent = Utility.CreatePrefab(this.ContentGrid.gameObject, "ScenePhotoMode/SimpleMaidPlateSelectNot", true);
  156. }
  157. else
  158. {
  159. f_goParent = Utility.CreatePrefab(this.ContentGrid.gameObject, "ScenePhotoMode/SimpleMaidPlateSelect", true);
  160. }
  161. SimpleMaidPlate component = UTY.GetChildObject(f_goParent, "Plate", false).GetComponent<SimpleMaidPlate>();
  162. component.SetMaidData(list[k]);
  163. UIWFTabButton component2 = UTY.GetChildObject(f_goParent, "Plate/Button", false).GetComponent<UIWFTabButton>();
  164. EventDelegate.Add(component2.onSelect, new EventDelegate.Callback(this.OnSelectMaid));
  165. if (list[k] == null)
  166. {
  167. component2.gameObject.name = string.Empty;
  168. }
  169. else
  170. {
  171. component2.gameObject.name = list[k].status.guid;
  172. }
  173. if (uiwftabButton == null)
  174. {
  175. uiwftabButton = component2;
  176. }
  177. }
  178. this.ContentGrid.Reposition();
  179. this.scroll_view_.ResetPosition();
  180. this.TabPanel.UpdateChildren();
  181. this.TabPanel.Select(uiwftabButton);
  182. return true;
  183. }
  184. public void OnClickOK()
  185. {
  186. this.replace_result_dic_.Add(this.not_exist_maid_list_[0].Key, this.select_maid_);
  187. this.not_exist_maid_list_.RemoveAt(0);
  188. this.already_used_maid_list_.Add(this.select_maid_);
  189. this.select_maid_ = null;
  190. if (!this.SelectReplaceMaid())
  191. {
  192. this.ui_panel_.alpha = 0f;
  193. base.gameObject.SetActive(false);
  194. if (this.OnReplaceEndEvent != null)
  195. {
  196. this.OnReplaceEndEvent(this.replace_result_dic_);
  197. }
  198. }
  199. }
  200. public void OnSelectMaid()
  201. {
  202. if (!UIWFSelectButton.current.isSelected)
  203. {
  204. return;
  205. }
  206. if (string.IsNullOrEmpty(UIWFSelectButton.current.gameObject.name))
  207. {
  208. this.select_maid_ = null;
  209. }
  210. else
  211. {
  212. this.select_maid_ = this.chara_mgr_.GetStockMaid(UIWFSelectButton.current.gameObject.name);
  213. }
  214. }
  215. public UIWFTabPanel TabPanel;
  216. public UIGrid ContentGrid;
  217. public UILabel TextLabel;
  218. public UIButton OKButton;
  219. public UIWidget bgWidget;
  220. public UI2DSprite ui2dSprite;
  221. public Action<Dictionary<string, Maid>> OnReplaceEndEvent;
  222. private Dictionary<Transform, Vector3> positionBackup = new Dictionary<Transform, Vector3>();
  223. private Vector2 bgBackupSize;
  224. private static string kText = "ScenePhotoMode/シチュ/ダイアログ/メイド{0}が見つかりませんでした。";
  225. private CharacterMgr chara_mgr_;
  226. private List<KeyValuePair<string, string>> not_exist_maid_list_ = new List<KeyValuePair<string, string>>();
  227. private HashSet<Maid> already_used_maid_list_ = new HashSet<Maid>();
  228. private Dictionary<string, Maid> replace_result_dic_ = new Dictionary<string, Maid>();
  229. private Maid select_maid_;
  230. private UIScrollView scroll_view_;
  231. private UIPanel ui_panel_;
  232. [CompilerGenerated]
  233. private static Comparison<Maid> <>f__mg$cache0;
  234. }