summaryrefslogtreecommitdiffstats
path: root/src/UI
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/UI/EnchantingWindow.cpp29
-rw-r--r--src/UI/EnchantingWindow.h10
-rw-r--r--src/UI/SlotArea.cpp20
-rw-r--r--src/UI/SlotArea.h2
-rw-r--r--src/UI/Window.cpp150
-rw-r--r--src/UI/Window.h11
6 files changed, 89 insertions, 133 deletions
diff --git a/src/UI/EnchantingWindow.cpp b/src/UI/EnchantingWindow.cpp
index 15d27fc63..9ebb70f32 100644
--- a/src/UI/EnchantingWindow.cpp
+++ b/src/UI/EnchantingWindow.cpp
@@ -26,25 +26,9 @@ cEnchantingWindow::cEnchantingWindow(Vector3i a_BlockPos, const AString & a_Titl
-void cEnchantingWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player)
+void cEnchantingWindow::SetProperty(size_t a_Property, short a_Value)
{
- ASSERT(a_Property >= 0);
- if (static_cast<size_t>(a_Property) < m_PropertyValue.size())
- {
- m_PropertyValue[a_Property] = a_Value;
- }
-
- Super::SetProperty(a_Property, a_Value, a_Player);
-}
-
-
-
-
-
-void cEnchantingWindow::SetProperty(short a_Property, short a_Value)
-{
- ASSERT(a_Property >= 0);
- if (static_cast<size_t>(a_Property) < m_PropertyValue.size())
+ if (a_Property < m_PropertyValue.size())
{
m_PropertyValue[a_Property] = a_Value;
}
@@ -56,14 +40,9 @@ void cEnchantingWindow::SetProperty(short a_Property, short a_Value)
-short cEnchantingWindow::GetProperty(short a_Property)
+short cEnchantingWindow::GetProperty(size_t a_Property)
{
- if ((a_Property < 0) || (static_cast<size_t>(a_Property) >= m_PropertyValue.size()))
- {
- ASSERT(!"a_Property is invalid");
- return 0;
- }
-
+ ASSERT(a_Property < m_PropertyValue.size());
return m_PropertyValue[a_Property];
}
diff --git a/src/UI/EnchantingWindow.h b/src/UI/EnchantingWindow.h
index 2b32f078a..e166fd1de 100644
--- a/src/UI/EnchantingWindow.h
+++ b/src/UI/EnchantingWindow.h
@@ -21,7 +21,7 @@ class cSlotAreaEnchanting;
-class cEnchantingWindow:
+class cEnchantingWindow final :
public cWindow
{
using Super = cWindow;
@@ -32,14 +32,10 @@ public:
/** Sends enchantment properties to the client.
If the property represents a level requirement, stores it for later GetProperty retrieval. */
- virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player) override;
-
- /** Sends enchantment properties to the client.
- If the property represents a level requirement, stores it for later GetProperty retrieval. */
- virtual void SetProperty(short a_Property, short a_Value) override;
+ virtual void SetProperty(size_t a_Property, short a_Value) override;
/** Return the level requirement of the given enchantment slot. */
- short GetProperty(short a_Property);
+ short GetProperty(size_t a_Property);
virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index bb597b2c9..53d406e65 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -1059,7 +1059,7 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player)
{
SetSlot(1, a_Player, cItem());
}
- m_ParentWindow.SetProperty(0, static_cast<short>(m_MaximumCost), a_Player);
+ m_ParentWindow.SetProperty(0, static_cast<short>(m_MaximumCost));
m_MaximumCost = 0;
static_cast<cAnvilWindow &>(m_ParentWindow).SetRepairedItemName("", nullptr);
@@ -1135,7 +1135,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
{
Output.Empty();
SetSlot(2, a_Player, Output);
- m_ParentWindow.SetProperty(0, 0, a_Player);
+ m_ParentWindow.SetProperty(0, 0);
return;
}
@@ -1157,7 +1157,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
// No enchantment
Output.Empty();
SetSlot(2, a_Player, Output);
- m_ParentWindow.SetProperty(0, 0, a_Player);
+ m_ParentWindow.SetProperty(0, 0);
return;
}
@@ -1180,7 +1180,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
// No enchantment
Output.Empty();
SetSlot(2, a_Player, Output);
- m_ParentWindow.SetProperty(0, 0, a_Player);
+ m_ParentWindow.SetProperty(0, 0);
return;
}
@@ -1264,7 +1264,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player)
}
SetSlot(2, a_Player, Input);
- m_ParentWindow.SetProperty(0, static_cast<Int16>(m_MaximumCost), a_Player);
+ m_ParentWindow.SetProperty(0, static_cast<Int16>(m_MaximumCost));
}
@@ -1700,10 +1700,10 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
// Properties set according to: https://wiki.vg/Protocol#Window_Property
// Fake a "seed" for the client to draw Standard Galactic Alphabet glyphs:
- m_ParentWindow.SetProperty(3, Random.RandInt<short>(), a_Player);
+ m_ParentWindow.SetProperty(3, Random.RandInt<short>());
// Calculate an enchanting possibility for each option (top, middle and bottom) and send details to window:
- for (short i = 0; i != OptionLevels.size(); i++)
+ for (size_t i = 0; i != OptionLevels.size(); i++)
{
// A copy of the item.
cItem EnchantedItem = Item.CopyOne();
@@ -1714,20 +1714,20 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
LOGD("Generated enchanted item %d with enchantments: %s", i, EnchantedItem.m_Enchantments.ToString());
// Send the level requirement for the enchantment option:
- m_ParentWindow.SetProperty(i, static_cast<short>(OptionLevels[i]), a_Player);
+ m_ParentWindow.SetProperty(i, static_cast<short>(OptionLevels[i]));
// Get the first enchantment ID, which must exist:
ASSERT(EnchantedItem.m_Enchantments.begin() != EnchantedItem.m_Enchantments.end());
const short EnchantmentID = static_cast<short>(EnchantedItem.m_Enchantments.begin()->first);
// Send the enchantment ID of the first enchantment on our item:
- m_ParentWindow.SetProperty(4 + i, EnchantmentID, a_Player);
+ m_ParentWindow.SetProperty(4 + i, EnchantmentID);
const short EnchantmentLevel = static_cast<short>(EnchantedItem.m_Enchantments.GetLevel(EnchantmentID));
ASSERT(EnchantmentLevel > 0);
// Send the level for the first enchantment on our item:
- m_ParentWindow.SetProperty(7 + i, EnchantmentLevel, a_Player);
+ m_ParentWindow.SetProperty(7 + i, EnchantmentLevel);
// Store the item we've enchanted as an option to be retrieved later:
m_EnchantedItemOptions[i] = std::move(EnchantedItem);
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index acf8c404b..96ea95c37 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -379,7 +379,7 @@ protected:
-class cSlotAreaEnchanting:
+class cSlotAreaEnchanting final :
public cSlotAreaTemporary
{
using Super = cSlotAreaTemporary;
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index b59268ac4..07b84916d 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -347,6 +347,75 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse)
+void cWindow::BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum)
+{
+ // Translate local slot num into global slot num:
+ int SlotNum = 0;
+ bool HasFound = false;
+ for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr)
+ {
+ if (a_Area == *itr)
+ {
+ SlotNum += a_LocalSlotNum;
+ HasFound = true;
+ break;
+ }
+ SlotNum += (*itr)->GetNumSlots();
+ } // for itr - m_SlotAreas[]
+ if (!HasFound)
+ {
+ LOGWARNING("%s: Invalid slot area parameter", __FUNCTION__);
+ ASSERT(!"Invalid slot area");
+ return;
+ }
+
+ // Broadcast the update packet:
+ cCSLock Lock(m_CS);
+ for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
+ {
+ (*itr)->GetClientHandle()->SendInventorySlot(m_WindowID, static_cast<short>(SlotNum), *a_Area->GetSlot(a_LocalSlotNum, **itr));
+ } // for itr - m_OpenedBy[]
+}
+
+
+
+
+
+void cWindow::SendWholeWindow(cClientHandle & a_Client)
+{
+ a_Client.SendWholeInventory(*this);
+}
+
+
+
+
+
+void cWindow::BroadcastWholeWindow(void)
+{
+ cCSLock Lock(m_CS);
+ for (auto Player : m_OpenedBy)
+ {
+ SendWholeWindow(*Player->GetClientHandle());
+ }
+}
+
+
+
+
+
+void cWindow::SetProperty(size_t a_Property, short a_Value)
+{
+ cCSLock Lock(m_CS);
+ for (auto Player : m_OpenedBy)
+ {
+ Player->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
+ }
+}
+
+
+
+
+
void cWindow::OwnerDestroyed()
{
m_Owner = nullptr;
@@ -685,84 +754,3 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int
} // for itr - SlotNums[]
return NumDistributed;
}
-
-
-
-
-
-void cWindow::BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum)
-{
- // Translate local slot num into global slot num:
- int SlotNum = 0;
- bool HasFound = false;
- for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr)
- {
- if (a_Area == *itr)
- {
- SlotNum += a_LocalSlotNum;
- HasFound = true;
- break;
- }
- SlotNum += (*itr)->GetNumSlots();
- } // for itr - m_SlotAreas[]
- if (!HasFound)
- {
- LOGWARNING("%s: Invalid slot area parameter", __FUNCTION__);
- ASSERT(!"Invalid slot area");
- return;
- }
-
- // Broadcast the update packet:
- cCSLock Lock(m_CS);
- for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
- {
- (*itr)->GetClientHandle()->SendInventorySlot(m_WindowID, static_cast<short>(SlotNum), *a_Area->GetSlot(a_LocalSlotNum, **itr));
- } // for itr - m_OpenedBy[]
-}
-
-
-
-
-
-void cWindow::SendWholeWindow(cClientHandle & a_Client)
-{
- a_Client.SendWholeInventory(*this);
-}
-
-
-
-
-
-void cWindow::BroadcastWholeWindow(void)
-{
- cCSLock Lock(m_CS);
- for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
- {
- SendWholeWindow(*(*itr)->GetClientHandle());
- } // for itr - m_OpenedBy[]
-}
-
-
-
-
-
-void cWindow::SetProperty(short a_Property, short a_Value)
-{
- cCSLock Lock(m_CS);
- for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr)
- {
- (*itr)->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
- } // for itr - m_OpenedBy[]
-}
-
-
-
-
-
-void cWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player)
-{
- a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value);
-}
-
-
-
diff --git a/src/UI/Window.h b/src/UI/Window.h
index 65fbc3756..46935acef 100644
--- a/src/UI/Window.h
+++ b/src/UI/Window.h
@@ -142,11 +142,7 @@ public:
/** Updates a numerical property associated with the window. Typically used for furnace progressbars.
Sends the UpdateWindowProperty packet to all clients of the window */
- virtual void SetProperty(short a_Property, short a_Value);
-
- /** Updates a numerical property associated with the window. Typically used for furnace progressbars.
- Sends the UpdateWindowProperty packet only to the specified player */
- virtual void SetProperty(short a_Property, short a_Value, cPlayer & a_Player);
+ virtual void SetProperty(size_t a_Property, short a_Value);
// tolua_end
@@ -179,6 +175,7 @@ public:
void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum);
protected:
+
cSlotAreas m_SlotAreas;
char m_WindowID;
@@ -227,7 +224,3 @@ protected:
@param a_LimitItems if false, no checks are performed on a_Item.m_ItemCount. */
int DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int a_NumToEachSlot, const cSlotNums & a_SlotNums, bool a_LimitItems = true);
} ; // tolua_export
-
-
-
-