summaryrefslogtreecommitdiffstats
path: root/src/UI
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/UI/CMakeLists.txt2
-rw-r--r--src/UI/HorseWindow.cpp61
-rw-r--r--src/UI/HorseWindow.h34
-rw-r--r--src/UI/SlotArea.cpp119
-rw-r--r--src/UI/SlotArea.h25
5 files changed, 241 insertions, 0 deletions
diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt
index 54236a929..6477882b3 100644
--- a/src/UI/CMakeLists.txt
+++ b/src/UI/CMakeLists.txt
@@ -15,6 +15,7 @@ SET (SRCS
EnderChestWindow.cpp
FurnaceWindow.cpp
HopperWindow.cpp
+ HorseWindow.cpp
InventoryWindow.cpp)
SET (HDRS
@@ -30,6 +31,7 @@ SET (HDRS
EnderChestWindow.h
FurnaceWindow.h
HopperWindow.h
+ HorseWindow.h
InventoryWindow.h
MinecartWithChestWindow.h
WindowOwner.h)
diff --git a/src/UI/HorseWindow.cpp b/src/UI/HorseWindow.cpp
new file mode 100644
index 000000000..ab060609d
--- /dev/null
+++ b/src/UI/HorseWindow.cpp
@@ -0,0 +1,61 @@
+
+// HorseWindow.cpp
+
+// Representing the UI window for a horse entity
+
+#include "Globals.h"
+#include "Mobs/Horse.h"
+#include "UI/HorseWindow.h"
+#include "UI/SlotArea.h"
+
+
+
+
+
+cHorseWindow::cHorseWindow(cHorse & a_Horse):
+ Super(wtAnimalChest, "Horse"),
+ m_Horse(a_Horse)
+{
+ m_SlotAreas.push_back(new cSlotAreaHorse(a_Horse, *this));
+ m_SlotAreas.push_back(new cSlotAreaInventory(*this));
+ m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
+}
+
+
+
+
+
+void cHorseWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
+{
+ cSlotAreas AreasInOrder;
+
+ if (a_ClickedArea == m_SlotAreas[0])
+ {
+ // Horse Area
+ AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
+ AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
+ Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true);
+ }
+ else
+ {
+ // Inventory or Hotbar
+ if (ItemCategory::IsHorseArmor(a_ItemStack.m_ItemType) || (a_ItemStack.m_ItemType == E_ITEM_SADDLE))
+ {
+ AreasInOrder.push_back(m_SlotAreas[0]); /* Horse */
+ Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
+ }
+ }
+}
+
+
+
+
+
+UInt32 cHorseWindow::GetHorseID() const
+{
+ return m_Horse.GetUniqueID();
+}
+
+
+
+
diff --git a/src/UI/HorseWindow.h b/src/UI/HorseWindow.h
new file mode 100644
index 000000000..77bc2d627
--- /dev/null
+++ b/src/UI/HorseWindow.h
@@ -0,0 +1,34 @@
+
+// HorseWindow.h
+
+// Representing the UI window for a horse entity
+
+#pragma once
+
+#include "Window.h"
+
+class cHorse;
+
+
+
+
+
+class cHorseWindow :
+ public cWindow
+{
+ using Super = cWindow;
+public:
+ cHorseWindow(cHorse & a_Horse);
+
+ virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override;
+
+ /** Returns the horse's entity ID. */
+ UInt32 GetHorseID() const;
+
+private:
+ cHorse & m_Horse;
+};
+
+
+
+
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 865e9cb44..d093bb337 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -21,6 +21,7 @@
#include "../BlockArea.h"
#include "../EffectID.h"
#include "../ClientHandle.h"
+#include "Mobs/Horse.h"
@@ -2596,3 +2597,121 @@ cItem * cSlotAreaTemporary::GetPlayerSlots(cPlayer & a_Player)
+////////////////////////////////////////////////////////////////////////////////
+// cSlotAreaHorse:
+
+cSlotAreaHorse::cSlotAreaHorse(cHorse & a_Horse, cWindow & a_ParentWindow) :
+ cSlotArea(2, a_ParentWindow),
+ m_Horse(a_Horse)
+{
+}
+
+
+
+
+
+void cSlotAreaHorse::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
+{
+ cItem & DraggingItem = a_Player.GetDraggingItem();
+
+ switch (a_ClickAction)
+ {
+ case caLeftClick:
+ case caRightClick:
+ case caDblClick:
+ {
+ // Check for invalid item types
+ if (DraggingItem.IsEmpty())
+ {
+ break;
+ }
+
+ switch (a_SlotNum)
+ {
+ case SaddleSlot:
+ {
+ if (DraggingItem.m_ItemType != E_ITEM_SADDLE)
+ {
+ return;
+ }
+ }
+ case ArmorSlot:
+ {
+ if (!ItemCategory::IsHorseArmor(DraggingItem.m_ItemType))
+ {
+ return;
+ }
+ }
+ default: break;
+ }
+ }
+ default: break;
+ }
+
+ cSlotArea::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem);
+}
+
+
+
+
+
+const cItem * cSlotAreaHorse::GetSlot(int a_SlotNum, cPlayer & a_Player) const
+{
+ static const cItem InvalidItem;
+ switch (a_SlotNum)
+ {
+ case SaddleSlot: return &m_Horse.GetHorseSaddle();
+ case ArmorSlot: return &m_Horse.GetHorseArmorItem();
+ default:
+ {
+ LOGWARN("cSlotAreaHorse::GetSlot: Invalid slot number %d", a_SlotNum);
+ return &InvalidItem;
+ }
+ }
+}
+
+
+
+
+
+void cSlotAreaHorse::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item)
+{
+ switch (a_SlotNum)
+ {
+ case SaddleSlot: m_Horse.SetHorseSaddle(a_Item); break;
+ case ArmorSlot: m_Horse.SetHorseArmor(a_Item); break;
+ default:
+ {
+ LOGWARN("cSlotAreaHorse::SetSlot: Invalid slot number %d", a_SlotNum);
+ }
+ }
+}
+
+
+
+
+
+void cSlotAreaHorse::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill)
+{
+ if (ItemCategory::IsHorseArmor(a_ItemStack.m_ItemType) && m_Horse.GetHorseArmorItem().IsEmpty())
+ {
+ if (a_ShouldApply)
+ {
+ m_Horse.SetHorseArmor(a_ItemStack.CopyOne());
+ }
+ --a_ItemStack.m_ItemCount;
+ }
+ else if ((a_ItemStack.m_ItemType == E_ITEM_SADDLE) && !m_Horse.IsSaddled())
+ {
+ if (a_ShouldApply)
+ {
+ m_Horse.SetHorseSaddle(a_ItemStack.CopyOne());
+ }
+ --a_ItemStack.m_ItemCount;
+ }
+}
+
+
+
+
+
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index be21cdada..4463cb315 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -14,6 +14,7 @@
+class cHorse;
class cWindow;
class cPlayer;
class cBeaconEntity;
@@ -520,3 +521,27 @@ protected:
+
+/** Slot area holding horse saddle and armor. */
+class cSlotAreaHorse:
+ public cSlotArea
+{
+public:
+ enum
+ {
+ SaddleSlot,
+ ArmorSlot
+ };
+
+ cSlotAreaHorse(cHorse & a_Horse, cWindow & a_ParentWindow);
+ virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
+ 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;
+ virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots, bool a_BackFill) override;
+private:
+ cHorse & m_Horse;
+};
+
+
+
+