Skip to content

Commit 8dce3ce

Browse files
authored
merge live (#3837)
<!-- IT'S NOT WIZDENS REPO, IF YOU WANT TO ADD YOUR CHANGES ON ALL SERVERS, CREATE PR TO WIZDENS REPO --> ## Short description <!-- What do you propose to change with your PR? --> ## Why we need to add this <!-- What is the reason for adding these changes? Please post links to Discussions as well as Bug Reports here. Please describe how this will change the game balance. --> ## Media (Video/Screenshots) <!-- If your PR contains in-game changes you must provide screenshots/videos of the changes. --> ## Checks <!-- check boxes for faster reviewing of your PR --> - [x] I do not require assistance to complete the PR. - [ ] Before posting/requesting review of a PR, I have verified that the changes work. - [ ] I have added screenshots/videos of the changes, or this PR does not change in-game mechanics. - [x] I affirm that my changes are licensed under the [MIT License](https://github.com/ss14Starlight/space-station-14/blob/Starlight/LICENSE.TXT) and grant permission for use in this repository under its conditions.
2 parents 5dbadfe + 77155b6 commit 8dce3ce

286 files changed

Lines changed: 5532 additions & 467 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Content.Client/CombatMode/CombatModeIndicatorsOverlay.cs

Lines changed: 143 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
using Robust.Client.Input;
77
using Robust.Client.UserInterface;
88
using Robust.Shared.Enums;
9-
using Robust.Shared.Utility;
9+
10+
#region Starlight
11+
using Content.Shared._Starlight.CombatMode;
12+
using Robust.Shared.Prototypes;
13+
using SixLabors.ImageSharp.PixelFormats;
14+
using Robust.Shared.Graphics.RSI;
15+
using Content.Client.Weapons.Ranged.Systems;
16+
#endregion
1017

1118
namespace Content.Client.CombatMode;
1219

@@ -23,42 +30,48 @@ public sealed class CombatModeIndicatorsOverlay : Overlay
2330
private readonly IEyeManager _eye;
2431
private readonly CombatModeSystem _combat;
2532
private readonly HandsSystem _hands = default!;
26-
27-
private readonly Texture _gunSight;
28-
private readonly Texture _gunBoltSight;
29-
private readonly Texture _meleeSight;
33+
private readonly IClyde _clyde = default!; // Starlight-edit
34+
35+
#region Starlight
36+
private readonly SightPrototype? _gunSight;
37+
private readonly SightPrototype? _gunBoltSight;
38+
private readonly SightPrototype? _meleeSight;
39+
private readonly float? _scale;
40+
private readonly float? _offset;
41+
private readonly Color? _main;
42+
private readonly Color? _second;
43+
private readonly bool _rotation = true;
44+
#endregion
3045

3146
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
3247

33-
public Color MainColor = Color.White.WithAlpha(0.3f);
34-
public Color StrokeColor = Color.Black.WithAlpha(0.5f);
35-
public float Scale = 0.6f; // 1 is a little big
36-
37-
public CombatModeIndicatorsOverlay(IInputManager input, IEntityManager entMan,
38-
IEyeManager eye, CombatModeSystem combatSys, HandsSystem hands)
48+
public CombatModeIndicatorsOverlay(IInputManager input, IEntityManager entMan, IPrototypeManager prototypes,
49+
IEyeManager eye, CombatModeSystem combatSys, HandsSystem hands, IClyde clyde, SightPrototype gunSight, SightPrototype meleeSight, float scale, float offset, Color main, Color second, bool rotation = true) // Starlight-edit
3950
{
4051
_inputManager = input;
4152
_entMan = entMan;
4253
_eye = eye;
4354
_combat = combatSys;
4455
_hands = hands;
45-
46-
var spriteSys = _entMan.EntitySysManager.GetEntitySystem<SpriteSystem>();
47-
_gunSight = spriteSys.Frame0(new SpriteSpecifier.Rsi(new ResPath("/Textures/Interface/Misc/crosshair_pointers.rsi"),
48-
"gun_sight"));
49-
_gunBoltSight = spriteSys.Frame0(new SpriteSpecifier.Rsi(new ResPath("/Textures/Interface/Misc/crosshair_pointers.rsi"),
50-
"gun_bolt_sight"));
51-
_meleeSight = spriteSys.Frame0(new SpriteSpecifier.Rsi(new ResPath("/Textures/Interface/Misc/crosshair_pointers.rsi"),
52-
"melee_sight"));
56+
// Starlight-start: replace Texture to Proto
57+
_gunSight = gunSight;
58+
_meleeSight = meleeSight;
59+
_clyde = clyde;
60+
_scale = scale;
61+
_offset = offset;
62+
_main = main;
63+
_second = second;
64+
_rotation = rotation;
65+
66+
if (_gunSight.BoltVariant != null)
67+
prototypes.TryIndex(_gunSight.BoltVariant, out _gunBoltSight);
68+
// Starlight-end
5369
}
5470

55-
protected override bool BeforeDraw(in OverlayDrawArgs args)
56-
{
57-
if (!_combat.IsInCombatMode())
58-
return false;
59-
60-
return base.BeforeDraw(in args);
61-
}
71+
// Starlight-start: Make it lambda
72+
protected override bool BeforeDraw(in OverlayDrawArgs args)
73+
=> !_combat.IsInCombatMode() ? false : base.BeforeDraw(in args);
74+
// Starlight-end
6275

6376
protected override void Draw(in OverlayDrawArgs args)
6477
{
@@ -68,28 +81,121 @@ protected override void Draw(in OverlayDrawArgs args)
6881
return;
6982

7083
var handEntity = _hands.GetActiveHandEntity();
71-
var isHandGunItem = _entMan.HasComponent<GunComponent>(handEntity);
84+
var isHandGunItem = _entMan.TryGetComponent<GunComponent>(handEntity, out var gun); // Starlight-edit
7285
var isGunBolted = true;
7386
if (_entMan.TryGetComponent(handEntity, out ChamberMagazineAmmoProviderComponent? chamber))
7487
isGunBolted = chamber.BoltClosed ?? true;
7588

76-
7789
var mousePos = mouseScreenPosition.Position;
7890
var uiScale = (args.ViewportControl as Control)?.UIScale ?? 1f;
7991
var limitedScale = uiScale > 1.25f ? 1.25f : uiScale;
8092

81-
var sight = isHandGunItem ? (isGunBolted ? _gunSight : _gunBoltSight) : _meleeSight;
82-
DrawSight(sight, args.ScreenHandle, mousePos, limitedScale * Scale);
93+
#region Starlight
94+
95+
var spriteSys = _entMan.EntitySysManager.GetEntitySystem<SpriteSystem>();
96+
97+
var sight = isHandGunItem ? (isGunBolted || _gunBoltSight == null ? _gunSight : _gunBoltSight) : _meleeSight;
98+
if (sight != null)
99+
{
100+
if (!sight.ShowCursor)
101+
_clyde.SetCursor(_clyde.CreateCursor(new SixLabors.ImageSharp.Image<Rgba32>(32, 32), Vector2i.Zero));
102+
else
103+
_clyde.SetCursor(null);
104+
105+
var scale = limitedScale * Math.Clamp(_scale ?? 0.6f, 0f, 1f);
106+
107+
var eyePos = _eye.CurrentEye.Position;
108+
var eyeScreen = _eye.MapToScreen(eyePos);
109+
var rot = MathF.Atan2(eyeScreen.Y - mousePos.Y, eyeScreen.X - mousePos.X);
110+
rot -= MathF.PI / 2f;
111+
var rsiState = spriteSys.RsiStateLike(sight.Sprite);
112+
if (rsiState.IsAnimated && rsiState.AnimationFrameCount >= 3)
113+
{
114+
115+
var currentAngle = 0f;
116+
if (isHandGunItem && handEntity != null)
117+
currentAngle = (float)_entMan.System<GunSystem>().GetCurrentAngle(handEntity.Value).Degrees;
118+
119+
var bracket1 = rsiState.GetFrame(RsiDirection.South, 0); // Left
120+
var sightTexture = rsiState.GetFrame(RsiDirection.South, 1); // Center
121+
var bracket2 = rsiState.GetFrame(RsiDirection.South, 2); // Right
122+
123+
Texture? bracket3 = null; // Down
124+
Texture? bracket4 = null; // Up
125+
126+
if (rsiState.AnimationFrameCount >= 4)
127+
bracket3 = rsiState.GetFrame(RsiDirection.South, 3);
128+
129+
if (rsiState.AnimationFrameCount >= 5)
130+
bracket4 = rsiState.GetFrame(RsiDirection.South, 4);
131+
132+
var offset = CalculateOffset(currentAngle, (eyeScreen.Position - mousePos).Length(), scale);
133+
DrawSightPartial(sightTexture, bracket1, bracket2, args.ScreenHandle, rot, mousePos, scale,_main ?? sight.MainColor,_second ?? sight.StrokeColor, offset, bracket3, bracket4);
134+
}
135+
else
136+
{
137+
var sightTexture = spriteSys.Frame0(sight.Sprite);
138+
DrawOverlayPart(sightTexture, args.ScreenHandle, mousePos, scale, _main ?? sight.MainColor, _second ?? sight.StrokeColor);
139+
}
140+
}
141+
142+
#endregion
143+
}
144+
145+
#region Starlight
146+
private float CalculateOffset(float currentAngle, float distance, float scale)
147+
{
148+
var angleRad = currentAngle * MathF.PI / 180f;
149+
var offset = MathF.Tan(angleRad) * distance;
150+
offset *= scale;
151+
// So if slider is in center: 0.5 + 0.5 = 1, meaning no change. If slider is at minimum: 0 + 0.5 = 0.5, meaning offset is halved. If slider is at maximum: 1 + 0.5 = 1.5, meaning offset is increased by 50%.
152+
offset *= (_offset ?? 0.5f) + 0.5f;
153+
return offset;
154+
}
155+
156+
private void DrawSightPartial(Texture sight, Texture bracket1, Texture bracket2, DrawingHandleScreen screen, float rotation, Vector2 centerPos, float scale, Color mainColor, Color strokeColor, float offset, Texture? bracket3 = null, Texture? bracket4 = null)
157+
{
158+
DrawOverlayPart(sight, screen, centerPos, scale, mainColor, strokeColor);
159+
160+
var bracketSize1 = bracket1.Size * scale;
161+
var bracketSize2 = bracket2.Size * scale;
162+
163+
if (_rotation)
164+
screen.SetTransform(Matrix3x2.CreateRotation(rotation, centerPos));
165+
166+
var bracket1Pos = centerPos + new Vector2(-offset - bracketSize1.X * 0.5f, 0f);
167+
var bracket2Pos = centerPos + new Vector2(offset + bracketSize2.X * 0.5f, 0f);
168+
DrawOverlayPart(bracket1, screen, bracket1Pos, scale, mainColor, strokeColor);
169+
DrawOverlayPart(bracket2, screen, bracket2Pos, scale, mainColor, strokeColor);
170+
171+
if (bracket3 != null)
172+
{
173+
var bracket3Pos = centerPos + new Vector2(0f, offset + bracketSize1.Y * 0.5f);
174+
DrawOverlayPart(bracket3, screen, bracket3Pos, scale, mainColor, strokeColor);
175+
}
176+
177+
if (bracket4 != null)
178+
{
179+
var bracket4Pos = centerPos + new Vector2(0f, -offset - bracketSize2.Y * 0.5f);
180+
DrawOverlayPart(bracket4, screen, bracket4Pos, scale, mainColor, strokeColor);
181+
}
83182
}
84183

85-
private void DrawSight(Texture sight, DrawingHandleScreen screen, Vector2 centerPos, float scale)
184+
private static void DrawOverlayPart(Texture texture, DrawingHandleScreen screen, Vector2 position, float scale, Color mainColor, Color strokeColor)
86185
{
87-
var sightSize = sight.Size * scale;
88-
var expandedSize = sightSize + new Vector2(7f, 7f);
186+
var size = texture.Size * scale;
187+
screen.DrawTextureRect(texture,
188+
UIBox2.FromDimensions(position - size * 0.5f, size), strokeColor);
189+
screen.DrawTextureRect(texture,
190+
UIBox2.FromDimensions(position - size * 0.5f - new Vector2(3f, 3f), size + new Vector2(7f, 7f)), mainColor);
191+
}
89192

90-
screen.DrawTextureRect(sight,
91-
UIBox2.FromDimensions(centerPos - sightSize * 0.5f, sightSize), StrokeColor);
92-
screen.DrawTextureRect(sight,
93-
UIBox2.FromDimensions(centerPos - expandedSize * 0.5f, expandedSize), MainColor);
193+
private sealed class DummyCursor : ICursor
194+
{
195+
public void Dispose()
196+
{
197+
}
94198
}
199+
200+
#endregion
95201
}

