MaidFaceSliderPane.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. private static readonly Dictionary<string, float[]> SliderRange = new Dictionary<string, float[]>()
  10. {
  11. ["eyeclose"] = new[] { 0f, 1f },
  12. ["eyeclose2"] = new[] { 0f, 1f },
  13. ["eyeclose3"] = new[] { 0f, 1f },
  14. ["eyebig"] = new[] { 0f, 1f },
  15. ["eyeclose6"] = new[] { 0f, 1f },
  16. ["eyeclose5"] = new[] { 0f, 1f },
  17. ["hitomih"] = new[] { 0f, 2f },
  18. ["hitomis"] = new[] { 0f, 1f },
  19. ["mayuha"] = new[] { 0f, 1f },
  20. ["mayuw"] = new[] { 0f, 1f },
  21. ["mayuup"] = new[] { 0f, 0.8f },
  22. ["mayuv"] = new[] { 0f, 0.8f },
  23. ["mayuvhalf"] = new[] { 0f, 0.9f },
  24. ["moutha"] = new[] { 0f, 1f },
  25. ["mouths"] = new[] { 0f, 0.9f },
  26. ["mouthc"] = new[] { 0f, 1f },
  27. ["mouthi"] = new[] { 0f, 1f },
  28. ["mouthup"] = new[] { 0f, 1.4f },
  29. ["mouthdw"] = new[] { 0f, 1f },
  30. ["mouthhe"] = new[] { 0f, 1f },
  31. ["mouthuphalf"] = new[] { 0f, 2f },
  32. ["tangout"] = new[] { 0f, 1f },
  33. ["tangup"] = new[] { 0f, 0.7f },
  34. ["tangopen"] = new[] { 0f, 1f }
  35. };
  36. public static readonly string[] faceKeys = new string[24]
  37. {
  38. "eyeclose", "eyeclose2", "eyeclose3", "eyebig", "eyeclose6", "eyeclose5", "hitomih",
  39. "hitomis", "mayuha", "mayuw", "mayuup", "mayuv", "mayuvhalf", "moutha", "mouths",
  40. "mouthc", "mouthi", "mouthup", "mouthdw", "mouthhe", "mouthuphalf", "tangout",
  41. "tangup", "tangopen"
  42. };
  43. public static readonly string[] faceToggleKeys = new string[12]
  44. {
  45. "hoho2", "shock", "nosefook", "namida", "yodare", "toothoff",
  46. "tear1", "tear2", "tear3", "hohos", "hoho", "hohol"
  47. };
  48. public MaidFaceSliderPane(MeidoManager meidoManager)
  49. {
  50. this.meidoManager = meidoManager;
  51. for (int i = 0; i < faceKeys.Length; i++)
  52. {
  53. string key = faceKeys[i];
  54. string uiName = Translation.Get("faceBlendValues", key);
  55. Slider slider = new Slider(uiName, SliderRange[key][0], SliderRange[key][1]);
  56. int myIndex = i;
  57. slider.ControlEvent += (s, a) => this.SetFaceValue(faceKeys[myIndex], slider.Value);
  58. this.Controls.Add(slider);
  59. }
  60. for (int i = 0; i < faceToggleKeys.Length; i++)
  61. {
  62. string uiName = Translation.Get("faceBlendValues", faceToggleKeys[i]);
  63. Toggle toggle = new Toggle(uiName);
  64. int myIndex = i;
  65. toggle.ControlEvent += (s, a) => this.SetFaceValue(faceToggleKeys[myIndex], toggle.Value);
  66. this.Controls.Add(toggle);
  67. }
  68. }
  69. public void SetFaceValue(string key, float value)
  70. {
  71. if (updating) return;
  72. this.meidoManager.ActiveMeido.SetFaceBlendValue(key, value);
  73. }
  74. public void SetFaceValue(string key, bool value)
  75. {
  76. float max = (key == "hoho" || key == "hoho2") ? 0.5f : 1f;
  77. if (key == "toothoff") value = !value;
  78. SetFaceValue(key, value ? max : 0f);
  79. }
  80. public void SetControlValues()
  81. {
  82. this.updating = true;
  83. TMorph morph = this.meidoManager.ActiveMeido.Maid.body0.Face.morph;
  84. float[] blendValues = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValues");
  85. float[] blendValuesBackup = Utility.GetFieldValue<TMorph, float[]>(morph, "BlendValuesBackup");
  86. for (int i = 0; i < faceKeys.Length; i++)
  87. {
  88. string hash = faceKeys[i];
  89. Slider slider = this.Controls[i] as Slider;
  90. try
  91. {
  92. if (hash.StartsWith("eyeclose"))
  93. slider.Value = blendValuesBackup[(int)morph.hash[hash]];
  94. else
  95. slider.Value = blendValues[(int)morph.hash[hash]];
  96. }
  97. catch { }
  98. }
  99. for (int i = 0; i < faceToggleKeys.Length; i++)
  100. {
  101. string hash = faceToggleKeys[i];
  102. Toggle toggle = this.Controls[24 + i] as Toggle;
  103. if (hash == "nosefook") toggle.Value = morph.boNoseFook;
  104. else toggle.Value = blendValues[(int)morph.hash[hash]] > 0f;
  105. if (hash == "toothoff") toggle.Value = !toggle.Value;
  106. }
  107. this.updating = false;
  108. }
  109. public override void Draw(params GUILayoutOption[] layoutOptions)
  110. {
  111. for (int i = 0; i < faceKeys.Length; i += 2)
  112. {
  113. GUILayout.BeginHorizontal();
  114. for (int j = 0; j < 2; j++)
  115. {
  116. Controls[i + j].Draw(GUILayout.Width(90));
  117. if (i + j == 12 || i + j == 23)
  118. {
  119. i--;
  120. break;
  121. }
  122. }
  123. GUILayout.EndHorizontal();
  124. }
  125. MiscGUI.WhiteLine();
  126. for (int i = 0; i < faceToggleKeys.Length; i += 3)
  127. {
  128. GUILayout.BeginHorizontal();
  129. for (int j = 0; j < 3; j++)
  130. {
  131. Controls[24 + i + j].Draw();
  132. }
  133. GUILayout.EndHorizontal();
  134. }
  135. }
  136. }
  137. }