Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item Offer Bind #2423

Merged
merged 3 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Input;
using Content.Shared.SS220.Input;
using Robust.Shared.Input;

namespace Content.Client.Input
Expand Down Expand Up @@ -57,6 +58,7 @@ public static void SetupContexts(IInputContextContainer contexts)
human.AddFunction(EngineKeyFunctions.Walk);
human.AddFunction(ContentKeyFunctions.SwapHands);
human.AddFunction(ContentKeyFunctions.Drop);
human.AddFunction(KeyFunctions220.ItemOffer); // SS220 ItemOffer bind
human.AddFunction(ContentKeyFunctions.UseItemInHand);
human.AddFunction(ContentKeyFunctions.AltUseItemInHand);
human.AddFunction(ContentKeyFunctions.OpenCharacterMenu);
Expand Down
2 changes: 2 additions & 0 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Client.Stylesheets;
using Content.Shared.CCVar;
using Content.Shared.Input;
using Content.Shared.SS220.Input;
using Robust.Client.AutoGenerated;
using Robust.Client.Input;
using Robust.Client.UserInterface;
Expand Down Expand Up @@ -179,6 +180,7 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
AddButton(ContentKeyFunctions.ActivateItemInWorld);
AddButton(ContentKeyFunctions.AltActivateItemInWorld);
AddButton(ContentKeyFunctions.Drop);
AddButton(KeyFunctions220.ItemOffer); // SS220 ItemOffer bind
AddButton(ContentKeyFunctions.ExamineEntity);
AddButton(ContentKeyFunctions.SwapHands);
AddButton(ContentKeyFunctions.MoveStoredItem);
Expand Down
65 changes: 53 additions & 12 deletions Content.Server/SS220/ItemOfferVerb/Systems/ItemOfferSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using System.Linq;
using Content.Shared.Silicons.Borgs.Components;
using Content.Shared.Interaction.Components;
using Robust.Shared.Input.Binding;
using Content.Shared.SS220.Input;

namespace Content.Server.SS220.ItemOfferVerb.Systems
{
Expand All @@ -30,6 +32,23 @@ public override void Initialize()
base.Initialize();
SubscribeLocalEvent<HandsComponent, GetVerbsEvent<EquipmentVerb>>(AddOfferVerb);
SubscribeLocalEvent<ItemReceiverComponent, ItemOfferAlertEvent>(OnItemOffserAlertClicked);

CommandBinds.Builder
.Bind(KeyFunctions220.ItemOffer,
new PointerInputCmdHandler(HandleItemOfferKey))
.Register<ItemOfferSystem>();
}

private bool HandleItemOfferKey(in PointerInputCmdHandler.PointerInputCmdArgs args)
{
if (!args.EntityUid.IsValid() || !EntityManager.EntityExists(args.EntityUid))
return false;

if (args.Session?.AttachedEntity == null)
return false;

DoItemOffer(args.Session.AttachedEntity.Value, args.EntityUid);
return true;
}

private void OnItemOffserAlertClicked(Entity<ItemReceiverComponent> ent, ref ItemOfferAlertEvent args)
Expand Down Expand Up @@ -80,24 +99,15 @@ then when we checked the first hand we didn't find it and deleted the transfer r

