MaidFaceSliderPane.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. private bool hasTangOpen = false;
  63. public MaidFaceSliderPane(MeidoManager meidoManager)
  64. {
  65. this.meidoManager = meidoManager;
  66. this.faceControls = new Dictionary<string, BaseControl>();
  67. foreach (string key in faceKeys)
  68. {
  69. string uiName = Translation.Get("faceBlendValues", key);
  70. Slider slider = new Slider(uiName, SliderRange[key]);
  71. string myKey = key;
  72. slider.ControlEvent += (s, a) => this.SetFaceValue(myKey, slider.Value);
  73. faceControls[key] = slider;
  74. }
  75. foreach (string key in faceToggleKeys)
  76. {
  77. string uiName = Translation.Get("faceBlendValues", key);
  78. Toggle toggle = new Toggle(uiName);
  79. string myKey = key;
  80. toggle.ControlEvent += (s, a) => this.SetFaceValue(myKey, toggle.Value);
  81. faceControls[key] = toggle;
  82. }
  83. }
  84. protected override void ReloadTranslation()
  85. {
  86. for (int i = 0; i < faceKeys.Length; i++)
  87. {
  88. Slider slider = (Slider)faceControls[faceKeys[i]];
  89. slider.Label = Translation.Get("faceBlendValues", faceKeys[i]);
  90. }
  91. for (int i = 0; i < faceToggleKeys.Length; i++)
  92. {
  93. Toggle toggle = (Toggle)faceControls[faceToggleKeys[i]];
  94. toggle.Label = Translation.Get("faceBlendValues", faceToggleKeys[i]);
  95. }
  96. }
  97. public override void UpdatePane()
  98. {
  99. this.updating = true;
  100. Meido meido = this.meidoManager.ActiveMeido;
  101. for (int i = 0; i < faceKeys.Length; i++)
  102. {
  103. Slider slider = (Slider)faceControls[faceKeys[i]];
  104. try
  105. {
  106. slider.Value = meido.GetFaceBlendValue(faceKeys[i]);
  107. }
  108. catch { }
  109. }
  110. for (int i = 0; i < faceToggleKeys.Length; i++)
  111. {
  112. string hash = faceToggleKeys[i];
  113. Toggle toggle = (Toggle)faceControls[hash];
  114. toggle.Value = meido.GetFaceBlendValue(hash) > 0f;
  115. if (hash == "toothoff") toggle.Value = !toggle.Value;
  116. }
  117. hasTangOpen = meido.Body.Face.morph.hash["tangopen"] != null;
  118. this.updating = false;
  119. }
  120. public override void Draw()
  121. {
  122. GUI.enabled = this.meidoManager.HasActiveMeido;
  123. DrawSliders("eyeclose", "eyeclose2");
  124. DrawSliders("eyeclose3", "eyebig");
  125. DrawSliders("eyeclose6", "eyeclose5");
  126. DrawSliders("hitomih", "hitomis");
  127. DrawSliders("mayuha", "mayuw");
  128. DrawSliders("mayuup", "mayuv");
  129. DrawSliders("mayuvhalf");
  130. DrawSliders("moutha", "mouths");
  131. DrawSliders("mouthc", "mouthi");
  132. DrawSliders("mouthup", "mouthdw");
  133. DrawSliders("mouthhe", "mouthuphalf");
  134. DrawSliders("tangout", "tangup");
  135. if (hasTangOpen) DrawSliders("tangopen");
  136. MiscGUI.WhiteLine();
  137. DrawToggles("hoho2", "shock", "nosefook");
  138. DrawToggles("namida", "yodare", "toothoff");
  139. DrawToggles("tear1", "tear2", "tear3");
  140. DrawToggles("hohos", "hoho", "hohol");
  141. GUI.enabled = true;
  142. }
  143. private void DrawSliders(params string[] keys)
  144. {
  145. GUILayout.BeginHorizontal();
  146. foreach (string key in keys)
  147. {
  148. ((Slider)faceControls[key]).Draw(MiscGUI.HalfSlider);
  149. }
  150. GUILayout.EndHorizontal();
  151. }
  152. private void DrawToggles(params string[] keys)
  153. {
  154. GUILayout.BeginHorizontal();
  155. foreach (string key in keys)
  156. {
  157. ((Toggle)faceControls[key]).Draw();
  158. }
  159. GUILayout.EndHorizontal();
  160. }
  161. private void SetFaceValue(string key, float value)
  162. {
  163. if (updating) return;
  164. this.meidoManager.ActiveMeido.SetFaceBlendValue(key, value);
  165. }
  166. private void SetFaceValue(string key, bool value)
  167. {
  168. float max = key.StartsWith("hoho") ? 0.5f : 1f;
  169. if (key == "toothoff") value = !value;
  170. SetFaceValue(key, value ? max : 0f);
  171. }
  172. }
  173. }