MaidSelectorPane.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. internal class MaidSelectorPane : BasePane
  5. {
  6. private readonly MeidoManager meidoManager;
  7. private Vector2 maidListScrollPos;
  8. private readonly Button clearMaidsButton;
  9. private readonly Button callMaidsButton;
  10. public MaidSelectorPane(MeidoManager meidoManager)
  11. {
  12. this.meidoManager = meidoManager;
  13. clearMaidsButton = new Button(Translation.Get("maidCallWindow", "clearButton"));
  14. clearMaidsButton.ControlEvent += (s, a) => this.meidoManager.SelectMeidoList.Clear();
  15. callMaidsButton = new Button(Translation.Get("maidCallWindow", "callButton"));
  16. callMaidsButton.ControlEvent += (s, a) => this.meidoManager.CallMeidos();
  17. }
  18. protected override void ReloadTranslation()
  19. {
  20. clearMaidsButton.Label = Translation.Get("maidCallWindow", "clearButton");
  21. callMaidsButton.Label = Translation.Get("maidCallWindow", "callButton");
  22. }
  23. public override void Draw()
  24. {
  25. clearMaidsButton.Draw();
  26. callMaidsButton.Draw();
  27. GUIStyle labelStyle = new GUIStyle(GUI.skin.label) { fontSize = 14 };
  28. GUIStyle selectLabelStyle = new GUIStyle(labelStyle);
  29. selectLabelStyle.normal.textColor = Color.black;
  30. selectLabelStyle.alignment = TextAnchor.UpperRight;
  31. GUIStyle labelSelectedStyle = new GUIStyle(labelStyle);
  32. labelSelectedStyle.normal.textColor = Color.black;
  33. Rect windowRect = parent.WindowRect;
  34. float windowHeight = windowRect.height;
  35. float buttonWidth = windowRect.width - 30f;
  36. const float buttonHeight = 85f;
  37. Rect positionRect = new Rect(5, 115f, windowRect.width - 10f, windowHeight - 150f);
  38. Rect viewRect = new Rect(0, 0, buttonWidth, (buttonHeight * meidoManager.Meidos.Length) + 5f);
  39. maidListScrollPos = GUI.BeginScrollView(positionRect, maidListScrollPos, viewRect);
  40. for (int i = 0; i < meidoManager.Meidos.Length; i++)
  41. {
  42. Meido meido = meidoManager.Meidos[i];
  43. float y = i * buttonHeight;
  44. bool selectedMaid = meidoManager.SelectMeidoList.Contains(i);
  45. if (GUI.Button(new Rect(0f, y, buttonWidth, buttonHeight), ""))
  46. {
  47. if (selectedMaid) meidoManager.SelectMeidoList.Remove(i);
  48. else meidoManager.SelectMeidoList.Add(i);
  49. }
  50. if (selectedMaid)
  51. {
  52. int selectedIndex = meidoManager.SelectMeidoList.IndexOf(i) + 1;
  53. GUI.DrawTexture(
  54. new Rect(5f, y + 5f, buttonWidth - 10f, buttonHeight - 10f), Texture2D.whiteTexture
  55. );
  56. GUI.Label(
  57. new Rect(0f, y + 5f, buttonWidth - 10f, buttonHeight),
  58. selectedIndex.ToString(), selectLabelStyle
  59. );
  60. }
  61. GUI.DrawTexture(new Rect(5f, y, buttonHeight, buttonHeight), meido.Portrait);
  62. GUI.Label(
  63. new Rect(95f, y + 30f, buttonWidth - 80f, buttonHeight),
  64. $"{meido.LastName}\n{meido.FirstName}", selectedMaid ? labelSelectedStyle : labelStyle
  65. );
  66. }
  67. GUI.EndScrollView();
  68. }
  69. }
  70. }