2012-09-20 09:25:54 -04:00
|
|
|
|
|
|
|
// SlotArea.h
|
|
|
|
|
|
|
|
// Interfaces to the cSlotArea class representing a contiguous area of slots in a UI window
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-05-24 03:30:39 -04:00
|
|
|
#include "../Inventory.h"
|
2012-09-20 09:25:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cWindow;
|
|
|
|
class cPlayer;
|
|
|
|
class cChestEntity;
|
2013-05-26 10:39:04 -04:00
|
|
|
class cDropSpenserEntity;
|
2012-09-20 09:25:54 -04:00
|
|
|
class cFurnaceEntity;
|
|
|
|
class cCraftingRecipe;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cSlotArea
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cSlotArea(int a_NumSlots, cWindow & a_ParentWindow);
|
2012-09-25 04:23:19 -04:00
|
|
|
virtual ~cSlotArea() {} // force a virtual destructor in all subclasses
|
2012-09-20 09:25:54 -04:00
|
|
|
|
|
|
|
int GetNumSlots(void) const { return m_NumSlots; }
|
|
|
|
|
|
|
|
/// Called to retrieve an item in the specified slot for the specified player. Must return a valid cItem.
|
2013-05-30 04:40:13 -04:00
|
|
|
virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const = 0;
|
2012-09-20 09:25:54 -04:00
|
|
|
|
|
|
|
/// Called to set an item in the specified slot for the specified player
|
|
|
|
virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) = 0;
|
|
|
|
|
|
|
|
/// Called when a player clicks in the window. Parameters taken from the click packet.
|
2013-05-08 05:45:07 -04:00
|
|
|
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem);
|
2012-09-20 09:25:54 -04:00
|
|
|
|
2012-09-20 16:10:46 -04:00
|
|
|
/// Called from Clicked if it is a valid shiftclick
|
|
|
|
virtual void ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem);
|
|
|
|
|
2012-09-20 09:25:54 -04:00
|
|
|
/// 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) {} ;
|
|
|
|
|
2012-09-20 16:10:46 -04:00
|
|
|
/** 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);
|
|
|
|
|
2012-09-20 09:25:54 -04:00
|
|
|
protected:
|
|
|
|
int m_NumSlots;
|
|
|
|
cWindow & m_ParentWindow;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-20 16:10:46 -04:00
|
|
|
/// Handles any part of the inventory, using parameters in constructor to distinguish between the parts
|
|
|
|
class cSlotAreaInventoryBase :
|
2012-09-20 09:25:54 -04:00
|
|
|
public cSlotArea
|
|
|
|
{
|
|
|
|
typedef cSlotArea super;
|
|
|
|
|
|
|
|
public:
|
2012-09-20 16:10:46 -04:00
|
|
|
cSlotAreaInventoryBase(int a_NumSlots, int a_SlotOffset, cWindow & a_ParentWindow);
|
2012-09-20 09:25:54 -04:00
|
|
|
|
|
|
|
// Creative inventory's click handling is somewhat different from survival inventory's, handle that here:
|
2013-05-08 05:45:07 -04:00
|
|
|
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
|
2012-09-20 09:25:54 -04:00
|
|
|
|
2013-05-30 04:40:13 -04:00
|
|
|
virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
|
2012-09-20 09:25:54 -04:00
|
|
|
virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
|
2012-09-20 16:10:46 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_SlotOffset; // Index that this area's slot 0 has in the underlying cInventory
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-30 15:34:09 -04:00
|
|
|
/// Handles the main inventory of each player, excluding the armor and hotbar
|
2012-09-20 16:10:46 -04:00
|
|
|
class cSlotAreaInventory :
|
|
|
|
public cSlotAreaInventoryBase
|
|
|
|
{
|
|
|
|
typedef cSlotAreaInventoryBase super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
cSlotAreaInventory(cWindow & a_ParentWindow) :
|
2013-05-24 03:30:39 -04:00
|
|
|
cSlotAreaInventoryBase(cInventory::invInventoryCount, cInventory::invInventoryOffset, a_ParentWindow)
|
2012-09-20 16:10:46 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-30 15:34:09 -04:00
|
|
|
/// Handles the hotbar of each player
|
2012-09-20 16:10:46 -04:00
|
|
|
class cSlotAreaHotBar :
|
|
|
|
public cSlotAreaInventoryBase
|
|
|
|
{
|
|
|
|
typedef cSlotAreaInventoryBase super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
cSlotAreaHotBar(cWindow & a_ParentWindow) :
|
2013-05-24 03:30:39 -04:00
|
|
|
cSlotAreaInventoryBase(cInventory::invHotbarCount, cInventory::invHotbarOffset, a_ParentWindow)
|
2012-09-20 16:10:46 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-30 15:34:09 -04:00
|
|
|
/// Handles the armor area of the player's inventory
|
2012-09-20 16:10:46 -04:00
|
|
|
class cSlotAreaArmor :
|
|
|
|
public cSlotAreaInventoryBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cSlotAreaArmor(cWindow & a_ParentWindow) :
|
2013-05-24 03:30:39 -04:00
|
|
|
cSlotAreaInventoryBase(cInventory::invArmorCount, cInventory::invArmorOffset, a_ParentWindow)
|
2012-09-20 16:10:46 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2012-09-20 09:25:54 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-30 15:34:09 -04:00
|
|
|
/// Handles any slot area that is representing a cItemGrid; same items for all the players
|
|
|
|
class cSlotAreaItemGrid :
|
2013-06-13 03:36:43 -04:00
|
|
|
public cSlotArea,
|
|
|
|
public cItemGrid::cListener
|
2013-05-30 15:34:09 -04:00
|
|
|
{
|
|
|
|
typedef cSlotArea super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
cSlotAreaItemGrid(cItemGrid & a_ItemGrid, cWindow & a_ParentWindow);
|
|
|
|
|
2013-06-13 03:36:43 -04:00
|
|
|
virtual ~cSlotAreaItemGrid();
|
|
|
|
|
2013-05-30 15:34:09 -04:00
|
|
|
virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
|
|
|
|
virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
cItemGrid & m_ItemGrid;
|
2013-06-13 03:36:43 -04:00
|
|
|
|
|
|
|
// cItemGrid::cListener overrides:
|
|
|
|
virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
|
2013-05-30 15:34:09 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-20 09:25:54 -04:00
|
|
|
/** A cSlotArea with items layout that is private to each player and is temporary, such as
|
|
|
|
a crafting grid or an enchantment table.
|
|
|
|
This common ancestor stores the items in a per-player map. It also implements tossing items from the map.
|
|
|
|
*/
|
|
|
|
class cSlotAreaTemporary :
|
|
|
|
public cSlotArea
|
|
|
|
{
|
|
|
|
typedef cSlotArea super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
cSlotAreaTemporary(int a_NumSlots, cWindow & a_ParentWindow);
|
|
|
|
|
|
|
|
// cSlotArea overrides:
|
2013-05-30 04:40:13 -04:00
|
|
|
virtual const cItem * GetSlot (int a_SlotNum, cPlayer & a_Player) const override;
|
2012-09-20 09:25:54 -04:00
|
|
|
virtual void SetSlot (int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
|
|
|
|
virtual void OnPlayerAdded (cPlayer & a_Player) override;
|
|
|
|
virtual void OnPlayerRemoved(cPlayer & a_Player) override;
|
|
|
|
|
|
|
|
/// Tosses the player's items in slots [a_Begin, a_End) (ie. incl. a_Begin, but excl. a_End)
|
|
|
|
void TossItems(cPlayer & a_Player, int a_Begin, int a_End);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
typedef std::map<int, std::vector<cItem> > cItemMap; // Maps EntityID -> items
|
|
|
|
|
|
|
|
cItemMap m_Items;
|
|
|
|
|
|
|
|
/// Returns the pointer to the slot array for the player specified.
|
|
|
|
cItem * GetPlayerSlots(cPlayer & a_Player);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cSlotAreaCrafting :
|
|
|
|
public cSlotAreaTemporary
|
|
|
|
{
|
|
|
|
typedef cSlotAreaTemporary super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// a_GridSize is allowed to be only 2 or 3
|
|
|
|
cSlotAreaCrafting(int a_GridSize, cWindow & a_ParentWindow);
|
|
|
|
|
|
|
|
// cSlotAreaTemporary overrides:
|
2013-05-08 05:45:07 -04:00
|
|
|
virtual void Clicked (cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
|
2012-09-20 09:25:54 -04:00
|
|
|
virtual void OnPlayerRemoved(cPlayer & a_Player) override;
|
|
|
|
|
2012-09-20 16:10:46 -04:00
|
|
|
// Distributing items into this area is completely disabled
|
|
|
|
virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override {}
|
|
|
|
|
2012-09-20 09:25:54 -04:00
|
|
|
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;
|
|
|
|
|
|
|
|
int m_GridSize;
|
|
|
|
cRecipeMap m_Recipes;
|
|
|
|
|
|
|
|
/// Handles a click in the result slot. Crafts using the current recipe, if possible
|
2012-09-21 16:50:34 -04:00
|
|
|
void ClickedResult(cPlayer & a_Player);
|
|
|
|
|
|
|
|
/// 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);
|
2012-09-20 09:25:54 -04:00
|
|
|
|
|
|
|
/// 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);
|
|
|
|
|
|
|
|
/// Retrieves the recipe for the specified player from the map, or creates one if not found
|
|
|
|
cCraftingRecipe & GetRecipeForPlayer(cPlayer & a_Player);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cSlotAreaChest :
|
|
|
|
public cSlotArea
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cSlotAreaChest(cChestEntity * a_Chest, cWindow & a_ParentWindow);
|
|
|
|
|
2013-05-30 04:40:13 -04:00
|
|
|
virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
|
2012-09-20 09:25:54 -04:00
|
|
|
virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
cChestEntity * m_Chest;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-08 00:01:06 -05:00
|
|
|
class cSlotAreaDoubleChest :
|
|
|
|
public cSlotArea
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cSlotAreaDoubleChest(cChestEntity * a_TopChest, cChestEntity * a_BottomChest, cWindow & a_ParentWindow);
|
|
|
|
|
2013-05-30 04:40:13 -04:00
|
|
|
virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
|
2013-01-08 00:01:06 -05:00
|
|
|
virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
cChestEntity * m_TopChest;
|
|
|
|
cChestEntity * m_BottomChest;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-20 09:25:54 -04:00
|
|
|
class cSlotAreaFurnace :
|
2013-06-16 16:24:07 -04:00
|
|
|
public cSlotArea,
|
|
|
|
public cItemGrid::cListener
|
2012-09-20 09:25:54 -04:00
|
|
|
{
|
|
|
|
typedef cSlotArea super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
cSlotAreaFurnace(cFurnaceEntity * a_Furnace, cWindow & a_ParentWindow);
|
|
|
|
|
2013-06-16 16:24:07 -04:00
|
|
|
virtual ~cSlotAreaFurnace();
|
|
|
|
|
2013-05-08 05:45:07 -04:00
|
|
|
virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
|
2013-05-30 04:40:13 -04:00
|
|
|
virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
|
2012-09-20 09:25:54 -04:00
|
|
|
virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
cFurnaceEntity * m_Furnace;
|
2013-06-16 16:24:07 -04:00
|
|
|
|
|
|
|
// cItemGrid::cListener overrides:
|
|
|
|
virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
|
2012-09-20 09:25:54 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|