SaveHandPane.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class SaveHandPane : BasePane
  5. {
  6. private readonly MeidoManager meidoManager;
  7. private readonly ComboBox categoryComboBox;
  8. private readonly TextField handNameTextField;
  9. private readonly Button saveLeftHandButton;
  10. private readonly Button saveRightHandButton;
  11. private string categoryHeader;
  12. private string nameHeader;
  13. public SaveHandPane(MeidoManager meidoManager)
  14. {
  15. Constants.CustomHandChange += (s, a)
  16. => categoryComboBox.SetDropdownItems(Constants.CustomHandGroupList.ToArray());
  17. this.meidoManager = meidoManager;
  18. categoryHeader = Translation.Get("handPane", "categoryHeader");
  19. nameHeader = Translation.Get("handPane", "nameHeader");
  20. saveLeftHandButton = new Button(Translation.Get("handPane", "saveLeftButton"));
  21. saveLeftHandButton.ControlEvent += (s, a) => SaveHand(right: false);
  22. saveRightHandButton = new Button(Translation.Get("handPane", "saveRightButton"));
  23. saveRightHandButton.ControlEvent += (s, a) => SaveHand(right: true);
  24. categoryComboBox = new ComboBox(Constants.CustomHandGroupList.ToArray());
  25. handNameTextField = new TextField();
  26. }
  27. protected override void ReloadTranslation()
  28. {
  29. categoryHeader = Translation.Get("handPane", "categoryHeader");
  30. nameHeader = Translation.Get("handPane", "nameHeader");
  31. saveLeftHandButton.Label = Translation.Get("handPane", "saveLeftButton");
  32. saveRightHandButton.Label = Translation.Get("handPane", "saveRightButton");
  33. }
  34. public override void Draw()
  35. {
  36. GUI.enabled = meidoManager.HasActiveMeido;
  37. MpsGui.Header(categoryHeader);
  38. categoryComboBox.Draw(GUILayout.Width(165f));
  39. MpsGui.Header(nameHeader);
  40. handNameTextField.Draw(GUILayout.Width(165f));
  41. GUILayout.BeginHorizontal();
  42. saveRightHandButton.Draw();
  43. saveLeftHandButton.Draw();
  44. GUILayout.EndHorizontal();
  45. GUI.enabled = true;
  46. }
  47. private void SaveHand(bool right)
  48. {
  49. byte[] handBinary = meidoManager.ActiveMeido.IKManager.SerializeHand(right);
  50. Constants.AddHand(handBinary, right, handNameTextField.Value, categoryComboBox.Value);
  51. handNameTextField.Value = string.Empty;
  52. }
  53. }
  54. }