MaidDressingPane.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using static TBody;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. internal class MaidDressingPane : BasePane
  7. {
  8. private MeidoManager meidoManager;
  9. private Dictionary<SlotID, Toggle> ClothingToggles;
  10. private Dictionary<SlotID, bool> LoadedSlots;
  11. public static readonly SlotID[] clothingSlots = {
  12. // main slots
  13. SlotID.wear, SlotID.skirt, SlotID.bra, SlotID.panz, SlotID.headset, SlotID.megane,
  14. SlotID.accUde, SlotID.glove, SlotID.accSenaka, SlotID.stkg, SlotID.shoes, SlotID.body,
  15. // detailed slots
  16. SlotID.accAshi, SlotID.accHana, SlotID.accHat, SlotID.accHeso, SlotID.accKamiSubL,
  17. SlotID.accKamiSubR, SlotID.accKami_1_, SlotID.accKami_2_, SlotID.accKami_3_, SlotID.accKubi,
  18. SlotID.accKubiwa, SlotID.accMiMiL, SlotID.accMiMiR, SlotID.accNipL, SlotID.accNipR,
  19. SlotID.accShippo, SlotID.accXXX,
  20. // unused slots
  21. // SlotID.mizugi, SlotID.onepiece, SlotID.accHead,
  22. };
  23. public static readonly SlotID[] bodySlots = {
  24. SlotID.body, SlotID.head, SlotID.eye, SlotID.hairF, SlotID.hairR,
  25. SlotID.hairS, SlotID.hairT, SlotID.hairAho, SlotID.chikubi, SlotID.underhair,
  26. SlotID.moza, SlotID.accHa
  27. };
  28. public static readonly SlotID[] wearSlots = {
  29. SlotID.wear, SlotID.mizugi, SlotID.onepiece
  30. };
  31. public static readonly SlotID[] headwearSlots = {
  32. SlotID.headset, SlotID.accHat, SlotID.accKamiSubL,
  33. SlotID.accKamiSubR, SlotID.accKami_1_, SlotID.accKami_2_, SlotID.accKami_3_
  34. };
  35. private Toggle detailedClothingToggle;
  36. private Toggle curlingFrontToggle;
  37. private Toggle curlingBackToggle;
  38. private Toggle pantsuShiftToggle;
  39. private bool detailedClothing = false;
  40. public MaidDressingPane(MeidoManager meidoManager)
  41. {
  42. this.meidoManager = meidoManager;
  43. ClothingToggles = new Dictionary<SlotID, Toggle>(clothingSlots.Length);
  44. LoadedSlots = new Dictionary<SlotID, bool>(clothingSlots.Length);
  45. foreach (SlotID slot in clothingSlots)
  46. {
  47. Toggle slotToggle = new Toggle(Translation.Get("clothing", slot.ToString()));
  48. slotToggle.ControlEvent += (s, a) => ToggleClothing(slot, slotToggle.Value);
  49. ClothingToggles.Add(slot, slotToggle);
  50. LoadedSlots[slot] = true;
  51. }
  52. detailedClothingToggle = new Toggle(Translation.Get("clothing", "detail"));
  53. detailedClothingToggle.ControlEvent += (s, a) => UpdateDetailedClothing();
  54. curlingFrontToggle = new Toggle(Translation.Get("clothing", "curlingFront"));
  55. curlingFrontToggle.ControlEvent += (s, a) => ToggleCurling(Meido.Curl.front, curlingFrontToggle.Value);
  56. curlingBackToggle = new Toggle(Translation.Get("clothing", "curlingBack"));
  57. curlingBackToggle.ControlEvent += (s, a) => ToggleCurling(Meido.Curl.back, curlingBackToggle.Value);
  58. pantsuShiftToggle = new Toggle(Translation.Get("clothing", "shiftPanties"));
  59. pantsuShiftToggle.ControlEvent += (s, a) => ToggleCurling(Meido.Curl.shift, pantsuShiftToggle.Value);
  60. UpdateDetailedClothing();
  61. }
  62. protected override void ReloadTranslation()
  63. {
  64. foreach (SlotID slot in clothingSlots)
  65. {
  66. Toggle clothingToggle = ClothingToggles[slot];
  67. if (slot == SlotID.headset)
  68. {
  69. clothingToggle.Label = detailedClothing
  70. ? Translation.Get("clothing", "headset")
  71. : Translation.Get("clothing", "headwear");
  72. }
  73. else
  74. {
  75. clothingToggle.Label = Translation.Get("clothing", slot.ToString());
  76. }
  77. }
  78. detailedClothingToggle.Label = Translation.Get("clothing", "detail");
  79. curlingFrontToggle.Label = Translation.Get("clothing", "curlingFront");
  80. curlingBackToggle.Label = Translation.Get("clothing", "curlingBack");
  81. pantsuShiftToggle.Label = Translation.Get("clothing", "shiftPanties");
  82. }
  83. public void ToggleClothing(SlotID slot, bool enabled)
  84. {
  85. if (this.updating) return;
  86. if (slot == SlotID.body)
  87. {
  88. this.meidoManager.ActiveMeido.SetBodyMask(enabled);
  89. return;
  90. }
  91. TBody body = this.meidoManager.ActiveMeido.Maid.body0;
  92. if (!detailedClothing && slot == SlotID.headset)
  93. {
  94. this.updating = true;
  95. foreach (SlotID wearSlot in headwearSlots)
  96. {
  97. body.SetMask(wearSlot, enabled);
  98. ClothingToggles[wearSlot].Value = enabled;
  99. }
  100. this.updating = false;
  101. }
  102. else
  103. {
  104. if (slot == SlotID.wear)
  105. {
  106. foreach (SlotID wearSlot in wearSlots)
  107. {
  108. body.SetMask(wearSlot, enabled);
  109. }
  110. }
  111. else if (slot == SlotID.megane)
  112. {
  113. body.SetMask(SlotID.megane, enabled);
  114. body.SetMask(SlotID.accHead, enabled);
  115. }
  116. else body.SetMask(slot, enabled);
  117. }
  118. }
  119. public void ToggleCurling(Meido.Curl curl, bool enabled)
  120. {
  121. if (updating) return;
  122. this.meidoManager.ActiveMeido.SetCurling(curl, enabled);
  123. if (enabled)
  124. {
  125. this.updating = true;
  126. if (curl == Meido.Curl.front && curlingBackToggle.Value)
  127. {
  128. curlingBackToggle.Value = false;
  129. }
  130. else if (curl == Meido.Curl.back && curlingFrontToggle.Value)
  131. {
  132. curlingFrontToggle.Value = false;
  133. }
  134. this.updating = false;
  135. }
  136. }
  137. public override void UpdatePane()
  138. {
  139. if (!this.meidoManager.HasActiveMeido) return;
  140. this.updating = true;
  141. Meido meido = this.meidoManager.ActiveMeido;
  142. TBody body = meido.Maid.body0;
  143. foreach (SlotID clothingSlot in clothingSlots)
  144. {
  145. bool toggleValue = false;
  146. bool hasSlot = false;
  147. if (clothingSlot == SlotID.wear)
  148. {
  149. foreach (SlotID wearSlot in wearSlots)
  150. {
  151. if (body.GetMask(wearSlot)) toggleValue = true;
  152. if (body.GetSlotLoaded(wearSlot)) hasSlot = true;
  153. if (hasSlot && toggleValue) break;
  154. }
  155. }
  156. else if (clothingSlot == SlotID.megane)
  157. {
  158. toggleValue = body.GetMask(SlotID.megane) || body.GetMask(SlotID.accHead);
  159. hasSlot = body.GetSlotLoaded(SlotID.megane) || body.GetSlotLoaded(SlotID.accHead);
  160. }
  161. else if (!detailedClothing && clothingSlot == SlotID.headset)
  162. {
  163. foreach (SlotID headwearSlot in headwearSlots)
  164. {
  165. if (body.GetMask(headwearSlot)) toggleValue = true;
  166. if (body.GetSlotLoaded(headwearSlot)) hasSlot = true;
  167. if (hasSlot && toggleValue) break;
  168. }
  169. }
  170. else
  171. {
  172. toggleValue = body.GetMask(clothingSlot);
  173. hasSlot = body.GetSlotLoaded(clothingSlot);
  174. }
  175. ClothingToggles[clothingSlot].Value = hasSlot ? toggleValue : false;
  176. LoadedSlots[clothingSlot] = hasSlot;
  177. }
  178. curlingFrontToggle.Value = meido.CurlingFront;
  179. curlingBackToggle.Value = meido.CurlingBack;
  180. pantsuShiftToggle.Value = meido.PantsuShift;
  181. this.updating = false;
  182. }
  183. private void DrawSlotGroup(params SlotID[] slots)
  184. {
  185. GUILayout.BeginHorizontal();
  186. for (int i = 0; i < slots.Length; i++)
  187. {
  188. SlotID slot = slots[i];
  189. if (!this.Enabled) GUI.enabled = false;
  190. else GUI.enabled = LoadedSlots[slot];
  191. ClothingToggles[slot].Draw();
  192. if (i < slots.Length - 1) GUILayout.FlexibleSpace();
  193. }
  194. GUILayout.EndHorizontal();
  195. }
  196. private void UpdateDetailedClothing()
  197. {
  198. detailedClothing = detailedClothingToggle.Value;
  199. ClothingToggles[SlotID.headset].Label = detailedClothing
  200. ? Translation.Get("clothing", "headset")
  201. : Translation.Get("clothing", "headwear");
  202. UpdatePane();
  203. }
  204. public override void Draw()
  205. {
  206. this.Enabled = this.meidoManager.HasActiveMeido;
  207. GUI.enabled = this.Enabled;
  208. detailedClothingToggle.Draw();
  209. MiscGUI.BlackLine();
  210. DrawSlotGroup(SlotID.wear, SlotID.skirt);
  211. DrawSlotGroup(SlotID.bra, SlotID.panz);
  212. DrawSlotGroup(SlotID.headset, SlotID.megane);
  213. DrawSlotGroup(SlotID.accUde, SlotID.glove, SlotID.accSenaka);
  214. DrawSlotGroup(SlotID.stkg, SlotID.shoes, SlotID.body);
  215. if (detailedClothing)
  216. {
  217. MiscGUI.BlackLine();
  218. DrawSlotGroup(SlotID.accShippo, SlotID.accHat);
  219. DrawSlotGroup(SlotID.accKami_1_, SlotID.accKami_2_, SlotID.accKami_3_);
  220. DrawSlotGroup(SlotID.accKamiSubL, SlotID.accKamiSubR);
  221. DrawSlotGroup(SlotID.accMiMiL, SlotID.accMiMiR);
  222. DrawSlotGroup(SlotID.accNipL, SlotID.accNipR);
  223. DrawSlotGroup(SlotID.accHana, SlotID.accKubi, SlotID.accKubiwa);
  224. DrawSlotGroup(SlotID.accHeso, SlotID.accAshi, SlotID.accXXX);
  225. }
  226. GUI.enabled = this.Enabled;
  227. GUILayout.BeginHorizontal();
  228. curlingFrontToggle.Draw();
  229. GUILayout.FlexibleSpace();
  230. curlingBackToggle.Draw();
  231. GUILayout.FlexibleSpace();
  232. pantsuShiftToggle.Draw();
  233. GUILayout.FlexibleSpace();
  234. GUILayout.EndHorizontal();
  235. GUI.enabled = true;
  236. }
  237. }
  238. }