MaidSelectorPane.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.ClearSelectList();
  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.SelectedMeidoSet.Contains(i);
  45. if (GUI.Button(new Rect(0f, y, buttonWidth, buttonHeight), string.Empty)) meidoManager.SelectMeido(i);
  46. if (selectedMaid)
  47. {
  48. int selectedIndex = meidoManager.SelectMeidoList.IndexOf(i) + 1;
  49. GUI.DrawTexture(
  50. new Rect(5f, y + 5f, buttonWidth - 10f, buttonHeight - 10f), Texture2D.whiteTexture
  51. );
  52. GUI.Label(
  53. new Rect(0f, y + 5f, buttonWidth - 10f, buttonHeight),
  54. selectedIndex.ToString(), selectLabelStyle
  55. );
  56. }
  57. GUI.DrawTexture(new Rect(5f, y, buttonHeight, buttonHeight), meido.Portrait);
  58. GUI.Label(
  59. new Rect(95f, y + 30f, buttonWidth - 80f, buttonHeight),
  60. $"{meido.LastName}\n{meido.FirstName}", selectedMaid ? labelSelectedStyle : labelStyle
  61. );
  62. }
  63. GUI.EndScrollView();
  64. }
  65. }
  66. }