MaidFaceSliderPane.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. internal class MaidFaceSliderPane : BasePane
  7. {
  8. private MeidoManager meidoManager;
  9. // TODO: Consider placing in external file to be user editable
  10. private static readonly Dictionary<string, float[]> SliderRange = new Dictionary<string, float[]>()
  11. {
  12. // Eye Shut
  13. ["eyeclose"] = new[] { 0f, 1f },
  14. // Eye Smile
  15. ["eyeclose2"] = new[] { 0f, 1f },
  16. // Glare
  17. ["eyeclose3"] = new[] { 0f, 1f },
  18. // Wide Eyes
  19. ["eyebig"] = new[] { 0f, 1f },
  20. // Wink 1
  21. ["eyeclose6"] = new[] { 0f, 1f },
  22. // Wink 2
  23. ["eyeclose5"] = new[] { 0f, 1f },
  24. // Highlight
  25. ["hitomih"] = new[] { 0f, 2f },
  26. // Pupil Size
  27. ["hitomis"] = new[] { 0f, 3f },
  28. // Brow 1
  29. ["mayuha"] = new[] { 0f, 1f },
  30. // Brow 2
  31. ["mayuw"] = new[] { 0f, 1f },
  32. // Brow Up
  33. ["mayuup"] = new[] { 0f, 0.8f },
  34. // Brow Down 1
  35. ["mayuv"] = new[] { 0f, 0.8f },
  36. // Brow Down 2
  37. ["mayuvhalf"] = new[] { 0f, 0.9f },
  38. // Mouth Open 1
  39. ["moutha"] = new[] { 0f, 1f },
  40. // Mouth Open 2
  41. ["mouths"] = new[] { 0f, 0.9f },
  42. // Mouth Narrow
  43. ["mouthc"] = new[] { 0f, 1f },
  44. // Mouth Widen
  45. ["mouthi"] = new[] { 0f, 1f },
  46. // Smile
  47. ["mouthup"] = new[] { 0f, 1.4f },
  48. // Frown
  49. ["mouthdw"] = new[] { 0f, 1f },
  50. // Mouth Pucker
  51. ["mouthhe"] = new[] { 0f, 1f },
  52. // Grin
  53. ["mouthuphalf"] = new[] { 0f, 2f },
  54. // Tongue Out
  55. ["tangout"] = new[] { 0f, 1f },
  56. // Tongue Up
  57. ["tangup"] = new[] { 0f, 0.7f },
  58. // Tongue Base
  59. ["tangopen"] = new[] { 0f, 1f }
  60. };
  61. public static readonly string[] faceKeys = new string[24]
  62. {
  63. "eyeclose", "eyeclose2", "eyeclose3", "eyebig", "eyeclose6", "eyeclose5", "hitomih",
  64. "hitomis", "mayuha", "mayuw", "mayuup", "mayuv", "mayuvhalf", "moutha", "mouths",
  65. "mouthc", "mouthi", "mouthup", "mouthdw", "mouthhe", "mouthuphalf", "tangout",
  66. "tangup", "tangopen"
  67. };
  68. public static readonly string[] faceToggleKeys = new string[12]
  69. {
  70. // blush, shade, nose up, tears, drool, teeth
  71. "hoho2", "shock", "nosefook", "namida", "yodare", "toothoff",
  72. // cry 1, cry 2, cry 3, blush 1, blush 2, blush 3
  73. "tear1", "tear2", "tear3", "hohos", "hoho", "hohol"
  74. };
  75. public MaidFaceSliderPane(MeidoManager meidoManager)
  76. {
  77. this.meidoManager = meidoManager;
  78. for (int i = 0; i < faceKeys.Length; i++)
  79. {
  80. string key = faceKeys[i];
  81. string uiName = Translation.Get("faceBlendValues", key);
  82. Slider slider = new Slider(uiName, SliderRange[key][0], SliderRange[key][1]);
  83. int myIndex = i;
  84. slider.ControlEvent += (s, a) => this.SetFaceValue(faceKeys[myIndex], slider.Value);
  85. this.Controls.Add(slider);
  86. }
  87. for (int i = 0; i < faceToggleKeys.Length; i++)
  88. {
  89. string uiName = Translation.Get("faceBlendValues", faceToggleKeys[i]);
  90. Toggle toggle = new Toggle(uiName);
  91. int myIndex = i;
  92. toggle.ControlEvent += (s, a) => this.SetFaceValue(faceToggleKeys[myIndex], toggle.Value);
  93. this.Controls.Add(toggle);
  94. }
  95. }
  96. protected override void ReloadTranslation()
  97. {
  98. for (int i = 0; i < faceKeys.Length; i++)
  99. {
  100. Slider slider = (Slider)Controls[i];
  101. slider.Label = Translation.Get("faceBlendValues", faceKeys[i]);
  102. }
  103. for (int i = faceKeys.Length; i < faceKeys.Length + faceToggleKeys.Length; i++)
  104. {
  105. Toggle toggle = (Toggle)Controls[i];
  106. toggle.Label = Translation.Get("faceBlendValues", faceToggleKeys[i - faceKeys.Length]);
  107. }
  108. }
  109. public void SetFaceValue(string key, float value)
  110. {
  111. if (updating) return;
  112. this.meidoManager.ActiveMeido.SetFaceBlendValue(key, value);
  113. }
  114. public void SetFaceValue(string key, bool value)
  115. {
  116. float max = (key == "hoho" || key == "hoho2") ? 0.5f : 1f;
  117. if (key == "toothoff") value = !value;
  118. SetFaceValue(key, value ? max : 0f);
  119. }
  120. public override void UpdatePane()
  121. {
  122. this.updating = true;
  123. TMorph morph = this.meidoManager.ActiveMeido.Maid.body0.Face.morph;
  124. float[] blendValues = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValues");
  125. float[] blendValuesBackup = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValuesBackup");
  126. for (int i = 0; i < faceKeys.Length; i++)
  127. {
  128. string hash = faceKeys[i];
  129. Slider slider = this.Controls[i] as Slider;
  130. try
  131. {
  132. if (hash.StartsWith("eyeclose"))
  133. slider.Value = blendValuesBackup[(int)morph.hash[hash]];
  134. else
  135. slider.Value = blendValues[(int)morph.hash[hash]];
  136. }
  137. catch { }
  138. }
  139. for (int i = 0; i < faceToggleKeys.Length; i++)
  140. {
  141. string hash = faceToggleKeys[i];
  142. Toggle toggle = this.Controls[24 + i] as Toggle;
  143. if (hash == "nosefook") toggle.Value = morph.boNoseFook;
  144. else toggle.Value = blendValues[(int)morph.hash[hash]] > 0f;
  145. if (hash == "toothoff") toggle.Value = !toggle.Value;
  146. }
  147. this.updating = false;
  148. }
  149. public override void Draw()
  150. {
  151. GUILayoutOption sliderWidth = MiscGUI.HalfSlider;
  152. for (int i = 0; i < faceKeys.Length; i += 2)
  153. {
  154. GUILayout.BeginHorizontal();
  155. for (int j = 0; j < 2; j++)
  156. {
  157. Controls[i + j].Draw(sliderWidth);
  158. if (i + j == 12 || i + j == 23)
  159. {
  160. i--;
  161. break;
  162. }
  163. }
  164. GUILayout.EndHorizontal();
  165. }
  166. MiscGUI.WhiteLine();
  167. for (int i = 0; i < faceToggleKeys.Length; i += 3)
  168. {
  169. GUILayout.BeginHorizontal();
  170. for (int j = 0; j < 3; j++)
  171. {
  172. Controls[24 + i + j].Draw();
  173. }
  174. GUILayout.EndHorizontal();
  175. }
  176. }
  177. }
  178. }