Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FireNameFN committed Nov 10, 2024
1 parent a9f29fd commit 4759bf0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 67 deletions.
23 changes: 8 additions & 15 deletions Content.Client/_CorvaxNext/OfferItem/OfferItemIndicatorsOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,43 @@ 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;
_eye = eye;
_offer = offerSys;

var spriteSys = _entMan.EntitySysManager.GetEntitySystem<SpriteSystem>();
_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);
}

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);
}
}
20 changes: 5 additions & 15 deletions Content.Server/_CorvaxNext/OfferItemSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,28 @@ 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<OfferItemComponent,HandsComponent>();
var query = EntityQueryEnumerator<OfferItemComponent, HandsComponent>();
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;
Dirty(uid, offerItem);
}
else
UnOffer(uid, offerItem);
}

if (!offerItem.IsInReceiveMode)
{
Expand All @@ -53,6 +45,4 @@ public override void Update(float frameTime)
_alertsSystem.ShowAlert(uid, OfferAlert);
}
}


}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<OfferItemComponent>(uid, out var offerItem))
return;

if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHand == null)
if (!TryComp<HandsComponent>(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;
Expand All @@ -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;
Expand Down
59 changes: 31 additions & 28 deletions Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,21 +16,22 @@ public abstract partial class SharedOfferItemSystem : EntitySystem
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _timing = default!;

[ValidatePrototypeId<AlertPrototype>]
protected const string OfferAlert = "Offer";

public override void Initialize()
{
SubscribeLocalEvent<OfferItemComponent, InteractUsingEvent>(SetInReceiveMode);
SubscribeLocalEvent<OfferItemComponent, MoveEvent>(OnMove);

InitializeInteractions();

SubscribeLocalEvent<OfferItemComponent,AcceptOfferAlertEvent>(OnClickAlertEvent);
SubscribeLocalEvent<OfferItemComponent, AcceptOfferAlertEvent>(OnClickAlertEvent);
}

[ValidatePrototypeId<AlertPrototype>]
protected const string OfferAlert = "Offer";
private void OnClickAlertEvent(Entity<OfferItemComponent> ent, ref AcceptOfferAlertEvent ev)
{
if(ev.Handled)
if (ev.Handled)
return;

if (ev.AlertId != OfferAlert)
Expand All @@ -49,14 +49,22 @@ public void Receive(Entity<OfferItemComponent?> ent)
if (!_timing.IsFirstTimePredicted)
return;

if (!Resolve(ent, ref ent.Comp) ||
!TryComp<OfferItemComponent>(ent.Comp.Target, out var offerItem) ||
offerItem.Hand == null ||
ent.Comp.Target == null ||
!TryComp<HandsComponent>(ent, out var hands))
if (!Resolve(ent, ref ent.Comp))
return;

if (!TryComp<OfferItemComponent>(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<HandsComponent>(ent, out var hands))
return;

if (offerItem.Item is not null)
{
if (!_hands.TryPickup(ent, offerItem.Item.Value, handsComp: hands))
{
Expand Down Expand Up @@ -85,8 +93,7 @@ private void SetInReceiveMode(EntityUid uid, OfferItemComponent component, Inter
if (!TryComp<OfferItemComponent>(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;
Expand Down Expand Up @@ -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)
Expand All @@ -129,13 +136,12 @@ private void OnMove(EntityUid uid, OfferItemComponent component, MoveEvent args)
/// </summary>
protected void UnOffer(EntityUid uid, OfferItemComponent component)
{
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHand == null)
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHand is null)
return;

if (TryComp<OfferItemComponent>(component.Target, out var offerItem) && component.Target != null)
if (TryComp<OfferItemComponent>(component.Target, out var offerItem) && component.Target is not null)
{

if (component.Item != null)
if (component.Item is not null)
{
if (!_timing.IsFirstTimePredicted)
{
Expand All @@ -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",
Expand All @@ -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;
Expand All @@ -186,17 +189,17 @@ protected void UnOffer(EntityUid uid, OfferItemComponent component)
/// </summary>
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<HandsComponent>(uid, out var hands) || hands.ActiveHand == null ||
component.Target == null)
if (!TryComp<HandsComponent>(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)),
Expand Down Expand Up @@ -224,6 +227,6 @@ protected void UnReceive(EntityUid uid, OfferItemComponent? component = null, Of
/// </summary>
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;
}
}

0 comments on commit 4759bf0

Please sign in to comment.