MaidDressingPane.cs 10 KB

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