SaveFacePane.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class SaveFacePane : BasePane
  5. {
  6. private readonly MeidoManager meidoManager;
  7. private readonly ComboBox categoryComboBox;
  8. private readonly TextField faceNameTextField;
  9. private readonly Button saveFaceButton;
  10. private string categoryHeader;
  11. private string nameHeader;
  12. public SaveFacePane(MeidoManager meidoManager)
  13. {
  14. Constants.CustomFaceChange += (s, a)
  15. => categoryComboBox.SetDropdownItems(Constants.CustomFaceGroupList.ToArray());
  16. this.meidoManager = meidoManager;
  17. categoryHeader = Translation.Get("faceSave", "categoryHeader");
  18. nameHeader = Translation.Get("faceSave", "nameHeader");
  19. saveFaceButton = new Button(Translation.Get("faceSave", "saveButton"));
  20. saveFaceButton.ControlEvent += (s, a) => SaveFace();
  21. categoryComboBox = new ComboBox(Constants.CustomFaceGroupList.ToArray());
  22. faceNameTextField = new TextField();
  23. }
  24. protected override void ReloadTranslation()
  25. {
  26. categoryHeader = Translation.Get("faceSave", "categoryHeader");
  27. nameHeader = Translation.Get("faceSave", "nameHeader");
  28. saveFaceButton.Label = Translation.Get("faceSave", "saveButton");
  29. }
  30. public override void Draw()
  31. {
  32. GUI.enabled = meidoManager.HasActiveMeido;
  33. MpsGui.Header(categoryHeader);
  34. categoryComboBox.Draw(GUILayout.Width(165f));
  35. MpsGui.Header(nameHeader);
  36. GUILayout.BeginHorizontal();
  37. faceNameTextField.Draw(GUILayout.Width(160f));
  38. saveFaceButton.Draw(GUILayout.ExpandWidth(false));
  39. GUILayout.EndHorizontal();
  40. GUI.enabled = true;
  41. }
  42. private void SaveFace()
  43. {
  44. if (!meidoManager.HasActiveMeido) return;
  45. Meido meido = meidoManager.ActiveMeido;
  46. Constants.AddFacePreset(meido.SerializeFace(), faceNameTextField.Value, categoryComboBox.Value);
  47. faceNameTextField.Value = string.Empty;
  48. }
  49. }
  50. }