Skip to content

Commit

Permalink
Merge branch 'WWhiteDreamProject:master' into Ru-translation
Browse files Browse the repository at this point in the history
  • Loading branch information
6Mirage6 authored Aug 23, 2024
2 parents c149d70 + b985fc9 commit e7c1e17
Show file tree
Hide file tree
Showing 20 changed files with 429 additions and 0 deletions.
1 change: 1 addition & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.Arcade1);
human.AddFunction(ContentKeyFunctions.Arcade2);
human.AddFunction(ContentKeyFunctions.Arcade3);
human.AddFunction(ContentKeyFunctions.LookUp); // WD EDIT

// actions should be common (for ghosts, mobs, etc)
common.AddFunction(ContentKeyFunctions.OpenActionsMenu);
Expand Down
9 changes: 9 additions & 0 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Numerics;
using Content.Client.Stylesheets;
using Content.Shared._White;
using Content.Shared.CCVar;
using Content.Shared.Input;
using Robust.Client.AutoGenerated;
Expand Down Expand Up @@ -97,6 +98,12 @@ private void HandleToggleWalk(BaseButton.ButtonToggledEventArgs args)
_deferCommands.Add(_inputManager.SaveToUserData);
}

private void HandleHoldLookUp(BaseButton.ButtonToggledEventArgs args) // WD EDIT
{
_cfg.SetCVar(WhiteCVars.HoldLookUp, args.Pressed);
_cfg.SaveToFile();
}

private void HandleStaticStorageUI(BaseButton.ButtonToggledEventArgs args)
{
_cfg.SetCVar(CCVars.StaticStorageUI, args.Pressed);
Expand Down Expand Up @@ -186,6 +193,8 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.OfferItem);
AddButton(ContentKeyFunctions.SaveItemLocation);
AddButton(ContentKeyFunctions.ToggleStanding);
AddButton(ContentKeyFunctions.LookUp); // WD EDIT
AddCheckBox("ui-options-function-hold-look-up", _cfg.GetCVar(WhiteCVars.HoldLookUp), HandleHoldLookUp); // WD EDIT

AddHeader("ui-options-header-interaction-adv");
AddButton(ContentKeyFunctions.SmartEquipBackpack);
Expand Down
126 changes: 126 additions & 0 deletions Content.Client/_White/Telescope/TelescopeSystem.cs
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
});
}
}
24 changes: 24 additions & 0 deletions Content.Server/_White/EmpFlashlight/EmpOnHitComponent.cs
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;
}
52 changes: 52 additions & 0 deletions Content.Server/_White/EmpFlashlight/EmpOnHitSystem.cs
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;
}
}

5 changes: 5 additions & 0 deletions Content.Server/_White/Telescope/TelescopeSystem.cs
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;
1 change: 1 addition & 0 deletions Content.Shared/Input/ContentKeyFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static class ContentKeyFunctions
public static readonly BoundKeyFunction ResetZoom = "ResetZoom";
public static readonly BoundKeyFunction OfferItem = "OfferItem";
public static readonly BoundKeyFunction ToggleStanding = "ToggleStanding";
public static readonly BoundKeyFunction LookUp = "LookUp"; // WD EDIT

public static readonly BoundKeyFunction ArcadeUp = "ArcadeUp";
public static readonly BoundKeyFunction ArcadeDown = "ArcadeDown";
Expand Down
14 changes: 14 additions & 0 deletions Content.Shared/_White/CVars.cs
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 Content.Shared/_White/Telescope/SharedTelescopeSystem.cs
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;
}
Loading

0 comments on commit e7c1e17

Please sign in to comment.