CopyPosePane.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Linq;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. internal class CopyPosePane : BasePane
  7. {
  8. private MeidoManager meidoManager;
  9. private Button copyButton;
  10. private Dropdown meidoDropdown;
  11. private int[] copyMeidoSlot;
  12. private bool PlentyOfMaids => this.meidoManager.ActiveMeidoList.Count >= 2;
  13. private Meido FromMeido
  14. {
  15. get => this.meidoManager.HasActiveMeido
  16. ? this.meidoManager.ActiveMeidoList[this.copyMeidoSlot[this.meidoDropdown.SelectedItemIndex]]
  17. : null;
  18. }
  19. public CopyPosePane(MeidoManager meidoManager)
  20. {
  21. this.meidoManager = meidoManager;
  22. this.meidoDropdown = new Dropdown(new[] { Translation.Get("systemMessage", "noMaids") });
  23. this.copyButton = new Button(Translation.Get("copyPosePane", "copyButton"));
  24. this.copyButton.ControlEvent += (s, a) => CopyPose();
  25. }
  26. protected override void ReloadTranslation()
  27. {
  28. if (!PlentyOfMaids)
  29. {
  30. this.meidoDropdown.SetDropdownItem(0, Translation.Get("systemMessage", "noMaids"));
  31. }
  32. this.copyButton.Label = Translation.Get("copyPosePane", "copyButton");
  33. }
  34. public override void Draw()
  35. {
  36. GUI.enabled = PlentyOfMaids;
  37. GUILayout.BeginHorizontal();
  38. this.meidoDropdown.Draw(GUILayout.Width(160f));
  39. this.copyButton.Draw(GUILayout.ExpandWidth(false));
  40. GUILayout.EndHorizontal();
  41. GUI.enabled = false;
  42. }
  43. public override void UpdatePane()
  44. {
  45. SetMeidoDropdown();
  46. }
  47. private void CopyPose()
  48. {
  49. if (this.meidoManager.ActiveMeidoList.Count >= 2)
  50. {
  51. this.meidoManager.ActiveMeido.CopyPose(FromMeido);
  52. }
  53. }
  54. private void SetMeidoDropdown()
  55. {
  56. if (this.meidoManager.ActiveMeidoList.Count >= 2)
  57. {
  58. IEnumerable<Meido> copyMeidoList = this.meidoManager.ActiveMeidoList
  59. .Where(meido => meido.ActiveSlot != this.meidoManager.ActiveMeido.ActiveSlot);
  60. copyMeidoSlot = copyMeidoList.Select(meido => meido.ActiveSlot).ToArray();
  61. string[] dropdownList = copyMeidoList
  62. .Select((meido, i) => $"{copyMeidoSlot[i] + 1}: {meido.LastName} {meido.FirstName}").ToArray();
  63. this.meidoDropdown.SetDropdownItems(dropdownList, 0);
  64. }
  65. else this.meidoDropdown.SetDropdownItems(new[] { Translation.Get("systemMessage", "noMaids") });
  66. }
  67. }
  68. }