Skip to content

Commit

Permalink
English is not my thing
Browse files Browse the repository at this point in the history
  • Loading branch information
Spatison committed Jun 18, 2024
1 parent ad13a4f commit b5a1617
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 190 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(ContentKeyFunctions.SmartEquipBelt);
human.AddFunction(ContentKeyFunctions.OpenBackpack);
human.AddFunction(ContentKeyFunctions.OpenBelt);
human.AddFunction(ContentKeyFunctions.OfferingItem);
human.AddFunction(ContentKeyFunctions.OfferItem);
human.AddFunction(ContentKeyFunctions.MouseMiddle);
human.AddFunction(ContentKeyFunctions.ArcadeUp);
human.AddFunction(ContentKeyFunctions.ArcadeDown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
using Robust.Shared.Enums;
using Robust.Shared.Utility;

namespace Content.Client.OfferingItem;
namespace Content.Client.OfferItem;

public sealed class OfferingItemIndicatorsOverlay : Overlay
public sealed class OfferItemIndicatorsOverlay : Overlay
{
private readonly IInputManager _inputManager;
private readonly IEntityManager _entMan;
private readonly IEyeManager _eye;
private readonly OfferingItemSystem _offer;
private readonly OfferItemSystem _offer;

private readonly Texture _sight;

Expand All @@ -23,8 +23,8 @@ public sealed class OfferingItemIndicatorsOverlay : Overlay
private readonly Color _strokeColor = Color.Black.WithAlpha(0.5f);
private readonly float _scale = 0.6f; // 1 is a little big

public OfferingItemIndicatorsOverlay(IInputManager input, IEntityManager entMan,
IEyeManager eye, OfferingItemSystem offerSys)
public OfferItemIndicatorsOverlay(IInputManager input, IEntityManager entMan,
IEyeManager eye, OfferItemSystem offerSys)
{
_inputManager = input;
_entMan = entMan;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Content.Shared.CCVar;
using Content.Shared.OfferingItem;
using Content.Shared.OfferItem;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Shared.Configuration;

namespace Content.Client.OfferingItem;
namespace Content.Client.OfferItem;

public sealed class OfferingItemSystem : SharedOfferingItemSystem
public sealed class OfferItemSystem : SharedOfferItemSystem
{
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
Expand All @@ -21,7 +21,7 @@ public override void Initialize()
}
public override void Shutdown()
{
_overlayManager.RemoveOverlay<OfferingItemIndicatorsOverlay>();
_overlayManager.RemoveOverlay<OfferItemIndicatorsOverlay>();

base.Shutdown();
}
Expand All @@ -39,13 +39,13 @@ private void OnShowOfferIndicatorsChanged(bool isShow)
{
if (isShow)
{
_overlayManager.AddOverlay(new OfferingItemIndicatorsOverlay(
_overlayManager.AddOverlay(new OfferItemIndicatorsOverlay(
_inputManager,
EntityManager,
_eye,
this));
}
else
_overlayManager.RemoveOverlay<OfferingItemIndicatorsOverlay>();
_overlayManager.RemoveOverlay<OfferItemIndicatorsOverlay>();
}
}
2 changes: 1 addition & 1 deletion Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.SwapHands);
AddButton(ContentKeyFunctions.MoveStoredItem);
AddButton(ContentKeyFunctions.RotateStoredItem);
AddButton(ContentKeyFunctions.OfferingItem);
AddButton(ContentKeyFunctions.OfferItem);

AddHeader("ui-options-header-interaction-adv");
AddButton(ContentKeyFunctions.SmartEquipBackpack);
Expand Down
10 changes: 5 additions & 5 deletions Content.Server/Alert/Click/AcceptingOffer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Content.Shared.OfferingItem;
using Content.Server.OfferingItem;
using Content.Shared.OfferItem;
using Content.Server.OfferItem;
using Content.Shared.Alert;
using JetBrains.Annotations;

Expand All @@ -10,15 +10,15 @@ namespace Content.Server.Alert.Click;
/// </summary>
[UsedImplicitly]
[DataDefinition]
public sealed partial class AcceptingOffer : IAlertClick
public sealed partial class AcceptOffer : IAlertClick
{
public void AlertClicked(EntityUid player)
{
var entManager = IoCManager.Resolve<IEntityManager>();

if (entManager.TryGetComponent(player, out OfferingItemComponent? offeringItem))
if (entManager.TryGetComponent(player, out OfferItemComponent? offerItem))
{
entManager.System<OfferingItemSystem>().Receiving(player, offeringItem);
entManager.System<OfferItemSystem>().Receiving(player, offerItem);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Content.Shared.Hands.Components;
using Content.Shared.Alert;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.OfferingItem;
using Content.Shared.OfferItem;

namespace Content.Server.OfferingItem;
namespace Content.Server.OfferItem;

public sealed class OfferingItemSystem : SharedOfferingItemSystem
public sealed class OfferItemSystem : SharedOfferItemSystem
{
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
Expand All @@ -14,36 +14,36 @@ public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<OfferingItemComponent>();
while (query.MoveNext(out var uid, out var offeringItem))
var query = EntityQueryEnumerator<OfferItemComponent>();
while (query.MoveNext(out var uid, out var offerItem))
{
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHand == null)
continue;

if (offeringItem.Hand != null &&
hands.Hands[offeringItem.Hand].HeldEntity == null)
UnOffer(uid, offeringItem);
if (offerItem.Hand != null &&
hands.Hands[offerItem.Hand].HeldEntity == null)
UnOffer(uid, offerItem);

if (!offeringItem.IsInReceiveMode)
if (!offerItem.IsInReceiveMode)
{
_alertsSystem.ClearAlert(uid, AlertType.Offering);
_alertsSystem.ClearAlert(uid, AlertType.Offer);
continue;
}

_alertsSystem.ShowAlert(uid, AlertType.Offering);
_alertsSystem.ShowAlert(uid, AlertType.Offer);
}
}

public void Receiving(EntityUid uid, OfferingItemComponent? component = null)
public void Receiving(EntityUid uid, OfferItemComponent? component = null)
{
if (!Resolve(uid, ref component) ||
!TryComp<OfferingItemComponent>(component.Target, out var offeringItem) ||
offeringItem.Hand == null ||
!TryComp<OfferItemComponent>(component.Target, out var offerItem) ||
offerItem.Hand == null ||
!TryComp<HandsComponent>(uid, out var hands) ||
!TryComp<HandsComponent>(component.Target, out var handsTarget))
return;

var item = handsTarget.Hands[offeringItem.Hand].HeldEntity;
var item = handsTarget.Hands[offerItem.Hand].HeldEntity;
_hands.TryPickup(component.Target.GetValueOrDefault(), item.GetValueOrDefault(), handsComp:hands);

UnOffer(uid, component);
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Alert/AlertType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum AlertType : byte
BorgHealth,
BorgCrit,
BorgDead,
Offering
Offer
}

}
2 changes: 1 addition & 1 deletion Content.Shared/Input/ContentKeyFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static class ContentKeyFunctions
public static readonly BoundKeyFunction ZoomOut = "ZoomOut";
public static readonly BoundKeyFunction ZoomIn = "ZoomIn";
public static readonly BoundKeyFunction ResetZoom = "ResetZoom";
public static readonly BoundKeyFunction OfferingItem = "OfferingItem";
public static readonly BoundKeyFunction OfferItem = "OfferItem";

public static readonly BoundKeyFunction ArcadeUp = "ArcadeUp";
public static readonly BoundKeyFunction ArcadeDown = "ArcadeDown";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Robust.Shared.GameStates;

namespace Content.Shared.OfferingItem;
namespace Content.Shared.OfferItem;

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
[Access(typeof(SharedOfferingItemSystem))]
public sealed partial class OfferingItemComponent : Component
[Access(typeof(SharedOfferItemSystem))]
public sealed partial class OfferItemComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
public bool IsInOfferMode;
Expand Down
73 changes: 73 additions & 0 deletions Content.Shared/OfferItem/SharedOfferItemSystem.Interactions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Input;
using Content.Shared.Hands.Components;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;

namespace Content.Shared.OfferItem;

public abstract partial class SharedOfferItemSystem
{
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;

private void InitializeInteractions()
{
CommandBinds.Builder
.Bind(ContentKeyFunctions.OfferItem, InputCmdHandler.FromDelegate(SetInOfferMode, handle: false, outsidePrediction: false))
.Register<SharedOfferItemSystem>();
}

public override void Shutdown()
{
base.Shutdown();

CommandBinds.Unregister<SharedOfferItemSystem>();
}

private void SetInOfferMode(ICommonSession? session)
{
if (session is not { } playerSession)
return;

if ((playerSession.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)
return;

var handItem = hands.ActiveHand.HeldEntity;

if (offerItem.IsInOfferMode == false)
{
if (handItem == null)
return;

if (offerItem.Hand == null || offerItem.Target == null)
{
offerItem.IsInOfferMode = true;
offerItem.Hand = hands.ActiveHand.Name;

Dirty(uid, offerItem);
return;
}

if (TryComp<OfferItemComponent>(offerItem.Target, out var offerItemTarget))
{
offerItemTarget.IsInReceiveMode = false;
offerItemTarget.Target = null;

Dirty(offerItem.Target.Value, offerItemTarget);
}
}

offerItem.Hand = null;
offerItem.IsInOfferMode = false;
offerItem.Target = null;

Dirty(uid, offerItem);
}
}
67 changes: 67 additions & 0 deletions Content.Shared/OfferItem/SharedOfferItemSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Content.Shared.Interaction;

namespace Content.Shared.OfferItem;

public abstract partial class SharedOfferItemSystem : EntitySystem
{
[Dependency] private readonly SharedTransformSystem _transform = default!;

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

InitializeInteractions();
}

private void SetInReceiveMode(EntityUid uid, OfferItemComponent component, AfterInteractUsingEvent args)
{
if (!TryComp<OfferItemComponent>(args.User, out var offerItem))
return;

component.IsInReceiveMode = true;
component.Target = args.User;

Dirty(uid, component);

offerItem.Target = uid;
offerItem.IsInOfferMode = false;

Dirty(args.User, offerItem);
}

private void OnMove(EntityUid uid, OfferItemComponent component, MoveEvent args)
{
if (component.Target == null ||
args.NewPosition.InRange(EntityManager, _transform,
Transform(component.Target.GetValueOrDefault()).Coordinates, component.MaxOfferDistance))
return;

UnOffer(uid, component);
}

protected void UnOffer(EntityUid uid, OfferItemComponent component)
{
if (TryComp<OfferItemComponent>(component.Target, out var offerItem) && component.Target != null)
{
offerItem.IsInOfferMode = false;
offerItem.IsInReceiveMode = false;
offerItem.Hand = null;
offerItem.Target = null;

Dirty(component.Target.Value, offerItem);
}

component.IsInOfferMode = false;
component.IsInReceiveMode = false;
component.Hand = null;
component.Target = null;

Dirty(uid, component);
}

public bool IsInOfferMode(EntityUid? entity, OfferItemComponent? component = null)
{
return entity != null && Resolve(entity.Value, ref component, false) && component.IsInOfferMode;
}
}
Loading

0 comments on commit b5a1617

Please sign in to comment.