From afd52833a92d5b0f8034add9f2ca133fe818785b Mon Sep 17 00:00:00 2001 From: Aviu00 <93730715+Aviu00@users.noreply.github.com> Date: Wed, 14 Aug 2024 18:27:24 +0000 Subject: [PATCH] - add: Better telescope keybind. (#618) --- .../Options/UI/Tabs/KeyRebindTab.xaml.cs | 7 +++ .../_White/Telescope/TelescopeSystem.cs | 43 ++++++++++++++++--- Content.Shared/_White/WhiteCVars.cs | 6 +++ .../ru-RU/escape-menu/ui/options-menu.ftl | 2 + Resources/keybinds.yml | 5 +-- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs index 2a077806a2..9c7b3c256d 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs @@ -98,6 +98,12 @@ namespace Content.Client.Options.UI.Tabs _deferCommands.Add(_inputManager.SaveToUserData); } + private void HandleHoldLookUp(BaseButton.ButtonToggledEventArgs args) // WD EDIT + { + _cfg.SetCVar(WhiteCVars.HoldLookUp, args.Pressed); + _cfg.SaveToFile(); + } + private void HandleToggleAutoGetUp(BaseButton.ButtonToggledEventArgs args) // WD EDIT { _cfg.SetCVar(WhiteCVars.AutoGetUp, args.Pressed); @@ -194,6 +200,7 @@ namespace Content.Client.Options.UI.Tabs AddButton(ContentKeyFunctions.OfferItem); // WD EDIT AddButton(ContentKeyFunctions.LieDown); // WD EDIT AddButton(ContentKeyFunctions.LookUp); // WD EDIT + AddCheckBox("ui-options-function-hold-look-up", _cfg.GetCVar(WhiteCVars.HoldLookUp), HandleHoldLookUp); // WD EDIT AddCheckBox("ui-options-function-auto-get-up", _cfg.GetCVar(WhiteCVars.AutoGetUp), HandleToggleAutoGetUp); // WD EDIT AddHeader("ui-options-header-interaction-adv"); diff --git a/Content.Client/_White/Telescope/TelescopeSystem.cs b/Content.Client/_White/Telescope/TelescopeSystem.cs index c1f90a7b98..5a1f3a0cf6 100644 --- a/Content.Client/_White/Telescope/TelescopeSystem.cs +++ b/Content.Client/_White/Telescope/TelescopeSystem.cs @@ -1,14 +1,16 @@ using System.Numerics; using Content.Client.Viewport; +using Content.Shared._White; using Content.Shared._White.Telescope; -using Content.Shared.Hands.Components; using Content.Shared.Input; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.Input; using Robust.Client.Player; using Robust.Client.UserInterface; +using Robust.Shared.Configuration; using Robust.Shared.Input; +using Robust.Shared.Input.Binding; using Robust.Shared.Timing; namespace Content.Client._White.Telescope; @@ -21,9 +23,26 @@ public sealed class TelescopeSystem : SharedTelescopeSystem [Dependency] private readonly IInputManager _input = default!; [Dependency] private readonly IEyeManager _eyeManager = default!; [Dependency] private readonly IUserInterfaceManager _uiManager = default!; + [Dependency] private readonly IConfigurationManager _cfg = default!; private ScalingViewport? _viewport; + private bool _holdLookUp; + private bool _toggled; + public override void Initialize() + { + base.Initialize(); + + _cfg.OnValueChanged(WhiteCVars.HoldLookUp, + val => + { + var input = val ? null : InputCmdHandler.FromDelegate(_ => _toggled = !_toggled); + _input.SetInputCommand(ContentKeyFunctions.LookUp, input); + _holdLookUp = val; + _toggled = false; + }, + true); + } public override void FrameUpdate(float frameTime) { @@ -37,7 +56,10 @@ public sealed class TelescopeSystem : SharedTelescopeSystem var entity = GetRightEntity(player); if (entity == EntityUid.Invalid) + { + _toggled = false; return; + } var telescope = Comp(entity); @@ -46,13 +68,17 @@ public sealed class TelescopeSystem : SharedTelescopeSystem var offset = Vector2.Zero; - if (_inputSystem.CmdStates.GetState(ContentKeyFunctions.LookUp) != BoundKeyState.Down) + if (_holdLookUp) { - RaisePredictiveEvent(new EyeOffsetChangedEvent + if (_inputSystem.CmdStates.GetState(ContentKeyFunctions.LookUp) != BoundKeyState.Down) { - Offset = offset - }); - + RaiseEvent(offset); + return; + } + } + else if (!_toggled) + { + RaiseEvent(offset); return; } @@ -89,6 +115,11 @@ public sealed class TelescopeSystem : SharedTelescopeSystem offset = new Angle(-eye.Rotation.Theta).RotateVec(offset); } + RaiseEvent(offset); + } + + private void RaiseEvent(Vector2 offset) + { RaisePredictiveEvent(new EyeOffsetChangedEvent { Offset = offset diff --git a/Content.Shared/_White/WhiteCVars.cs b/Content.Shared/_White/WhiteCVars.cs index c72f957ec6..ec7bb60bd1 100644 --- a/Content.Shared/_White/WhiteCVars.cs +++ b/Content.Shared/_White/WhiteCVars.cs @@ -320,6 +320,12 @@ public sealed class WhiteCVars public static readonly CVarDef AutoGetUp = CVarDef.Create("white.auto_get_up", true, CVar.CLIENT | CVar.ARCHIVE | CVar.REPLICATED); + /// + /// Determines whether telescope functions by holing a button or via toggle + /// + public static readonly CVarDef HoldLookUp = + CVarDef.Create("white.hold_look_up", false, CVar.CLIENT | CVar.ARCHIVE); + /* * Aspects */ diff --git a/Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl b/Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl index 16a8697fd0..f47019e5ec 100644 --- a/Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl +++ b/Resources/Locale/ru-RU/escape-menu/ui/options-menu.ftl @@ -144,6 +144,8 @@ ui-options-function-auto-get-up = Автоматически вставать п ui-options-function-save-item-location = Сохранить позицию предмета ui-options-static-storage-ui = Закрепить интерфейс хранилища на хотбаре ui-options-function-offer-item = Передать что-то +ui-options-function-look-up = Присмотреться/Прицелиться +ui-options-function-hold-look-up = Удерживать клавишу для прицеливания ui-options-function-smart-equip-backpack = Умная экипировка в рюкзак ui-options-function-smart-equip-belt = Умная экипировка на пояс diff --git a/Resources/keybinds.yml b/Resources/keybinds.yml index add2d5cd31..ebed0d1f21 100644 --- a/Resources/keybinds.yml +++ b/Resources/keybinds.yml @@ -1,4 +1,4 @@ -version: 1 # Not used right now, whatever. +version: 1 # Not used right now, whatever. binds: - function: UIClick type: State @@ -545,5 +545,4 @@ binds: key: U - function: LookUp type: State - key: MouseRight - mod1: Space + key: Space