Implement inventory mouse item dragging (#1208)

* Implement inventory mouse item dragging
* SendWindowAction: Format switch/align statements
* Document window action types
Co-authored-by: ORelio <ORelio@users.noreply.github.com>
This commit is contained in:
ReinforceZwei 2020-08-15 20:17:18 +08:00 committed by GitHub
parent 4a3a23eb1d
commit 526dabd1e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 15 deletions

View file

@ -5,13 +5,84 @@ using System.Text;
namespace MinecraftClient.Inventory
{
/// <summary>
/// Represents mouse interactions with an inventory window
/// </summary>
public enum WindowActionType
{
/// <summary>
/// Left click with mouse on a slot: grab or drop a whole item stack
/// </summary>
LeftClick,
/// <summary>
/// Right click with mouse on a slot: grab half a stack or drop a single item
/// </summary>
RightClick,
/// <summary>
/// Middle click with mouse on a slot: grab a full stack from creative inventory
/// </summary>
MiddleClick,
/// <summary>
/// Shift+Left click with mouse on a slot: send a whole item stack to the hotbar or other inventory
/// </summary>
ShiftClick,
/// <summary>
/// Drop a single item on ground after grabbing an item stack
/// </summary>
DropItem,
DropItemStack
/// <summary>
/// Drop a whole item stack on ground after grabbing it
/// </summary>
DropItemStack,
/// <summary>
/// Start hovering slots with left button pressed: Distribute evenly the stack on hovered slots
/// </summary>
StartDragLeft,
/// <summary>
/// Start hovering slots with right button pressed: Drop one item on each hovered slot
/// </summary>
StartDragRight,
/// <summary>
/// Start hovering slots with middle button pressed: Create one item stack on each hovered slot in creative mode
/// </summary>
StartDragMiddle,
/// <summary>
/// Hover a slot to distribute evenly an item stack
/// </summary>
AddDragLeft,
/// <summary>
/// Hover a slot to drop one item from an item stack
/// </summary>
AddDragRight,
/// <summary>
/// Hover a slot to create one item stack in creative mode
/// </summary>
AddDragMiddle,
/// <summary>
/// Stop hovering slots with left button pressed
/// </summary>
EndDragLeft,
/// <summary>
/// Stop hovering slots with right button pressed
/// </summary>
EndDragRight,
/// <summary>
/// Stop hovering slots with middble button pressed
/// </summary>
EndDragMiddle,
}
}

View file

@ -1609,6 +1609,7 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item)
{
try
@ -1624,22 +1625,24 @@ namespace MinecraftClient.Protocol.Handlers
byte button = 0;
byte mode = 0;
switch (action)
{
case WindowActionType.LeftClick: button = 0; break;
case WindowActionType.RightClick: button = 1; break;
case WindowActionType.MiddleClick: button = 2; mode = 3; break;
case WindowActionType.ShiftClick: button = 0; mode = 1; item = new Item(-1, 0, null); break;
case WindowActionType.DropItem:
button = 0;
mode = 4;
item = new Item(-1, 0, null);
break;
case WindowActionType.DropItemStack:
button = 1;
mode = 4;
item = new Item(-1, 0, null);
break;
case WindowActionType.LeftClick: button = 0; break;
case WindowActionType.RightClick: button = 1; break;
case WindowActionType.MiddleClick: button = 2; mode = 3; break;
case WindowActionType.ShiftClick: button = 0; mode = 1; item = new Item(-1, 0, null); break;
case WindowActionType.DropItem: button = 0; mode = 4; item = new Item(-1, 0, null); break;
case WindowActionType.DropItemStack: button = 1; mode = 4; item = new Item(-1, 0, null); break;
case WindowActionType.StartDragLeft: button = 0; mode = 5; item = new Item(-1, 0, null); slotId = -999; break;
case WindowActionType.StartDragRight: button = 4; mode = 5; item = new Item(-1, 0, null); slotId = -999; break;
case WindowActionType.StartDragMiddle: button = 8; mode = 5; item = new Item(-1, 0, null); slotId = -999; break;
case WindowActionType.EndDragLeft: button = 2; mode = 5; item = new Item(-1, 0, null); slotId = -999; break;
case WindowActionType.EndDragRight: button = 6; mode = 5; item = new Item(-1, 0, null); slotId = -999; break;
case WindowActionType.EndDragMiddle: button = 10; mode = 5; item = new Item(-1, 0, null); slotId = -999; break;
case WindowActionType.AddDragLeft: button = 1; mode = 5; item = new Item(-1, 0, null); break;
case WindowActionType.AddDragRight: button = 5; mode = 5; item = new Item(-1, 0, null); break;
case WindowActionType.AddDragMiddle: button = 9; mode = 5; item = new Item(-1, 0, null); break;
}
List<byte> packet = new List<byte>();