MaidDressingPane.cs 11 KB

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