Add keybind for swapping hands in the other direction (#37588)

add swap hands reverse
This commit is contained in:
slarticodefast
2025-05-19 03:17:35 +02:00
committed by GitHub
parent f62f0fbae9
commit f3c4ff8a2a
6 changed files with 33 additions and 12 deletions

View File

@@ -56,6 +56,7 @@ namespace Content.Client.Input
human.AddFunction(EngineKeyFunctions.MoveRight); human.AddFunction(EngineKeyFunctions.MoveRight);
human.AddFunction(EngineKeyFunctions.Walk); human.AddFunction(EngineKeyFunctions.Walk);
human.AddFunction(ContentKeyFunctions.SwapHands); human.AddFunction(ContentKeyFunctions.SwapHands);
human.AddFunction(ContentKeyFunctions.SwapHandsReverse);
human.AddFunction(ContentKeyFunctions.Drop); human.AddFunction(ContentKeyFunctions.Drop);
human.AddFunction(ContentKeyFunctions.UseItemInHand); human.AddFunction(ContentKeyFunctions.UseItemInHand);
human.AddFunction(ContentKeyFunctions.AltUseItemInHand); human.AddFunction(ContentKeyFunctions.AltUseItemInHand);
@@ -100,6 +101,7 @@ namespace Content.Client.Input
aghost.AddFunction(EngineKeyFunctions.MoveRight); aghost.AddFunction(EngineKeyFunctions.MoveRight);
aghost.AddFunction(EngineKeyFunctions.Walk); aghost.AddFunction(EngineKeyFunctions.Walk);
aghost.AddFunction(ContentKeyFunctions.SwapHands); aghost.AddFunction(ContentKeyFunctions.SwapHands);
aghost.AddFunction(ContentKeyFunctions.SwapHandsReverse);
aghost.AddFunction(ContentKeyFunctions.Drop); aghost.AddFunction(ContentKeyFunctions.Drop);
aghost.AddFunction(ContentKeyFunctions.UseItemInHand); aghost.AddFunction(ContentKeyFunctions.UseItemInHand);
aghost.AddFunction(ContentKeyFunctions.AltUseItemInHand); aghost.AddFunction(ContentKeyFunctions.AltUseItemInHand);

View File

@@ -181,6 +181,7 @@ namespace Content.Client.Options.UI.Tabs
AddButton(ContentKeyFunctions.Drop); AddButton(ContentKeyFunctions.Drop);
AddButton(ContentKeyFunctions.ExamineEntity); AddButton(ContentKeyFunctions.ExamineEntity);
AddButton(ContentKeyFunctions.SwapHands); AddButton(ContentKeyFunctions.SwapHands);
AddButton(ContentKeyFunctions.SwapHandsReverse);
AddButton(ContentKeyFunctions.MoveStoredItem); AddButton(ContentKeyFunctions.MoveStoredItem);
AddButton(ContentKeyFunctions.RotateStoredItem); AddButton(ContentKeyFunctions.RotateStoredItem);
AddButton(ContentKeyFunctions.SaveItemLocation); AddButton(ContentKeyFunctions.SaveItemLocation);

View File

@@ -31,6 +31,7 @@ public abstract partial class SharedHandsSystem : EntitySystem
.Bind(ContentKeyFunctions.UseItemInHand, InputCmdHandler.FromDelegate(HandleUseItem, handle: false, outsidePrediction: false)) .Bind(ContentKeyFunctions.UseItemInHand, InputCmdHandler.FromDelegate(HandleUseItem, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.AltUseItemInHand, InputCmdHandler.FromDelegate(HandleAltUseInHand, handle: false, outsidePrediction: false)) .Bind(ContentKeyFunctions.AltUseItemInHand, InputCmdHandler.FromDelegate(HandleAltUseInHand, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(SwapHandsPressed, handle: false, outsidePrediction: false)) .Bind(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(SwapHandsPressed, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.SwapHandsReverse, InputCmdHandler.FromDelegate(SwapHandsReversePressed, handle: false, outsidePrediction: false))
.Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed)) .Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed))
.Register<SharedHandsSystem>(); .Register<SharedHandsSystem>();
} }
@@ -79,6 +80,16 @@ public abstract partial class SharedHandsSystem : EntitySystem
} }
private void SwapHandsPressed(ICommonSession? session) private void SwapHandsPressed(ICommonSession? session)
{
SwapHands(session, false);
}
private void SwapHandsReversePressed(ICommonSession? session)
{
SwapHands(session, true);
}
private void SwapHands(ICommonSession? session, bool reverse)
{ {
if (!TryComp(session?.AttachedEntity, out HandsComponent? component)) if (!TryComp(session?.AttachedEntity, out HandsComponent? component))
return; return;
@@ -89,8 +100,9 @@ public abstract partial class SharedHandsSystem : EntitySystem
if (component.ActiveHand == null || component.Hands.Count < 2) if (component.ActiveHand == null || component.Hands.Count < 2)
return; return;
var newActiveIndex = component.SortedHands.IndexOf(component.ActiveHand.Name) + 1; var currentIndex = component.SortedHands.IndexOf(component.ActiveHand.Name);
var nextHand = component.SortedHands[newActiveIndex % component.Hands.Count]; var newActiveIndex = (currentIndex + (reverse ? -1 : 1) + component.Hands.Count) % component.Hands.Count;
var nextHand = component.SortedHands[newActiveIndex];
TrySetActiveHand(session.AttachedEntity.Value, nextHand, component); TrySetActiveHand(session.AttachedEntity.Value, nextHand, component);
} }

