MaidSwitcherPane.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class MaidSwitcherPane : BasePane
  6. {
  7. public static MeidoManager meidoManager;
  8. private static Button PreviousButton;
  9. private static Button NextButton;
  10. public static event EventHandler<MeidoChangeEventArgs> MaidChange;
  11. private static int SelectedMeido => meidoManager.SelectedMeido;
  12. static MaidSwitcherPane()
  13. {
  14. PreviousButton = new Button("<");
  15. PreviousButton.ControlEvent += (s, a) => ChangeMaid(-1);
  16. NextButton = new Button(">");
  17. NextButton.ControlEvent += (s, a) => ChangeMaid(1);
  18. }
  19. public static void Draw()
  20. {
  21. GUIStyle boxStyle = new GUIStyle(GUI.skin.box);
  22. GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
  23. GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
  24. boxStyle.padding.top = -15;
  25. buttonStyle.margin.top = 20;
  26. labelStyle.alignment = TextAnchor.UpperLeft;
  27. GUILayout.BeginHorizontal();
  28. bool previousState = GUI.enabled;
  29. GUI.enabled = meidoManager.HasActiveMeido;
  30. PreviousButton.Draw(buttonStyle, GUILayout.Height(40), GUILayout.ExpandWidth(false));
  31. if (meidoManager.HasActiveMeido)
  32. MiscGUI.DrawTexture(meidoManager.ActiveMeido.Image, GUILayout.Width(70), GUILayout.Height(70));
  33. else
  34. GUILayout.Box("", boxStyle, GUILayout.Height(70), GUILayout.Width(70));
  35. GUILayout.BeginVertical();
  36. GUILayout.Space(30);
  37. GUILayout.Label(meidoManager.HasActiveMeido ? meidoManager.ActiveMeido.NameJP : "", labelStyle, GUILayout.ExpandWidth(false));
  38. GUILayout.EndVertical();
  39. NextButton.Draw(buttonStyle, GUILayout.Height(40), GUILayout.ExpandWidth(false));
  40. GUI.enabled = previousState;
  41. GUILayout.EndHorizontal();
  42. }
  43. private static void ChangeMaid(int dir)
  44. {
  45. dir = (int)Mathf.Sign(dir);
  46. int selected = Utility.Wrap(SelectedMeido + dir, 0, meidoManager.ActiveMeidoList.Count);
  47. OnMaidChange(new MeidoChangeEventArgs(selected));
  48. }
  49. private static void OnMaidChange(MeidoChangeEventArgs args)
  50. {
  51. EventHandler<MeidoChangeEventArgs> handler = MaidChange;
  52. if (handler != null) handler(null, args);
  53. }
  54. }
  55. }