-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description This PR adds the ability to transfer objects from one player's hand to another player's hand, as in SS13. I have little coding experience, so my solutions may not be ideal. --- # TODO - [x] Make the code work - [x] Add popup - [x] Write a summary of the code - [x] Сorrect inaccuracies <details><summary><h1>Media</h1></summary> <p> https://youtu.be/zTQWTsYm1gw </p> </details> --- # Changelog :cl: - add: Added system - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --------- Co-authored-by: Danger Revolution! <[email protected]>
- Loading branch information
1 parent
726fd0f
commit c8a9002
Showing
24 changed files
with
559 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
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.OfferItem; | ||
|
||
public sealed class OfferItemIndicatorsOverlay : Overlay | ||
{ | ||
private readonly IInputManager _inputManager; | ||
private readonly IEntityManager _entMan; | ||
private readonly IEyeManager _eye; | ||
private readonly OfferItemSystem _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 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/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.OfferItem; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Input; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Configuration; | ||
|
||
namespace Content.Client.OfferItem; | ||
|
||
public sealed class OfferItemSystem : SharedOfferItemSystem | ||
{ | ||
[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<OfferItemIndicatorsOverlay>(); | ||
|
||
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 OfferItemIndicatorsOverlay( | ||
_inputManager, | ||
EntityManager, | ||
_eye, | ||
this)); | ||
} | ||
else | ||
_overlayManager.RemoveOverlay<OfferItemIndicatorsOverlay>(); | ||
} | ||
} |
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.OfferItem; | ||
using Content.Server.OfferItem; | ||
using Content.Shared.Alert; | ||
using JetBrains.Annotations; | ||
|
||
namespace Content.Server.Alert.Click; | ||
|
||
/// <summary> | ||
/// Accepting the offer and receive item | ||
/// </summary> | ||
[UsedImplicitly] | ||
[DataDefinition] | ||
public sealed partial class AcceptOffer : IAlertClick | ||
{ | ||
public void AlertClicked(EntityUid player) | ||
{ | ||
var entManager = IoCManager.Resolve<IEntityManager>(); | ||
|
||
if (entManager.TryGetComponent(player, out OfferItemComponent? offerItem)) | ||
{ | ||
entManager.System<OfferItemSystem>().Receive(player, offerItem); | ||
} | ||
} | ||
} |
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,83 @@ | ||
using Content.Server.Popups; | ||
using Content.Shared.Hands.Components; | ||
using Content.Shared.Alert; | ||
using Content.Shared.Hands.EntitySystems; | ||
using Content.Shared.OfferItem; | ||
using Content.Shared.IdentityManagement; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Server.OfferItem; | ||
|
||
public sealed class OfferItemSystem : SharedOfferItemSystem | ||
{ | ||
[Dependency] private readonly AlertsSystem _alertsSystem = default!; | ||
[Dependency] private readonly SharedHandsSystem _hands = default!; | ||
[Dependency] private readonly PopupSystem _popup = default!; | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
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 (offerItem.Hand != null && | ||
hands.Hands[offerItem.Hand].HeldEntity == null) | ||
{ | ||
if (offerItem.Target != null) | ||
{ | ||
UnReceive(offerItem.Target.Value, offerItem: offerItem); | ||
offerItem.IsInOfferMode = false; | ||
Dirty(uid, offerItem); | ||
} | ||
else | ||
UnOffer(uid, offerItem); | ||
} | ||
|
||
if (!offerItem.IsInReceiveMode) | ||
{ | ||
_alertsSystem.ClearAlert(uid, AlertType.Offer); | ||
continue; | ||
} | ||
|
||
_alertsSystem.ShowAlert(uid, AlertType.Offer); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Accepting the offer and receive item | ||
/// </summary> | ||
public void Receive(EntityUid uid, OfferItemComponent? component = null) | ||
{ | ||
if (!Resolve(uid, ref component) || | ||
!TryComp<OfferItemComponent>(component.Target, out var offerItem) || | ||
offerItem.Hand == null || | ||
component.Target == null || | ||
!TryComp<HandsComponent>(uid, out var hands)) | ||
return; | ||
|
||
if (offerItem.Item != null) | ||
{ | ||
if (!_hands.TryPickup(uid, offerItem.Item.Value, handsComp: hands)) | ||
{ | ||
_popup.PopupEntity(Loc.GetString("offer-item-full-hand"), uid, uid); | ||
return; | ||
} | ||
|
||
_popup.PopupEntity(Loc.GetString("offer-item-give", | ||
("item", Identity.Entity(offerItem.Item.Value, EntityManager)), | ||
("target", Identity.Entity(uid, EntityManager))), component.Target.Value, component.Target.Value); | ||
_popup.PopupEntity(Loc.GetString("offer-item-give-other", | ||
("user", Identity.Entity(component.Target.Value, EntityManager)), | ||
("item", Identity.Entity(offerItem.Item.Value, EntityManager)), | ||
("target", Identity.Entity(uid, EntityManager))) | ||
, component.Target.Value, Filter.PvsExcept(component.Target.Value, entityManager: EntityManager), true); | ||
} | ||
|
||
offerItem.Item = null; | ||
UnReceive(uid, component, offerItem); | ||
} | ||
} |
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, | ||
Offer, | ||
} | ||
|
||
} |
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,26 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.OfferItem; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] | ||
[Access(typeof(SharedOfferItemSystem))] | ||
public sealed partial class OfferItemComponent : Component | ||
{ | ||
[ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] | ||
public bool IsInOfferMode; | ||
|
||
[DataField, AutoNetworkedField] | ||
public bool IsInReceiveMode; | ||
|
||
[DataField, AutoNetworkedField] | ||
public string? Hand; | ||
|
||
[DataField, AutoNetworkedField] | ||
public EntityUid? Item; | ||
|
||
[DataField, AutoNetworkedField] | ||
public EntityUid? Target; | ||
|
||
[DataField] | ||
public float MaxOfferDistance = 2f; | ||
} |
Oops, something went wrong.