MaidSelectorPane.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace COM3D2.MeidoPhotoStudio.Plugin
  5. {
  6. public class MaidSelectorPane : BasePane
  7. {
  8. private MeidoManager meidoManager;
  9. public List<int> selectedMaidList { get; private set; }
  10. private Vector2 maidListScrollPos;
  11. private Button clearMaidsButton;
  12. private Button callMaidsButton;
  13. public event EventHandler MaidCall;
  14. public MaidSelectorPane(MeidoManager meidoManager) : base()
  15. {
  16. this.meidoManager = meidoManager;
  17. selectedMaidList = new List<int>();
  18. clearMaidsButton = new Button("Clear");
  19. clearMaidsButton.ControlEvent += (s, a) => selectedMaidList.Clear();
  20. Controls.Add(clearMaidsButton);
  21. callMaidsButton = new Button("Call");
  22. callMaidsButton.ControlEvent += (s, a) => MaidCall?.Invoke(this, EventArgs.Empty);
  23. Controls.Add(callMaidsButton);
  24. }
  25. public override void Draw(params GUILayoutOption[] layoutOptions)
  26. {
  27. clearMaidsButton.Draw();
  28. callMaidsButton.Draw();
  29. GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
  30. labelStyle.fontSize = 14;
  31. GUIStyle selectLabelStyle = new GUIStyle(labelStyle);
  32. selectLabelStyle.normal.textColor = Color.black;
  33. selectLabelStyle.alignment = TextAnchor.UpperRight;
  34. GUIStyle labelSelectedStyle = new GUIStyle(labelStyle);
  35. labelSelectedStyle.normal.textColor = Color.black;
  36. float windowHeight = Screen.height * 0.8f;
  37. int buttonHeight = 85;
  38. int buttonWidth = 190;
  39. Rect positionRect = new Rect(5, 115, 208, windowHeight - 140);
  40. Rect viewRect = new Rect(0, 0, 185, buttonHeight * meidoManager.meidos.Length + 5);
  41. maidListScrollPos = GUI.BeginScrollView(positionRect, maidListScrollPos, viewRect);
  42. for (int i = 0; i < meidoManager.meidos.Length; i++)
  43. {
  44. Meido meido = meidoManager.meidos[i];
  45. float y = i * buttonHeight;
  46. bool selectedMaid = selectedMaidList.Contains(i);
  47. if (GUI.Button(new Rect(0, y, buttonWidth, buttonHeight), ""))
  48. {
  49. if (selectedMaid) selectedMaidList.Remove(i);
  50. else selectedMaidList.Add(i);
  51. }
  52. if (selectedMaid)
  53. {
  54. int selectedIndex = selectedMaidList.IndexOf(i) + 1;
  55. GUI.DrawTexture(new Rect(5, y + 5, buttonWidth - 10, buttonHeight - 10), Texture2D.whiteTexture);
  56. GUI.Label(new Rect(0, y + 5, buttonWidth - 10, buttonHeight), selectedIndex.ToString(), selectLabelStyle);
  57. }
  58. GUI.DrawTexture(new Rect(5, y, buttonHeight, buttonHeight), meido.Image);
  59. GUI.Label(new Rect(95, y + 30, buttonWidth - 80, buttonHeight), meido.NameJP, selectedMaid ? labelSelectedStyle : labelStyle);
  60. }
  61. GUI.EndScrollView();
  62. }
  63. }
  64. }