summaryrefslogtreecommitdiffstats
path: root/source/UI
diff options
context:
space:
mode:
Diffstat (limited to 'source/UI')
-rw-r--r--source/UI/SlotArea.cpp31
-rw-r--r--source/UI/SlotArea.h26
-rw-r--r--source/UI/Window.cpp37
-rw-r--r--source/UI/Window.h37
4 files changed, 102 insertions, 29 deletions
diff --git a/source/UI/SlotArea.cpp b/source/UI/SlotArea.cpp
index 0d26edbb7..8333d0574 100644
--- a/source/UI/SlotArea.cpp
+++ b/source/UI/SlotArea.cpp
@@ -658,6 +658,37 @@ void cSlotAreaArmor::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bo
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cSlotAreaItemGrid:
+
+cSlotAreaItemGrid::cSlotAreaItemGrid(cItemGrid & a_ItemGrid, cWindow & a_ParentWindow) :
+ super(a_ItemGrid.GetNumSlots(), a_ParentWindow),
+ m_ItemGrid(a_ItemGrid)
+{
+}
+
+
+
+
+
+const cItem * cSlotAreaItemGrid::GetSlot(int a_SlotNum, cPlayer & a_Player) const
+{
+ return &m_ItemGrid.GetSlot(a_SlotNum);
+}
+
+
+
+
+
+void cSlotAreaItemGrid::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item)
+{
+ m_ItemGrid.SetSlot(a_SlotNum, a_Item);
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cSlotAreaTemporary:
cSlotAreaTemporary::cSlotAreaTemporary(int a_NumSlots, cWindow & a_ParentWindow) :
diff --git a/source/UI/SlotArea.h b/source/UI/SlotArea.h
index cdf14baad..0ad5296db 100644
--- a/source/UI/SlotArea.h
+++ b/source/UI/SlotArea.h
@@ -89,7 +89,7 @@ protected:
-/// Handles the "inner" inventory of each player, excluding the armor and hotbar
+/// Handles the main inventory of each player, excluding the armor and hotbar
class cSlotAreaInventory :
public cSlotAreaInventoryBase
{
@@ -106,7 +106,7 @@ public:
-/// Handles the "outer" inevntory of each player - the hotbar
+/// Handles the hotbar of each player
class cSlotAreaHotBar :
public cSlotAreaInventoryBase
{
@@ -123,7 +123,7 @@ public:
-/// Handles the armor area of the inventory
+/// Handles the armor area of the player's inventory
class cSlotAreaArmor :
public cSlotAreaInventoryBase
{
@@ -141,6 +141,26 @@ public:
+/// Handles any slot area that is representing a cItemGrid; same items for all the players
+class cSlotAreaItemGrid :
+ public cSlotArea
+{
+ typedef cSlotArea super;
+
+public:
+ cSlotAreaItemGrid(cItemGrid & a_ItemGrid, cWindow & a_ParentWindow);
+
+ 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;
+} ;
+
+
+
+
+
/** 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.
diff --git a/source/UI/Window.cpp b/source/UI/Window.cpp
index 2b279a22c..661f9f62f 100644
--- a/source/UI/Window.cpp
+++ b/source/UI/Window.cpp
@@ -101,6 +101,39 @@ void cWindow::SetSlot(cPlayer & a_Player, int a_SlotNum, const cItem & a_Item)
+bool cWindow::IsSlotInPlayerMainInventory(int a_SlotNum) const
+{
+ // Returns true if the specified slot is in the Player Main Inventory slotarea
+ // The player main inventory is always 27 slots, 9 slots from the end of the inventory
+ return ((a_SlotNum >= GetNumSlots() - 36) && (a_SlotNum < GetNumSlots() - 9));
+}
+
+
+
+
+
+bool cWindow::IsSlotInPlayerHotbar(int a_SlotNum) const
+{
+ // Returns true if the specified slot is in the Player Hotbar slotarea
+ // The hotbar is always the last 9 slots
+ return ((a_SlotNum >= GetNumSlots() - 9) && (a_SlotNum < GetNumSlots()));
+}
+
+
+
+
+
+bool cWindow::IsSlotInPlayerInventory(int a_SlotNum) const
+{
+ // Returns true if the specified slot is in the Player Main Inventory or Hotbar slotareas. Note that returns false for Armor.
+ // The player combined inventory is always the last 36 slots
+ return ((a_SlotNum >= GetNumSlots() - 36) && (a_SlotNum < GetNumSlots()));
+}
+
+
+
+
+
void cWindow::GetSlots(cPlayer & a_Player, cItems & a_Slots) const
{
a_Slots.clear();
@@ -264,9 +297,9 @@ void cWindow::OwnerDestroyed()
// Close window for each player. Note that the last one needs special handling
while (m_OpenedBy.size() > 1)
{
- (*m_OpenedBy.begin() )->CloseWindow((char)GetWindowType());
+ (*m_OpenedBy.begin() )->CloseWindow();
}
- (*m_OpenedBy.begin() )->CloseWindow((char)GetWindowType());
+ (*m_OpenedBy.begin() )->CloseWindow();
}
diff --git a/source/UI/Window.h b/source/UI/Window.h
index c31ed8a4d..1f2495a46 100644
--- a/source/UI/Window.h
+++ b/source/UI/Window.h
@@ -68,7 +68,7 @@ public:
cWindow(WindowType a_WindowType, const AString & a_WindowTitle);
virtual ~cWindow();
- char GetWindowID(void) const { return m_WindowID; }
+ char GetWindowID(void) const { return m_WindowID; } // tolua_export
int GetWindowType(void) const { return m_WindowType; } // tolua_export
cWindowOwner * GetOwner(void) { return m_Owner; }
@@ -84,6 +84,15 @@ public:
/// Sets the item to the specified slot for the specified player
void SetSlot(cPlayer & a_Player, int a_SlotNum, const cItem & a_Item);
+ /// Returns true if the specified slot is in the Player Main Inventory slotarea
+ bool IsSlotInPlayerMainInventory(int a_SlotNum) const;
+
+ /// Returns true if the specified slot is in the Player Hotbar slotarea
+ bool IsSlotInPlayerHotbar(int a_SlotNum) const;
+
+ /// Returns true if the specified slot is in the Player Main Inventory or Hotbar slotareas. Note that returns false for Armor.
+ bool IsSlotInPlayerInventory(int a_SlotNum) const;
+
// tolua_end
/// Fills a_Slots with the slots read from m_SlotAreas[], for the specified player
@@ -144,7 +153,8 @@ protected:
static char m_WindowIDCounter;
- void Destroy(void);
+ /// Sets the internal flag as "destroyed"; notifies the owner that the window is destroying
+ virtual void Destroy(void);
/** Returns the correct slot area for the specified window-global SlotNum
Also returns the area-local SlotNum corresponding to the GlobalSlotNum
@@ -173,7 +183,7 @@ protected:
/// Distributes a_NumToEachSlot items into the slots specified in a_SlotNums; returns the total number of items distributed
int DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums);
-} ;
+} ; // tolua_export
@@ -244,24 +254,3 @@ protected:
-
-// tolua_begin
-
-/// A window that has been created by a Lua plugin and is handled entirely by that plugin
-class cLuaWindow :
- public cWindow
-{
-public:
- /// Create a window of the specified type, with a slot grid of a_SlotsX * a_SlotsY size
- cLuaWindow(cWindow::WindowType a_WindowType, int a_SlotsX, int a_SlotsY, const AString & a_Title);
-
- // tolua_end
-
-protected:
- /// Contents of the non-inventory part
- cItemGrid m_Contents;
-} ;
-
-
-
-