MaidSelectorPane.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public 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. GUILayout.BeginHorizontal();
  26. clearMaidsButton.Draw(GUILayout.ExpandWidth(false));
  27. callMaidsButton.Draw();
  28. GUILayout.EndHorizontal();
  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. Rect windowRect = parent.WindowRect;
  36. float windowHeight = windowRect.height;
  37. float buttonWidth = windowRect.width - 30f;
  38. const float buttonHeight = 85f;
  39. Rect positionRect = new Rect(5f, 90f, windowRect.width - 10f, windowHeight - 125f);
  40. Rect viewRect = new Rect(0f, 0f, buttonWidth, (buttonHeight * meidoManager.Meidos.Length) + 5f);
  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 = meidoManager.SelectedMeidoSet.Contains(i);
  47. if (GUI.Button(new Rect(0f, y, buttonWidth, buttonHeight), string.Empty)) meidoManager.SelectMeido(i);
  48. if (selectedMaid)
  49. {
  50. int selectedIndex = meidoManager.SelectMeidoList.IndexOf(i) + 1;
  51. GUI.DrawTexture(
  52. new Rect(5f, y + 5f, buttonWidth - 10f, buttonHeight - 10f), Texture2D.whiteTexture
  53. );
  54. GUI.Label(
  55. new Rect(0f, y + 5f, buttonWidth - 10f, buttonHeight),
  56. selectedIndex.ToString(), selectLabelStyle
  57. );
  58. }
  59. if (meido.Portrait) GUI.DrawTexture(new Rect(5f, y, buttonHeight, buttonHeight), meido.Portrait);
  60. GUI.Label(
  61. new Rect(95f, y + 30f, buttonWidth - 80f, buttonHeight),
  62. $"{meido.LastName}\n{meido.FirstName}", selectedMaid ? labelSelectedStyle : labelStyle
  63. );
  64. }
  65. GUI.EndScrollView();
  66. }
  67. }
  68. }