KeyRebindTab.xaml.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. using System.Numerics;
  2. using Content.Client.Stylesheets;
  3. using Content.Shared.CCVar;
  4. using Content.Shared.Input;
  5. using Robust.Client.AutoGenerated;
  6. using Robust.Client.Input;
  7. using Robust.Client.UserInterface;
  8. using Robust.Client.UserInterface.Controls;
  9. using Robust.Client.UserInterface.XAML;
  10. using Robust.Shared;
  11. using Robust.Shared.Configuration;
  12. using Robust.Shared.Input;
  13. using Robust.Shared.Timing;
  14. using Robust.Shared.Utility;
  15. using static Robust.Client.UserInterface.Controls.BoxContainer;
  16. namespace Content.Client.Options.UI.Tabs
  17. {
  18. [GenerateTypedNameReferences]
  19. public sealed partial class KeyRebindTab : Control
  20. {
  21. // List of key functions that must be registered as toggle instead.
  22. private static readonly HashSet<BoundKeyFunction> ToggleFunctions = new()
  23. {
  24. EngineKeyFunctions.ShowDebugMonitors,
  25. EngineKeyFunctions.HideUI,
  26. };
  27. [Dependency] private readonly IInputManager _inputManager = default!;
  28. [Dependency] private readonly IConfigurationManager _cfg = default!;
  29. private BindButton? _currentlyRebinding;
  30. private readonly Dictionary<BoundKeyFunction, KeyControl> _keyControls =
  31. new();
  32. private readonly List<Action> _deferCommands = new();
  33. private void HandleToggleUSQWERTYCheckbox(BaseButton.ButtonToggledEventArgs args)
  34. {
  35. _cfg.SetCVar(CVars.DisplayUSQWERTYHotkeys, args.Pressed);
  36. _cfg.SaveToFile();
  37. }
  38. private void InitToggleWalk()
  39. {
  40. if (_cfg.GetCVar(CCVars.ToggleWalk))
  41. {
  42. ToggleFunctions.Add(EngineKeyFunctions.Walk);
  43. }
  44. else
  45. {
  46. ToggleFunctions.Remove(EngineKeyFunctions.Walk);
  47. }
  48. }
  49. private void HandleToggleWalk(BaseButton.ButtonToggledEventArgs args)
  50. {
  51. _cfg.SetCVar(CCVars.ToggleWalk, args.Pressed);
  52. _cfg.SaveToFile();
  53. InitToggleWalk();
  54. if (!_keyControls.TryGetValue(EngineKeyFunctions.Walk, out var keyControl))
  55. {
  56. return;
  57. }
  58. var bindingType = args.Pressed ? KeyBindingType.Toggle : KeyBindingType.State;
  59. for (var i = 0; i <= 1; i++)
  60. {
  61. var binding = (i == 0 ? keyControl.BindButton1 : keyControl.BindButton2).Binding;
  62. if (binding == null)
  63. {
  64. continue;
  65. }
  66. var registration = new KeyBindingRegistration
  67. {
  68. Function = EngineKeyFunctions.Walk,
  69. BaseKey = binding.BaseKey,
  70. Mod1 = binding.Mod1,
  71. Mod2 = binding.Mod2,
  72. Mod3 = binding.Mod3,
  73. Priority = binding.Priority,
  74. Type = bindingType,
  75. CanFocus = binding.CanFocus,
  76. CanRepeat = binding.CanRepeat,
  77. };
  78. _deferCommands.Add(() =>
  79. {
  80. _inputManager.RemoveBinding(binding);
  81. _inputManager.RegisterBinding(registration);
  82. });
  83. }
  84. _deferCommands.Add(_inputManager.SaveToUserData);
  85. }
  86. private void HandleStaticStorageUI(BaseButton.ButtonToggledEventArgs args)
  87. {
  88. _cfg.SetCVar(CCVars.StaticStorageUI, args.Pressed);
  89. _cfg.SaveToFile();
  90. }
  91. public KeyRebindTab()
  92. {
  93. IoCManager.InjectDependencies(this);
  94. RobustXamlLoader.Load(this);
  95. ResetAllButton.OnPressed += _ =>
  96. {
  97. _deferCommands.Add(() =>
  98. {
  99. _inputManager.ResetAllBindings();
  100. _inputManager.SaveToUserData();
  101. });
  102. };
  103. var first = true;
  104. void AddHeader(string headerContents)
  105. {
  106. if (!first)
  107. {
  108. KeybindsContainer.AddChild(new Control { MinSize = new Vector2(0, 8) });
  109. }
  110. first = false;
  111. KeybindsContainer.AddChild(new Label
  112. {
  113. Text = Loc.GetString(headerContents),
  114. FontColorOverride = StyleNano.NanoGold,
  115. StyleClasses = { StyleNano.StyleClassLabelKeyText }
  116. });
  117. }
  118. void AddButton(BoundKeyFunction function)
  119. {
  120. var control = new KeyControl(this, function);
  121. KeybindsContainer.AddChild(control);
  122. _keyControls.Add(function, control);
  123. }
  124. void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.ButtonToggledEventArgs>? callBackOnClick)
  125. {
  126. CheckBox newCheckBox = new CheckBox() { Text = Loc.GetString(checkBoxName) };
  127. newCheckBox.Pressed = currentState;
  128. newCheckBox.OnToggled += callBackOnClick;
  129. KeybindsContainer.AddChild(newCheckBox);
  130. }
  131. AddHeader("ui-options-header-general");
  132. AddCheckBox("ui-options-hotkey-keymap", _cfg.GetCVar(CVars.DisplayUSQWERTYHotkeys), HandleToggleUSQWERTYCheckbox);
  133. AddHeader("ui-options-header-movement");
  134. AddButton(EngineKeyFunctions.MoveUp);
  135. AddButton(EngineKeyFunctions.MoveLeft);
  136. AddButton(EngineKeyFunctions.MoveDown);
  137. AddButton(EngineKeyFunctions.MoveRight);
  138. AddButton(EngineKeyFunctions.Walk);
  139. AddCheckBox("ui-options-hotkey-toggle-walk", _cfg.GetCVar(CCVars.ToggleWalk), HandleToggleWalk);
  140. InitToggleWalk();
  141. AddHeader("ui-options-header-camera");
  142. AddButton(EngineKeyFunctions.CameraRotateLeft);
  143. AddButton(EngineKeyFunctions.CameraRotateRight);
  144. AddButton(EngineKeyFunctions.CameraReset);
  145. AddButton(ContentKeyFunctions.ZoomIn);
  146. AddButton(ContentKeyFunctions.ZoomOut);
  147. AddButton(ContentKeyFunctions.ResetZoom);
  148. AddHeader("ui-options-header-interaction-basic");
  149. AddButton(EngineKeyFunctions.Use);
  150. AddButton(EngineKeyFunctions.UseSecondary);
  151. AddButton(ContentKeyFunctions.UseItemInHand);
  152. AddButton(ContentKeyFunctions.AltUseItemInHand);
  153. AddButton(ContentKeyFunctions.ActivateItemInWorld);
  154. AddButton(ContentKeyFunctions.AltActivateItemInWorld);
  155. AddButton(ContentKeyFunctions.Drop);
  156. AddButton(ContentKeyFunctions.ExamineEntity);
  157. AddButton(ContentKeyFunctions.SwapHands);
  158. AddButton(ContentKeyFunctions.MoveStoredItem);
  159. AddButton(ContentKeyFunctions.RotateStoredItem);
  160. AddButton(ContentKeyFunctions.SaveItemLocation);
  161. AddHeader("ui-options-header-interaction-adv");
  162. AddButton(ContentKeyFunctions.SmartEquipBackpack);
  163. AddButton(ContentKeyFunctions.SmartEquipBelt);
  164. AddButton(ContentKeyFunctions.OpenBackpack);
  165. AddButton(ContentKeyFunctions.Lay); // Stalker-Changes-UI
  166. AddButton(ContentKeyFunctions.OpenBelt);
  167. AddButton(ContentKeyFunctions.ThrowItemInHand);
  168. AddButton(ContentKeyFunctions.TryPullObject);
  169. AddButton(ContentKeyFunctions.MovePulledObject);
  170. AddButton(ContentKeyFunctions.ReleasePulledObject);
  171. AddButton(ContentKeyFunctions.Point);
  172. AddButton(ContentKeyFunctions.RotateObjectClockwise);
  173. AddButton(ContentKeyFunctions.RotateObjectCounterclockwise);
  174. AddButton(ContentKeyFunctions.FlipObject);
  175. AddHeader("ui-options-header-ui");
  176. AddButton(ContentKeyFunctions.FocusChat);
  177. AddButton(ContentKeyFunctions.FocusLocalChat);
  178. AddButton(ContentKeyFunctions.FocusEmote);
  179. AddButton(ContentKeyFunctions.FocusWhisperChat);
  180. AddButton(ContentKeyFunctions.FocusRadio);
  181. AddButton(ContentKeyFunctions.FocusLOOC);
  182. AddButton(ContentKeyFunctions.FocusOOC);
  183. AddButton(ContentKeyFunctions.FocusAdminChat);
  184. AddButton(ContentKeyFunctions.FocusDeadChat);
  185. AddButton(ContentKeyFunctions.FocusConsoleChat);
  186. AddButton(ContentKeyFunctions.CycleChatChannelForward);
  187. AddButton(ContentKeyFunctions.CycleChatChannelBackward);
  188. AddButton(ContentKeyFunctions.OpenCharacterMenu);
  189. AddButton(ContentKeyFunctions.OpenCraftingMenu);
  190. AddButton(ContentKeyFunctions.OpenGuidebook);
  191. AddButton(ContentKeyFunctions.OpenInventoryMenu);
  192. AddButton(ContentKeyFunctions.OpenAHelp);
  193. AddButton(ContentKeyFunctions.OpenActionsMenu);
  194. AddButton(ContentKeyFunctions.OpenEmotesMenu);
  195. AddButton(ContentKeyFunctions.ToggleRoundEndSummaryWindow);
  196. AddButton(ContentKeyFunctions.OpenEntitySpawnWindow);
  197. AddButton(ContentKeyFunctions.OpenSandboxWindow);
  198. AddButton(ContentKeyFunctions.OpenTileSpawnWindow);
  199. AddButton(ContentKeyFunctions.OpenDecalSpawnWindow);
  200. AddButton(ContentKeyFunctions.OpenAdminMenu);
  201. AddButton(EngineKeyFunctions.WindowCloseAll);
  202. AddButton(EngineKeyFunctions.WindowCloseRecent);
  203. AddButton(EngineKeyFunctions.EscapeMenu);
  204. AddButton(ContentKeyFunctions.EscapeContext);
  205. AddHeader("ui-options-header-misc");
  206. AddButton(ContentKeyFunctions.TakeScreenshot);
  207. AddButton(ContentKeyFunctions.TakeScreenshotNoUI);
  208. AddButton(ContentKeyFunctions.ToggleFullscreen);
  209. AddHeader("ui-options-header-hotbar");
  210. foreach (var boundKey in ContentKeyFunctions.GetHotbarBoundKeys())
  211. {
  212. AddButton(boundKey);
  213. }
  214. AddHeader("ui-options-header-shuttle");
  215. AddButton(ContentKeyFunctions.ShuttleStrafeUp);
  216. AddButton(ContentKeyFunctions.ShuttleStrafeRight);
  217. AddButton(ContentKeyFunctions.ShuttleStrafeLeft);
  218. AddButton(ContentKeyFunctions.ShuttleStrafeDown);
  219. AddButton(ContentKeyFunctions.ShuttleRotateLeft);
  220. AddButton(ContentKeyFunctions.ShuttleRotateRight);
  221. AddButton(ContentKeyFunctions.ShuttleBrake);
  222. AddHeader("ui-options-header-map-editor");
  223. AddButton(EngineKeyFunctions.EditorPlaceObject);
  224. AddButton(EngineKeyFunctions.EditorCancelPlace);
  225. AddButton(EngineKeyFunctions.EditorGridPlace);
  226. AddButton(EngineKeyFunctions.EditorLinePlace);
  227. AddButton(EngineKeyFunctions.EditorRotateObject);
  228. AddButton(ContentKeyFunctions.EditorFlipObject);
  229. AddButton(ContentKeyFunctions.EditorCopyObject);
  230. AddHeader("ui-options-header-dev");
  231. AddButton(EngineKeyFunctions.ShowDebugConsole);
  232. AddButton(EngineKeyFunctions.ShowDebugMonitors);
  233. AddButton(EngineKeyFunctions.HideUI);
  234. AddButton(ContentKeyFunctions.InspectEntity);
  235. AddHeader("ui-options-header-text-cursor");
  236. AddButton(EngineKeyFunctions.TextCursorLeft);
  237. AddButton(EngineKeyFunctions.TextCursorRight);
  238. AddButton(EngineKeyFunctions.TextCursorUp);
  239. AddButton(EngineKeyFunctions.TextCursorDown);
  240. AddButton(EngineKeyFunctions.TextCursorWordLeft);
  241. AddButton(EngineKeyFunctions.TextCursorWordRight);
  242. AddButton(EngineKeyFunctions.TextCursorBegin);
  243. AddButton(EngineKeyFunctions.TextCursorEnd);
  244. AddHeader("ui-options-header-text-cursor-select");
  245. AddButton(EngineKeyFunctions.TextCursorSelect);
  246. AddButton(EngineKeyFunctions.TextCursorSelectLeft);
  247. AddButton(EngineKeyFunctions.TextCursorSelectRight);
  248. AddButton(EngineKeyFunctions.TextCursorSelectUp);
  249. AddButton(EngineKeyFunctions.TextCursorSelectDown);
  250. AddButton(EngineKeyFunctions.TextCursorSelectWordLeft);
  251. AddButton(EngineKeyFunctions.TextCursorSelectWordRight);
  252. AddButton(EngineKeyFunctions.TextCursorSelectBegin);
  253. AddButton(EngineKeyFunctions.TextCursorSelectEnd);
  254. AddHeader("ui-options-header-text-edit");
  255. AddButton(EngineKeyFunctions.TextBackspace);
  256. AddButton(EngineKeyFunctions.TextDelete);
  257. AddButton(EngineKeyFunctions.TextWordBackspace);
  258. AddButton(EngineKeyFunctions.TextWordDelete);
  259. AddButton(EngineKeyFunctions.TextNewline);
  260. AddButton(EngineKeyFunctions.TextSubmit);
  261. AddButton(EngineKeyFunctions.MultilineTextSubmit);
  262. AddButton(EngineKeyFunctions.TextSelectAll);
  263. AddButton(EngineKeyFunctions.TextCopy);
  264. AddButton(EngineKeyFunctions.TextCut);
  265. AddButton(EngineKeyFunctions.TextPaste);
  266. AddHeader("ui-options-header-text-chat");
  267. AddButton(EngineKeyFunctions.TextHistoryPrev);
  268. AddButton(EngineKeyFunctions.TextHistoryNext);
  269. AddButton(EngineKeyFunctions.TextReleaseFocus);
  270. AddButton(EngineKeyFunctions.TextScrollToBottom);
  271. AddHeader("ui-options-header-text-other");
  272. AddButton(EngineKeyFunctions.TextTabComplete);
  273. AddButton(EngineKeyFunctions.TextCompleteNext);
  274. AddButton(EngineKeyFunctions.TextCompletePrev);
  275. foreach (var control in _keyControls.Values)
  276. {
  277. UpdateKeyControl(control);
  278. }
  279. }
  280. private void UpdateKeyControl(KeyControl control)
  281. {
  282. var activeBinds = _inputManager.GetKeyBindings(control.Function);
  283. IKeyBinding? bind1 = null;
  284. IKeyBinding? bind2 = null;
  285. if (activeBinds.Count > 0)
  286. {
  287. bind1 = activeBinds[0];
  288. if (activeBinds.Count > 1)
  289. {
  290. bind2 = activeBinds[1];
  291. }
  292. }
  293. control.BindButton1.Binding = bind1;
  294. control.BindButton1.UpdateText();
  295. control.BindButton2.Binding = bind2;
  296. control.BindButton2.UpdateText();
  297. control.BindButton2.Button.Disabled = activeBinds.Count == 0;
  298. control.ResetButton.Disabled = !_inputManager.IsKeyFunctionModified(control.Function);
  299. }
  300. protected override void EnteredTree()
  301. {
  302. base.EnteredTree();
  303. _inputManager.FirstChanceOnKeyEvent += InputManagerOnFirstChanceOnKeyEvent;
  304. _inputManager.OnKeyBindingAdded += OnKeyBindAdded;
  305. _inputManager.OnKeyBindingRemoved += OnKeyBindRemoved;
  306. }
  307. protected override void ExitedTree()
  308. {
  309. base.ExitedTree();
  310. _inputManager.FirstChanceOnKeyEvent -= InputManagerOnFirstChanceOnKeyEvent;
  311. _inputManager.OnKeyBindingAdded -= OnKeyBindAdded;
  312. _inputManager.OnKeyBindingRemoved -= OnKeyBindRemoved;
  313. }
  314. private void OnKeyBindRemoved(IKeyBinding obj)
  315. {
  316. OnKeyBindModified(obj, true);
  317. }
  318. private void OnKeyBindAdded(IKeyBinding obj)
  319. {
  320. OnKeyBindModified(obj, false);
  321. }
  322. private void OnKeyBindModified(IKeyBinding bind, bool removal)
  323. {
  324. if (!_keyControls.TryGetValue(bind.Function, out var keyControl))
  325. {
  326. return;
  327. }
  328. if (removal && _currentlyRebinding?.KeyControl == keyControl)
  329. {
  330. // Don't do update if the removal was from initiating a rebind.
  331. return;
  332. }
  333. UpdateKeyControl(keyControl);
  334. if (_currentlyRebinding == keyControl.BindButton1 || _currentlyRebinding == keyControl.BindButton2)
  335. {
  336. _currentlyRebinding = null;
  337. }
  338. }
  339. private void InputManagerOnFirstChanceOnKeyEvent(KeyEventArgs keyEvent, KeyEventType type)
  340. {
  341. DebugTools.Assert(IsInsideTree);
  342. if (_currentlyRebinding == null)
  343. {
  344. return;
  345. }
  346. keyEvent.Handle();
  347. if (type != KeyEventType.Up)
  348. {
  349. return;
  350. }
  351. var key = keyEvent.Key;
  352. // Figure out modifiers based on key event.
  353. // TODO: this won't allow for combinations with keys other than the standard modifier keys,
  354. // even though the input system totally supports it.
  355. var mods = new Keyboard.Key[3];
  356. var i = 0;
  357. if (keyEvent.Control && key != Keyboard.Key.Control)
  358. {
  359. mods[i] = Keyboard.Key.Control;
  360. i += 1;
  361. }
  362. if (keyEvent.Shift && key != Keyboard.Key.Shift)
  363. {
  364. mods[i] = Keyboard.Key.Shift;
  365. i += 1;
  366. }
  367. if (keyEvent.Alt && key != Keyboard.Key.Alt)
  368. {
  369. mods[i] = Keyboard.Key.Alt;
  370. i += 1;
  371. }
  372. // The input system can only handle 3 modifier keys so if you hold all 4 of the modifier keys
  373. // then system gets the shaft, I guess.
  374. if (keyEvent.System && i != 3 && key != Keyboard.Key.LSystem && key != Keyboard.Key.RSystem)
  375. {
  376. mods[i] = Keyboard.Key.LSystem;
  377. }
  378. var function = _currentlyRebinding.KeyControl.Function;
  379. var bindType = KeyBindingType.State;
  380. if (ToggleFunctions.Contains(function))
  381. {
  382. bindType = KeyBindingType.Toggle;
  383. }
  384. var registration = new KeyBindingRegistration
  385. {
  386. Function = function,
  387. BaseKey = key,
  388. Mod1 = mods[0],
  389. Mod2 = mods[1],
  390. Mod3 = mods[2],
  391. Priority = _currentlyRebinding.Binding?.Priority ?? 0,
  392. Type = bindType,
  393. CanFocus = key == Keyboard.Key.MouseLeft
  394. || key == Keyboard.Key.MouseRight
  395. || key == Keyboard.Key.MouseMiddle,
  396. CanRepeat = false
  397. };
  398. _inputManager.RegisterBinding(registration);
  399. // OnKeyBindModified will cause _currentlyRebinding to be reset and the UI to update.
  400. _inputManager.SaveToUserData();
  401. }
  402. private void RebindButtonPressed(BindButton button)
  403. {
  404. if (_currentlyRebinding != null)
  405. {
  406. return;
  407. }
  408. _currentlyRebinding = button;
  409. _currentlyRebinding.Button.Text = Loc.GetString("ui-options-key-prompt");
  410. if (button.Binding != null)
  411. {
  412. _deferCommands.Add(() =>
  413. {
  414. // Have to do defer this or else there will be an exception in InputManager.
  415. // Because this IS fired from an input event.
  416. _inputManager.RemoveBinding(button.Binding);
  417. });
  418. }
  419. }
  420. protected override void FrameUpdate(FrameEventArgs args)
  421. {
  422. base.FrameUpdate(args);
  423. if (_deferCommands.Count == 0)
  424. {
  425. return;
  426. }
  427. foreach (var command in _deferCommands)
  428. {
  429. command();
  430. }
  431. _deferCommands.Clear();
  432. }
  433. private sealed class KeyControl : Control
  434. {
  435. public readonly BoundKeyFunction Function;
  436. public readonly BindButton BindButton1;
  437. public readonly BindButton BindButton2;
  438. public readonly Button ResetButton;
  439. public KeyControl(KeyRebindTab parent, BoundKeyFunction function)
  440. {
  441. Function = function;
  442. var name = new Label
  443. {
  444. Text = Loc.GetString(
  445. $"ui-options-function-{CaseConversion.PascalToKebab(function.FunctionName)}"),
  446. HorizontalExpand = true,
  447. HorizontalAlignment = HAlignment.Left
  448. };
  449. BindButton1 = new BindButton(parent, this, StyleBase.ButtonOpenRight);
  450. BindButton2 = new BindButton(parent, this, StyleBase.ButtonOpenLeft);
  451. ResetButton = new Button { Text = Loc.GetString("ui-options-bind-reset"), StyleClasses = { StyleBase.ButtonCaution } };
  452. var hBox = new BoxContainer
  453. {
  454. Orientation = LayoutOrientation.Horizontal,
  455. Children =
  456. {
  457. new Control {MinSize = new Vector2(5, 0)},
  458. name,
  459. BindButton1,
  460. BindButton2,
  461. new Control {MinSize = new Vector2(10, 0)},
  462. ResetButton
  463. }
  464. };
  465. ResetButton.OnPressed += args =>
  466. {
  467. parent._deferCommands.Add(() =>
  468. {
  469. parent._inputManager.ResetBindingsFor(function);
  470. parent._inputManager.SaveToUserData();
  471. });
  472. };
  473. AddChild(hBox);
  474. }
  475. }
  476. private sealed class BindButton : Control
  477. {
  478. private readonly KeyRebindTab _tab;
  479. public readonly KeyControl KeyControl;
  480. public readonly Button Button;
  481. public IKeyBinding? Binding;
  482. public BindButton(KeyRebindTab tab, KeyControl keyControl, string styleClass)
  483. {
  484. _tab = tab;
  485. KeyControl = keyControl;
  486. Button = new Button { StyleClasses = { styleClass } };
  487. UpdateText();
  488. AddChild(Button);
  489. Button.OnPressed += args =>
  490. {
  491. tab.RebindButtonPressed(this);
  492. };
  493. Button.OnKeyBindDown += ButtonOnOnKeyBindDown;
  494. MinSize = new Vector2(200, 0);
  495. }
  496. protected override void EnteredTree()
  497. {
  498. base.EnteredTree();
  499. _tab._inputManager.OnInputModeChanged += UpdateText;
  500. }
  501. protected override void ExitedTree()
  502. {
  503. base.ExitedTree();
  504. _tab._inputManager.OnInputModeChanged -= UpdateText;
  505. }
  506. private void ButtonOnOnKeyBindDown(GUIBoundKeyEventArgs args)
  507. {
  508. if (args.Function == EngineKeyFunctions.UIRightClick)
  509. {
  510. if (Binding != null)
  511. {
  512. _tab._deferCommands.Add(() =>
  513. {
  514. _tab._inputManager.RemoveBinding(Binding);
  515. _tab._inputManager.SaveToUserData();
  516. });
  517. }
  518. args.Handle();
  519. }
  520. }
  521. public void UpdateText()
  522. {
  523. Button.Text = Binding?.GetKeyString() ?? Loc.GetString("ui-options-unbound");
  524. }
  525. }
  526. }
  527. }