MaidSwitcherPane.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using UnityEngine;
  2. namespace MeidoPhotoStudio.Plugin
  3. {
  4. public class MaidSwitcherPane : BasePane
  5. {
  6. private readonly MeidoManager meidoManager;
  7. private readonly Button previousButton;
  8. private readonly Button nextButton;
  9. private readonly Toggle editToggle;
  10. public MaidSwitcherPane(MeidoManager meidoManager)
  11. {
  12. this.meidoManager = meidoManager;
  13. this.meidoManager.UpdateMeido += (s, a) => UpdatePane();
  14. previousButton = new("<");
  15. previousButton.ControlEvent += (s, a) => ChangeMaid(-1);
  16. nextButton = new(">");
  17. nextButton.ControlEvent += (s, a) => ChangeMaid(1);
  18. editToggle = new("Edit", true);
  19. editToggle.ControlEvent += (s, a) => SetEditMaid();
  20. }
  21. public override void Draw()
  22. {
  23. const float boxSize = 70;
  24. const int margin = (int)(boxSize / 2.8f);
  25. var buttonStyle = new GUIStyle(GUI.skin.button);
  26. buttonStyle.margin.top = margin;
  27. var labelStyle = new GUIStyle(GUI.skin.label);
  28. labelStyle.margin.top = margin;
  29. var boxStyle = new GUIStyle(GUI.skin.box)
  30. {
  31. margin = new RectOffset(0, 0, 0, 0),
  32. };
  33. var horizontalStyle = new GUIStyle
  34. {
  35. padding = new RectOffset(4, 4, 0, 0),
  36. };
  37. var buttonOptions = new[] {
  38. GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(false)
  39. };
  40. var boxLayoutOptions = new[] {
  41. GUILayout.Height(boxSize), GUILayout.Width(boxSize)
  42. };
  43. GUI.enabled = meidoManager.HasActiveMeido;
  44. var meido = meidoManager.ActiveMeido;
  45. GUILayout.BeginHorizontal(horizontalStyle, GUILayout.Height(boxSize));
  46. previousButton.Draw(buttonStyle, buttonOptions);
  47. GUILayout.Space(20);
  48. if (meidoManager.HasActiveMeido && meido.Portrait)
  49. MpsGui.DrawTexture(meido.Portrait, boxLayoutOptions);
  50. else
  51. GUILayout.Box(GUIContent.none, boxStyle, boxLayoutOptions);
  52. var label = meidoManager.HasActiveMeido ? $"{meido.LastName}\n{meido.FirstName}" : string.Empty;
  53. GUILayout.Label(label, labelStyle, GUILayout.ExpandWidth(false));
  54. GUILayout.FlexibleSpace();
  55. nextButton.Draw(buttonStyle, buttonOptions);
  56. GUILayout.EndHorizontal();
  57. var previousRect = GUILayoutUtility.GetLastRect();
  58. if (MeidoPhotoStudio.EditMode)
  59. editToggle.Draw(new Rect(previousRect.x + 4f, previousRect.y, 40f, 20f));
  60. var labelRect = new Rect(previousRect.width - 45f, previousRect.y, 40f, 20f);
  61. var slotStyle = new GUIStyle()
  62. {
  63. alignment = TextAnchor.UpperRight,
  64. fontSize = 13,
  65. };
  66. slotStyle.padding.right = 5;
  67. slotStyle.normal.textColor = Color.white;
  68. if (meidoManager.HasActiveMeido)
  69. GUI.Label(labelRect, $"{meidoManager.ActiveMeido.Slot + 1}", slotStyle);
  70. }
  71. public override void UpdatePane()
  72. {
  73. if (!meidoManager.HasActiveMeido)
  74. return;
  75. updating = true;
  76. editToggle.Value = meidoManager.ActiveMeido.IsEditMaid;
  77. updating = false;
  78. }
  79. private void ChangeMaid(int dir)
  80. {
  81. var selected = Utility.Wrap(
  82. meidoManager.SelectedMeido + (int)Mathf.Sign(dir), 0, meidoManager.ActiveMeidoList.Count
  83. );
  84. meidoManager.ChangeMaid(selected);
  85. }
  86. private void SetEditMaid()
  87. {
  88. if (updating)
  89. return;
  90. if (!editToggle.Value)
  91. {
  92. updating = true;
  93. editToggle.Value = true;
  94. updating = false;
  95. return;
  96. }
  97. if (meidoManager.HasActiveMeido)
  98. meidoManager.SetEditMaid(meidoManager.ActiveMeido);
  99. }
  100. }
  101. }