SettingsWindowPane.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace MeidoPhotoStudio.Plugin;
  6. public class SettingsWindowPane : BaseMainWindowPane
  7. {
  8. private static readonly string[] HeaderTranslationKeys =
  9. {
  10. "controls", "controlsGeneral", "controlsMaids", "controlsCamera", "controlsDragPoint", "controlsScene",
  11. };
  12. private static readonly Dictionary<string, string> Headers = new();
  13. private static readonly string[] ActionTranslationKeys;
  14. private static readonly string[] ActionLabels;
  15. private readonly Button reloadTranslationButton;
  16. private readonly Button reloadAllPresetsButton;
  17. private readonly KeyRebindButton[] rebindButtons;
  18. static SettingsWindowPane()
  19. {
  20. ActionTranslationKeys = Enum.GetNames(typeof(MpsKey))
  21. .Select(action => char.ToLowerInvariant(action[0]) + action.Substring(1))
  22. .ToArray();
  23. ActionLabels = new string[ActionTranslationKeys.Length];
  24. }
  25. public SettingsWindowPane()
  26. {
  27. rebindButtons = new KeyRebindButton[ActionTranslationKeys.Length];
  28. for (var i = 0; i < rebindButtons.Length; i++)
  29. {
  30. var action = (MpsKey)i;
  31. var button = new KeyRebindButton(KeyCode.None);
  32. button.ControlEvent += (_, _) =>
  33. InputManager.Rebind(action, button.KeyCode);
  34. rebindButtons[i] = button;
  35. ActionLabels[i] = Translation.Get("controls", ActionTranslationKeys[i]);
  36. }
  37. for (var i = 0; i < HeaderTranslationKeys.Length; i++)
  38. Headers[HeaderTranslationKeys[i]] = Translation.Get("settingsHeaders", HeaderTranslationKeys[i]);
  39. reloadTranslationButton = new(Translation.Get("settingsLabels", "reloadTranslation"));
  40. reloadTranslationButton.ControlEvent += (_, _) =>
  41. Translation.ReinitializeTranslation();
  42. reloadAllPresetsButton = new(Translation.Get("settingsLabels", "reloadAllPresets"));
  43. reloadAllPresetsButton.ControlEvent += (_, _) =>
  44. {
  45. Constants.InitializeCustomFaceBlends();
  46. Constants.InitializeHandPresets();
  47. Constants.InitializeCustomPoses();
  48. };
  49. }
  50. public override void Draw()
  51. {
  52. scrollPos = GUILayout.BeginScrollView(scrollPos);
  53. MpsGui.Header(Headers["controls"]);
  54. MpsGui.WhiteLine();
  55. MpsGui.Header(Headers["controlsGeneral"]);
  56. MpsGui.WhiteLine();
  57. for (var key = MpsKey.Activate; key <= MpsKey.ToggleMessage; key++)
  58. DrawSetting(key);
  59. MpsGui.Header(Headers["controlsMaids"]);
  60. MpsGui.WhiteLine();
  61. DrawSetting(MpsKey.MeidoUndressing);
  62. MpsGui.Header(Headers["controlsCamera"]);
  63. MpsGui.WhiteLine();
  64. for (var key = MpsKey.CameraLayer; key <= MpsKey.CameraLoad; key++)
  65. DrawSetting(key);
  66. MpsGui.Header(Headers["controlsDragPoint"]);
  67. MpsGui.WhiteLine();
  68. for (var key = MpsKey.DragSelect; key <= MpsKey.DragFinger; key++)
  69. DrawSetting(key);
  70. MpsGui.Header(Headers["controlsScene"]);
  71. MpsGui.WhiteLine();
  72. for (var key = MpsKey.SaveScene; key <= MpsKey.OpenSceneManager; key++)
  73. DrawSetting(key);
  74. GUI.enabled = !InputManager.Listening;
  75. // Translation settings
  76. MpsGui.WhiteLine();
  77. reloadTranslationButton.Draw();
  78. reloadAllPresetsButton.Draw();
  79. GUILayout.EndScrollView();
  80. GUI.enabled = true;
  81. }
  82. public override void UpdatePanes()
  83. {
  84. for (var i = 0; i < rebindButtons.Length; i++)
  85. rebindButtons[i].KeyCode = InputManager.GetActionKey((MpsKey)i);
  86. }
  87. protected override void ReloadTranslation()
  88. {
  89. for (var i = 0; i < rebindButtons.Length; i++)
  90. ActionLabels[i] = Translation.Get("controls", ActionTranslationKeys[i]);
  91. for (var i = 0; i < HeaderTranslationKeys.Length; i++)
  92. Headers[HeaderTranslationKeys[i]] = Translation.Get("settingsHeaders", HeaderTranslationKeys[i]);
  93. reloadTranslationButton.Label = Translation.Get("settingsLabels", "reloadTranslation");
  94. reloadAllPresetsButton.Label = Translation.Get("settingsLabels", "reloadAllPresets");
  95. }
  96. private void DrawSetting(MpsKey key)
  97. {
  98. var keyIndex = (int)key;
  99. GUILayout.BeginHorizontal();
  100. GUILayout.Label(ActionLabels[keyIndex]);
  101. GUILayout.FlexibleSpace();
  102. rebindButtons[keyIndex].Draw(GUILayout.Width(90f));
  103. if (GUILayout.Button("×", GUILayout.ExpandWidth(false)))
  104. {
  105. rebindButtons[keyIndex].KeyCode = KeyCode.None;
  106. InputManager.Rebind(key, KeyCode.None);
  107. }
  108. GUILayout.EndHorizontal();
  109. }
  110. }