Add keybind for swapping hands in the other direction (#37588)
add swap hands reverse
This commit is contained in:
@@ -31,6 +31,7 @@ public abstract partial class SharedHandsSystem : EntitySystem
|
||||
.Bind(ContentKeyFunctions.UseItemInHand, InputCmdHandler.FromDelegate(HandleUseItem, 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.SwapHandsReverse, InputCmdHandler.FromDelegate(SwapHandsReversePressed, handle: false, outsidePrediction: false))
|
||||
.Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed))
|
||||
.Register<SharedHandsSystem>();
|
||||
}
|
||||
@@ -79,6 +80,16 @@ public abstract partial class SharedHandsSystem : EntitySystem
|
||||
}
|
||||
|
||||
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))
|
||||
return;
|
||||
@@ -89,8 +100,9 @@ public abstract partial class SharedHandsSystem : EntitySystem
|
||||
if (component.ActiveHand == null || component.Hands.Count < 2)
|
||||
return;
|
||||
|
||||
var newActiveIndex = component.SortedHands.IndexOf(component.ActiveHand.Name) + 1;
|
||||
var nextHand = component.SortedHands[newActiveIndex % component.Hands.Count];
|
||||
var currentIndex = component.SortedHands.IndexOf(component.ActiveHand.Name);
|
||||
var newActiveIndex = (currentIndex + (reverse ? -1 : 1) + component.Hands.Count) % component.Hands.Count;
|
||||
var nextHand = component.SortedHands[newActiveIndex];
|
||||
|
||||
TrySetActiveHand(session.AttachedEntity.Value, nextHand, component);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user