New indicators for combat mode (#15427)

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Artjom
2023-05-06 08:06:42 +03:00
committed by GitHub
parent aac7aa2792
commit a2bf2207a2
11 changed files with 301 additions and 165 deletions

View File

@@ -0,0 +1,87 @@
using Content.Client.Hands.Systems;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Shared.Enums;
using Robust.Shared.Utility;
namespace Content.Client.CombatMode;
/// <summary>
/// This shows something like crosshairs for the combat mode next to the mouse cursor.
/// For weapons with the gun class, a crosshair of one type is displayed,
/// while for all other types of weapons and items in hand, as well as for an empty hand,
/// a crosshair of a different type is displayed. These crosshairs simply show the state of combat mode (on|off).
/// </summary>
public sealed class CombatModeIndicatorsOverlay : Overlay
{
private readonly IInputManager _inputManager;
private readonly IEntityManager _entMan;
private readonly IEyeManager _eye;
private readonly CombatModeSystem _combat;
private readonly HandsSystem _hands = default!;
private readonly Texture _gunSight;
private readonly Texture _meleeSight;
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
public Color MainColor = Color.White.WithAlpha(0.3f);
public Color StrokeColor = Color.Black.WithAlpha(0.5f);
public float Scale = 0.8f; // 1 is a little big
public CombatModeIndicatorsOverlay(IInputManager input, IEntityManager entMan,
IEyeManager eye, CombatModeSystem combatSys, HandsSystem hands)
{
_inputManager = input;
_entMan = entMan;
_eye = eye;
_combat = combatSys;
_hands = hands;
var spriteSys = _entMan.EntitySysManager.GetEntitySystem<SpriteSystem>();
_gunSight = spriteSys.Frame0(new SpriteSpecifier.Rsi(new ResPath("/Textures/Interface/Misc/crosshair_pointers.rsi"),
"gun_sight"));
_meleeSight = spriteSys.Frame0(new SpriteSpecifier.Rsi(new ResPath("/Textures/Interface/Misc/crosshair_pointers.rsi"),
"melee_sight"));
}
protected override bool BeforeDraw(in OverlayDrawArgs args)
{
if (!_combat.IsInCombatMode())
return false;
return base.BeforeDraw(in args);
}
protected override void Draw(in OverlayDrawArgs args)
{
var mouseScreenPosition = _inputManager.MouseScreenPosition;
var mousePosMap = _eye.ScreenToMap(mouseScreenPosition);
if (mousePosMap.MapId != args.MapId)
return;
var handEntity = _hands.GetActiveHandEntity();
var isHandGunItem = _entMan.HasComponent<GunComponent>(handEntity);
var mousePos = mouseScreenPosition.Position;
var uiScale = (args.ViewportControl as Control)?.UIScale ?? 1f;
var limitedScale = uiScale > 1.25f ? 1.25f : uiScale;
var sight = isHandGunItem ? _gunSight : _meleeSight;
DrawSight(sight, args.ScreenHandle, mousePos, limitedScale * Scale);
}
private void DrawSight(Texture sight, DrawingHandleScreen screen, Vector2 centerPos, float scale)
{
var sightSize = sight.Size * scale;
var expandedSize = sightSize + 7f;
screen.DrawTextureRect(sight,
UIBox2.FromDimensions(centerPos - sightSize * 0.5f, sightSize), StrokeColor);
screen.DrawTextureRect(sight,
UIBox2.FromDimensions(centerPos - expandedSize * 0.5f, expandedSize), MainColor);
}
}

View File

@@ -1,17 +1,22 @@
using Content.Client.Hands.Systems;
using Content.Shared.CombatMode; using Content.Shared.CombatMode;
using Content.Shared.Targeting; using Content.Shared.Targeting;
using JetBrains.Annotations; using Content.Shared.CCVar;
using Robust.Client.Player; using Robust.Client.Player;
using Robust.Client.Input;
using Robust.Client.Graphics;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Input.Binding; using Robust.Shared.Configuration;
namespace Content.Client.CombatMode namespace Content.Client.CombatMode;
public sealed class CombatModeSystem : SharedCombatModeSystem
{ {
[UsedImplicitly] [Dependency] private readonly IOverlayManager _overlayManager = default!;
public sealed class CombatModeSystem : SharedCombatModeSystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IEyeManager _eye = default!;
public event Action? LocalPlayerCombatModeUpdated; public event Action? LocalPlayerCombatModeUpdated;
public override void Initialize() public override void Initialize()
@@ -19,6 +24,8 @@ namespace Content.Client.CombatMode
base.Initialize(); base.Initialize();
SubscribeLocalEvent<CombatModeComponent, ComponentHandleState>(OnHandleState); SubscribeLocalEvent<CombatModeComponent, ComponentHandleState>(OnHandleState);
_cfg.OnValueChanged(CCVars.CombatModeIndicatorsPointShow, OnShowCombatIndicatorsChanged, true);
} }
private void OnHandleState(EntityUid uid, CombatModeComponent component, ref ComponentHandleState args) private void OnHandleState(EntityUid uid, CombatModeComponent component, ref ComponentHandleState args)
@@ -33,7 +40,9 @@ namespace Content.Client.CombatMode
public override void Shutdown() public override void Shutdown()
{ {
CommandBinds.Unregister<CombatModeSystem>(); _cfg.OnValueChanged(CCVars.CombatModeIndicatorsPointShow, OnShowCombatIndicatorsChanged);
_overlayManager.RemoveOverlay<CombatModeIndicatorsOverlay>();
base.Shutdown(); base.Shutdown();
} }
@@ -73,5 +82,21 @@ namespace Content.Client.CombatMode
LocalPlayerCombatModeUpdated?.Invoke(); LocalPlayerCombatModeUpdated?.Invoke();
} }
private void OnShowCombatIndicatorsChanged(bool isShow)
{
if (isShow)
{
_overlayManager.AddOverlay(new CombatModeIndicatorsOverlay(
_inputManager,
EntityManager,
_eye,
this,
EntityManager.System<HandsSystem>()));
}
else
{
_overlayManager.RemoveOverlay<CombatModeIndicatorsOverlay>();
}
} }
} }

