Show held item next to cursor (option). (#4658)
* Show held item next to cursor (option). * UI scale Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
committed by
GitHub
parent
7b7562f75b
commit
3d19a991d8
@@ -19,6 +19,7 @@
|
|||||||
<Control MinSize="4 0" />
|
<Control MinSize="4 0" />
|
||||||
<OptionButton Name="HudThemeOption" />
|
<OptionButton Name="HudThemeOption" />
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
|
<CheckBox Name="ShowHeldItemCheckBox" Text="{Loc 'ui-options-show-held-item'}" />
|
||||||
<BoxContainer Orientation="Horizontal">
|
<BoxContainer Orientation="Horizontal">
|
||||||
<CheckBox Name="ViewportStretchCheckBox" Text="{Loc 'ui-options-vp-stretch'}" />
|
<CheckBox Name="ViewportStretchCheckBox" Text="{Loc 'ui-options-vp-stretch'}" />
|
||||||
<BoxContainer Name="ViewportScaleBox" Orientation="Horizontal">
|
<BoxContainer Name="ViewportScaleBox" Orientation="Horizontal">
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
UpdateViewportScale();
|
UpdateViewportScale();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ShowHeldItemCheckBox.OnToggled += OnCheckBoxToggled;
|
||||||
IntegerScalingCheckBox.OnToggled += OnCheckBoxToggled;
|
IntegerScalingCheckBox.OnToggled += OnCheckBoxToggled;
|
||||||
ViewportLowResCheckBox.OnToggled += OnCheckBoxToggled;
|
ViewportLowResCheckBox.OnToggled += OnCheckBoxToggled;
|
||||||
ApplyButton.OnPressed += OnApplyButtonPressed;
|
ApplyButton.OnPressed += OnApplyButtonPressed;
|
||||||
@@ -85,6 +86,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
ViewportStretchCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportStretch);
|
ViewportStretchCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportStretch);
|
||||||
IntegerScalingCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0;
|
IntegerScalingCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0;
|
||||||
ViewportLowResCheckBox.Pressed = !_cfg.GetCVar(CCVars.ViewportScaleRender);
|
ViewportLowResCheckBox.Pressed = !_cfg.GetCVar(CCVars.ViewportScaleRender);
|
||||||
|
ShowHeldItemCheckBox.Pressed = _cfg.GetCVar(CCVars.HudHeldItemShow);
|
||||||
|
|
||||||
UpdateViewportScale();
|
UpdateViewportScale();
|
||||||
UpdateApplyButton();
|
UpdateApplyButton();
|
||||||
@@ -119,6 +121,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
_cfg.SetCVar(CCVars.ViewportSnapToleranceMargin,
|
_cfg.SetCVar(CCVars.ViewportSnapToleranceMargin,
|
||||||
IntegerScalingCheckBox.Pressed ? CCVars.ViewportSnapToleranceMargin.DefaultValue : 0);
|
IntegerScalingCheckBox.Pressed ? CCVars.ViewportSnapToleranceMargin.DefaultValue : 0);
|
||||||
_cfg.SetCVar(CCVars.ViewportScaleRender, !ViewportLowResCheckBox.Pressed);
|
_cfg.SetCVar(CCVars.ViewportScaleRender, !ViewportLowResCheckBox.Pressed);
|
||||||
|
_cfg.SetCVar(CCVars.HudHeldItemShow, ShowHeldItemCheckBox.Pressed);
|
||||||
_cfg.SaveToFile();
|
_cfg.SaveToFile();
|
||||||
UpdateApplyButton();
|
UpdateApplyButton();
|
||||||
}
|
}
|
||||||
@@ -145,6 +148,7 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
var isVPScaleSame = (int) ViewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
|
var isVPScaleSame = (int) ViewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
|
||||||
var isIntegerScalingSame = IntegerScalingCheckBox.Pressed == (_cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0);
|
var isIntegerScalingSame = IntegerScalingCheckBox.Pressed == (_cfg.GetCVar(CCVars.ViewportSnapToleranceMargin) != 0);
|
||||||
var isVPResSame = ViewportLowResCheckBox.Pressed == !_cfg.GetCVar(CCVars.ViewportScaleRender);
|
var isVPResSame = ViewportLowResCheckBox.Pressed == !_cfg.GetCVar(CCVars.ViewportScaleRender);
|
||||||
|
var isShowHeldItemSame = ShowHeldItemCheckBox.Pressed == _cfg.GetCVar(CCVars.HudHeldItemShow);
|
||||||
|
|
||||||
ApplyButton.Disabled = isVSyncSame &&
|
ApplyButton.Disabled = isVSyncSame &&
|
||||||
isFullscreenSame &&
|
isFullscreenSame &&
|
||||||
@@ -154,7 +158,8 @@ namespace Content.Client.EscapeMenu.UI.Tabs
|
|||||||
isVPScaleSame &&
|
isVPScaleSame &&
|
||||||
isIntegerScalingSame &&
|
isIntegerScalingSame &&
|
||||||
isVPResSame &&
|
isVPResSame &&
|
||||||
isHudThemeSame;
|
isHudThemeSame &&
|
||||||
|
isShowHeldItemSame;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ConfigIsFullscreen =>
|
private bool ConfigIsFullscreen =>
|
||||||
|
|||||||
66
Content.Client/Hands/ShowHandItemOverlay.cs
Normal file
66
Content.Client/Hands/ShowHandItemOverlay.cs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
using Content.Shared.CCVar;
|
||||||
|
using Robust.Client.Graphics;
|
||||||
|
using Robust.Client.Input;
|
||||||
|
using Robust.Shared;
|
||||||
|
using Robust.Shared.Configuration;
|
||||||
|
using Robust.Shared.Enums;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
|
|
||||||
|
namespace Content.Client.Hands
|
||||||
|
{
|
||||||
|
public sealed class ShowHandItemOverlay : Overlay
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||||
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||||
|
[Dependency] private readonly IClyde _clyde = default!;
|
||||||
|
|
||||||
|
private readonly IRenderTexture _renderBackbuffer;
|
||||||
|
|
||||||
|
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
|
||||||
|
|
||||||
|
public ShowHandItemOverlay()
|
||||||
|
{
|
||||||
|
IoCManager.InjectDependencies(this);
|
||||||
|
|
||||||
|
_renderBackbuffer = _clyde.CreateRenderTarget(
|
||||||
|
(64, 64),
|
||||||
|
new RenderTargetFormatParameters(RenderTargetColorFormat.Rgba8Srgb, true),
|
||||||
|
new TextureSampleParameters
|
||||||
|
{
|
||||||
|
Filter = true
|
||||||
|
}, nameof(ShowHandItemOverlay));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DisposeBehavior()
|
||||||
|
{
|
||||||
|
base.DisposeBehavior();
|
||||||
|
|
||||||
|
_renderBackbuffer.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Draw(in OverlayDrawArgs args)
|
||||||
|
{
|
||||||
|
var sys = EntitySystem.Get<HandsSystem>();
|
||||||
|
var handEntity = sys.GetActiveHandEntity();
|
||||||
|
|
||||||
|
if (handEntity == null || !_cfg.GetCVar(CCVars.HudHeldItemShow))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var screen = args.ScreenHandle;
|
||||||
|
var halfSize = _renderBackbuffer.Size / 2;
|
||||||
|
|
||||||
|
screen.RenderInRenderTarget(_renderBackbuffer, () =>
|
||||||
|
{
|
||||||
|
screen.DrawEntity(handEntity, halfSize, new Vector2(1f, 1f) * _cfg.GetCVar(CVars.DisplayUIScale), Direction.South);
|
||||||
|
}, Color.Transparent);
|
||||||
|
|
||||||
|
var offset = _cfg.GetCVar(CCVars.HudHeldItemOffset);
|
||||||
|
|
||||||
|
var mousePos = _inputManager.MouseScreenPosition.Position;
|
||||||
|
screen.DrawTexture(_renderBackbuffer.Texture, mousePos - halfSize + offset, Color.White.WithAlpha(0.75f));
|
||||||
|
// screen.DrawRect(UIBox2.FromDimensions((offset, offset) + mousePos, (32, 32)), Color.Red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,9 +67,7 @@ namespace Content.Client.Hands
|
|||||||
|
|
||||||
public HandsGuiState GetGuiState()
|
public HandsGuiState GetGuiState()
|
||||||
{
|
{
|
||||||
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
if (GetPlayerHandsComponent() is not { } hands)
|
||||||
|
|
||||||
if (player == null || !player.TryGetComponent(out HandsComponent? hands))
|
|
||||||
return new HandsGuiState(Array.Empty<GuiHand>());
|
return new HandsGuiState(Array.Empty<GuiHand>());
|
||||||
|
|
||||||
var states = hands.Hands
|
var states = hands.Hands
|
||||||
@@ -79,6 +77,24 @@ namespace Content.Client.Hands
|
|||||||
return new HandsGuiState(states, hands.ActiveHand);
|
return new HandsGuiState(states, hands.ActiveHand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEntity? GetActiveHandEntity()
|
||||||
|
{
|
||||||
|
if (GetPlayerHandsComponent() is not { ActiveHand: { } active } hands)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return hands.GetHand(active).HeldEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HandsComponent? GetPlayerHandsComponent()
|
||||||
|
{
|
||||||
|
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
||||||
|
|
||||||
|
if (player == null || !player.TryGetComponent(out HandsComponent? hands))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return hands;
|
||||||
|
}
|
||||||
|
|
||||||
public void UIHandClick(HandsComponent hands, string handName)
|
public void UIHandClick(HandsComponent hands, string handName)
|
||||||
{
|
{
|
||||||
if (!hands.TryGetHand(handName, out var pressedHand))
|
if (!hands.TryGetHand(handName, out var pressedHand))
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Content.Client.Chat;
|
|||||||
using Content.Client.Chat.Managers;
|
using Content.Client.Chat.Managers;
|
||||||
using Content.Client.Chat.UI;
|
using Content.Client.Chat.UI;
|
||||||
using Content.Client.Construction.UI;
|
using Content.Client.Construction.UI;
|
||||||
|
using Content.Client.Hands;
|
||||||
using Content.Client.HUD;
|
using Content.Client.HUD;
|
||||||
using Content.Client.HUD.UI;
|
using Content.Client.HUD.UI;
|
||||||
using Content.Client.Voting;
|
using Content.Client.Voting;
|
||||||
@@ -29,6 +30,7 @@ namespace Content.Client.Viewport
|
|||||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
[Dependency] private readonly IVoteManager _voteManager = default!;
|
[Dependency] private readonly IVoteManager _voteManager = default!;
|
||||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||||
|
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||||
|
|
||||||
[ViewVariables] private ChatBox? _gameChat;
|
[ViewVariables] private ChatBox? _gameChat;
|
||||||
private ConstructionMenuPresenter? _constructionMenu;
|
private ConstructionMenuPresenter? _constructionMenu;
|
||||||
@@ -70,10 +72,13 @@ namespace Content.Client.Viewport
|
|||||||
SetupPresenters();
|
SetupPresenters();
|
||||||
|
|
||||||
_eyeManager.MainViewport = Viewport.Viewport;
|
_eyeManager.MainViewport = Viewport.Viewport;
|
||||||
|
|
||||||
|
_overlayManager.AddOverlay(new ShowHandItemOverlay());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
{
|
{
|
||||||
|
_overlayManager.RemoveOverlay<ShowHandItemOverlay>();
|
||||||
DisposePresenters();
|
DisposePresenters();
|
||||||
|
|
||||||
base.Shutdown();
|
base.Shutdown();
|
||||||
|
|||||||
@@ -245,6 +245,13 @@ namespace Content.Shared.CCVar
|
|||||||
public static readonly CVarDef<int> HudTheme =
|
public static readonly CVarDef<int> HudTheme =
|
||||||
CVarDef.Create("hud.theme", 0, CVar.ARCHIVE | CVar.CLIENTONLY);
|
CVarDef.Create("hud.theme", 0, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||||
|
|
||||||
|
public static readonly CVarDef<bool> HudHeldItemShow =
|
||||||
|
CVarDef.Create("hud.held_item_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||||
|
|
||||||
|
public static readonly CVarDef<float> HudHeldItemOffset =
|
||||||
|
CVarDef.Create("hud.held_item_offset", 28f, CVar.ARCHIVE | CVar.CLIENTONLY);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AI
|
* AI
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ ui-options-volume-percent = { TOSTRING($volume, "P0") }
|
|||||||
|
|
||||||
## Graphics menu
|
## Graphics menu
|
||||||
|
|
||||||
|
ui-options-show-held-item = Show held item next to cursor?
|
||||||
ui-options-vsync = VSync
|
ui-options-vsync = VSync
|
||||||
ui-options-fullscreen = Fullscreen
|
ui-options-fullscreen = Fullscreen
|
||||||
ui-options-lighting-label = Lighting Quality:
|
ui-options-lighting-label = Lighting Quality:
|
||||||
|
|||||||
Reference in New Issue
Block a user