PhotUndressingManager.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PhotUndressingManager : MonoBehaviour
  5. {
  6. public void Awake()
  7. {
  8. if (0 < this.unit_slot_dic_.Count)
  9. {
  10. return;
  11. }
  12. using (AFileBase afileBase = GameUty.FileSystem.FileOpen("phot_undressing_list.nei"))
  13. {
  14. using (CsvParser csvParser = new CsvParser())
  15. {
  16. bool condition = csvParser.Open(afileBase);
  17. NDebug.Assert(condition, "file open error[phot_undressing_list.nei]");
  18. for (int i = 1; i < csvParser.max_cell_y; i++)
  19. {
  20. if (csvParser.IsCellToExistData(0, i))
  21. {
  22. int num = 0;
  23. string cellAsString = csvParser.GetCellAsString(num++, i);
  24. string cellAsString2 = csvParser.GetCellAsString(num++, i);
  25. if (!string.IsNullOrEmpty(cellAsString2))
  26. {
  27. string[] array = cellAsString2.Split(new char[]
  28. {
  29. ','
  30. });
  31. for (int j = 0; j < array.Length; j++)
  32. {
  33. TBody.SlotID item = TBody.SlotID.wear;
  34. try
  35. {
  36. item = (TBody.SlotID)Enum.Parse(typeof(TBody.SlotID), array[j]);
  37. }
  38. catch
  39. {
  40. NDebug.Assert("TBody.SlotID enum parse error.\n" + array[j], false);
  41. }
  42. if (!this.unit_slot_dic_.ContainsKey(cellAsString))
  43. {
  44. this.unit_slot_dic_.Add(cellAsString, new List<TBody.SlotID>());
  45. }
  46. this.unit_slot_dic_[cellAsString].Add(item);
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. public void SetUnitButtonList(Dictionary<string, UIButton> unit_dic)
  55. {
  56. this.Awake();
  57. foreach (KeyValuePair<string, UIButton> keyValuePair in unit_dic)
  58. {
  59. PhotUndressingManager.UndressingData undressingData = new PhotUndressingManager.UndressingData();
  60. undressingData.unit_type = keyValuePair.Key;
  61. undressingData.button_object = keyValuePair.Value;
  62. undressingData.button_default_color = undressingData.button_object.defaultColor;
  63. if (this.unit_slot_dic_.ContainsKey(undressingData.unit_type))
  64. {
  65. undressingData.target_sloat_id_list = this.unit_slot_dic_[undressingData.unit_type];
  66. }
  67. EventDelegate eventDelegate = new EventDelegate(this, "OnClickButton");
  68. eventDelegate.parameters[0].value = undressingData;
  69. undressingData.button_object.onClick.Add(eventDelegate);
  70. this.unit_dic_.Add(undressingData.unit_type, undressingData);
  71. }
  72. }
  73. public void SetMaid(Maid maid)
  74. {
  75. this.maid_ = maid;
  76. foreach (KeyValuePair<string, PhotUndressingManager.UndressingData> keyValuePair in this.unit_dic_)
  77. {
  78. PhotUndressingManager.UndressingData value = keyValuePair.Value;
  79. value.UpdateMaskStatus(maid);
  80. }
  81. int num = 1;
  82. if (this.maid_linked_array_ != null)
  83. {
  84. num += this.maid_linked_array_.Length;
  85. }
  86. this.all_maid_data_ = new Maid[num];
  87. this.all_maid_data_[0] = this.maid_;
  88. if (this.maid_linked_array_ != null)
  89. {
  90. for (int i = 0; i < this.maid_linked_array_.Length; i++)
  91. {
  92. this.all_maid_data_[i + 1] = this.maid_linked_array_[i];
  93. }
  94. }
  95. }
  96. public void SetMaskMode(string unit_type, PhotUndressingManager.MaskStatus status)
  97. {
  98. if (!this.unit_dic_.ContainsKey(unit_type))
  99. {
  100. return;
  101. }
  102. PhotUndressingManager.UndressingData undressingData = this.unit_dic_[unit_type];
  103. if (undressingData.unit_type != "全脱衣")
  104. {
  105. this.unit_dic_["全脱衣"].mask_mode = PhotUndressingManager.MaskStatus.Off;
  106. }
  107. if (undressingData.unit_type != "全着衣")
  108. {
  109. this.unit_dic_["全着衣"].mask_mode = PhotUndressingManager.MaskStatus.Off;
  110. }
  111. undressingData.mask_mode = status;
  112. this.ApplyAllMaid();
  113. }
  114. private void OnClickButton(PhotUndressingManager.UndressingData unit_data)
  115. {
  116. PhotUndressingManager.MaskStatus status = (unit_data.mask_mode != PhotUndressingManager.MaskStatus.On) ? PhotUndressingManager.MaskStatus.On : PhotUndressingManager.MaskStatus.Off;
  117. this.SetMaskMode(unit_data.unit_type, status);
  118. if (this.onClickEvent != null)
  119. {
  120. this.onClickEvent();
  121. }
  122. }
  123. private void ApplyAllMaid()
  124. {
  125. if (this.unit_dic_["全脱衣"].mask_mode == PhotUndressingManager.MaskStatus.On)
  126. {
  127. for (int i = 0; i < this.all_maid_data_.Length; i++)
  128. {
  129. foreach (KeyValuePair<string, PhotUndressingManager.UndressingData> keyValuePair in this.unit_dic_)
  130. {
  131. if (!(keyValuePair.Key == "全脱衣") && !(keyValuePair.Key == "全着衣") && keyValuePair.Value.button_object.isEnabled)
  132. {
  133. this.SetMaskMode(keyValuePair.Key, PhotUndressingManager.MaskStatus.On);
  134. }
  135. }
  136. }
  137. return;
  138. }
  139. if (this.unit_dic_["全着衣"].mask_mode == PhotUndressingManager.MaskStatus.On)
  140. {
  141. for (int j = 0; j < this.all_maid_data_.Length; j++)
  142. {
  143. foreach (KeyValuePair<string, PhotUndressingManager.UndressingData> keyValuePair2 in this.unit_dic_)
  144. {
  145. if (!(keyValuePair2.Key == "全脱衣") && !(keyValuePair2.Key == "全着衣") && keyValuePair2.Value.button_object.isEnabled)
  146. {
  147. this.SetMaskMode(keyValuePair2.Key, PhotUndressingManager.MaskStatus.Off);
  148. }
  149. }
  150. }
  151. return;
  152. }
  153. foreach (KeyValuePair<string, PhotUndressingManager.UndressingData> keyValuePair3 in this.unit_dic_)
  154. {
  155. PhotUndressingManager.UndressingData value = keyValuePair3.Value;
  156. for (int k = 0; k < this.all_maid_data_.Length; k++)
  157. {
  158. value.ApplyMask(this.all_maid_data_[k]);
  159. }
  160. value.UpdateMaskStatus(this.maid_);
  161. }
  162. }
  163. public HashSet<TBody.SlotID> GetTargetSlotID()
  164. {
  165. HashSet<TBody.SlotID> hashSet = new HashSet<TBody.SlotID>();
  166. foreach (KeyValuePair<string, List<TBody.SlotID>> keyValuePair in this.unit_slot_dic_)
  167. {
  168. List<TBody.SlotID> value = keyValuePair.Value;
  169. for (int i = 0; i < value.Count; i++)
  170. {
  171. if (!hashSet.Contains(value[i]))
  172. {
  173. hashSet.Add(value[i]);
  174. }
  175. }
  176. }
  177. return hashSet;
  178. }
  179. public Action onClickEvent;
  180. private Dictionary<string, PhotUndressingManager.UndressingData> unit_dic_ = new Dictionary<string, PhotUndressingManager.UndressingData>();
  181. private Dictionary<string, List<TBody.SlotID>> unit_slot_dic_ = new Dictionary<string, List<TBody.SlotID>>();
  182. private Maid maid_;
  183. private Maid[] maid_linked_array_;
  184. private Maid[] all_maid_data_;
  185. public enum MaskStatus
  186. {
  187. On,
  188. Off
  189. }
  190. private class UndressingData
  191. {
  192. public PhotUndressingManager.MaskStatus mask_mode
  193. {
  194. get
  195. {
  196. return this.button_mask_status_;
  197. }
  198. set
  199. {
  200. if (this.button_mask_status_ == value)
  201. {
  202. return;
  203. }
  204. this.button_mask_status_ = value;
  205. if (this.unit_type == "全着衣" || this.unit_type == "全脱衣")
  206. {
  207. return;
  208. }
  209. if (this.button_mask_status_ == PhotUndressingManager.MaskStatus.Off)
  210. {
  211. this.button_object.defaultColor = this.button_default_color;
  212. this.button_object.hover = this.button_object.defaultColor;
  213. }
  214. else
  215. {
  216. Color defaultColor = this.button_default_color;
  217. defaultColor.a = 0.5f;
  218. this.button_object.defaultColor = defaultColor;
  219. this.button_object.hover = this.button_object.defaultColor;
  220. }
  221. }
  222. }
  223. public void UpdateMaskStatus(Maid maid)
  224. {
  225. if (maid == null || maid.body0 == null)
  226. {
  227. this.button_object.isEnabled = false;
  228. return;
  229. }
  230. if (this.unit_type == "全着衣" || this.unit_type == "全脱衣")
  231. {
  232. this.button_object.isEnabled = true;
  233. return;
  234. }
  235. bool flag = false;
  236. for (int i = 0; i < this.target_sloat_id_list.Count; i++)
  237. {
  238. if (maid.body0.GetSlotLoaded(this.target_sloat_id_list[i]))
  239. {
  240. flag = true;
  241. break;
  242. }
  243. }
  244. if (!flag)
  245. {
  246. this.button_object.isEnabled = false;
  247. return;
  248. }
  249. this.button_object.isEnabled = true;
  250. bool flag2 = true;
  251. for (int j = 0; j < this.target_sloat_id_list.Count; j++)
  252. {
  253. if (maid.body0.GetMask(this.target_sloat_id_list[j]))
  254. {
  255. flag2 = false;
  256. break;
  257. }
  258. }
  259. this.mask_mode = ((!flag2) ? PhotUndressingManager.MaskStatus.Off : PhotUndressingManager.MaskStatus.On);
  260. }
  261. public void ApplyMask(Maid[] maid_array)
  262. {
  263. if (maid_array == null)
  264. {
  265. return;
  266. }
  267. for (int i = 0; i < maid_array.Length; i++)
  268. {
  269. this.ApplyMask(maid_array[i]);
  270. }
  271. }
  272. public void ApplyMask(Maid maid)
  273. {
  274. if (maid == null || maid.body0 == null || !this.button_object.isEnabled || this.unit_type == "全着衣" || this.unit_type == "全脱衣")
  275. {
  276. return;
  277. }
  278. bool flag = this.mask_mode == PhotUndressingManager.MaskStatus.On;
  279. for (int i = 0; i < this.target_sloat_id_list.Count; i++)
  280. {
  281. maid.body0.SetMask(this.target_sloat_id_list[i], !flag);
  282. }
  283. }
  284. public string unit_type;
  285. public List<TBody.SlotID> target_sloat_id_list = new List<TBody.SlotID>();
  286. public string call_scenario = string.Empty;
  287. public Color button_default_color;
  288. public UIButton button_object;
  289. private PhotUndressingManager.MaskStatus button_mask_status_ = PhotUndressingManager.MaskStatus.Off;
  290. }
  291. }