CopyPosePane.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. private string copyIKHeader;
  20. public CopyPosePane(MeidoManager meidoManager)
  21. {
  22. this.meidoManager = meidoManager;
  23. this.meidoDropdown = new Dropdown(new[] { Translation.Get("systemMessage", "noMaids") });
  24. this.copyButton = new Button(Translation.Get("copyPosePane", "copyButton"));
  25. this.copyButton.ControlEvent += (s, a) => CopyPose();
  26. this.copyIKHeader = Translation.Get("copyPosePane", "header");
  27. }
  28. protected override void ReloadTranslation()
  29. {
  30. if (!PlentyOfMaids)
  31. {
  32. this.meidoDropdown.SetDropdownItem(0, Translation.Get("systemMessage", "noMaids"));
  33. }
  34. this.copyButton.Label = Translation.Get("copyPosePane", "copyButton");
  35. this.copyIKHeader = Translation.Get("copyPosePane", "header");
  36. }
  37. public override void Draw()
  38. {
  39. GUI.enabled = PlentyOfMaids;
  40. MiscGUI.Header(copyIKHeader);
  41. MiscGUI.WhiteLine();
  42. GUILayout.BeginHorizontal();
  43. this.meidoDropdown.Draw(GUILayout.Width(160f));
  44. this.copyButton.Draw(GUILayout.ExpandWidth(false));
  45. GUILayout.EndHorizontal();
  46. GUI.enabled = true;
  47. }
  48. public override void UpdatePane()
  49. {
  50. SetMeidoDropdown();
  51. }
  52. private void CopyPose()
  53. {
  54. if (this.meidoManager.ActiveMeidoList.Count >= 2)
  55. {
  56. this.meidoManager.ActiveMeido.CopyPose(FromMeido);
  57. }
  58. }
  59. private void SetMeidoDropdown()
  60. {
  61. if (this.meidoManager.ActiveMeidoList.Count >= 2)
  62. {
  63. IEnumerable<Meido> copyMeidoList = this.meidoManager.ActiveMeidoList
  64. .Where(meido => meido.Slot != this.meidoManager.ActiveMeido.Slot);
  65. copyMeidoSlot = copyMeidoList.Select(meido => meido.Slot).ToArray();
  66. string[] dropdownList = copyMeidoList
  67. .Select((meido, i) => $"{copyMeidoSlot[i] + 1}: {meido.LastName} {meido.FirstName}").ToArray();
  68. this.meidoDropdown.SetDropdownItems(dropdownList, 0);
  69. }
  70. else this.meidoDropdown.SetDropdownItems(new[] { Translation.Get("systemMessage", "noMaids") });
  71. }
  72. }
  73. }