Hand to hand (#365)

This commit is contained in:
JunJun
2025-11-05 16:16:48 +03:00
committed by GitHub
parent 0c126a2a9b
commit 45fd3e6d98
22 changed files with 581 additions and 0 deletions

View File

@@ -88,6 +88,7 @@ namespace Content.Client.Input
human.AddFunction(ContentKeyFunctions.Arcade2);
human.AddFunction(ContentKeyFunctions.Arcade3);
human.AddFunction(ContentKeyFunctions.LanguageChoose); //WL-Changes: Languages
human.AddFunction(ContentKeyFunctions.OfferItem); // CorvaxGoob-OfferItem
// actions should be common (for ghosts, mobs, etc)
common.AddFunction(ContentKeyFunctions.OpenActionsMenu);

View File

@@ -187,6 +187,7 @@ namespace Content.Client.Options.UI.Tabs
AddButton(ContentKeyFunctions.RotateStoredItem);
AddButton(ContentKeyFunctions.SaveItemLocation);
AddButton(ContentKeyFunctions.OfferItem); // CorvaxGoob-Offer
AddHeader("ui-options-header-interaction-adv");
AddButton(ContentKeyFunctions.SmartEquipBackpack);
AddButton(ContentKeyFunctions.SmartEquipBelt);

View File

@@ -22,6 +22,7 @@
StyleClasses="LabelKeyText"/>
<CheckBox Name="ShowHeldItemCheckBox" Text="{Loc 'ui-options-show-held-item'}" />
<CheckBox Name="ShowCombatModeIndicatorsCheckBox" Text="{Loc 'ui-options-show-combat-mode-indicators'}" />
<CheckBox Name="ShowOfferModeIndicatorsCheckBox" Text="{Loc 'ui-options-show-offer-mode-indicators'}" /> <!-- CorvaxGoob-Offer -->
<Label Text="{Loc 'ui-options-general-storage'}"
StyleClasses="LabelKeyText"/>
<CheckBox Name="OpaqueStorageWindowCheckBox" Text="{Loc 'ui-options-opaque-storage-window'}" />

View File

@@ -8,6 +8,7 @@ using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared;
using Robust.Shared.Prototypes;
using Content.Shared.Corvax.CCCVars; // # CorvaxGoob-Offer
namespace Content.Client.Options.UI.Tabs;
@@ -52,6 +53,7 @@ public sealed partial class MiscTab : Control
Control.AddOptionCheckBox(CCVars.ChatEnableFancyBubbles, FancySpeechBubblesCheckBox);
Control.AddOptionCheckBox(CCVars.ChatFancyNameBackground, FancyNameBackgroundsCheckBox);
Control.AddOptionCheckBox(CCVars.StaticStorageUI, StaticStorageUI);
Control.AddOptionCheckBox(CCCVars.OfferModeIndicatorsPointShow, ShowOfferModeIndicatorsCheckBox); // CorvaxGoob-Offer
Control.Initialize();
}

View File

@@ -0,0 +1,62 @@
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._CorvaxGoob.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/_CorvaxGoob/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 mousePosMap = _eye.PixelToMap(_inputManager.MouseScreenPosition);
if (mousePosMap.MapId != args.MapId)
return;
var limitedScale = Math.Min(1.25f, (args.ViewportControl as Control)?.UIScale ?? 1f) * _scale;
DrawSight(_sight, args.ScreenHandle, _inputManager.MouseScreenPosition.Position, limitedScale);
}
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);
}
}

View File

@@ -0,0 +1,44 @@
using Content.Shared.Corvax.CCCVars;
using Content.Shared._CorvaxGoob.OfferItem;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Shared.Configuration;
namespace Content.Client._CorvaxGoob.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, CCCVars.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>();
}
}

View File

@@ -0,0 +1,50 @@
using Content.Shared._CorvaxGoob.OfferItem;
using Content.Shared.Alert;
using Content.Server.Hands.Systems;
using Content.Shared.Hands.Components;
namespace Content.Server._CorvaxGoob.OfferItem;
public sealed class OfferItemSystem : SharedOfferItemSystem
{
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly HandsSystem _hands = 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.ActiveHandId is null)
continue;
if (offerItem.Hand is not null && _hands.GetActiveItem(uid) 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);
}
}
}

View File

