MaidSwitcherPane.cs 4.0 KB

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