MaidSelectorPane.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. Controls.Add(clearMaidsButton);
  16. callMaidsButton = new Button(Translation.Get("maidCallWindow", "callButton"));
  17. callMaidsButton.ControlEvent += (s, a) => this.meidoManager.CallMeidos();
  18. Controls.Add(callMaidsButton);
  19. }
  20. protected override void ReloadTranslation()
  21. {
  22. clearMaidsButton.Label = Translation.Get("maidCallWindow", "clearButton");
  23. callMaidsButton.Label = Translation.Get("maidCallWindow", "callButton");
  24. }
  25. public override void Draw()
  26. {
  27. clearMaidsButton.Draw();
  28. callMaidsButton.Draw();
  29. GUIStyle labelStyle = new GUIStyle(GUI.skin.label) { fontSize = 14 };
  30. GUIStyle selectLabelStyle = new GUIStyle(labelStyle);
  31. selectLabelStyle.normal.textColor = Color.black;
  32. selectLabelStyle.alignment = TextAnchor.UpperRight;
  33. GUIStyle labelSelectedStyle = new GUIStyle(labelStyle);
  34. labelSelectedStyle.normal.textColor = Color.black;
  35. float windowHeight = Screen.height * 0.8f;
  36. const int buttonHeight = 85;
  37. const int buttonWidth = 205;
  38. Rect positionRect = new Rect(5, 115, buttonWidth + 15, windowHeight - 140);
  39. Rect viewRect = new Rect(0, 0, buttonWidth - 5, (buttonHeight * meidoManager.Meidos.Length) + 5);
  40. maidListScrollPos = GUI.BeginScrollView(positionRect, maidListScrollPos, viewRect);
  41. for (int i = 0; i < meidoManager.Meidos.Length; i++)
  42. {
  43. Meido meido = meidoManager.Meidos[i];
  44. float y = i * buttonHeight;
  45. bool selectedMaid = meidoManager.SelectMeidoList.Contains(i);
  46. if (GUI.Button(new Rect(0, y, buttonWidth, buttonHeight), ""))
  47. {
  48. if (selectedMaid) meidoManager.SelectMeidoList.Remove(i);
  49. else meidoManager.SelectMeidoList.Add(i);
  50. }
  51. if (selectedMaid)
  52. {
  53. int selectedIndex = meidoManager.SelectMeidoList.IndexOf(i) + 1;
  54. GUI.DrawTexture(new Rect(5, y + 5, buttonWidth - 10, buttonHeight - 10), Texture2D.whiteTexture);
  55. GUI.Label(
  56. new Rect(0, y + 5, buttonWidth - 10, buttonHeight), selectedIndex.ToString(), selectLabelStyle
  57. );
  58. }
  59. GUI.DrawTexture(new Rect(5, y, buttonHeight, buttonHeight), meido.Portrait);
  60. GUI.Label(
  61. new Rect(95, y + 30, buttonWidth - 80, buttonHeight),
  62. $"{meido.LastName}\n{meido.FirstName}", selectedMaid ? labelSelectedStyle : labelStyle
  63. );
  64. }
  65. GUI.EndScrollView();
  66. }
  67. }
  68. }