123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using System.Collections.Generic;
- using UnityEngine;
- namespace COM3D2.MeidoPhotoStudio.Plugin
- {
- using static Meido;
- internal class MaidFaceSliderPane : BasePane
- {
- // TODO: Consider placing in external file to be user editable
- private static readonly Dictionary<string, SliderProp> SliderRange = new Dictionary<string, SliderProp>()
- {
- // Eye Shut
- ["eyeclose"] = new SliderProp(0f, 1f),
- // Eye Smile
- ["eyeclose2"] = new SliderProp(0f, 1f),
- // Glare
- ["eyeclose3"] = new SliderProp(0f, 1f),
- // Wide Eyes
- ["eyebig"] = new SliderProp(0f, 1f),
- // Wink 1
- ["eyeclose6"] = new SliderProp(0f, 1f),
- // Wink 2
- ["eyeclose5"] = new SliderProp(0f, 1f),
- // Highlight
- ["hitomih"] = new SliderProp(0f, 2f),
- // Pupil Size
- ["hitomis"] = new SliderProp(0f, 3f),
- // Brow 1
- ["mayuha"] = new SliderProp(0f, 1f),
- // Brow 2
- ["mayuw"] = new SliderProp(0f, 1f),
- // Brow Up
- ["mayuup"] = new SliderProp(0f, 0.8f),
- // Brow Down 1
- ["mayuv"] = new SliderProp(0f, 0.8f),
- // Brow Down 2
- ["mayuvhalf"] = new SliderProp(0f, 0.9f),
- // Mouth Open 1
- ["moutha"] = new SliderProp(0f, 1f),
- // Mouth Open 2
- ["mouths"] = new SliderProp(0f, 0.9f),
- // Mouth Narrow
- ["mouthc"] = new SliderProp(0f, 1f),
- // Mouth Widen
- ["mouthi"] = new SliderProp(0f, 1f),
- // Smile
- ["mouthup"] = new SliderProp(0f, 1.4f),
- // Frown
- ["mouthdw"] = new SliderProp(0f, 1f),
- // Mouth Pucker
- ["mouthhe"] = new SliderProp(0f, 1f),
- // Grin
- ["mouthuphalf"] = new SliderProp(0f, 2f),
- // Tongue Out
- ["tangout"] = new SliderProp(0f, 1f),
- // Tongue Up
- ["tangup"] = new SliderProp(0f, 0.7f),
- // Tongue Base
- ["tangopen"] = new SliderProp(0f, 1f)
- };
- private MeidoManager meidoManager;
- private Dictionary<string, BaseControl> faceControls;
- private bool hasTangOpen = false;
- public MaidFaceSliderPane(MeidoManager meidoManager)
- {
- this.meidoManager = meidoManager;
- this.faceControls = new Dictionary<string, BaseControl>();
- foreach (string key in faceKeys)
- {
- string uiName = Translation.Get("faceBlendValues", key);
- Slider slider = new Slider(uiName, SliderRange[key]);
- string myKey = key;
- slider.ControlEvent += (s, a) => this.SetFaceValue(myKey, slider.Value);
- faceControls[key] = slider;
- }
- foreach (string key in faceToggleKeys)
- {
- string uiName = Translation.Get("faceBlendValues", key);
- Toggle toggle = new Toggle(uiName);
- string myKey = key;
- toggle.ControlEvent += (s, a) => this.SetFaceValue(myKey, toggle.Value);
- faceControls[key] = toggle;
- }
- }
- protected override void ReloadTranslation()
- {
- for (int i = 0; i < faceKeys.Length; i++)
- {
- Slider slider = (Slider)faceControls[faceKeys[i]];
- slider.Label = Translation.Get("faceBlendValues", faceKeys[i]);
- }
- for (int i = 0; i < faceToggleKeys.Length; i++)
- {
- Toggle toggle = (Toggle)faceControls[faceToggleKeys[i]];
- toggle.Label = Translation.Get("faceBlendValues", faceToggleKeys[i]);
- }
- }
- public override void UpdatePane()
- {
- this.updating = true;
- Meido meido = this.meidoManager.ActiveMeido;
- for (int i = 0; i < faceKeys.Length; i++)
- {
- Slider slider = (Slider)faceControls[faceKeys[i]];
- try
- {
- slider.Value = meido.GetFaceBlendValue(faceKeys[i]);
- }
- catch { }
- }
- for (int i = 0; i < faceToggleKeys.Length; i++)
- {
- string hash = faceToggleKeys[i];
- Toggle toggle = (Toggle)faceControls[hash];
- toggle.Value = meido.GetFaceBlendValue(hash) > 0f;
- if (hash == "toothoff") toggle.Value = !toggle.Value;
- }
- hasTangOpen = meido.Body.Face.morph.hash["tangopen"] != null;
- this.updating = false;
- }
- public override void Draw()
- {
- GUI.enabled = this.meidoManager.HasActiveMeido;
- DrawSliders("eyeclose", "eyeclose2");
- DrawSliders("eyeclose3", "eyebig");
- DrawSliders("eyeclose6", "eyeclose5");
- DrawSliders("hitomih", "hitomis");
- DrawSliders("mayuha", "mayuw");
- DrawSliders("mayuup", "mayuv");
- DrawSliders("mayuvhalf");
- DrawSliders("moutha", "mouths");
- DrawSliders("mouthc", "mouthi");
- DrawSliders("mouthup", "mouthdw");
- DrawSliders("mouthhe", "mouthuphalf");
- DrawSliders("tangout", "tangup");
- if (hasTangOpen) DrawSliders("tangopen");
- MiscGUI.WhiteLine();
- DrawToggles("hoho2", "shock", "nosefook");
- DrawToggles("namida", "yodare", "toothoff");
- DrawToggles("tear1", "tear2", "tear3");
- DrawToggles("hohos", "hoho", "hohol");
- GUI.enabled = true;
- }
- private void DrawSliders(params string[] keys)
- {
- GUILayout.BeginHorizontal();
- foreach (string key in keys)
- {
- ((Slider)faceControls[key]).Draw(MiscGUI.HalfSlider);
- }
- GUILayout.EndHorizontal();
- }
- private void DrawToggles(params string[] keys)
- {
- GUILayout.BeginHorizontal();
- foreach (string key in keys)
- {
- ((Toggle)faceControls[key]).Draw();
- }
- GUILayout.EndHorizontal();
- }
- private void SetFaceValue(string key, float value)
- {
- if (updating) return;
- this.meidoManager.ActiveMeido.SetFaceBlendValue(key, value);
- }
- private void SetFaceValue(string key, bool value)
- {
- float max = key.StartsWith("hoho") ? 0.5f : 1f;
- if (key == "toothoff") value = !value;
- SetFaceValue(key, value ? max : 0f);
- }
- }
- }
|