MpnAttachPropPane.cs 3.8 KB

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