1
0

Handle middle mouse drag (#3847)

This commit is contained in:
peterbell10 2017-07-13 14:43:48 +01:00 committed by Mattes D
parent 6a19841121
commit 41d016cf5b
6 changed files with 177 additions and 10 deletions

View File

@ -13616,6 +13616,130 @@ end
}, },
Constants = Constants =
{ {
caLeftClick =
{
Notes = "Left click on a slot",
},
caRightClick =
{
Notes = "Right click on a slot",
},
caShiftLeftClick =
{
Notes = "Shift + left click on a slot",
},
caShiftRightClick =
{
Notes = "Shift + right click on a slot",
},
caNumber1 =
{
Notes = "Number key 1",
},
caNumber2 =
{
Notes = "Number key 2",
},
caNumber3 =
{
Notes = "Number key 3",
},
caNumber4 =
{
Notes = "Number key 4",
},
caNumber5 =
{
Notes = "Number key 5",
},
caNumber6 =
{
Notes = "Number key 6",
},
caNumber7 =
{
Notes = "Number key 7",
},
caNumber8 =
{
Notes = "Number key 8",
},
caNumber9 =
{
Notes = "Number key 9",
},
caMiddleClick =
{
Notes = "Middle click, only valid for creative players",
},
caDropKey =
{
Notes = "Drop a single item",
},
caCtrlDropKey =
{
Notes = "Drop a full stack",
},
caLeftClickOutside =
{
Notes = "Left click outside of inventory",
},
caRightClickOutside =
{
Notes = "Right click outside of inventory",
},
caLeftClickOutsideHoldNothing =
{
Notes = "Left click outside inventory holding nothing",
},
caRightClickOutsideHoldNothing =
{
Notes = "Right click outside inventory holding nothing",
},
caLeftPaintBegin =
{
Notes = "Begining of left click paint drag action",
},
caRightPaintBegin =
{
Notes = "Begining of right click paint drag action",
},
caMiddlePaintBegin =
{
Notes = "Begining of middle click paint drag action, only valid for creative players",
},
caLeftPaintProgress =
{
Notes = "Add slot for left click paint drag action",
},
caRightPaintProgress =
{
Notes = "Add slot for right click paint drag action",
},
caMiddlePaintProgress =
{
Notes = "Add slot for middle click paint drag action, only valid for creative players",
},
caLeftPaintEnd =
{
Notes = "End of left click paint drag action",
},
caRightPaintEnd =
{
Notes = "End of right click paint drag action",
},
caMiddlePaintEnd =
{
Notes = "End of middle click paint drag action, only valid for creative players",
},
caDblClick =
{
Notes = "Double click action",
},
caUnknown =
{
Notes = "Unknown click action"
},
E_BLOCK_ACACIA_DOOR = E_BLOCK_ACACIA_DOOR =
{ {
Notes = "The blocktype for acacia door" Notes = "The blocktype for acacia door"

View File

@ -99,10 +99,13 @@ enum eClickAction
caRightClickOutsideHoldNothing, caRightClickOutsideHoldNothing,
caLeftPaintBegin, caLeftPaintBegin,
caRightPaintBegin, caRightPaintBegin,
caMiddlePaintBegin,
caLeftPaintProgress, caLeftPaintProgress,
caRightPaintProgress, caRightPaintProgress,
caMiddlePaintProgress,
caLeftPaintEnd, caLeftPaintEnd,
caRightPaintEnd, caRightPaintEnd,
caMiddlePaintEnd,
caDblClick, caDblClick,
// Add new actions here // Add new actions here
caUnknown = 255, caUnknown = 255,
@ -266,10 +269,13 @@ inline const char * ClickActionToString(int a_ClickAction)
case caRightClickOutsideHoldNothing: return "caRightClickOutsideHoldNothing"; case caRightClickOutsideHoldNothing: return "caRightClickOutsideHoldNothing";
case caLeftPaintBegin: return "caLeftPaintBegin"; case caLeftPaintBegin: return "caLeftPaintBegin";
case caRightPaintBegin: return "caRightPaintBegin"; case caRightPaintBegin: return "caRightPaintBegin";
case caMiddlePaintBegin: return "caMiddlePaintBegin";
case caLeftPaintProgress: return "caLeftPaintProgress"; case caLeftPaintProgress: return "caLeftPaintProgress";
case caRightPaintProgress: return "caRightPaintProgress"; case caRightPaintProgress: return "caRightPaintProgress";
case caMiddlePaintProgress: return "caMiddlePaintProgress";
case caLeftPaintEnd: return "caLeftPaintEnd"; case caLeftPaintEnd: return "caLeftPaintEnd";
case caRightPaintEnd: return "caRightPaintEnd"; case caRightPaintEnd: return "caRightPaintEnd";
case caMiddlePaintEnd: return "caMiddlePaintEnd";
case caDblClick: return "caDblClick"; case caDblClick: return "caDblClick";
case caUnknown: return "caUnknown"; case caUnknown: return "caUnknown";

View File

@ -2690,6 +2690,9 @@ void cProtocol_1_8_0::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
case 0x0504: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintBegin : caUnknown; break; case 0x0504: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintBegin : caUnknown; break;
case 0x0505: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightPaintProgress : caUnknown; break; case 0x0505: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightPaintProgress : caUnknown; break;
case 0x0506: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintEnd : caUnknown; break; case 0x0506: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintEnd : caUnknown; break;
case 0x0508: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caMiddlePaintBegin : caUnknown; break;
case 0x0509: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caMiddlePaintProgress : caUnknown; break;
case 0x050a: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caMiddlePaintEnd : caUnknown; break;
case 0x0600: Action = caDblClick; break; case 0x0600: Action = caDblClick; break;
default: default:
{ {

View File

@ -2788,6 +2788,9 @@ void cProtocol_1_9_0::HandlePacketWindowClick(cByteBuffer & a_ByteBuffer)
case 0x0504: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintBegin : caUnknown; break; case 0x0504: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintBegin : caUnknown; break;
case 0x0505: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightPaintProgress : caUnknown; break; case 0x0505: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caRightPaintProgress : caUnknown; break;
case 0x0506: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintEnd : caUnknown; break; case 0x0506: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caRightPaintEnd : caUnknown; break;
case 0x0508: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caMiddlePaintBegin : caUnknown; break;
case 0x0509: Action = (SlotNum != SLOT_NUM_OUTSIDE) ? caMiddlePaintProgress : caUnknown; break;
case 0x050a: Action = (SlotNum == SLOT_NUM_OUTSIDE) ? caMiddlePaintEnd : caUnknown; break;
case 0x0600: Action = caDblClick; break; case 0x0600: Action = caDblClick; break;
default: default:
{ {

View File

@ -244,10 +244,13 @@ void cWindow::Clicked(
} }
case caLeftPaintBegin: OnPaintBegin (a_Player); return; case caLeftPaintBegin: OnPaintBegin (a_Player); return;
case caRightPaintBegin: OnPaintBegin (a_Player); return; case caRightPaintBegin: OnPaintBegin (a_Player); return;
case caMiddlePaintBegin: OnPaintBegin (a_Player); return;
case caLeftPaintProgress: OnPaintProgress (a_Player, a_SlotNum); return; case caLeftPaintProgress: OnPaintProgress (a_Player, a_SlotNum); return;
case caRightPaintProgress: OnPaintProgress (a_Player, a_SlotNum); return; case caRightPaintProgress: OnPaintProgress (a_Player, a_SlotNum); return;
case caMiddlePaintProgress: OnPaintProgress (a_Player, a_SlotNum); return;
case caLeftPaintEnd: OnLeftPaintEnd (a_Player); return; case caLeftPaintEnd: OnLeftPaintEnd (a_Player); return;
case caRightPaintEnd: OnRightPaintEnd (a_Player); return; case caRightPaintEnd: OnRightPaintEnd (a_Player); return;
case caMiddlePaintEnd: OnMiddlePaintEnd(a_Player); return;
default: default:
{ {
break; break;
@ -643,9 +646,33 @@ void cWindow::OnRightPaintEnd(cPlayer & a_Player)
int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums) void cWindow::OnMiddlePaintEnd(cPlayer & a_Player)
{ {
if (static_cast<size_t>(a_Item.m_ItemCount) < a_SlotNums.size()) if (!a_Player.IsGameModeCreative())
{
// Midle click paint is only valid for creative mode
return;
}
// Fill available slots with full stacks of the dragging item
const auto & DraggingItem = a_Player.GetDraggingItem();
auto StackSize = ItemHandler(DraggingItem.m_ItemType)->GetMaxStackSize();
if (0 < DistributeItemToSlots(a_Player, DraggingItem, StackSize, a_Player.GetInventoryPaintSlots(), false))
{
// If any items were distibuted, set dragging item empty
a_Player.GetDraggingItem().Empty();
}
SendWholeWindow(*a_Player.GetClientHandle());
}
int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums, bool a_LimitItems)
{
if (a_LimitItems && (static_cast<size_t>(a_Item.m_ItemCount) < a_SlotNums.size()))
{ {
LOGWARNING("%s: Distributing less items (%d) than slots (" SIZE_T_FMT ")", __FUNCTION__, static_cast<int>(a_Item.m_ItemCount), a_SlotNums.size()); LOGWARNING("%s: Distributing less items (%d) than slots (" SIZE_T_FMT ")", __FUNCTION__, static_cast<int>(a_Item.m_ItemCount), a_SlotNums.size());
// This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now // This doesn't seem to happen with the 1.5.1 client, so we don't worry about it for now

View File

@ -218,8 +218,12 @@ protected:
/** Processes the entire action stored in the internal structures for inventory painting; distributes one item into each slot */ /** Processes the entire action stored in the internal structures for inventory painting; distributes one item into each slot */
void OnRightPaintEnd(cPlayer & a_Player); void OnRightPaintEnd(cPlayer & a_Player);
/** Distributes a_NumToEachSlot items into the slots specified in a_SlotNums; returns the total number of items distributed */ /** Processes the entire action stored in the internal structures for inventory painting; distributes a full stack into each slot */
int DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums); void OnMiddlePaintEnd(cPlayer & a_Player);
/** Distributes a_NumToEachSlot items into the slots specified in a_SlotNums; returns the total number of items distributed.
@param a_LimitItems if false, no checks are performed on a_Item.m_ItemCount. */
int DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums, bool a_LimitItems = true);
} ; // tolua_export } ; // tolua_export