MaidFaceSliderPane.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. public 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. "hoho2", "shock", "nosefook", "namida", "yodare", "toothoff",
  71. "tear1", "tear2", "tear3", "hohos", "hoho", "hohol"
  72. };
  73. public MaidFaceSliderPane(MeidoManager meidoManager)
  74. {
  75. this.meidoManager = meidoManager;
  76. for (int i = 0; i < faceKeys.Length; i++)
  77. {
  78. string key = faceKeys[i];
  79. string uiName = Translation.Get("faceBlendValues", key);
  80. Slider slider = new Slider(uiName, SliderRange[key][0], SliderRange[key][1]);
  81. int myIndex = i;
  82. slider.ControlEvent += (s, a) => this.SetFaceValue(faceKeys[myIndex], slider.Value);
  83. this.Controls.Add(slider);
  84. }
  85. for (int i = 0; i < faceToggleKeys.Length; i++)
  86. {
  87. string uiName = Translation.Get("faceBlendValues", faceToggleKeys[i]);
  88. Toggle toggle = new Toggle(uiName);
  89. int myIndex = i;
  90. toggle.ControlEvent += (s, a) => this.SetFaceValue(faceToggleKeys[myIndex], toggle.Value);
  91. this.Controls.Add(toggle);
  92. }
  93. }
  94. public void SetFaceValue(string key, float value)
  95. {
  96. if (updating) return;
  97. this.meidoManager.ActiveMeido.SetFaceBlendValue(key, value);
  98. }
  99. public void SetFaceValue(string key, bool value)
  100. {
  101. float max = (key == "hoho" || key == "hoho2") ? 0.5f : 1f;
  102. if (key == "toothoff") value = !value;
  103. SetFaceValue(key, value ? max : 0f);
  104. }
  105. public override void Update()
  106. {
  107. this.updating = true;
  108. TMorph morph = this.meidoManager.ActiveMeido.Maid.body0.Face.morph;
  109. float[] blendValues = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValues");
  110. float[] blendValuesBackup = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValuesBackup");
  111. for (int i = 0; i < faceKeys.Length; i++)
  112. {
  113. string hash = faceKeys[i];
  114. Slider slider = this.Controls[i] as Slider;
  115. try
  116. {
  117. if (hash.StartsWith("eyeclose"))
  118. slider.Value = blendValuesBackup[(int)morph.hash[hash]];
  119. else
  120. slider.Value = blendValues[(int)morph.hash[hash]];
  121. }
  122. catch { }
  123. }
  124. for (int i = 0; i < faceToggleKeys.Length; i++)
  125. {
  126. string hash = faceToggleKeys[i];
  127. Toggle toggle = this.Controls[24 + i] as Toggle;
  128. if (hash == "nosefook") toggle.Value = morph.boNoseFook;
  129. else toggle.Value = blendValues[(int)morph.hash[hash]] > 0f;
  130. if (hash == "toothoff") toggle.Value = !toggle.Value;
  131. }
  132. this.updating = false;
  133. }
  134. public override void Draw(params GUILayoutOption[] layoutOptions)
  135. {
  136. for (int i = 0; i < faceKeys.Length; i += 2)
  137. {
  138. GUILayout.BeginHorizontal();
  139. for (int j = 0; j < 2; j++)
  140. {
  141. Controls[i + j].Draw(GUILayout.Width(90));
  142. if (i + j == 12 || i + j == 23)
  143. {
  144. i--;
  145. break;
  146. }
  147. }
  148. GUILayout.EndHorizontal();
  149. }
  150. MiscGUI.WhiteLine();
  151. for (int i = 0; i < faceToggleKeys.Length; i += 3)
  152. {
  153. GUILayout.BeginHorizontal();
  154. for (int j = 0; j < 3; j++)
  155. {
  156. Controls[24 + i + j].Draw();
  157. }
  158. GUILayout.EndHorizontal();
  159. }
  160. }
  161. }
  162. }