@@ -87,4 +87,12 @@ public sealed class CCCVars
/// </summary>
public static readonly CVarDef<bool> StationGoal =
CVarDef.Create("game.station_goal", true, CVar.SERVERONLY);
/// CorvaxGoob-Offer-Start
/// <summary>
/// Offer item.
/// </summary>
public static readonly CVarDef<bool> OfferModeIndicatorsPointShow =
CVarDef.Create("hud.offer_mode_indicators_point_show", true, CVar.ARCHIVE | CVar.CLIENTONLY);
/// CorvaxGoob-Offer-End
}

View File

@@ -59,6 +59,7 @@ namespace Content.Shared.Input
public static readonly BoundKeyFunction TakeScreenshotNoUI = "TakeScreenshotNoUI";
public static readonly BoundKeyFunction ToggleFullscreen = "ToggleFullscreen";
public static readonly BoundKeyFunction Point = "Point";
public static readonly BoundKeyFunction OfferItem = "OfferItem"; // CorvaxGoob-Offer
public static readonly BoundKeyFunction ZoomOut = "ZoomOut";
public static readonly BoundKeyFunction ZoomIn = "ZoomIn";
public static readonly BoundKeyFunction ResetZoom = "ResetZoom";

View File

@@ -0,0 +1,8 @@
using Content.Shared.Alert;
namespace Content.Shared._CorvaxGoob.Alert.Click;
/// <summary>
/// Accepting the offer and receive item
/// </summary>
public sealed partial class AcceptOfferAlertEvent : BaseAlertEvent;

View File

@@ -0,0 +1,26 @@
using Robust.Shared.GameStates;
namespace Content.Shared._CorvaxGoob.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;
}

View File

@@ -0,0 +1,76 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Hands.Components;
using Content.Shared.Input;
using Content.Shared.Hands.EntitySystems;
using Robust.Shared.Input.Binding;
using Robust.Shared.Player;
namespace Content.Shared._CorvaxGoob.OfferItem;
public abstract partial class SharedOfferItemSystem
{
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly SharedHandsSystem _hand = 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.ActiveHandId is null)
return;
offerItem.Item = _hand.GetActiveItem((uid, hands));
if (!offerItem.IsInOfferMode)
{
if (offerItem.Item is null)
{
_popup.PopupClient(Loc.GetString("offer-item-empty-hand"), uid, uid);
return;
}
if (offerItem.Hand is null || offerItem.Target is null)
{
offerItem.IsInOfferMode = true;
offerItem.Hand = hands.ActiveHandId;
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);
}
}

View File

