MpnAttachPropPane.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System.Linq;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. public class MpnAttachPropPane : BasePane
  7. {
  8. private readonly MeidoManager meidoManager;
  9. private readonly Dropdown mpnAttachDropdown;
  10. private readonly Button previousPropButton;
  11. private readonly Button nextPropButton;
  12. private readonly Button attachPropButton;
  13. private readonly Button detachPropButton;
  14. private readonly Button detachAllButton;
  15. private string header;
  16. public MpnAttachPropPane(MeidoManager meidoManager)
  17. {
  18. this.meidoManager = meidoManager;
  19. mpnAttachDropdown = new Dropdown(new[] { string.Empty });
  20. if (!Constants.MpnAttachInitialized) Constants.MenuFilesChange += InitializeMpnAttach;
  21. SetDropdownList();
  22. previousPropButton = new Button("<");
  23. previousPropButton.ControlEvent += (s, a) => mpnAttachDropdown.Step(-1);
  24. nextPropButton = new Button(">");
  25. nextPropButton.ControlEvent += (s, a) => mpnAttachDropdown.Step(1);
  26. attachPropButton = new Button(Translation.Get("attachMpnPropPane", "attachButton"));
  27. attachPropButton.ControlEvent += (s, a) => AttachProp();
  28. detachPropButton = new Button(Translation.Get("attachMpnPropPane", "detachButton"));
  29. detachPropButton.ControlEvent += (s, a) => AttachProp(detach: true);
  30. detachAllButton = new Button(Translation.Get("attachMpnPropPane", "detachAllButton"));
  31. detachAllButton.ControlEvent += (s, a) => DetachAll();
  32. header = Translation.Get("attachMpnPropPane", "header");
  33. }
  34. protected override void ReloadTranslation()
  35. {
  36. attachPropButton.Label = Translation.Get("attachMpnPropPane", "attachButton");
  37. detachPropButton.Label = Translation.Get("attachMpnPropPane", "detachButton");
  38. detachAllButton.Label = Translation.Get("attachMpnPropPane", "detachAllButton");
  39. header = Translation.Get("attachMpnPropPane", "header");
  40. SetDropdownList();
  41. }
  42. public override void Draw()
  43. {
  44. GUI.enabled = meidoManager.HasActiveMeido && Constants.MpnAttachInitialized;
  45. GUILayoutOption noExpand = GUILayout.ExpandWidth(false);
  46. MpsGui.Header(header);
  47. MpsGui.WhiteLine();
  48. GUILayout.BeginHorizontal();
  49. previousPropButton.Draw(noExpand);
  50. mpnAttachDropdown.Draw(GUILayout.Width(153f));
  51. nextPropButton.Draw(noExpand);
  52. GUILayout.EndHorizontal();
  53. GUILayout.BeginHorizontal();
  54. attachPropButton.Draw();
  55. detachPropButton.Draw();
  56. GUILayout.EndHorizontal();
  57. detachAllButton.Draw();
  58. GUI.enabled = true;
  59. }
  60. private void InitializeMpnAttach(object sender, MenuFilesEventArgs args)
  61. {
  62. if (args.Type == MenuFilesEventArgs.EventType.MpnAttach) SetDropdownList();
  63. }
  64. private void SetDropdownList()
  65. {
  66. IEnumerable<string> dropdownList = !Constants.MpnAttachInitialized
  67. ? new[] { Translation.Get("systemMessage", "initializing") }
  68. : Translation.GetArray(
  69. "mpnAttachPropNames", Constants.MpnAttachPropList.Select(mpnProp => mpnProp.MenuFile)
  70. );
  71. mpnAttachDropdown.SetDropdownItems(dropdownList.ToArray());
  72. }
  73. private void AttachProp(bool detach = false)
  74. {
  75. if (!meidoManager.HasActiveMeido) return;
  76. MpnAttachProp prop = Constants.MpnAttachPropList[mpnAttachDropdown.SelectedItemIndex];
  77. meidoManager.ActiveMeido.SetMpnProp(prop, detach);
  78. }
  79. private void DetachAll()
  80. {
  81. if (!meidoManager.HasActiveMeido) return;
  82. meidoManager.ActiveMeido.DetachAllMpnAttach();
  83. }
  84. }
  85. }