SettingsWindowPane.cs 4.5 KB

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