SettingsWindowPane.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace MeidoPhotoStudio.Plugin
  6. {
  7. public class SettingsWindowPane : BaseMainWindowPane
  8. {
  9. private static readonly string[] headerTranslationKeys = {
  10. "controls", "controlsGeneral", "controlsMaids", "controlsCamera", "controlsDragPoint", "controlsScene"
  11. };
  12. private static readonly Dictionary<string, string> headers = new Dictionary<string, string>();
  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 (int i = 0; i < rebindButtons.Length; i++)
  29. {
  30. MpsKey action = (MpsKey)i;
  31. KeyRebindButton button = new KeyRebindButton(KeyCode.None);
  32. button.ControlEvent += (s, a) => InputManager.Rebind(action, button.KeyCode);
  33. rebindButtons[i] = button;
  34. actionLabels[i] = Translation.Get("controls", actionTranslationKeys[i]);
  35. }
  36. for (int i = 0; i < headerTranslationKeys.Length; i++)
  37. {
  38. headers[headerTranslationKeys[i]] = Translation.Get("settingsHeaders", headerTranslationKeys[i]);
  39. }
  40. reloadTranslationButton = new Button(Translation.Get("settingsLabels", "reloadTranslation"));
  41. reloadTranslationButton.ControlEvent += (s, a) => Translation.ReinitializeTranslation();
  42. reloadAllPresetsButton = new Button(Translation.Get("settingsLabels", "reloadAllPresets"));
  43. reloadAllPresetsButton.ControlEvent += (s, a) =>
  44. {
  45. Constants.InitializeCustomFaceBlends();
  46. Constants.InitializeHandPresets();
  47. Constants.InitializeCustomPoses();
  48. };
  49. }
  50. protected override void ReloadTranslation()
  51. {
  52. for (int i = 0; i < rebindButtons.Length; i++)
  53. {
  54. actionLabels[i] = Translation.Get("controls", actionTranslationKeys[i]);
  55. }
  56. for (int i = 0; i < headerTranslationKeys.Length; i++)
  57. {
  58. headers[headerTranslationKeys[i]] = Translation.Get("settingsHeaders", headerTranslationKeys[i]);
  59. }
  60. reloadTranslationButton.Label = Translation.Get("settingsLabels", "reloadTranslation");
  61. reloadAllPresetsButton.Label = Translation.Get("settingsLabels", "reloadAllPresets");
  62. }
  63. public override void Draw()
  64. {
  65. scrollPos = GUILayout.BeginScrollView(scrollPos);
  66. MpsGui.Header(headers["controls"]);
  67. MpsGui.WhiteLine();
  68. MpsGui.Header(headers["controlsGeneral"]);
  69. MpsGui.WhiteLine();
  70. for (MpsKey key = MpsKey.Activate; key <= MpsKey.ToggleMessage; key++)
  71. {
  72. DrawSetting(key);
  73. }
  74. MpsGui.Header(headers["controlsMaids"]);
  75. MpsGui.WhiteLine();
  76. DrawSetting(MpsKey.MeidoUndressing);
  77. MpsGui.Header(headers["controlsCamera"]);
  78. MpsGui.WhiteLine();
  79. for (MpsKey key = MpsKey.CameraLayer; key <= MpsKey.CameraLoad; key++)
  80. {
  81. DrawSetting(key);
  82. }
  83. MpsGui.Header(headers["controlsDragPoint"]);
  84. MpsGui.WhiteLine();
  85. for (MpsKey key = MpsKey.DragSelect; key <= MpsKey.DragFinger; key++)
  86. {
  87. DrawSetting(key);
  88. }
  89. MpsGui.Header(headers["controlsScene"]);
  90. MpsGui.WhiteLine();
  91. for (MpsKey key = MpsKey.SaveScene; key <= MpsKey.OpenSceneManager; key++)
  92. {
  93. DrawSetting(key);
  94. }
  95. GUI.enabled = !InputManager.Listening;
  96. // Translation settings
  97. MpsGui.WhiteLine();
  98. reloadTranslationButton.Draw();
  99. reloadAllPresetsButton.Draw();
  100. GUILayout.EndScrollView();
  101. GUI.enabled = true;
  102. }
  103. private void DrawSetting(MpsKey key)
  104. {
  105. int keyIndex = (int)key;
  106. GUILayout.BeginHorizontal();
  107. GUILayout.Label(actionLabels[keyIndex]);
  108. GUILayout.FlexibleSpace();
  109. rebindButtons[keyIndex].Draw(GUILayout.Width(90f));
  110. if (GUILayout.Button("×", GUILayout.ExpandWidth(false)))
  111. {
  112. rebindButtons[keyIndex].KeyCode = KeyCode.None;
  113. InputManager.Rebind(key, KeyCode.None);
  114. }
  115. GUILayout.EndHorizontal();
  116. }
  117. public override void UpdatePanes()
  118. {
  119. for (int i = 0; i < rebindButtons.Length; i++)
  120. {
  121. rebindButtons[i].KeyCode = InputManager.GetActionKey((MpsKey)i);
  122. }
  123. }
  124. }
  125. }