- add: Better telescope keybind. (#618)

This commit is contained in:
Aviu00
2024-08-14 18:27:24 +00:00
committed by GitHub
parent 5a0bc40b7e
commit afd52833a9
5 changed files with 54 additions and 9 deletions

View File

@@ -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");

View File

@@ -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<TelescopeComponent>(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

View File

@@ -320,6 +320,12 @@ public sealed class WhiteCVars
public static readonly CVarDef<bool> AutoGetUp =
CVarDef.Create("white.auto_get_up", true, CVar.CLIENT | CVar.ARCHIVE | CVar.REPLICATED);
/// <summary>
/// Determines whether telescope functions by holing a button or via toggle
/// </summary>
public static readonly CVarDef<bool> HoldLookUp =
CVarDef.Create("white.hold_look_up", false, CVar.CLIENT | CVar.ARCHIVE);
/*
* Aspects
*/

View File

@@ -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 = Умная экипировка на пояс

View File

@@ -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