MaidSwitcherPane.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. internal class MaidSwitcherPane : BasePane
  5. {
  6. private readonly MeidoManager meidoManager;
  7. private readonly Button previousButton;
  8. private readonly Button nextButton;
  9. public MaidSwitcherPane(MeidoManager meidoManager)
  10. {
  11. this.meidoManager = meidoManager;
  12. previousButton = new Button("<");
  13. previousButton.ControlEvent += (s, a) => ChangeMaid(-1);
  14. nextButton = new Button(">");
  15. nextButton.ControlEvent += (s, a) => ChangeMaid(1);
  16. }
  17. public override void Draw()
  18. {
  19. const float boxSize = 70;
  20. const int margin = (int)(boxSize / 2.8f);
  21. GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
  22. buttonStyle.margin.top = margin;
  23. GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
  24. labelStyle.margin.top = margin;
  25. GUIStyle boxStyle = new GUIStyle(GUI.skin.box) { margin = new RectOffset(0, 0, 0, 0) };
  26. GUIStyle horizontalStyle = new GUIStyle { padding = new RectOffset(4, 4, 0, 0) };
  27. GUILayoutOption[] buttonOptions = new[] { GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(false) };
  28. GUILayoutOption[] boxLayoutOptions = new[] { GUILayout.Height(boxSize), GUILayout.Width(boxSize) };
  29. GUI.enabled = meidoManager.HasActiveMeido;
  30. Meido meido = meidoManager.ActiveMeido;
  31. GUILayout.BeginHorizontal(horizontalStyle, GUILayout.Height(boxSize));
  32. previousButton.Draw(buttonStyle, buttonOptions);
  33. GUILayout.Space(20);
  34. if (meidoManager.HasActiveMeido && meido.Portrait) MpsGui.DrawTexture(meido.Portrait, boxLayoutOptions);
  35. else GUILayout.Box(GUIContent.none, boxStyle, boxLayoutOptions);
  36. string label = meidoManager.HasActiveMeido ? $"{meido.LastName}\n{meido.FirstName}" : string.Empty;
  37. GUILayout.Label(label, labelStyle, GUILayout.ExpandWidth(false));
  38. GUILayout.FlexibleSpace();
  39. nextButton.Draw(buttonStyle, buttonOptions);
  40. GUILayout.EndHorizontal();
  41. Rect previousRect = GUILayoutUtility.GetLastRect();
  42. Rect labelRect = new Rect(previousRect.width - 45f, previousRect.y, 40f, 20f);
  43. GUIStyle slotStyle = new GUIStyle()
  44. {
  45. alignment = TextAnchor.UpperRight,
  46. fontSize = 13
  47. };
  48. slotStyle.padding.right = 5;
  49. slotStyle.normal.textColor = Color.white;
  50. if (meidoManager.HasActiveMeido) GUI.Label(labelRect, $"{meidoManager.ActiveMeido.Slot + 1}", slotStyle);
  51. }
  52. private void ChangeMaid(int dir)
  53. {
  54. int selected = Utility.Wrap(
  55. meidoManager.SelectedMeido + (int)Mathf.Sign(dir), 0, meidoManager.ActiveMeidoList.Count
  56. );
  57. meidoManager.ChangeMaid(selected);
  58. }
  59. }
  60. }