MaidFaceSliderPane.cs 7.0 KB

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