View File

@@ -21,6 +21,7 @@
<OptionButton Name="HudThemeOption" /> <OptionButton Name="HudThemeOption" />
</BoxContainer> </BoxContainer>
<CheckBox Name="ShowHeldItemCheckBox" Text="{Loc 'ui-options-show-held-item'}" /> <CheckBox Name="ShowHeldItemCheckBox" Text="{Loc 'ui-options-show-held-item'}" />
<CheckBox Name="ShowCombatModeIndicatorsCheckBox" Text="{Loc 'ui-options-show-combat-mode-indicators'}" />
<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">

View File

@@ -99,6 +99,7 @@ namespace Content.Client.Options.UI.Tabs
}; };
ShowHeldItemCheckBox.OnToggled += OnCheckBoxToggled; ShowHeldItemCheckBox.OnToggled += OnCheckBoxToggled;
ShowCombatModeIndicatorsCheckBox.OnToggled += OnCheckBoxToggled;
IntegerScalingCheckBox.OnToggled += OnCheckBoxToggled; IntegerScalingCheckBox.OnToggled += OnCheckBoxToggled;
ViewportLowResCheckBox.OnToggled += OnCheckBoxToggled; ViewportLowResCheckBox.OnToggled += OnCheckBoxToggled;
ParallaxLowQualityCheckBox.OnToggled += OnCheckBoxToggled; ParallaxLowQualityCheckBox.OnToggled += OnCheckBoxToggled;
@@ -116,6 +117,7 @@ namespace Content.Client.Options.UI.Tabs
ParallaxLowQualityCheckBox.Pressed = _cfg.GetCVar(CCVars.ParallaxLowQuality); ParallaxLowQualityCheckBox.Pressed = _cfg.GetCVar(CCVars.ParallaxLowQuality);
FpsCounterCheckBox.Pressed = _cfg.GetCVar(CCVars.HudFpsCounterVisible); FpsCounterCheckBox.Pressed = _cfg.GetCVar(CCVars.HudFpsCounterVisible);
ShowHeldItemCheckBox.Pressed = _cfg.GetCVar(CCVars.HudHeldItemShow); ShowHeldItemCheckBox.Pressed = _cfg.GetCVar(CCVars.HudHeldItemShow);
ShowCombatModeIndicatorsCheckBox.Pressed = _cfg.GetCVar(CCVars.CombatModeIndicatorsPointShow);
ViewportWidthSlider.Value = _cfg.GetCVar(CCVars.ViewportWidth); ViewportWidthSlider.Value = _cfg.GetCVar(CCVars.ViewportWidth);
_cfg.OnValueChanged(CCVars.ViewportMinimumWidth, _ => UpdateViewportWidthRange()); _cfg.OnValueChanged(CCVars.ViewportMinimumWidth, _ => UpdateViewportWidthRange());
@@ -158,6 +160,7 @@ namespace Content.Client.Options.UI.Tabs
_cfg.SetCVar(CCVars.ViewportScaleRender, !ViewportLowResCheckBox.Pressed); _cfg.SetCVar(CCVars.ViewportScaleRender, !ViewportLowResCheckBox.Pressed);
_cfg.SetCVar(CCVars.ParallaxLowQuality, ParallaxLowQualityCheckBox.Pressed); _cfg.SetCVar(CCVars.ParallaxLowQuality, ParallaxLowQualityCheckBox.Pressed);
_cfg.SetCVar(CCVars.HudHeldItemShow, ShowHeldItemCheckBox.Pressed); _cfg.SetCVar(CCVars.HudHeldItemShow, ShowHeldItemCheckBox.Pressed);
_cfg.SetCVar(CCVars.CombatModeIndicatorsPointShow, ShowCombatModeIndicatorsCheckBox.Pressed);
_cfg.SetCVar(CCVars.HudFpsCounterVisible, FpsCounterCheckBox.Pressed); _cfg.SetCVar(CCVars.HudFpsCounterVisible, FpsCounterCheckBox.Pressed);
_cfg.SetCVar(CCVars.ViewportWidth, (int) ViewportWidthSlider.Value); _cfg.SetCVar(CCVars.ViewportWidth, (int) ViewportWidthSlider.Value);
@@ -194,6 +197,7 @@ namespace Content.Client.Options.UI.Tabs
var isVPResSame = ViewportLowResCheckBox.Pressed == !_cfg.GetCVar(CCVars.ViewportScaleRender); var isVPResSame = ViewportLowResCheckBox.Pressed == !_cfg.GetCVar(CCVars.ViewportScaleRender);
var isPLQSame = ParallaxLowQualityCheckBox.Pressed == _cfg.GetCVar(CCVars.ParallaxLowQuality); var isPLQSame = ParallaxLowQualityCheckBox.Pressed == _cfg.GetCVar(CCVars.ParallaxLowQuality);
var isShowHeldItemSame = ShowHeldItemCheckBox.Pressed == _cfg.GetCVar(CCVars.HudHeldItemShow); var isShowHeldItemSame = ShowHeldItemCheckBox.Pressed == _cfg.GetCVar(CCVars.HudHeldItemShow);
var isCombatModeIndicatorsSame = ShowCombatModeIndicatorsCheckBox.Pressed == _cfg.GetCVar(CCVars.CombatModeIndicatorsPointShow);
var isFpsCounterVisibleSame = FpsCounterCheckBox.Pressed == _cfg.GetCVar(CCVars.HudFpsCounterVisible); var isFpsCounterVisibleSame = FpsCounterCheckBox.Pressed == _cfg.GetCVar(CCVars.HudFpsCounterVisible);
var isWidthSame = (int) ViewportWidthSlider.Value == _cfg.GetCVar(CCVars.ViewportWidth); var isWidthSame = (int) ViewportWidthSlider.Value == _cfg.GetCVar(CCVars.ViewportWidth);
var isLayoutSame = HudLayoutOption.SelectedMetadata is string opt && opt == _cfg.GetCVar(CCVars.UILayout); var isLayoutSame = HudLayoutOption.SelectedMetadata is string opt && opt == _cfg.GetCVar(CCVars.UILayout);
@@ -209,6 +213,7 @@ namespace Content.Client.Options.UI.Tabs
isPLQSame && isPLQSame &&
isHudThemeSame && isHudThemeSame &&
isShowHeldItemSame && isShowHeldItemSame &&
isCombatModeIndicatorsSame &&
isFpsCounterVisibleSame && isFpsCounterVisibleSame &&
isWidthSame && isWidthSame &&
isLayoutSame; isLayoutSame;

