From 0bacda32692729e4b9743f91d92cd329e198d73a Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Sat, 21 Oct 2017 17:56:09 +0100 Subject: Implement horse inventory (#4053) * Implement horse inventory * Fix sign conversions * Add API doc for ItemCategory::IsHorseArmor * Improve HandleOpenHorseInventory comment and style fixes. --- src/UI/SlotArea.cpp | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) (limited to 'src/UI/SlotArea.cpp') 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; + } +} + + + + + -- cgit v1.2.3