summaryrefslogtreecommitdiffstats
path: root/source/UI/SlotArea.h
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-20 22:10:46 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-09-20 22:10:46 +0200
commitfdf83870925d30560ec7f853fdc19ec6c9e29155 (patch)
treedb4a9743f510da5409b91482be5d174c028ac794 /source/UI/SlotArea.h
parentRefactored windows. (diff)
downloadcuberite-fdf83870925d30560ec7f853fdc19ec6c9e29155.tar
cuberite-fdf83870925d30560ec7f853fdc19ec6c9e29155.tar.gz
cuberite-fdf83870925d30560ec7f853fdc19ec6c9e29155.tar.bz2
cuberite-fdf83870925d30560ec7f853fdc19ec6c9e29155.tar.lz
cuberite-fdf83870925d30560ec7f853fdc19ec6c9e29155.tar.xz
cuberite-fdf83870925d30560ec7f853fdc19ec6c9e29155.tar.zst
cuberite-fdf83870925d30560ec7f853fdc19ec6c9e29155.zip
Diffstat (limited to '')
-rw-r--r--source/UI/SlotArea.h88
1 files changed, 72 insertions, 16 deletions
diff --git a/source/UI/SlotArea.h b/source/UI/SlotArea.h
index 0e620cd54..0f3182036 100644
--- a/source/UI/SlotArea.h
+++ b/source/UI/SlotArea.h
@@ -38,12 +38,23 @@ public:
/// Called when a player clicks in the window. Parameters taken from the click packet.
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, bool a_IsRightClick, bool a_IsShiftPressed, const cItem & a_ClickedItem);
+ /// Called from Clicked if it is a valid shiftclick
+ virtual void ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem);
+
/// Called when a new player opens the same parent window. The window already tracks the player. CS-locked.
virtual void OnPlayerAdded(cPlayer & a_Player) {} ;
/// Called when one of the players closes the parent window. The window already doesn't track the player. CS-locked.
virtual void OnPlayerRemoved(cPlayer & a_Player) {} ;
+ /** Called to store as much of a_ItemStack in the area as possible. a_ItemStack is modified to reflect the change.
+ The default implementation searches each slot for available space and distributes the stack there.
+ if a_ShouldApply is true, the changes are written into the slots;
+ if a_ShouldApply is false, only a_ItemStack is modified to reflect the number of fits (for fit-testing purposes)
+ If a_KeepEmptySlots is true, empty slots will be skipped and won't be filled
+ */
+ virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots);
+
protected:
int m_NumSlots;
cWindow & m_ParentWindow;
@@ -53,19 +64,75 @@ protected:
-class cSlotAreaInventory :
+/// Handles any part of the inventory, using parameters in constructor to distinguish between the parts
+class cSlotAreaInventoryBase :
public cSlotArea
{
typedef cSlotArea super;
public:
- cSlotAreaInventory(cWindow & a_ParentWindow);
+ cSlotAreaInventoryBase(int a_NumSlots, int a_SlotOffset, cWindow & a_ParentWindow);
// Creative inventory's click handling is somewhat different from survival inventory's, handle that here:
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, bool a_IsRightClick, bool a_IsShiftPressed, const cItem & a_ClickedItem) override;
virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) override;
virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
+
+protected:
+ int m_SlotOffset; // Index that this area's slot 0 has in the underlying cInventory
+} ;
+
+
+
+
+
+/// Handles the "inner" inventory of each player, excluding the armor and hotbar
+class cSlotAreaInventory :
+ public cSlotAreaInventoryBase
+{
+ typedef cSlotAreaInventoryBase super;
+
+public:
+ cSlotAreaInventory(cWindow & a_ParentWindow) :
+ cSlotAreaInventoryBase(27, 9, a_ParentWindow) // 27 slots, starting at inventory index 9
+ {
+ }
+} ;
+
+
+
+
+
+/// Handles the "outer" inevntory of each player - the hotbar
+class cSlotAreaHotBar :
+ public cSlotAreaInventoryBase
+{
+ typedef cSlotAreaInventoryBase super;
+
+public:
+ cSlotAreaHotBar(cWindow & a_ParentWindow) :
+ cSlotAreaInventoryBase(9, 36, a_ParentWindow)
+ {
+ }
+} ;
+
+
+
+
+
+/// Handles the armor area of the inventory
+class cSlotAreaArmor :
+ public cSlotAreaInventoryBase
+{
+public:
+ cSlotAreaArmor(cWindow & a_ParentWindow) :
+ cSlotAreaInventoryBase(4, 5, a_ParentWindow)
+ {
+ }
+
+ // Distributing the stack is allowed only for compatible items (helmets into helmet slot etc.)
+ virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override;
} ;
@@ -119,6 +186,9 @@ public:
virtual void Clicked (cPlayer & a_Player, int a_SlotNum, bool a_IsRightClick, bool a_IsShiftPressed, const cItem & a_ClickedItem) override;
virtual void OnPlayerRemoved(cPlayer & a_Player) override;
+ // 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;
@@ -176,17 +246,3 @@ protected:
-
-class cSlotAreaArmor :
- public cSlotArea
-{
-public:
- cSlotAreaArmor(cWindow & a_ParentWindow);
-
- virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) override;
- virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
-} ;
-
-
-
-