From 4759bf052823728b056567ea4c7ea772dbd9612e Mon Sep 17 00:00:00 2001 From: FN Date: Sun, 10 Nov 2024 08:05:29 +0700 Subject: [PATCH] Fixes --- .../OfferItem/OfferItemIndicatorsOverlay.cs | 23 +++----- Content.Server/_CorvaxNext/OfferItemSystem.cs | 20 ++----- .../SharedOfferItemSystem.Interactions.cs | 16 +++-- .../OfferItem/SharedOfferItemSystem.cs | 59 ++++++++++--------- .../interaction/offer-item-system.ftl | 0 5 files changed, 51 insertions(+), 67 deletions(-) rename Resources/Locale/ru-RU/{ => _CorvaxNext}/interaction/offer-item-system.ftl (100%) diff --git a/Content.Client/_CorvaxNext/OfferItem/OfferItemIndicatorsOverlay.cs b/Content.Client/_CorvaxNext/OfferItem/OfferItemIndicatorsOverlay.cs index 8b3e7f587a6..a233ec833ec 100644 --- a/Content.Client/_CorvaxNext/OfferItem/OfferItemIndicatorsOverlay.cs +++ b/Content.Client/_CorvaxNext/OfferItem/OfferItemIndicatorsOverlay.cs @@ -23,8 +23,7 @@ public sealed class OfferItemIndicatorsOverlay : Overlay private readonly Color _strokeColor = Color.Black.WithAlpha(0.5f); private readonly float _scale = 0.6f; // 1 is a little big - public OfferItemIndicatorsOverlay(IInputManager input, IEntityManager entMan, - IEyeManager eye, OfferItemSystem offerSys) + public OfferItemIndicatorsOverlay(IInputManager input, IEntityManager entMan, IEyeManager eye, OfferItemSystem offerSys) { _inputManager = input; _entMan = entMan; @@ -32,29 +31,25 @@ public OfferItemIndicatorsOverlay(IInputManager input, IEntityManager entMan, _offer = offerSys; var spriteSys = _entMan.EntitySysManager.GetEntitySystem(); - _sight = spriteSys.Frame0(new SpriteSpecifier.Rsi(new ResPath("/Textures/_CorvaxNext/Misc/give_item.rsi"), - "give_item")); + _sight = spriteSys.Frame0(new SpriteSpecifier.Rsi(new ResPath("/Textures/_CorvaxNext/Misc/give_item.rsi"), "give_item")); } protected override bool BeforeDraw(in OverlayDrawArgs args) { - if (!_offer.IsInOfferMode()) - return false; - - return base.BeforeDraw(in args); + return _offer.IsInOfferMode() && base.BeforeDraw(in args); } protected override void Draw(in OverlayDrawArgs args) { var mouseScreenPosition = _inputManager.MouseScreenPosition; var mousePosMap = _eye.PixelToMap(mouseScreenPosition); + if (mousePosMap.MapId != args.MapId) return; - var mousePos = mouseScreenPosition.Position; var uiScale = (args.ViewportControl as Control)?.UIScale ?? 1f; - var limitedScale = uiScale > 1.25f ? 1.25f : uiScale; + var limitedScale = Math.Min(1.25f, uiScale); DrawSight(_sight, args.ScreenHandle, mousePos, limitedScale * _scale); } @@ -62,11 +57,9 @@ protected override void Draw(in OverlayDrawArgs args) private void DrawSight(Texture sight, DrawingHandleScreen screen, Vector2 centerPos, float scale) { var sightSize = sight.Size * scale; - var expandedSize = sightSize + new Vector2(7f, 7f); + var expandedSize = sightSize + new Vector2(7); - screen.DrawTextureRect(sight, - UIBox2.FromDimensions(centerPos - sightSize * 0.5f, sightSize), _strokeColor); - screen.DrawTextureRect(sight, - UIBox2.FromDimensions(centerPos - expandedSize * 0.5f, expandedSize), _mainColor); + screen.DrawTextureRect(sight, UIBox2.FromDimensions(centerPos - sightSize * 0.5f, sightSize), _strokeColor); + screen.DrawTextureRect(sight, UIBox2.FromDimensions(centerPos - expandedSize * 0.5f, expandedSize), _mainColor); } } diff --git a/Content.Server/_CorvaxNext/OfferItemSystem.cs b/Content.Server/_CorvaxNext/OfferItemSystem.cs index d8af26f97ad..b21512ec065 100644 --- a/Content.Server/_CorvaxNext/OfferItemSystem.cs +++ b/Content.Server/_CorvaxNext/OfferItemSystem.cs @@ -13,28 +13,21 @@ public sealed class OfferItemSystem : SharedOfferItemSystem public override void Update(float frameTime) { - base.Update(frameTime); - _offerAcc += frameTime; + if (_offerAcc >= OfferAccMax) - { _offerAcc -= OfferAccMax; - } else - { return; - } - var query = EntityQueryEnumerator(); + var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var offerItem, out var hands)) { - if (hands.ActiveHand == null) + if (hands.ActiveHand is null) continue; - if (offerItem.Hand != null && - hands.Hands[offerItem.Hand].HeldEntity == null) - { - if (offerItem.Target != null) + if (offerItem.Hand is not null && hands.Hands[offerItem.Hand].HeldEntity is null) + if (offerItem.Target is not null) { UnReceive(offerItem.Target.Value, offerItem: offerItem); offerItem.IsInOfferMode = false; @@ -42,7 +35,6 @@ public override void Update(float frameTime) } else UnOffer(uid, offerItem); - } if (!offerItem.IsInReceiveMode) { @@ -53,6 +45,4 @@ public override void Update(float frameTime) _alertsSystem.ShowAlert(uid, OfferAlert); } } - - } diff --git a/Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.Interactions.cs b/Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.Interactions.cs index efc573d8278..2c54c0aa606 100644 --- a/Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.Interactions.cs +++ b/Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.Interactions.cs @@ -1,7 +1,6 @@ using Content.Shared.ActionBlocker; using Content.Shared.Hands.Components; using Content.Shared.Input; -using Content.Shared.Popups; using Robust.Shared.Input.Binding; using Robust.Shared.Player; @@ -30,30 +29,29 @@ private void SetInOfferMode(ICommonSession? session) if (!_timing.IsFirstTimePredicted) return; - if (session is not { } playerSession) + if (session is null) return; - if ((playerSession.AttachedEntity is not { Valid: true } uid || !Exists(uid)) || - !_actionBlocker.CanInteract(uid, null)) + if (session.AttachedEntity is not { Valid: true } uid || !Exists(uid) || !_actionBlocker.CanInteract(uid, null)) return; if (!TryComp(uid, out var offerItem)) return; - if (!TryComp(uid, out var hands) || hands.ActiveHand == null) + if (!TryComp(uid, out var hands) || hands.ActiveHand is null) return; offerItem.Item = hands.ActiveHand.HeldEntity; - if (offerItem.IsInOfferMode == false) + if (!offerItem.IsInOfferMode) { - if (offerItem.Item == null) + if (offerItem.Item is null) { _popup.PopupEntity(Loc.GetString("offer-item-empty-hand"), uid, uid); return; } - if (offerItem.Hand == null || offerItem.Target == null) + if (offerItem.Hand is null || offerItem.Target is null) { offerItem.IsInOfferMode = true; offerItem.Hand = hands.ActiveHand.Name; @@ -63,7 +61,7 @@ private void SetInOfferMode(ICommonSession? session) } } - if (offerItem.Target != null) + if (offerItem.Target is not null) { UnReceive(offerItem.Target.Value, offerItem: offerItem); offerItem.IsInOfferMode = false; diff --git a/Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.cs b/Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.cs index 5df594d3c80..ddcf774aef1 100644 --- a/Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.cs +++ b/Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.cs @@ -5,7 +5,6 @@ using Content.Shared.IdentityManagement; using Content.Shared.Interaction; using Content.Shared.Popups; -using Robust.Shared.Player; using Robust.Shared.Timing; namespace Content.Shared._CorvaxNext.OfferItem; @@ -17,6 +16,9 @@ public abstract partial class SharedOfferItemSystem : EntitySystem [Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly IGameTiming _timing = default!; + [ValidatePrototypeId] + protected const string OfferAlert = "Offer"; + public override void Initialize() { SubscribeLocalEvent(SetInReceiveMode); @@ -24,14 +26,12 @@ public override void Initialize() InitializeInteractions(); - SubscribeLocalEvent(OnClickAlertEvent); + SubscribeLocalEvent(OnClickAlertEvent); } - [ValidatePrototypeId] - protected const string OfferAlert = "Offer"; private void OnClickAlertEvent(Entity ent, ref AcceptOfferAlertEvent ev) { - if(ev.Handled) + if (ev.Handled) return; if (ev.AlertId != OfferAlert) @@ -49,14 +49,22 @@ public void Receive(Entity ent) if (!_timing.IsFirstTimePredicted) return; - if (!Resolve(ent, ref ent.Comp) || - !TryComp(ent.Comp.Target, out var offerItem) || - offerItem.Hand == null || - ent.Comp.Target == null || - !TryComp(ent, out var hands)) + if (!Resolve(ent, ref ent.Comp)) + return; + + if (!TryComp(ent.Comp.Target, out var offerItem)) + return; + + if (offerItem.Hand is null) return; - if (offerItem.Item != null) + if (ent.Comp.Target is null) + return; + + if (!TryComp(ent, out var hands)) + return; + + if (offerItem.Item is not null) { if (!_hands.TryPickup(ent, offerItem.Item.Value, handsComp: hands)) { @@ -85,8 +93,7 @@ private void SetInReceiveMode(EntityUid uid, OfferItemComponent component, Inter if (!TryComp(args.User, out var offerItem)) return; - if (args.User == uid || component.IsInReceiveMode || !offerItem.IsInOfferMode || - (offerItem.IsInReceiveMode && offerItem.Target != uid)) + if (args.User == uid || component.IsInReceiveMode || !offerItem.IsInOfferMode || offerItem.IsInReceiveMode && offerItem.Target != uid) return; component.IsInReceiveMode = true; @@ -114,7 +121,7 @@ private void SetInReceiveMode(EntityUid uid, OfferItemComponent component, Inter private void OnMove(EntityUid uid, OfferItemComponent component, MoveEvent args) { - if (component.Target == null || + if (component.Target is null || _transform.InRange(args.NewPosition, Transform(component.Target.Value).Coordinates, component.MaxOfferDistance) @@ -129,13 +136,12 @@ private void OnMove(EntityUid uid, OfferItemComponent component, MoveEvent args) /// protected void UnOffer(EntityUid uid, OfferItemComponent component) { - if (!TryComp(uid, out var hands) || hands.ActiveHand == null) + if (!TryComp(uid, out var hands) || hands.ActiveHand is null) return; - if (TryComp(component.Target, out var offerItem) && component.Target != null) + if (TryComp(component.Target, out var offerItem) && component.Target is not null) { - - if (component.Item != null) + if (component.Item is not null) { if (!_timing.IsFirstTimePredicted) { @@ -148,9 +154,7 @@ protected void UnOffer(EntityUid uid, OfferItemComponent component) } } - - else if (offerItem.Item != null) - { + else if (offerItem.Item is not null) if (!_timing.IsFirstTimePredicted) { _popup.PopupClient(Loc.GetString("offer-item-no-give", @@ -160,7 +164,6 @@ protected void UnOffer(EntityUid uid, OfferItemComponent component) ("user", Identity.Entity(component.Target.Value, EntityManager)), ("item", Identity.Entity(offerItem.Item.Value, EntityManager))), component.Target.Value, uid); } - } offerItem.IsInOfferMode = false; offerItem.IsInReceiveMode = false; @@ -186,17 +189,17 @@ protected void UnOffer(EntityUid uid, OfferItemComponent component) /// protected void UnReceive(EntityUid uid, OfferItemComponent? component = null, OfferItemComponent? offerItem = null) { - if (component == null && !TryComp(uid, out component)) + if (component is null && !TryComp(uid, out component)) return; - if (offerItem == null && !TryComp(component.Target, out offerItem)) + if (offerItem is null && !TryComp(component.Target, out offerItem)) return; - if (!TryComp(uid, out var hands) || hands.ActiveHand == null || - component.Target == null) + if (!TryComp(uid, out var hands) || hands.ActiveHand is null || + component.Target is null) return; - if (offerItem.Item != null) + if (offerItem.Item is not null) { _popup.PopupClient(Loc.GetString("offer-item-no-give", ("item", Identity.Entity(offerItem.Item.Value, EntityManager)), @@ -224,6 +227,6 @@ protected void UnReceive(EntityUid uid, OfferItemComponent? component = null, Of /// protected bool IsInOfferMode(EntityUid? entity, OfferItemComponent? component = null) { - return entity != null && Resolve(entity.Value, ref component, false) && component.IsInOfferMode; + return entity is not null && Resolve(entity.Value, ref component, false) && component.IsInOfferMode; } } diff --git a/Resources/Locale/ru-RU/interaction/offer-item-system.ftl b/Resources/Locale/ru-RU/_CorvaxNext/interaction/offer-item-system.ftl similarity index 100% rename from Resources/Locale/ru-RU/interaction/offer-item-system.ftl rename to Resources/Locale/ru-RU/_CorvaxNext/interaction/offer-item-system.ftl