MaidFaceSliderPane.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. // 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. public void SetFaceValue(string key, float value)
  97. {
  98. if (updating) return;
  99. this.meidoManager.ActiveMeido.SetFaceBlendValue(key, value);
  100. }
  101. public void SetFaceValue(string key, bool value)
  102. {
  103. float max = (key == "hoho" || key == "hoho2") ? 0.5f : 1f;
  104. if (key == "toothoff") value = !value;
  105. SetFaceValue(key, value ? max : 0f);
  106. }
  107. public override void Update()
  108. {
  109. this.updating = true;
  110. TMorph morph = this.meidoManager.ActiveMeido.Maid.body0.Face.morph;
  111. float[] blendValues = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValues");
  112. float[] blendValuesBackup = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValuesBackup");
  113. for (int i = 0; i < faceKeys.Length; i++)
  114. {
  115. string hash = faceKeys[i];
  116. Slider slider = this.Controls[i] as Slider;
  117. try
  118. {
  119. if (hash.StartsWith("eyeclose"))
  120. slider.Value = blendValuesBackup[(int)morph.hash[hash]];
  121. else
  122. slider.Value = blendValues[(int)morph.hash[hash]];
  123. }
  124. catch { }
  125. }
  126. for (int i = 0; i < faceToggleKeys.Length; i++)
  127. {
  128. string hash = faceToggleKeys[i];
  129. Toggle toggle = this.Controls[24 + i] as Toggle;
  130. if (hash == "nosefook") toggle.Value = morph.boNoseFook;
  131. else toggle.Value = blendValues[(int)morph.hash[hash]] > 0f;
  132. if (hash == "toothoff") toggle.Value = !toggle.Value;
  133. }
  134. this.updating = false;
  135. }
  136. public override void Draw(params GUILayoutOption[] layoutOptions)
  137. {
  138. for (int i = 0; i < faceKeys.Length; i += 2)
  139. {
  140. GUILayout.BeginHorizontal();
  141. for (int j = 0; j < 2; j++)
  142. {
  143. Controls[i + j].Draw(GUILayout.Width(90));
  144. if (i + j == 12 || i + j == 23)
  145. {
  146. i--;
  147. break;
  148. }
  149. }
  150. GUILayout.EndHorizontal();
  151. }
  152. MiscGUI.WhiteLine();
  153. for (int i = 0; i < faceToggleKeys.Length; i += 3)
  154. {
  155. GUILayout.BeginHorizontal();
  156. for (int j = 0; j < 3; j++)
  157. {
  158. Controls[24 + i + j].Draw();
  159. }
  160. GUILayout.EndHorizontal();
  161. }
  162. }
  163. }
  164. }