-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'WWhiteDreamProject:master' into Ru-translation
- Loading branch information
Showing
20 changed files
with
429 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System.Numerics; | ||
using Content.Client.Viewport; | ||
using Content.Shared._White; | ||
using Content.Shared._White.Telescope; | ||
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; | ||
|
||
public sealed class TelescopeSystem : SharedTelescopeSystem | ||
{ | ||
[Dependency] private readonly InputSystem _inputSystem = default!; | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
[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) | ||
{ | ||
base.FrameUpdate(frameTime); | ||
|
||
if (_timing.ApplyingState || !_timing.IsFirstTimePredicted || !_input.MouseScreenPosition.IsValid) | ||
return; | ||
|
||
var player = _player.LocalEntity; | ||
|
||
var telescope = GetRightTelescope(player); | ||
|
||
if (telescope == null) | ||
{ | ||
_toggled = false; | ||
return; | ||
} | ||
|
||
if (!TryComp<EyeComponent>(player, out var eye)) | ||
return; | ||
|
||
var offset = Vector2.Zero; | ||
|
||
if (_holdLookUp) | ||
{ | ||
if (_inputSystem.CmdStates.GetState(ContentKeyFunctions.LookUp) != BoundKeyState.Down) | ||
{ | ||
RaiseEvent(offset); | ||
return; | ||
} | ||
} | ||
else if (!_toggled) | ||
{ | ||
RaiseEvent(offset); | ||
return; | ||
} | ||
|
||
var mousePos = _input.MouseScreenPosition; | ||
|
||
if (_uiManager.MouseGetControl(mousePos) as ScalingViewport is { } viewport) | ||
_viewport = viewport; | ||
|
||
if (_viewport == null) | ||
return; | ||
|
||
var centerPos = _eyeManager.WorldToScreen(eye.Eye.Position.Position + eye.Offset); | ||
|
||
var diff = mousePos.Position - centerPos; | ||
var len = diff.Length(); | ||
|
||
var size = _viewport.PixelSize; | ||
|
||
var maxLength = Math.Min(size.X, size.Y) * 0.4f; | ||
var minLength = maxLength * 0.2f; | ||
|
||
if (len > maxLength) | ||
{ | ||
diff *= maxLength / len; | ||
len = maxLength; | ||
} | ||
|
||
var divisor = maxLength * telescope.Divisor; | ||
|
||
if (len > minLength) | ||
{ | ||
diff -= diff * minLength / len; | ||
offset = new Vector2(diff.X / divisor, -diff.Y / divisor); | ||
offset = new Angle(-eye.Rotation.Theta).RotateVec(offset); | ||
} | ||
|
||
RaiseEvent(offset); | ||
} | ||
|
||
private void RaiseEvent(Vector2 offset) | ||
{ | ||
RaisePredictiveEvent(new EyeOffsetChangedEvent | ||
{ | ||
Offset = offset | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Robust.Shared.Serialization.Manager.Attributes; | ||
using Robust.Shared.ViewVariables; | ||
using Content.Server._White.EmpFlashlight; | ||
using Content.Server.Emp; | ||
|
||
namespace Content.Server._White.EmpFlashlight; | ||
|
||
/// <summary> | ||
/// Upon being triggered will EMP target. | ||
/// </summary> | ||
[RegisterComponent] | ||
[Access(typeof(EmpOnHitSystem))] | ||
|
||
public sealed partial class EmpOnHitComponent: Component | ||
{ | ||
[DataField("range"), ViewVariables(VVAccess.ReadWrite)] | ||
public float Range = 1.0f; | ||
|
||
[DataField("energyConsumption"), ViewVariables(VVAccess.ReadWrite)] | ||
public float EnergyConsumption; | ||
|
||
[DataField("disableDuration"), ViewVariables(VVAccess.ReadWrite)] | ||
public float DisableDuration = 60f; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Content.Shared.Weapons.Melee.Events; | ||
using Content.Server.Emp; | ||
using Content.Shared.Charges.Systems; | ||
using Content.Shared.Charges.Components; | ||
|
||
namespace Content.Server._White.EmpFlashlight; | ||
|
||
public sealed class EmpOnHitSystem : EntitySystem | ||
{ | ||
|
||
[Dependency] private readonly EmpSystem _emp = default!; | ||
[Dependency] private readonly SharedChargesSystem _charges = default!; | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<EmpOnHitComponent, MeleeHitEvent>(HandleEmpHit); | ||
} | ||
|
||
public bool TryEmpHit(EntityUid uid, EmpOnHitComponent comp, MeleeHitEvent args) | ||
{ | ||
|
||
if (!TryComp<LimitedChargesComponent>(uid, out LimitedChargesComponent? charges)) | ||
return false; | ||
|
||
if (_charges.IsEmpty(uid, charges)) | ||
return false; | ||
|
||
if (args.HitEntities.Count > 0) | ||
{ | ||
_charges.UseCharge(uid,charges); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private void HandleEmpHit(EntityUid uid, EmpOnHitComponent comp, MeleeHitEvent args) | ||
{ | ||
if (!TryEmpHit(uid, comp, args)) | ||
return; | ||
|
||
foreach (var affected in args.HitEntities) | ||
{ | ||
_emp.EmpPulse(_transform.GetMapCoordinates(affected), comp.Range, comp.EnergyConsumption, comp.DisableDuration); | ||
} | ||
|
||
args.Handled = true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Content.Shared._White.Telescope; | ||
|
||
namespace Content.Server._White.Telescope; | ||
|
||
public sealed class TelescopeSystem : SharedTelescopeSystem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Robust.Shared.Configuration; | ||
|
||
namespace Content.Shared._White; | ||
|
||
[CVarDefs] | ||
public sealed class WhiteCVars | ||
{ | ||
#region Keybind | ||
|
||
public static readonly CVarDef<bool> HoldLookUp = | ||
CVarDef.Create("white.hold_look_up", false, CVar.CLIENT | CVar.ARCHIVE); | ||
|
||
#endregion | ||
} |
117 changes: 117 additions & 0 deletions
117
Content.Shared/_White/Telescope/SharedTelescopeSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System.Numerics; | ||
using Content.Shared.Camera; | ||
using Content.Shared.Hands; | ||
using Content.Shared.Hands.Components; | ||
using Content.Shared.Item; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared._White.Telescope; | ||
|
||
public abstract class SharedTelescopeSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedEyeSystem _eye = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeAllEvent<EyeOffsetChangedEvent>(OnEyeOffsetChanged); | ||
SubscribeLocalEvent<TelescopeComponent, GotUnequippedHandEvent>(OnUnequip); | ||
SubscribeLocalEvent<TelescopeComponent, HandDeselectedEvent>(OnHandDeselected); | ||
SubscribeLocalEvent<TelescopeComponent, ComponentShutdown>(OnShutdown); | ||
} | ||
|
||
private void OnShutdown(Entity<TelescopeComponent> ent, ref ComponentShutdown args) | ||
{ | ||
if (!TryComp(ent.Comp.LastEntity, out EyeComponent? eye) || ent.Comp.LastEntity == ent && TerminatingOrDeleted(ent)) | ||
return; | ||
|
||
SetOffset((ent.Comp.LastEntity.Value, eye), Vector2.Zero, ent); | ||
} | ||
|
||
private void OnHandDeselected(Entity<TelescopeComponent> ent, ref HandDeselectedEvent args) | ||
{ | ||
if (!TryComp(args.User, out EyeComponent? eye)) | ||
return; | ||
|
||
SetOffset((args.User, eye), Vector2.Zero, ent); | ||
} | ||
|
||
private void OnUnequip(Entity<TelescopeComponent> ent, ref GotUnequippedHandEvent args) | ||
{ | ||
if (!TryComp(args.User, out EyeComponent? eye)) | ||
return; | ||
|
||
if (!HasComp<ItemComponent>(ent.Owner)) | ||
return; | ||
|
||
SetOffset((args.User, eye), Vector2.Zero, ent); | ||
} | ||
|
||
public TelescopeComponent? GetRightTelescope(EntityUid? ent) | ||
{ | ||
TelescopeComponent? telescope = null; | ||
|
||
if (TryComp<HandsComponent>(ent, out var hands) && | ||
hands.ActiveHandEntity.HasValue && | ||
TryComp<TelescopeComponent>(hands.ActiveHandEntity, out var handTelescope)) | ||
{ | ||
telescope = handTelescope; | ||
} | ||
else if (TryComp<TelescopeComponent>(ent, out var entityTelescope)) | ||
{ | ||
telescope = entityTelescope; | ||
} | ||
|
||
return telescope; | ||
} | ||
|
||
private void OnEyeOffsetChanged(EyeOffsetChangedEvent msg, EntitySessionEventArgs args) | ||
{ | ||
if (args.SenderSession.AttachedEntity is not { } ent) | ||
return; | ||
|
||
if (!TryComp(ent, out EyeComponent? eye)) | ||
return; | ||
|
||
var telescope = GetRightTelescope(ent); | ||
|
||
if (telescope == null) | ||
return; | ||
|
||
var offset = Vector2.Lerp(eye.Offset, msg.Offset, telescope.LerpAmount); | ||
|
||
SetOffset((ent, eye), offset, telescope); | ||
} | ||
|
||
private void SetOffset(Entity<EyeComponent> ent, Vector2 offset, TelescopeComponent telescope) | ||
{ | ||
telescope.LastEntity = ent; | ||
|
||
if (TryComp(ent, out CameraRecoilComponent? recoil)) | ||
{ | ||
recoil.BaseOffset = offset; | ||
_eye.SetOffset(ent, offset + recoil.CurrentKick, ent); | ||
} | ||
else | ||
{ | ||
_eye.SetOffset(ent, offset, ent); | ||
} | ||
} | ||
|
||
public void SetParameters(Entity<TelescopeComponent> ent, float? divisor = null, float? lerpAmount = null) | ||
{ | ||
var telescope = ent.Comp; | ||
|
||
telescope.Divisor = divisor ?? telescope.Divisor; | ||
telescope.LerpAmount = lerpAmount ?? telescope.LerpAmount; | ||
|
||
Dirty(ent.Owner, telescope); | ||
} | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class EyeOffsetChangedEvent : EntityEventArgs | ||
{ | ||
public Vector2 Offset; | ||
} |
Oops, something went wrong.