SavePosePane.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class SavePosePane : BasePane
  6. {
  7. private readonly MeidoManager meidoManager;
  8. private readonly Button savePoseButton;
  9. private readonly TextField poseNameTextField;
  10. private readonly ComboBox categoryComboBox;
  11. private string categoryHeader;
  12. private string nameHeader;
  13. public SavePosePane(MeidoManager meidoManager)
  14. {
  15. Constants.CustomPoseChange += (s, a)
  16. => categoryComboBox.SetDropdownItems(Constants.CustomPoseGroupList.ToArray());
  17. this.meidoManager = meidoManager;
  18. categoryHeader = Translation.Get("posePane", "categoryHeader");
  19. nameHeader = Translation.Get("posePane", "nameHeader");
  20. savePoseButton = new Button(Translation.Get("posePane", "saveButton"));
  21. savePoseButton.ControlEvent += OnSavePose;
  22. categoryComboBox = new ComboBox(Constants.CustomPoseGroupList.ToArray());
  23. poseNameTextField = new TextField();
  24. poseNameTextField.ControlEvent += OnSavePose;
  25. }
  26. protected override void ReloadTranslation()
  27. {
  28. categoryHeader = Translation.Get("posePane", "categoryHeader");
  29. nameHeader = Translation.Get("posePane", "nameHeader");
  30. savePoseButton.Label = Translation.Get("posePane", "saveButton");
  31. }
  32. public override void Draw()
  33. {
  34. GUI.enabled = meidoManager.HasActiveMeido;
  35. MpsGui.Header(categoryHeader);
  36. categoryComboBox.Draw(GUILayout.Width(160f));
  37. MpsGui.Header(nameHeader);
  38. GUILayout.BeginHorizontal();
  39. poseNameTextField.Draw(GUILayout.Width(160f));
  40. savePoseButton.Draw(GUILayout.ExpandWidth(false));
  41. GUILayout.EndHorizontal();
  42. GUI.enabled = true;
  43. }
  44. private void OnSavePose(object sender, EventArgs args)
  45. {
  46. byte[] anmBinary = meidoManager.ActiveMeido.SerializePose();
  47. Constants.AddPose(anmBinary, poseNameTextField.Value, categoryComboBox.Value);
  48. poseNameTextField.Value = string.Empty;
  49. }
  50. }
  51. }