@@ -0,0 +1,226 @@
using Content.Shared._CorvaxGoob.Alert.Click;
using Content.Shared.Alert;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Robust.Shared.Timing;
namespace Content.Shared._CorvaxGoob.OfferItem;
public abstract partial class SharedOfferItemSystem : EntitySystem
{
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[ValidatePrototypeId<AlertPrototype>]
protected const string OfferAlert = "Offer";
public override void Initialize()
{
SubscribeLocalEvent<OfferItemComponent, InteractUsingEvent>(SetInReceiveMode);
SubscribeLocalEvent<OfferItemComponent, MoveEvent>(OnMove);
InitializeInteractions();
SubscribeLocalEvent<OfferItemComponent, AcceptOfferAlertEvent>(OnClickAlertEvent);
}
private void OnClickAlertEvent(Entity<OfferItemComponent> ent, ref AcceptOfferAlertEvent ev)
{
if (ev.Handled || ev.AlertId != OfferAlert)
return;
ev.Handled = true;
Receive(ent!);
}
/// <summary>
/// Accepting the offer and receive item
/// </summary>
public void Receive(Entity<OfferItemComponent?> ent)
{
if (!_timing.IsFirstTimePredicted)
return;
if (!Resolve(ent, ref ent.Comp))
return;
if (!TryComp<OfferItemComponent>(ent.Comp.Target, out var offerItem))
return;
if (offerItem.Hand is null)
return;
if (ent.Comp.Target is null)
return;
if (!TryComp<HandsComponent>(ent, out var hands))
return;
if (offerItem.Item is not null)
{
if (!_hand.TryPickup(ent, offerItem.Item.Value, handsComp: hands))
{
_popup.PopupClient(Loc.GetString("offer-item-full-hand"), ent, ent);
return;
}
_popup.PopupClient(Loc.GetString("offer-item-give",
("item", Identity.Entity(offerItem.Item.Value, EntityManager)),
("target", Identity.Entity(ent, EntityManager))), ent.Comp.Target.Value, ent.Comp.Target.Value);
_popup.PopupPredicted(Loc.GetString("offer-item-give-other",
("user", Identity.Entity(ent.Comp.Target.Value, EntityManager)),
("item", Identity.Entity(offerItem.Item.Value, EntityManager)),
("target", Identity.Entity(ent, EntityManager)))
, ent.Comp.Target.Value, ent);
}
offerItem.Item = null;
Dirty(ent);
UnReceive(ent, ent, offerItem);
}
private void SetInReceiveMode(EntityUid uid, OfferItemComponent component, InteractUsingEvent args)
{
if (!TryComp<OfferItemComponent>(args.User, out var offerItem))
return;
if (args.User == uid || component.IsInReceiveMode || !offerItem.IsInOfferMode || offerItem.IsInReceiveMode && offerItem.Target != uid)
return;
component.IsInReceiveMode = true;
component.Target = args.User;
Dirty(uid, component);
offerItem.Target = uid;
offerItem.IsInOfferMode = false;
Dirty(args.User, offerItem);
if (offerItem.Item == null)
return;
_popup.PopupPredicted(Loc.GetString("offer-item-try-give",
("item", Identity.Entity(offerItem.Item.Value, EntityManager)),
("target", Identity.Entity(uid, EntityManager))), component.Target.Value, component.Target.Value);
_popup.PopupClient(Loc.GetString("offer-item-try-give-target",
("user", Identity.Entity(component.Target.Value, EntityManager)),
("item", Identity.Entity(offerItem.Item.Value, EntityManager))), component.Target.Value, uid);
args.Handled = true;
}
private void OnMove(EntityUid uid, OfferItemComponent component, MoveEvent args)
{
if (component.Target is null ||
_transform.InRange(args.NewPosition,
Transform(component.Target.Value).Coordinates,
component.MaxOfferDistance)
)
return;
UnOffer(uid, component);
}
/// <summary>
/// Resets the <see cref="OfferItemComponent"/> of the user and the target
/// </summary>
protected void UnOffer(EntityUid uid, OfferItemComponent component)
{
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHandId is null)
return;
if (TryComp<OfferItemComponent>(component.Target, out var offerItem) && component.Target is not null)
{
if (component.Item is not null)
{
if (!_timing.IsFirstTimePredicted)
{
_popup.PopupClient(Loc.GetString("offer-item-no-give",
("item", Identity.Entity(component.Item.Value, EntityManager)),
("target", Identity.Entity(component.Target.Value, EntityManager))), uid, uid);
_popup.PopupClient(Loc.GetString("offer-item-no-give-target",
("user", Identity.Entity(uid, EntityManager)),
("item", Identity.Entity(component.Item.Value, EntityManager))), uid, component.Target.Value);
}
}
else if (offerItem.Item is not null)
if (!_timing.IsFirstTimePredicted)
{
_popup.PopupClient(Loc.GetString("offer-item-no-give",
("item", Identity.Entity(offerItem.Item.Value, EntityManager)),
("target", Identity.Entity(uid, EntityManager))), component.Target.Value, component.Target.Value);
_popup.PopupClient(Loc.GetString("offer-item-no-give-target",
("user", Identity.Entity(component.Target.Value, EntityManager)),
("item", Identity.Entity(offerItem.Item.Value, EntityManager))), component.Target.Value, uid);
}
offerItem.IsInOfferMode = false;
offerItem.IsInReceiveMode = false;
offerItem.Hand = null;
offerItem.Target = null;
offerItem.Item = null;
Dirty(component.Target.Value, offerItem);
}
component.IsInOfferMode = false;
component.IsInReceiveMode = false;
component.Hand = null;
component.Target = null;
component.Item = null;
Dirty(uid, component);
}
/// <summary>
/// Cancels the transfer of the item
/// </summary>
protected void UnReceive(EntityUid uid, OfferItemComponent? component = null, OfferItemComponent? offerItem = null)
{
if (component is null && !TryComp(uid, out component))
return;
if (offerItem is null && !TryComp(component.Target, out offerItem))
return;
if (!TryComp<HandsComponent>(uid, out var hands) || hands.ActiveHandId is null ||
component.Target is null)
return;
if (offerItem.Item is not null)
{
_popup.PopupClient(Loc.GetString("offer-item-no-give",
("item", Identity.Entity(offerItem.Item.Value, EntityManager)),
("target", Identity.Entity(uid, EntityManager))), component.Target.Value, component.Target.Value);
_popup.PopupClient(Loc.GetString("offer-item-no-give-target",
("user", Identity.Entity(component.Target.Value, EntityManager)),
("item", Identity.Entity(offerItem.Item.Value, EntityManager))), component.Target.Value, uid);
}
if (!offerItem.IsInReceiveMode)
{
offerItem.Target = null;
component.Target = null;
}
offerItem.Item = null;
offerItem.Hand = null;
component.IsInReceiveMode = false;
Dirty(uid, component);
}
/// <summary>
/// Returns true if <see cref="OfferItemComponent.IsInOfferMode"/> = true
/// </summary>
protected bool IsInOfferMode(EntityUid? entity, OfferItemComponent? component = null)
{
return entity is not null && Resolve(entity.Value, ref component, false) && component.IsInOfferMode;
}
}

