MaidSelectorPane.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace MeidoPhotoStudio.Plugin;
  4. public class MaidSelectorPane : BasePane
  5. {
  6. private readonly MeidoManager meidoManager;
  7. private readonly Button clearMaidsButton;
  8. private readonly Button callMaidsButton;
  9. private readonly Toggle activeMeidoListToggle;
  10. private Vector2 maidListScrollPos;
  11. private Vector2 activeMaidListScrollPos;
  12. public MaidSelectorPane(MeidoManager meidoManager)
  13. {
  14. this.meidoManager = meidoManager;
  15. clearMaidsButton = new(Translation.Get("maidCallWindow", "clearButton"));
  16. clearMaidsButton.ControlEvent += (_, _) =>
  17. this.meidoManager.ClearSelectList();
  18. callMaidsButton = new(Translation.Get("maidCallWindow", "callButton"));
  19. callMaidsButton.ControlEvent += (_, _) =>
  20. this.meidoManager.CallMeidos();
  21. activeMeidoListToggle = new(Translation.Get("maidCallWindow", "activeOnlyToggle"));
  22. this.meidoManager.BeginCallMeidos += (_, _) =>
  23. {
  24. if (meidoManager.SelectedMeidoSet.Count is 0)
  25. activeMeidoListToggle.Value = false;
  26. };
  27. }
  28. public override void Activate()
  29. {
  30. base.Activate();
  31. // NOTE: Leaving this mode enabled pretty much softlocks meido selection so disable it on activation
  32. activeMeidoListToggle.Value = false;
  33. }
  34. public override void Draw()
  35. {
  36. GUILayout.BeginHorizontal();
  37. clearMaidsButton.Draw(GUILayout.ExpandWidth(false));
  38. callMaidsButton.Draw();
  39. GUILayout.EndHorizontal();
  40. MpsGui.WhiteLine();
  41. GUI.enabled = meidoManager.HasActiveMeido;
  42. activeMeidoListToggle.Draw();
  43. GUI.enabled = true;
  44. var onlyActiveMeido = activeMeidoListToggle.Value;
  45. IList<Meido> meidoList = onlyActiveMeido
  46. ? meidoManager.ActiveMeidoList
  47. : meidoManager.Meidos;
  48. var labelStyle = new GUIStyle(GUI.skin.label)
  49. {
  50. fontSize = 14,
  51. };
  52. var selectLabelStyle = new GUIStyle(labelStyle)
  53. {
  54. normal = { textColor = Color.black },
  55. alignment = TextAnchor.UpperRight,
  56. };
  57. var labelSelectedStyle = new GUIStyle(labelStyle)
  58. {
  59. normal = { textColor = Color.black },
  60. };
  61. var windowRect = parent.WindowRect;
  62. var windowHeight = windowRect.height;
  63. var buttonWidth = windowRect.width - 30f;
  64. const float buttonHeight = 85f;
  65. const float offsetTop = 130f;
  66. var positionRect = new Rect(5f, offsetTop, windowRect.width - 10f, windowHeight - (offsetTop + 35));
  67. var viewRect = new Rect(0f, 0f, buttonWidth, buttonHeight * meidoList.Count + 5f);
  68. if (onlyActiveMeido)
  69. activeMaidListScrollPos = GUI.BeginScrollView(positionRect, activeMaidListScrollPos, viewRect);
  70. else
  71. maidListScrollPos = GUI.BeginScrollView(positionRect, maidListScrollPos, viewRect);
  72. for (var i = 0; i < meidoList.Count; i++)
  73. {
  74. var meido = meidoList[i];
  75. var y = i * buttonHeight;
  76. var selectedMaid = meidoManager.SelectedMeidoSet.Contains(meido.StockNo);
  77. if (GUI.Button(new(0f, y, buttonWidth, buttonHeight), string.Empty))
  78. meidoManager.SelectMeido(meido.StockNo);
  79. if (selectedMaid)
  80. {
  81. var selectedIndex = meidoManager.SelectMeidoList.IndexOf(meido.StockNo) + 1;
  82. GUI.DrawTexture(new(5f, y + 5f, buttonWidth - 10f, buttonHeight - 10f), Texture2D.whiteTexture);
  83. GUI.Label(new(0f, y + 5f, buttonWidth - 10f, buttonHeight), selectedIndex.ToString(), selectLabelStyle);
  84. }
  85. if (meido.Portrait)
  86. GUI.DrawTexture(new(5f, y, buttonHeight, buttonHeight), meido.Portrait);
  87. GUI.Label(
  88. new(95f, y + 30f, buttonWidth - 80f, buttonHeight),
  89. $"{meido.LastName}\n{meido.FirstName}",
  90. selectedMaid ? labelSelectedStyle : labelStyle);
  91. }
  92. GUI.EndScrollView();
  93. }
  94. protected override void ReloadTranslation()
  95. {
  96. clearMaidsButton.Label = Translation.Get("maidCallWindow", "clearButton");
  97. callMaidsButton.Label = Translation.Get("maidCallWindow", "callButton");
  98. activeMeidoListToggle.Label = Translation.Get("maidCallWindow", "activeOnlyToggle");
  99. }
  100. }