MaidFaceBlendPane.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace COM3D2.MeidoPhotoStudio.Plugin
  6. {
  7. public class MaidFaceBlendPane : BasePane
  8. {
  9. private readonly MeidoManager meidoManager;
  10. private readonly SelectionGrid faceBlendSourceGrid;
  11. private readonly Dropdown faceBlendCategoryDropdown;
  12. private readonly Button prevCategoryButton;
  13. private readonly Button nextCategoryButton;
  14. private readonly Dropdown faceBlendDropdown;
  15. private readonly Button facePrevButton;
  16. private readonly Button faceNextButton;
  17. private static readonly string[] tabTranslations = { "baseTab", "customTab" };
  18. private bool facePresetMode;
  19. private bool faceListEnabled;
  20. private Dictionary<string, List<string>> CurrentFaceDict => facePresetMode
  21. ? Constants.CustomFaceDict : Constants.FaceDict;
  22. private List<string> CurrentFaceGroupList => facePresetMode
  23. ? Constants.CustomFaceGroupList : Constants.FaceGroupList;
  24. private string SelectedFaceGroup => CurrentFaceGroupList[faceBlendCategoryDropdown.SelectedItemIndex];
  25. private List<string> CurrentFaceList => CurrentFaceDict[SelectedFaceGroup];
  26. private int SelectedFaceIndex => faceBlendDropdown.SelectedItemIndex;
  27. private string SelectedFace => CurrentFaceList[SelectedFaceIndex];
  28. public MaidFaceBlendPane(MeidoManager meidoManager)
  29. {
  30. Constants.CustomFaceChange += OnPresetChange;
  31. this.meidoManager = meidoManager;
  32. faceBlendSourceGrid = new SelectionGrid(Translation.GetArray("maidFaceWindow", tabTranslations));
  33. faceBlendSourceGrid.ControlEvent += (s, a) =>
  34. {
  35. facePresetMode = faceBlendSourceGrid.SelectedItemIndex == 1;
  36. if (updating) return;
  37. string[] list = facePresetMode
  38. ? CurrentFaceGroupList.ToArray()
  39. : Translation.GetArray("faceBlendCategory", Constants.FaceGroupList);
  40. faceBlendCategoryDropdown.SetDropdownItems(list, 0);
  41. };
  42. faceBlendCategoryDropdown = new Dropdown(
  43. Translation.GetArray("faceBlendCategory", Constants.FaceGroupList)
  44. );
  45. faceBlendCategoryDropdown.SelectionChange += (s, a) =>
  46. {
  47. faceListEnabled = CurrentFaceList.Count > 0;
  48. faceBlendDropdown.SetDropdownItems(UIFaceList(), 0);
  49. };
  50. prevCategoryButton = new Button("<");
  51. prevCategoryButton.ControlEvent += (s, a) => faceBlendCategoryDropdown.Step(-1);
  52. nextCategoryButton = new Button(">");
  53. nextCategoryButton.ControlEvent += (s, a) => faceBlendCategoryDropdown.Step(1);
  54. faceBlendDropdown = new Dropdown(UIFaceList());
  55. faceBlendDropdown.SelectionChange += (s, a) =>
  56. {
  57. if (!faceListEnabled || updating) return;
  58. this.meidoManager.ActiveMeido.SetFaceBlendSet(SelectedFace);
  59. };
  60. facePrevButton = new Button("<");
  61. facePrevButton.ControlEvent += (s, a) => faceBlendDropdown.Step(-1);
  62. faceNextButton = new Button(">");
  63. faceNextButton.ControlEvent += (s, a) => faceBlendDropdown.Step(1);
  64. faceListEnabled = CurrentFaceList.Count > 0;
  65. }
  66. protected override void ReloadTranslation()
  67. {
  68. updating = true;
  69. faceBlendSourceGrid.SetItems(Translation.GetArray("maidFaceWindow", tabTranslations));
  70. if (!facePresetMode)
  71. {
  72. faceBlendCategoryDropdown.SetDropdownItems(
  73. Translation.GetArray("faceBlendCategory", Constants.FaceGroupList)
  74. );
  75. }
  76. updating = false;
  77. }
  78. public override void Draw()
  79. {
  80. const float buttonHeight = 30;
  81. GUILayoutOption[] arrowLayoutOptions = {
  82. GUILayout.Width(buttonHeight),
  83. GUILayout.Height(buttonHeight)
  84. };
  85. const float dropdownButtonWidth = 153f;
  86. GUILayoutOption[] dropdownLayoutOptions = new GUILayoutOption[] {
  87. GUILayout.Height(buttonHeight),
  88. GUILayout.Width(dropdownButtonWidth)
  89. };
  90. GUI.enabled = meidoManager.HasActiveMeido;
  91. faceBlendSourceGrid.Draw();
  92. MpsGui.WhiteLine();
  93. GUILayout.BeginHorizontal();
  94. prevCategoryButton.Draw(arrowLayoutOptions);
  95. faceBlendCategoryDropdown.Draw(dropdownLayoutOptions);
  96. nextCategoryButton.Draw(arrowLayoutOptions);
  97. GUILayout.EndHorizontal();
  98. GUILayout.BeginHorizontal();
  99. GUI.enabled = GUI.enabled && faceListEnabled;
  100. facePrevButton.Draw(arrowLayoutOptions);
  101. faceBlendDropdown.Draw(dropdownLayoutOptions);
  102. faceNextButton.Draw(arrowLayoutOptions);
  103. GUILayout.EndHorizontal();
  104. GUI.enabled = true;
  105. }
  106. private string[] UIFaceList()
  107. {
  108. return CurrentFaceList.Count == 0
  109. ? (new[] { "No Face Presets" })
  110. : CurrentFaceList.Select(face => facePresetMode
  111. ? Path.GetFileNameWithoutExtension(face)
  112. : Translation.Get("faceBlendPresetsDropdown", face)
  113. ).ToArray();
  114. }
  115. private void OnPresetChange(object sender, PresetChangeEventArgs args)
  116. {
  117. if (args == PresetChangeEventArgs.Empty)
  118. {
  119. if (facePresetMode)
  120. {
  121. updating = true;
  122. faceBlendCategoryDropdown.SetDropdownItems(CurrentFaceGroupList.ToArray(), 0);
  123. faceBlendDropdown.SetDropdownItems(UIFaceList(), 0);
  124. updating = false;
  125. }
  126. }
  127. else
  128. {
  129. updating = true;
  130. faceBlendSourceGrid.SelectedItemIndex = 1;
  131. faceBlendCategoryDropdown.SetDropdownItems(
  132. CurrentFaceGroupList.ToArray(), CurrentFaceGroupList.IndexOf(args.Category)
  133. );
  134. updating = false;
  135. faceBlendDropdown.SetDropdownItems(UIFaceList(), CurrentFaceList.IndexOf(args.Path));
  136. }
  137. }
  138. }
  139. }