1
0
Fork 0

Added drop window action.

This commit is contained in:
Howaner 2014-07-06 00:40:59 +02:00
parent 7a78f23b4a
commit 9d7a59012c
3 changed files with 113 additions and 25 deletions

View File

@ -71,6 +71,12 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA
MiddleClicked(a_Player, a_SlotNum);
return;
}
case caDropKey:
case caCtrlDropKey:
{
DropClicked(a_Player, a_SlotNum, (a_ClickAction == caCtrlDropKey));
return;
}
default:
{
break;
@ -249,6 +255,34 @@ void cSlotArea::MiddleClicked(cPlayer & a_Player, int a_SlotNum)
void cSlotArea::DropClicked(cPlayer & a_Player, int a_SlotNum, bool a_DropStack)
{
cItem Slot(*GetSlot(a_SlotNum, a_Player));
if (Slot.IsEmpty())
{
return;
}
cItem ItemToDrop = Slot.CopyOne();
if (a_DropStack)
{
ItemToDrop.m_ItemCount = Slot.m_ItemCount;
}
Slot.m_ItemCount -= ItemToDrop.m_ItemCount;
if (Slot.m_ItemCount <= 0)
{
Slot.Empty();
}
SetSlot(a_SlotNum, a_Player, Slot);
a_Player.TossPickup(ItemToDrop);
}
void cSlotArea::OnPlayerAdded(cPlayer & a_Player)
{
UNUSED(a_Player);
@ -446,6 +480,10 @@ void cSlotAreaCrafting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction
{
ShiftClickedResult(a_Player);
}
else if ((a_ClickAction == caDropKey) || (a_ClickAction == caCtrlDropKey))
{
DropClickedResult(a_Player);
}
else
{
ClickedResult(a_Player);
@ -594,6 +632,27 @@ void cSlotAreaCrafting::ShiftClickedResult(cPlayer & a_Player)
void cSlotAreaCrafting::DropClickedResult(cPlayer & a_Player)
{
// Get the current recipe:
cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player);
const cItem & Result = Recipe.GetResult();
cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1;
cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize);
a_Player.TossPickup(Result);
Recipe.ConsumeIngredients(Grid);
Grid.CopyToItems(PlayerSlots);
HandleCraftItem(Result, a_Player);
UpdateRecipe(a_Player);
}
void cSlotAreaCrafting::UpdateRecipe(cPlayer & a_Player)
{
cCraftingGrid Grid(GetPlayerSlots(a_Player) + 1, m_GridSize, m_GridSize);
@ -698,6 +757,16 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C
MiddleClicked(a_Player, a_SlotNum);
return;
}
case caDropKey:
case caCtrlDropKey:
{
if (CanTakeResultItem(a_Player))
{
DropClicked(a_Player, a_SlotNum, true);
OnTakeResult(a_Player);
}
return;
}
default:
{
break;
@ -1453,17 +1522,32 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a
bAsync = true;
}
if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick))
switch (a_ClickAction)
{
HandleSmeltItem(Slot, a_Player);
ShiftClicked(a_Player, a_SlotNum, Slot);
return;
}
if (a_ClickAction == caMiddleClick)
{
MiddleClicked(a_Player, a_SlotNum);
return;
case caShiftLeftClick:
case caShiftRightClick:
{
HandleSmeltItem(Slot, a_Player);
ShiftClicked(a_Player, a_SlotNum, Slot);
return;
}
case caMiddleClick:
{
MiddleClicked(a_Player, a_SlotNum);
return;
}
case caDropKey:
case caCtrlDropKey:
{
DropClicked(a_Player, a_SlotNum, (a_SlotNum == caCtrlDropKey));
Slot.m_ItemCount = Slot.m_ItemCount - GetSlot(a_SlotNum, a_Player)->m_ItemCount;
HandleSmeltItem(Slot, a_Player);
return;
}
default:
{
break;
}
}
cItem & DraggingItem = a_Player.GetDraggingItem();
@ -1641,6 +1725,12 @@ void cSlotAreaInventoryBase::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAc
{
if (a_Player.IsGameModeCreative() && (m_ParentWindow.GetWindowType() == cWindow::wtInventory))
{
if ((a_ClickAction == caDropKey) || (a_ClickAction == caCtrlDropKey))
{
DropClicked(a_Player, a_SlotNum, (a_ClickAction == caCtrlDropKey));
return;
}
// Creative inventory must treat a_ClickedItem as a DraggedItem instead, replacing the inventory slot with it
SetSlot(a_SlotNum, a_Player, a_ClickedItem);
return;

View File

@ -53,6 +53,9 @@ public:
/** Called from Clicked when the action is a middleclick */
virtual void MiddleClicked(cPlayer & a_Player, int a_SlotNum);
/** Called from Clicked when the action is a drop click. */
virtual void DropClicked(cPlayer & a_Player, int a_SlotNum, bool a_DropStack);
/// Called when a new player opens the same parent window. The window already tracks the player. CS-locked.
virtual void OnPlayerAdded(cPlayer & a_Player);
@ -251,6 +254,9 @@ protected:
/// Handles a shift-click in the result slot. Crafts using the current recipe until it changes or no more space for result.
void ShiftClickedResult(cPlayer & a_Player);
/** Handles a drop-click in the result slot. */
void DropClickedResult(cPlayer & a_Player);
/// Updates the current recipe and result slot based on the ingredients currently in the crafting grid of the specified player
void UpdateRecipe(cPlayer & a_Player);

View File

@ -178,6 +178,7 @@ void cWindow::Clicked(
switch (a_ClickAction)
{
case caLeftClickOutside:
case caRightClickOutside:
{
if (PlgMgr->CallHookPlayerTossingItem(a_Player))
@ -190,25 +191,16 @@ void cWindow::Clicked(
a_Player.TossPickup(a_ClickedItem);
}
// Toss one of the dragged items:
a_Player.TossHeldItem();
return;
}
case caLeftClickOutside:
{
if (PlgMgr->CallHookPlayerTossingItem(a_Player))
if (a_ClickAction == caLeftClickOutside)
{
// A plugin doesn't agree with the tossing. The plugin itself is responsible for handling the consequences (possible inventory mismatch)
return;
// Toss all dragged items:
a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount);
}
if (a_Player.IsGameModeCreative())
else
{
a_Player.TossPickup(a_ClickedItem);
// Toss one of the dragged items:
a_Player.TossHeldItem();
}
// Toss all dragged items:
a_Player.TossHeldItem(a_Player.GetDraggingItem().m_ItemCount);
return;
}
case caLeftClickOutsideHoldNothing: