MaidSelectorPane.cs 3.5 KB

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