Content.Client/CombatMode/CombatModeSystem.cs

Lines changed: 103 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
using Robust.Client.Player;
88
using Robust.Shared.Configuration;
99

10+
#region Starlight
11+
using Content.Shared._Starlight.CombatMode;
12+
using Content.Shared.Starlight.CCVar;
13+
using Robust.Shared.Prototypes;
14+
#endregion
15+
1016
namespace Content.Client.CombatMode;
1117

1218
public sealed class CombatModeSystem : SharedCombatModeSystem
@@ -16,19 +22,43 @@ public sealed class CombatModeSystem : SharedCombatModeSystem
1622
[Dependency] private readonly IConfigurationManager _cfg = default!;
1723
[Dependency] private readonly IInputManager _inputManager = default!;
1824
[Dependency] private readonly IEyeManager _eye = default!;
25+
#region Starlight
26+
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
27+
[Dependency] private readonly IClyde _clyde = default!;
28+
#endregion
1929

2030
/// <summary>
2131
/// Raised whenever combat mode changes.
2232
/// </summary>
2333
public event Action<bool>? LocalPlayerCombatModeUpdated;
2434

35+
#region Starlight
36+
private bool _lastState = false;
37+
private string _rangedSight = "GunSight";
38+
private string _meleeSight = "MeleeSight";
39+
private float _scale = 0.6f;
40+
private float _offset = 0.5f;
41+
private bool _rotation = true;
42+
private Color _main = Color.White.WithAlpha(0.3f);
43+
private Color _second = Color.Black.WithAlpha(0.5f);
44+
#endregion
45+
2546
public override void Initialize()
2647
{
2748
base.Initialize();
2849

2950
SubscribeLocalEvent<CombatModeComponent, AfterAutoHandleStateEvent>(OnHandleState);
3051

3152
Subs.CVar(_cfg, CCVars.CombatModeIndicatorsPointShow, OnShowCombatIndicatorsChanged, true);
53+
// Starlight-start
54+
Subs.CVar(_cfg, StarlightCCVars.RangedSight, OnRangedSightChanged, true);
55+
Subs.CVar(_cfg, StarlightCCVars.RangedSightScale, OnRangedSightScaleChanged, true);
56+
Subs.CVar(_cfg, StarlightCCVars.RangedSightOffset, OnRangedSightOffsetChanged, true);
57+
Subs.CVar(_cfg, StarlightCCVars.SightMainColor, OnSightMainColorChanged, true);
58+
Subs.CVar(_cfg, StarlightCCVars.SightSecondColor, OnSightSecondColorChanged, true);
59+
Subs.CVar(_cfg, StarlightCCVars.MeleeSight, OnMeleeSightChanged, true);
60+
Subs.CVar(_cfg, StarlightCCVars.SightRotation, OnRotationChanged, true);
61+
// Starlight-end
3262
}
3363

