CopyPosePane.cs 2.7 KB

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