MaidDressingPane.cs 11 KB

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