View File

@@ -35,6 +35,7 @@ namespace Content.Shared.Input
public static readonly BoundKeyFunction OpenBelt = "OpenBelt"; public static readonly BoundKeyFunction OpenBelt = "OpenBelt";
public static readonly BoundKeyFunction OpenAHelp = "OpenAHelp"; public static readonly BoundKeyFunction OpenAHelp = "OpenAHelp";
public static readonly BoundKeyFunction SwapHands = "SwapHands"; public static readonly BoundKeyFunction SwapHands = "SwapHands";
public static readonly BoundKeyFunction SwapHandsReverse = "SwapHandsReverse";
public static readonly BoundKeyFunction MoveStoredItem = "MoveStoredItem"; public static readonly BoundKeyFunction MoveStoredItem = "MoveStoredItem";
public static readonly BoundKeyFunction RotateStoredItem = "RotateStoredItem"; public static readonly BoundKeyFunction RotateStoredItem = "RotateStoredItem";
public static readonly BoundKeyFunction SaveItemLocation = "SaveItemLocation"; public static readonly BoundKeyFunction SaveItemLocation = "SaveItemLocation";

View File

@@ -151,6 +151,7 @@ ui-options-function-alt-activate-item-in-world = Alternative activate item in wo
ui-options-function-drop = Drop item ui-options-function-drop = Drop item
ui-options-function-examine-entity = Examine ui-options-function-examine-entity = Examine
ui-options-function-swap-hands = Swap hands ui-options-function-swap-hands = Swap hands
ui-options-function-swap-hands-reverse = Swap hands (other direction)
ui-options-function-move-stored-item = Move stored item ui-options-function-move-stored-item = Move stored item
ui-options-function-rotate-stored-item = Rotate stored item ui-options-function-rotate-stored-item = Rotate stored item
ui-options-function-save-item-location = Save item location ui-options-function-save-item-location = Save item location
@@ -227,16 +228,16 @@ ui-options-function-hotbar7 = Hotbar slot 7
ui-options-function-hotbar8 = Hotbar slot 8 ui-options-function-hotbar8 = Hotbar slot 8
ui-options-function-hotbar9 = Hotbar slot 9 ui-options-function-hotbar9 = Hotbar slot 9
ui-options-function-hotbar0 = Hotbar slot 0 ui-options-function-hotbar0 = Hotbar slot 0
ui-options-function-hotbarshift1 = Hotbar slot Shift+1 ui-options-function-hotbar-shift1 = Hotbar slot Shift+1
ui-options-function-hotbarshift2 = Hotbar slot Shift+2 ui-options-function-hotbar-shift2 = Hotbar slot Shift+2
ui-options-function-hotbarshift3 = Hotbar slot Shift+3 ui-options-function-hotbar-shift3 = Hotbar slot Shift+3
ui-options-function-hotbarshift4 = Hotbar slot Shift+4 ui-options-function-hotbar-shift4 = Hotbar slot Shift+4
ui-options-function-hotbarshift5 = Hotbar slot Shift+5 ui-options-function-hotbar-shift5 = Hotbar slot Shift+5
ui-options-function-hotbarshift6 = Hotbar slot Shift+6 ui-options-function-hotbar-shift6 = Hotbar slot Shift+6
ui-options-function-hotbarshift7 = Hotbar slot Shift+7 ui-options-function-hotbar-shift7 = Hotbar slot Shift+7
ui-options-function-hotbarshift8 = Hotbar slot Shift+8 ui-options-function-hotbar-shift8 = Hotbar slot Shift+8
ui-options-function-hotbarshift9 = Hotbar slot Shift+9 ui-options-function-hotbar-shift9 = Hotbar slot Shift+9
ui-options-function-hotbarshift0 = Hotbar slot Shift+0 ui-options-function-hotbar-shift0 = Hotbar slot Shift+0
ui-options-function-loadout1 = Hotbar Loadout 1 ui-options-function-loadout1 = Hotbar Loadout 1
ui-options-function-loadout2 = Hotbar Loadout 2 ui-options-function-loadout2 = Hotbar Loadout 2
ui-options-function-loadout3 = Hotbar Loadout 3 ui-options-function-loadout3 = Hotbar Loadout 3

View File

@@ -163,6 +163,10 @@ binds:
- function: SwapHands - function: SwapHands
type: State type: State
key: X key: X
- function: SwapHandsReverse
type: State
key: X
mod1: Shift
- function: MoveStoredItem - function: MoveStoredItem
type: State type: State
key: MouseLeft key: MouseLeft