From c8a9002efc6ac89c280e95900f2ab70d5d9e89cb Mon Sep 17 00:00:00 2001 From: Spatison <137375981+Spatison@users.noreply.github.com> Date: Sat, 6 Jul 2024 03:19:35 +0300 Subject: [PATCH] Add Item Transfer System (#476) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 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

Media

https://youtu.be/zTQWTsYm1gw

--- # Changelog :cl: - add: Added system - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --------- Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com> --- Content.Client/Input/ContentContexts.cs | 1 + .../OfferItem/OfferItemIndicatorsOverlay.cs | 72 ++++++++ Content.Client/OfferItem/OfferItemSystem.cs | 51 ++++++ .../Options/UI/Tabs/KeyRebindTab.xaml.cs | 1 + Content.Client/Options/UI/Tabs/MiscTab.xaml | 1 + .../Options/UI/Tabs/MiscTab.xaml.cs | 5 + Content.Server/Alert/Click/AcceptingOffer.cs | 24 +++ Content.Server/OfferItem/OfferItemSystem.cs | 83 ++++++++++ Content.Shared/Alert/AlertType.cs | 3 +- Content.Shared/CCVar/CCVars.cs | 3 + Content.Shared/Input/ContentKeyFunctions.cs | 1 + .../OfferItem/OfferItemComponent.cs | 26 +++ .../SharedOfferItemSystem.Interactions.cs | 74 +++++++++ .../OfferItem/SharedOfferItemSystem.cs | 155 ++++++++++++++++++ Resources/Locale/en-US/alerts/alerts.ftl | 3 + .../en-US/escape-menu/ui/options-menu.ftl | 2 + .../en-US/interaction/offer-item-system.ftl | 13 ++ Resources/Prototypes/Alerts/alerts.yml | 10 ++ .../Prototypes/Entities/Mobs/Species/base.yml | 1 + .../Interface/Alerts/offer_item.rsi/meta.json | 14 ++ .../Alerts/offer_item.rsi/offer_item.png | Bin 0 -> 556 bytes .../Misc/give_item.rsi/give_item.png | Bin 0 -> 7276 bytes .../Interface/Misc/give_item.rsi/meta.json | 14 ++ Resources/keybinds.yml | 3 + 24 files changed, 559 insertions(+), 1 deletion(-) create mode 100644 Content.Client/OfferItem/OfferItemIndicatorsOverlay.cs create mode 100644 Content.Client/OfferItem/OfferItemSystem.cs create mode 100644 Content.Server/Alert/Click/AcceptingOffer.cs create mode 100644 Content.Server/OfferItem/OfferItemSystem.cs create mode 100644 Content.Shared/OfferItem/OfferItemComponent.cs create mode 100644 Content.Shared/OfferItem/SharedOfferItemSystem.Interactions.cs create mode 100644 Content.Shared/OfferItem/SharedOfferItemSystem.cs create mode 100644 Resources/Locale/en-US/interaction/offer-item-system.ftl create mode 100644 Resources/Textures/Interface/Alerts/offer_item.rsi/meta.json create mode 100644 Resources/Textures/Interface/Alerts/offer_item.rsi/offer_item.png create mode 100644 Resources/Textures/Interface/Misc/give_item.rsi/give_item.png create mode 100644 Resources/Textures/Interface/Misc/give_item.rsi/meta.json diff --git a/Content.Client/Input/ContentContexts.cs b/Content.Client/Input/ContentContexts.cs index fa631938100..ca22ab095d6 100644 --- a/Content.Client/Input/ContentContexts.cs +++ b/Content.Client/Input/ContentContexts.cs @@ -68,6 +68,7 @@ public static void SetupContexts(IInputContextContainer contexts) human.AddFunction(ContentKeyFunctions.SmartEquipBelt); human.AddFunction(ContentKeyFunctions.OpenBackpack); human.AddFunction(ContentKeyFunctions.OpenBelt); + human.AddFunction(ContentKeyFunctions.OfferItem); human.AddFunction(ContentKeyFunctions.MouseMiddle); human.AddFunction(ContentKeyFunctions.ArcadeUp); human.AddFunction(ContentKeyFunctions.ArcadeDown); diff --git a/Content.Client/OfferItem/OfferItemIndicatorsOverlay.cs b/Content.Client/OfferItem/OfferItemIndicatorsOverlay.cs new file mode 100644 index 00000000000..16a314a2cf4 --- /dev/null +++ b/Content.Client/OfferItem/OfferItemIndicatorsOverlay.cs @@ -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(); + _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); + } +} diff --git a/Content.Client/OfferItem/OfferItemSystem.cs b/Content.Client/OfferItem/OfferItemSystem.cs new file mode 100644 index 00000000000..51b8dcbc0bc --- /dev/null +++ b/Content.Client/OfferItem/OfferItemSystem.cs @@ -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(); + + 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(); + } +} diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs index 49e8099e0fb..9daca74dd3a 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs @@ -183,6 +183,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action +