1
0

Added inventory number click.

This commit is contained in:
Howaner 2014-07-09 14:30:06 +02:00
parent 9d7a59012c
commit 3615bf825b
2 changed files with 43 additions and 1 deletions

View File

@ -77,6 +77,19 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA
DropClicked(a_Player, a_SlotNum, (a_ClickAction == caCtrlDropKey));
return;
}
case caNumber1:
case caNumber2:
case caNumber3:
case caNumber4:
case caNumber5:
case caNumber6:
case caNumber7:
case caNumber8:
case caNumber9:
{
NumberClicked(a_Player, a_SlotNum, a_ClickAction);
return;
}
default:
{
break;
@ -283,6 +296,31 @@ void cSlotArea::DropClicked(cPlayer & a_Player, int a_SlotNum, bool a_DropStack)
void cSlotArea::NumberClicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction)
{
if ((a_ClickAction < caNumber1) || (a_ClickAction > caNumber9))
{
return;
}
int HotbarSlot = (int)a_ClickAction - (int)caNumber1;
cItem ItemInHotbar(a_Player.GetInventory().GetHotbarSlot(HotbarSlot));
cItem ItemInSlot(*GetSlot(a_SlotNum, a_Player));
// The items are equal. Do nothing.
if (ItemInHotbar.IsEqual(ItemInSlot))
{
return;
}
a_Player.GetInventory().SetHotbarSlot(HotbarSlot, ItemInSlot);
SetSlot(a_SlotNum, a_Player, ItemInHotbar);
}
void cSlotArea::OnPlayerAdded(cPlayer & a_Player)
{
UNUSED(a_Player);

View File

@ -56,6 +56,9 @@ public:
/** Called from Clicked when the action is a drop click. */
virtual void DropClicked(cPlayer & a_Player, int a_SlotNum, bool a_DropStack);
/** Called from Clicked when the action is a number click. */
virtual void NumberClicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction);
/// Called when a new player opens the same parent window. The window already tracks the player. CS-locked.
virtual void OnPlayerAdded(cPlayer & a_Player);
@ -242,6 +245,7 @@ public:
// Distributing items into this area is completely disabled
virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override;
protected:
/// Maps player's EntityID -> current recipe; not a std::map because cCraftingGrid needs proper constructor params
typedef std::list<std::pair<int, cCraftingRecipe> > cRecipeMap;
@ -257,7 +261,7 @@ protected:
/** 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);