View File

@@ -0,0 +1,23 @@
offer-item-empty-hand = У вас в руках ничего нет!
offer-item-full-hand = Ваши руки заняты!
offer-item-try-give = Вы предлагаете {$item} {$target}
offer-item-try-give-target = {CAPITALIZE($user)} предлагает вам {$item}
offer-item-give = Вы отдали {$item} {$target}
offer-item-give-other = {CAPITALIZE($user)} {GENDER($user) ->
[male] отдал
[female] отдала
[epicene] отдали
*[neuter] отдало
} {$item} {$target}
offer-item-give-target = {CAPITALIZE($user)} {GENDER($user) ->
[male] отдал
[female] отдала
[epicene] отдали
*[neuter] отдало
} вам {$item}
offer-item-no-give = Вы перестаёте предлагать {$item} {$target}
offer-item-no-give-target = {CAPITALIZE($user)} больше не предлагает вам {$item}

View File

@@ -78,6 +78,8 @@ alerts-revenant-essence-name = Эссенция
alerts-revenant-essence-desc = Сила душ. Поддерживает вас и используется при использовании способностей. Медленно восстанавливается с течением времени.
alerts-revenant-corporeal-name = Материальность
alerts-revenant-corporeal-desc = Вы физически воплотились. Окружающие могут видеть и наносить вам вред.
alerts-offer-name = Получить
alerts-offer-desc = Кто-то передаёт вам предмет.
alerts-rooted-name = Укоренены
alerts-rooted-desc = Вы прикреплены к земле. Вы не можете подскользнуться, но вы будете впитывать все жидкости под вами.
alerts-stealthy-name = Карманничество

View File

@@ -27,6 +27,7 @@
- alertType: Rooted
- alertType: Pacified
- alertType: Stealthy
- alertType: Offer # CorvaxGoob-Offer
- type: entity
id: AlertSpriteView
@@ -94,6 +95,17 @@
name: alerts-on-fire-name
description: alerts-on-fire-desc
# CorvaxGoob-Offer-Start
- type: alert
id: Offer
clickEvent: !type:AcceptOfferAlertEvent
icons:
- sprite: /Textures/_CorvaxGoob/Interface/Alerts/offer_item.rsi
state: offer_item
name: alerts-offer-name
description: alerts-offer-desc
# CorvaxGoob-Offer-Start
- type: alert
id: Cold

View File

@@ -217,6 +217,7 @@
- DoorBumpOpener
- AnomalyHost
- type: MobCollision # WL-Changes: MobCollision works for players only
- type: OfferItem # CorvaxGoob-Offer
- type: entity
save: false

View File

@@ -0,0 +1,20 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Made by Ko4erga",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "offer_item",
"delays": [
[
0.5,
0.5
]
]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@@ -0,0 +1,14 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "https://github.com/ss220-space/Paradise/blob/master220/icons/misc/mouse_icons/give_item.dmi",
"size": {
"x": 64,
"y": 64
},
"states": [
{
"name": "give_item"
}
]
}

View File

@@ -631,3 +631,6 @@ binds:
type: State
key: MouseRight
canFocus: true
- function: OfferItem # CorvaxGoob-Offer
type: State
key: H