-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
406 additions
and
1 deletion.
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
72 changes: 72 additions & 0 deletions
72
Content.Client/OfferingItem/OfferingItemIndicatorsOverlay.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,72 @@ | ||
using System.Numerics; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Input; | ||
using Robust.Client.UserInterface; | ||
using Robust.Shared.Enums; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Client.OfferingItem; | ||
|
||
public sealed class OfferingItemIndicatorsOverlay : Overlay | ||
{ | ||
private readonly IInputManager _inputManager; | ||
private readonly IEntityManager _entMan; | ||
private readonly IEyeManager _eye; | ||
private readonly OfferingItemSystem _offer; | ||
|
||
private readonly Texture _sight; | ||
|
||
public override OverlaySpace Space => OverlaySpace.ScreenSpace; | ||
|
||
private readonly Color _mainColor = Color.White.WithAlpha(0.3f); | ||
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) | ||
{ | ||
_inputManager = input; | ||
_entMan = entMan; | ||
_eye = eye; | ||
_offer = offerSys; | ||
|
||
var spriteSys = _entMan.EntitySysManager.GetEntitySystem<SpriteSystem>(); | ||
_sight = spriteSys.Frame0(new SpriteSpecifier.Rsi(new ResPath("/Textures/Interface/Misc/give_item.rsi"), | ||
"give_item")); | ||
} | ||
|
||
protected override bool BeforeDraw(in OverlayDrawArgs args) | ||
{ | ||
if (!_offer.IsInOfferMode()) | ||
return false; | ||
|
||
return 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; | ||
|
||
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); | ||
|
||
screen.DrawTextureRect(sight, | ||
UIBox2.FromDimensions(centerPos - sightSize * 0.5f, sightSize), _strokeColor); | ||
screen.DrawTextureRect(sight, | ||
UIBox2.FromDimensions(centerPos - expandedSize * 0.5f, expandedSize), _mainColor); | ||
} | ||
} |
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,51 @@ | ||
using Content.Shared.CCVar; | ||
using Content.Shared.OfferingItem; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Input; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Configuration; | ||
|
||
namespace Content.Client.OfferingItem; | ||
|
||
public sealed class OfferingItemSystem : SharedOfferingItemSystem | ||
{ | ||
[Dependency] private readonly IOverlayManager _overlayManager = default!; | ||
[Dependency] private readonly IPlayerManager _playerManager = default!; | ||
[Dependency] private readonly IConfigurationManager _cfg = default!; | ||
[Dependency] private readonly IInputManager _inputManager = default!; | ||
[Dependency] private readonly IEyeManager _eye = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
Subs.CVar(_cfg, CCVars.OfferModeIndicatorsPointShow, OnShowOfferIndicatorsChanged, true); | ||
} | ||
public override void Shutdown() | ||
{ | ||
_overlayManager.RemoveOverlay<OfferingItemIndicatorsOverlay>(); | ||
|
||
base.Shutdown(); | ||
} | ||
|
||
public bool IsInOfferMode() | ||
{ | ||
var entity = _playerManager.LocalEntity; | ||
|
||
if (entity == null) | ||
return false; | ||
|
||
return IsInOfferMode(entity.Value); | ||
} | ||
private void OnShowOfferIndicatorsChanged(bool isShow) | ||
{ | ||
if (isShow) | ||
{ | ||
_overlayManager.AddOverlay(new OfferingItemIndicatorsOverlay( | ||
_inputManager, | ||
EntityManager, | ||
_eye, | ||
this)); | ||
} | ||
else | ||
_overlayManager.RemoveOverlay<OfferingItemIndicatorsOverlay>(); | ||
} | ||
} |
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
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 Content.Shared.OfferingItem; | ||
using Content.Server.OfferingItem; | ||
using Content.Shared.Alert; | ||
using JetBrains.Annotations; | ||
|
||
namespace Content.Server.Alert.Click; | ||
|
||
/// <summary> | ||
/// Acceptance of the offer | ||
/// </summary> | ||
[UsedImplicitly] | ||
[DataDefinition] | ||
public sealed partial class AcceptingOffer : IAlertClick | ||
{ | ||
public void AlertClicked(EntityUid player) | ||
{ | ||
var entManager = IoCManager.Resolve<IEntityManager>(); | ||
|
||
if (entManager.TryGetComponent(player, out OfferingItemComponent? offeringItem)) | ||
{ | ||
entManager.System<OfferingItemSystem>().Receiving(player, offeringItem); | ||
} | ||
} | ||
} |
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,51 @@ | ||
using Content.Shared.Hands.Components; | ||
using Content.Shared.Alert; | ||
using Content.Shared.Hands.EntitySystems; | ||
using Content.Shared.OfferingItem; | ||
|
||
namespace Content.Server.OfferingItem; | ||
|
||
public sealed class OfferingItemSystem : SharedOfferingItemSystem | ||
{ | ||
[Dependency] private readonly AlertsSystem _alertsSystem = default!; | ||
[Dependency] private readonly SharedHandsSystem _hands = default!; | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
var query = EntityQueryEnumerator<OfferingItemComponent>(); | ||
while (query.MoveNext(out var uid, out var offeringItem)) | ||
{ | ||
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 (!offeringItem.IsInReceiveMode) | ||
{ | ||
_alertsSystem.ClearAlert(uid, AlertType.Offering); | ||
continue; | ||
} | ||
|
||
_alertsSystem.ShowAlert(uid, AlertType.Offering); | ||
} | ||
} | ||
|
||
public void Receiving(EntityUid uid, OfferingItemComponent? component = null) | ||
{ | ||
if (!Resolve(uid, ref component) || | ||
!TryComp<OfferingItemComponent>(component.Target, out var offeringItem) || | ||
offeringItem.Hand == null || | ||
!TryComp<HandsComponent>(uid, out var hands) || | ||
!TryComp<HandsComponent>(component.Target, out var handsTarget)) | ||
return; | ||
|
||
var item = handsTarget.Hands[offeringItem.Hand].HeldEntity; | ||
_hands.TryPickup(component.Target.GetValueOrDefault(), item.GetValueOrDefault(), handsComp:hands); | ||
|
||
UnOffer(uid, component); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -52,7 +52,8 @@ public enum AlertType : byte | |
SuitPower, | ||
BorgHealth, | ||
BorgCrit, | ||
BorgDead | ||
BorgDead, | ||
Offering | ||
} | ||
|
||
} |
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,23 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.OfferingItem; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] | ||
[Access(typeof(SharedOfferingItemSystem))] | ||
public sealed partial class OfferingItemComponent : Component | ||
{ | ||
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] | ||
public bool IsInOfferMode; | ||
|
||
[DataField, AutoNetworkedField] | ||
public bool IsInReceiveMode; | ||
|
||
[DataField, AutoNetworkedField] | ||
public string? Hand; | ||
|
||
[DataField, AutoNetworkedField] | ||
public EntityUid? Target; | ||
|
||
[DataField] | ||
public float MaxOfferDistance = 2f; | ||
} |
73 changes: 73 additions & 0 deletions
73
Content.Shared/OfferingItem/SharedOfferingItemSystem.Interactions.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,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.OfferingItem; | ||
|
||
public abstract partial class SharedOfferingItemSystem | ||
{ | ||
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; | ||
|
||
private void InitializeInteractions() | ||
{ | ||
CommandBinds.Builder | ||
.Bind(ContentKeyFunctions.OfferingItem, InputCmdHandler.FromDelegate(SetInOfferMode, handle: false, outsidePrediction: false)) | ||
.Register<SharedOfferingItemSystem>(); | ||
} | ||
|
||
public override void Shutdown() | ||
{ | ||
base.Shutdown(); | ||
|
||
CommandBinds.Unregister<SharedOfferingItemSystem>(); | ||
} | ||
|
||
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<OfferingItemComponent>(uid, out var offeringItem)) | ||
return; | ||
|
||
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHand == null) | ||
return; | ||
|
||
var handItem = hands.ActiveHand.HeldEntity; | ||
|
||
if (offeringItem.IsInOfferMode == false) | ||
{ | ||
if (handItem == null) | ||
return; | ||
|
||
if (offeringItem.Hand == null || offeringItem.Target == null) | ||
{ | ||
offeringItem.IsInOfferMode = true; | ||
offeringItem.Hand = hands.ActiveHand.Name; | ||
|
||
Dirty(uid, offeringItem); | ||
return; | ||
} | ||
|
||
if (TryComp<OfferingItemComponent>(offeringItem.Target, out var offeringItemTarget)) | ||
{ | ||
offeringItemTarget.IsInReceiveMode = false; | ||
offeringItemTarget.Target = null; | ||
|
||
Dirty(offeringItem.Target.Value, offeringItemTarget); | ||
} | ||
} | ||
|
||
offeringItem.Hand = null; | ||
offeringItem.IsInOfferMode = false; | ||
offeringItem.Target = null; | ||
|
||
Dirty(uid, offeringItem); | ||
} | ||
} |
Oops, something went wrong.