3464
private void OnHandleState(EntityUid uid, CombatModeComponent component, ref AfterAutoHandleStateEvent args)
@@ -72,23 +102,88 @@ private void UpdateHud(EntityUid entity)
72102
}
73103

74104
var inCombatMode = IsInCombatMode();
105+
// Starlight-start
106+
if (!inCombatMode)
107+
_clyde.SetCursor(null);
108+
// Starlight-end
75109
LocalPlayerCombatModeUpdated?.Invoke(inCombatMode);
76110
}
77111

78-
private void OnShowCombatIndicatorsChanged(bool isShow)
112+
private void OnShowCombatIndicatorsChanged(bool isShow) // Starlight-edit: moved into another method
113+
=> UpdateCombatIndicators(isShow);
114+
115+
#region Starlight
116+
117+
private void OnRangedSightChanged(string sight)
118+
{
119+
_rangedSight = sight;
120+
UpdateCombatIndicators();
121+
}
122+
123+
private void OnRangedSightScaleChanged(int scale)
124+
{
125+
float fScale = scale * 0.01f;
126+
_scale = fScale;
127+
UpdateCombatIndicators();
128+
}
129+
130+
private void OnRangedSightOffsetChanged(int offset)
131+
{
132+
float fOffset = offset * 0.01f;
133+
_offset = fOffset;
134+
UpdateCombatIndicators();
135+
}
136+
137+
private void OnSightMainColorChanged(string color)
138+
{
139+
_main = Color.FromHex(color).WithAlpha(0.3f);
140+
UpdateCombatIndicators();
141+
}
142+
143+
private void OnSightSecondColorChanged(string color)
79144
{
80-
if (isShow)
145+
_second = Color.FromHex(color).WithAlpha(0.5f);
146+
UpdateCombatIndicators();
147+
}
148+
149+
private void OnMeleeSightChanged(string sight)
150+
{
151+
_meleeSight = sight;
152+
UpdateCombatIndicators();
153+
}
154+
155+
private void OnRotationChanged(bool rotation)
156+
{
157+
_rotation = rotation;
158+
UpdateCombatIndicators();
159+
}
160+
161+
private void UpdateCombatIndicators(bool? isShow = null)
162+
{
163+
if (isShow != null && isShow != _lastState)
164+
_lastState = isShow.Value;
165+
166+
if ((isShow == null || !_lastState) && _overlayManager.HasOverlay<CombatModeIndicatorsOverlay>())
167+
_overlayManager.RemoveOverlay<CombatModeIndicatorsOverlay>();
168+
if ((isShow == null || _lastState) && _prototypeManager.TryIndex<SightPrototype>(_rangedSight, out var ranged) && _prototypeManager.TryIndex<SightPrototype>(_meleeSight, out var melee))
81169
{
82170
_overlayManager.AddOverlay(new CombatModeIndicatorsOverlay(
83171
_inputManager,
84172
EntityManager,
173+
_prototypeManager,
85174
_eye,
86175
this,
87-
EntityManager.System<HandsSystem>()));
88-
}
89-
else
90-
{
91-
_overlayManager.RemoveOverlay<CombatModeIndicatorsOverlay>();
176+
EntityManager.System<HandsSystem>(),
177+
_clyde,
178+
ranged,
179+
melee,
180+
_scale,
181+
_offset,
182+
_main,
183+
_second,
184+
_rotation));
92185
}
93186
}
94-
}
187+
188+
#endregion
189+
}

Content.Client/Humanoid/HumanoidAppearanceSystem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ public override void LoadProfile(EntityUid uid, HumanoidCharacterProfile? profil
155155
return;
156156
}
157157

158+
if (!humanoid.AllowProfileOverride) return; //Starlight
159+
158160
var customBaseLayers = new Dictionary<HumanoidVisualLayers, CustomBaseLayerInfo>();
159161

160162
var speciesPrototype = _prototypeManager.Index<SpeciesPrototype>(profile.Species);

0 commit comments

Comments
 (0)