diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-10-21 18:56:09 +0200 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2017-10-21 18:56:09 +0200 |
commit | 0bacda32692729e4b9743f91d92cd329e198d73a (patch) | |
tree | 6d5780aafb44679125145f3bc255a200a840c3c2 /src/UI/SlotArea.cpp | |
parent | Fixed some small passive mob issues (#4057) (diff) | |
download | cuberite-0bacda32692729e4b9743f91d92cd329e198d73a.tar cuberite-0bacda32692729e4b9743f91d92cd329e198d73a.tar.gz cuberite-0bacda32692729e4b9743f91d92cd329e198d73a.tar.bz2 cuberite-0bacda32692729e4b9743f91d92cd329e198d73a.tar.lz cuberite-0bacda32692729e4b9743f91d92cd329e198d73a.tar.xz cuberite-0bacda32692729e4b9743f91d92cd329e198d73a.tar.zst cuberite-0bacda32692729e4b9743f91d92cd329e198d73a.zip |
Diffstat (limited to '')
-rw-r--r-- | src/UI/SlotArea.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
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; + } +} + + + + + |