private void AddOfferVerb(EntityUid uid, HandsComponent component, GetVerbsEvent<EquipmentVerb> args)
{
if (!args.CanInteract || !args.CanAccess || args.Hands == null || args.Hands.ActiveHandEntity == null
|| HasComp<UnremoveableComponent>(args.Hands.ActiveHandEntity) || args.Target == args.User || !FindFreeHand(component, out var freeHand))
return;

// (fix https://github.com/SerbiaStrong-220/space-station-14/issues/2054)
if (HasComp<BorgChassisComponent>(args.User))
if (!args.CanInteract || !args.CanAccess || args.Hands == null || args.Hands.ActiveHandEntity == null)
return;

EquipmentVerb verb = new EquipmentVerb()
{
Text = "Передать предмет",
Act = () =>
{
var itemReceiver = EnsureComp<ItemReceiverComponent>(uid);
itemReceiver.Giver = args.User;
itemReceiver.Item = args.Hands.ActiveHandEntity;
_alerts.ShowAlert(uid, ItemOfferAlert);
_popupSystem.PopupEntity($"{Name(args.User)} протягивает {Name(args.Hands.ActiveHandEntity!.Value)} {Name(uid)}", args.User, PopupType.Small);
DoItemOffer(args.User, uid);
},
};

Expand All @@ -110,7 +120,11 @@ public void TransferItemInHands(EntityUid receiver, ItemReceiverComponent? itemR
_hands.PickupOrDrop(itemReceiver.Giver, itemReceiver.Item!.Value);
if (_hands.TryPickupAnyHand(receiver, itemReceiver.Item!.Value))
{
_popupSystem.PopupEntity($"{Name(itemReceiver.Giver)} передал {Name(itemReceiver.Item!.Value)} {Name(receiver)}!", itemReceiver.Giver, PopupType.Medium);
var loc = Loc.GetString("loc-item-offer-transfer",
("user", itemReceiver.Giver),
("item", itemReceiver.Item),
("target", receiver));
_popupSystem.PopupEntity(loc, itemReceiver.Giver, PopupType.Medium);
_alerts.ClearAlert(receiver, ItemOfferAlert);
_entMan.RemoveComponent<ItemReceiverComponent>(receiver);
};
Expand All @@ -119,5 +133,32 @@ private bool FindFreeHand(HandsComponent component, [NotNullWhen(true)] out stri
{
return (freeHand = component.GetFreeHandNames().Any() ? component.GetFreeHandNames().First() : null) != null;
}

private void DoItemOffer(EntityUid user, EntityUid target)
{
if (!TryComp<HandsComponent>(target, out var handsComponent))
return;

// (fix https://github.com/SerbiaStrong-220/space-station-14/issues/2054)
if (HasComp<BorgChassisComponent>(user) || !FindFreeHand(handsComponent, out _) || target == user )
return;

if (!_hands.TryGetActiveItem(user, out var item))
return;

if (HasComp<UnremoveableComponent>(item))
return;

var itemReceiver = EnsureComp<ItemReceiverComponent>(target);
itemReceiver.Giver = user;
itemReceiver.Item = item;
_alerts.ShowAlert(target, ItemOfferAlert);

var loc = Loc.GetString("loc-item-offer-attempt",
("user", user),
("item", item),
("target", target));
_popupSystem.PopupEntity(loc, user);
}
}
}
1 change: 1 addition & 0 deletions Content.Shared/SS220/Input/KeyFunctions220.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static class KeyFunctions220
public static readonly BoundKeyFunction CalculatorTypeDivide = "CalculatorTypeDivide";
public static readonly BoundKeyFunction CalculatorEnter = "CalculatorEnter";
public static readonly BoundKeyFunction CalculatorClear = "CalculatorClear";
public static readonly BoundKeyFunction ItemOffer = "ItemOffer";

public static void AddCalculatorKeys(IInputCmdContext context)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ui-options-function-smart-equip-neck = Умная экипировка на шею
ui-options-function-item-offer = Передать предмет
2 changes: 2 additions & 0 deletions Resources/Locale/ru-RU/ss220/itemoffer/itemoffer.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
loc-item-offer-attempt = { $user } протягивает { $item } { $target }
loc-item-offer-transfer = { $user } передал { $item } { $target }
8 changes: 7 additions & 1 deletion Resources/keybinds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,10 @@ binds:
- function: CalculatorClear
type: State
key: Delete
# SS220 Calculator end
# SS220 Calculator end
# SS220 ItemOffer bind begin
- function: ItemOffer
type: State
key: R
mod1: Shift
# SS220 ItemOffer bind end
Loading