MaidFaceSliderPane.cs 7.1 KB

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