View File

@@ -2,11 +2,10 @@ using Content.Shared.CombatMode;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
namespace Content.Server.CombatMode namespace Content.Server.CombatMode;
public sealed class CombatModeSystem : SharedCombatModeSystem
{ {
[UsedImplicitly]
public sealed class CombatModeSystem : SharedCombatModeSystem
{
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -18,5 +17,4 @@ namespace Content.Server.CombatMode
{ {
args.State = new CombatModeComponentState(component.IsInCombatMode, component.ActiveZone); args.State = new CombatModeComponentState(component.IsInCombatMode, component.ActiveZone);
} }
}
} }

View File

@@ -572,6 +572,9 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<bool> HudHeldItemShow = public static readonly CVarDef<bool> HudHeldItemShow =
CVarDef.Create("hud.held_item_show", true, CVar.ARCHIVE | CVar.CLIENTONLY); CVarDef.Create("hud.held_item_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);
public static readonly CVarDef<bool> CombatModeIndicatorsPointShow =
CVarDef.Create("hud.combat_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);
public static readonly CVarDef<float> HudHeldItemOffset = public static readonly CVarDef<float> HudHeldItemOffset =
CVarDef.Create("hud.held_item_offset", 28f, CVar.ARCHIVE | CVar.CLIENTONLY); CVarDef.Create("hud.held_item_offset", 28f, CVar.ARCHIVE | CVar.CLIENTONLY);
@@ -919,7 +922,7 @@ namespace Content.Shared.CCVar
/// Whether or not OOC chat should be enabled during a round. /// Whether or not OOC chat should be enabled during a round.
/// </summary> /// </summary>
public static readonly CVarDef<bool> OocEnableDuringRound = public static readonly CVarDef<bool> OocEnableDuringRound =
CVarDef.Create("ooc.enable_during_round", false, CVar.NOTIFY | CVar.REPLICATED |CVar.SERVER); CVarDef.Create("ooc.enable_during_round", false, CVar.NOTIFY | CVar.REPLICATED | CVar.SERVER);
/* /*
* LOOC * LOOC

View File

@@ -6,10 +6,10 @@ using Robust.Shared.Prototypes;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Timing; using Robust.Shared.Timing;
namespace Content.Shared.CombatMode namespace Content.Shared.CombatMode;
public abstract class SharedCombatModeSystem : EntitySystem
{ {
public abstract class SharedCombatModeSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!; [Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!; [Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly SharedPopupSystem _popup = default!;
@@ -100,7 +100,6 @@ namespace Content.Shared.CombatMode
TargetingZone = targetingZone; TargetingZone = targetingZone;
} }
} }
}
public sealed class ToggleCombatActionEvent : InstantActionEvent { }
} }
public sealed class ToggleCombatActionEvent : InstantActionEvent { }

View File

@@ -29,6 +29,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-show-held-item = Show held item next to cursor?
ui-options-show-combat-mode-indicators = Show combat mode indicators with 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:

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,17 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "https://github.com/Arteben",
"size": {
"x": 64,
"y": 64
},
"states": [
{
"name": "gun_sight"
},
{
"name": "melee_sight"
}
]
}