forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Система передачи из рук в руки (#29)
* [Feature] Система передачи из рук в руки (space-syndicate#780) * up 1 * refactor * Update alerts.yml * fix popups * Update SharedOfferItemSystem.cs --------- Co-authored-by: Zack Backmen <[email protected]> * sledi * fixim govno * Fixes * Last fix * apply suggestionges frome code reviewere * icon locale * rename + remove THE * fix1 * fix 2 * fix linter * Update Resources/Locale/ru-RU/alerts/alerts.ftl * Update Resources/Locale/ru-RU/alerts/alerts.ftl Co-authored-by: FN <[email protected]> * Update Resources/Locale/ru-RU/alerts/alerts.ftl Co-authored-by: FN <[email protected]> * Apply suggestions from code review * vzyat * Apply suggestions from code review --------- Co-authored-by: Zack Backmen <[email protected]> Co-authored-by: FN <[email protected]> Co-authored-by: FN <[email protected]>
- Loading branch information
1 parent
199dc73
commit c396a36
Showing
23 changed files
with
579 additions
and
2 deletions.
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
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
65 changes: 65 additions & 0 deletions
65
Content.Client/_CorvaxNext/OfferItem/OfferItemIndicatorsOverlay.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,65 @@ | ||
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._CorvaxNext.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/_CorvaxNext/Misc/give_item.rsi"), "give_item")); | ||
} | ||
|
||
protected override bool BeforeDraw(in OverlayDrawArgs 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 = 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(7); | ||
|
||
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,44 @@ | ||
using Content.Shared._CorvaxNext.OfferItem; | ||
using Content.Shared._CorvaxNext.NextVars; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Input; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Configuration; | ||
|
||
namespace Content.Client._CorvaxNext.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() | ||
{ | ||
base.Initialize(); | ||
Subs.CVar(_cfg, NextVars.OfferModeIndicatorsPointShow, OnShowOfferIndicatorsChanged, true); | ||
} | ||
|
||
public override void Shutdown() | ||
{ | ||
_overlayManager.RemoveOverlay<OfferItemIndicatorsOverlay>(); | ||
base.Shutdown(); | ||
} | ||
|
||
public bool IsInOfferMode() | ||
{ | ||
var entity = _playerManager.LocalEntity; | ||
|
||
return entity is not null && 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Content.Shared.Alert; | ||
using Content.Shared._CorvaxNext.OfferItem; | ||
using Content.Shared.Hands.Components; | ||
|
||
namespace Content.Server._CorvaxNext.OfferItem; | ||
|
||
public sealed class OfferItemSystem : SharedOfferItemSystem | ||
{ | ||
[Dependency] private readonly AlertsSystem _alertsSystem = default!; | ||
|
||
private float _offerAcc = 0; | ||
private const float OfferAccMax = 3f; | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
_offerAcc += frameTime; | ||
|
||
if (_offerAcc >= OfferAccMax) | ||
_offerAcc -= OfferAccMax; | ||
else | ||
return; | ||
|
||
var query = EntityQueryEnumerator<OfferItemComponent, HandsComponent>(); | ||
while (query.MoveNext(out var uid, out var offerItem, out var hands)) | ||
{ | ||
if (hands.ActiveHand is null) | ||
continue; | ||
|
||
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) | ||
{ | ||
_alertsSystem.ClearAlert(uid, OfferAlert); | ||
continue; | ||
} | ||
|
||
_alertsSystem.ShowAlert(uid, OfferAlert); | ||
} | ||
} | ||
} |
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,8 @@ | ||
using Content.Shared.Alert; | ||
|
||
namespace Content.Shared._CorvaxNext.Alert.Click; | ||
|
||
/// <summary> | ||
/// Accepting the offer and receive item | ||
/// </summary> | ||
public sealed partial class AcceptOfferAlertEvent : BaseAlertEvent; |
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,17 @@ | ||
using Robust.Shared.Configuration; | ||
|
||
namespace Content.Shared._CorvaxNext.NextVars; | ||
|
||
/// <summary> | ||
/// Corvax modules console variables | ||
/// </summary> | ||
[CVarDefs] | ||
// ReSharper disable once InconsistentNaming | ||
public sealed class NextVars | ||
{ | ||
/// <summary> | ||
/// Offer item. | ||
/// </summary> | ||
public static readonly CVarDef<bool> OfferModeIndicatorsPointShow = | ||
CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY); | ||
} |
26 changes: 26 additions & 0 deletions
26
Content.Shared/_CorvaxNext/OfferItem/OfferItemComponent.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,26 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared._CorvaxNext.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; | ||
} |
74 changes: 74 additions & 0 deletions
74
Content.Shared/_CorvaxNext/OfferItem/SharedOfferItemSystem.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,74 @@ | ||
using Content.Shared.ActionBlocker; | ||
using Content.Shared.Hands.Components; | ||
using Content.Shared.Input; | ||
using Robust.Shared.Input.Binding; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Shared._CorvaxNext.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 (!_timing.IsFirstTimePredicted) | ||
return; | ||
|
||
if (session is null) | ||
return; | ||
|
||
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 is null) | ||
return; | ||
|
||
offerItem.Item = hands.ActiveHand.HeldEntity; | ||
|
||
if (!offerItem.IsInOfferMode) | ||
{ | ||
if (offerItem.Item is null) | ||
{ | ||
_popup.PopupEntity(Loc.GetString("offer-item-empty-hand"), uid, uid); | ||
return; | ||
} | ||
|
||
if (offerItem.Hand is null || offerItem.Target is null) | ||
{ | ||
offerItem.IsInOfferMode = true; | ||
offerItem.Hand = hands.ActiveHand.Name; | ||
|
||
Dirty(uid, offerItem); | ||
return; | ||
} | ||
} | ||
|
||
if (offerItem.Target is not null) | ||
{ | ||
UnReceive(offerItem.Target.Value, offerItem: offerItem); | ||
offerItem.IsInOfferMode = false; | ||
Dirty(uid, offerItem); | ||
return; | ||
} | ||
|
||
UnOffer(uid, offerItem); | ||
} | ||
} |
Oops, something went wrong.