diff options
author | Kingsley Collie <kingsleydgs@gmail.com> | 2022-01-13 01:03:56 +0100 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2022-01-13 01:39:12 +0100 |
commit | 77a44e8dce29f4b4c5c3a81aea52473440594b07 (patch) | |
tree | 0d1091591c162afe8c8f8c1f2deede530d94dc56 /src/UI/SlotArea.cpp | |
parent | Refactor into switch statement (diff) | |
download | cuberite-77a44e8dce29f4b4c5c3a81aea52473440594b07.tar cuberite-77a44e8dce29f4b4c5c3a81aea52473440594b07.tar.gz cuberite-77a44e8dce29f4b4c5c3a81aea52473440594b07.tar.bz2 cuberite-77a44e8dce29f4b4c5c3a81aea52473440594b07.tar.lz cuberite-77a44e8dce29f4b4c5c3a81aea52473440594b07.tar.xz cuberite-77a44e8dce29f4b4c5c3a81aea52473440594b07.tar.zst cuberite-77a44e8dce29f4b4c5c3a81aea52473440594b07.zip |
Diffstat (limited to '')
-rw-r--r-- | src/UI/SlotArea.cpp | 179 |
1 files changed, 87 insertions, 92 deletions
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 97f5ca194..0b060a5e4 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1891,130 +1891,125 @@ void cSlotAreaFurnace::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a return; } - switch (a_SlotNum) + if (a_SlotNum == 1) { - case 1: // Fuel slot clicked + cItem & DraggingItem = a_Player.GetDraggingItem(); + cFurnaceRecipe * FurnaceRecipes = cRoot::Get()->GetFurnaceRecipe(); + + // Do not allow non-fuels to be placed in the fuel slot: + if (!DraggingItem.IsEmpty() && !FurnaceRecipes->IsFuel(DraggingItem) && (a_ClickAction != caShiftLeftClick) && (a_ClickAction != caShiftRightClick)) { - cItem & DraggingItem = a_Player.GetDraggingItem(); - cFurnaceRecipe * FurnaceRecipes = cRoot::Get()->GetFurnaceRecipe(); + return; + } + } + else if (a_SlotNum == 2) + { + bool bAsync = false; + if (GetSlot(a_SlotNum, a_Player) == nullptr) + { + LOGWARNING("GetSlot(%d) returned nullptr! Ignoring click", a_SlotNum); + return; + } - // Do not allow non-fuels to be placed in the fuel slot: - if (!DraggingItem.IsEmpty() && !FurnaceRecipes->IsFuel(DraggingItem) && (a_ClickAction != caShiftLeftClick) && (a_ClickAction != caShiftRightClick)) + cItem Slot(*GetSlot(a_SlotNum, a_Player)); + if (!Slot.IsSameType(a_ClickedItem)) + { + LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots); + LOGWARNING("My item: %s", ItemToFullString(Slot).c_str()); + LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str()); + bAsync = true; + } + + switch (a_ClickAction) + { + case caShiftLeftClick: + case caShiftRightClick: { - LOGD("Rejecting non fuel item being placed in fuel slot."); + HandleSmeltItem(Slot, a_Player); + ShiftClicked(a_Player, a_SlotNum, Slot); return; } - break; + case caMiddleClick: + { + MiddleClicked(a_Player, a_SlotNum); + return; + } + case caDropKey: + case caCtrlDropKey: + { + DropClicked(a_Player, a_SlotNum, (a_SlotNum == caCtrlDropKey)); + Slot.m_ItemCount = Slot.m_ItemCount - GetSlot(a_SlotNum, a_Player)->m_ItemCount; + HandleSmeltItem(Slot, a_Player); + return; + } + default: + { + break; + } } - case 2: // Result slot clicked + + cItem & DraggingItem = a_Player.GetDraggingItem(); + if (!DraggingItem.IsEmpty()) { - bool bAsync = false; - if (GetSlot(a_SlotNum, a_Player) == nullptr) + if (a_ClickAction == caDblClick) { - LOGWARNING("GetSlot(%d) returned nullptr! Ignoring click", a_SlotNum); return; } - - cItem Slot(*GetSlot(a_SlotNum, a_Player)); - if (!Slot.IsSameType(a_ClickedItem)) + if (!DraggingItem.IsEqual(Slot)) { - LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots); - LOGWARNING("My item: %s", ItemToFullString(Slot).c_str()); - LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str()); - bAsync = true; + return; + } + if ((DraggingItem.m_ItemCount + Slot.m_ItemCount) > Slot.GetMaxStackSize()) + { + return; } + DraggingItem.m_ItemCount += Slot.m_ItemCount; + HandleSmeltItem(Slot, a_Player); + Slot.Empty(); + } + else + { switch (a_ClickAction) { - case caShiftLeftClick: - case caShiftRightClick: - { - HandleSmeltItem(Slot, a_Player); - ShiftClicked(a_Player, a_SlotNum, Slot); - return; - } - case caMiddleClick: + case caDblClick: { - MiddleClicked(a_Player, a_SlotNum); + DblClicked(a_Player, a_SlotNum); return; } - case caDropKey: - case caCtrlDropKey: + case caLeftClick: { - DropClicked(a_Player, a_SlotNum, (a_SlotNum == caCtrlDropKey)); - Slot.m_ItemCount = Slot.m_ItemCount - GetSlot(a_SlotNum, a_Player)->m_ItemCount; + DraggingItem = Slot; HandleSmeltItem(Slot, a_Player); - return; - } - default: - { + Slot.Empty(); break; } - } - - cItem & DraggingItem = a_Player.GetDraggingItem(); - if (!DraggingItem.IsEmpty()) - { - if (a_ClickAction == caDblClick) + case caRightClick: { - return; - } - if (!DraggingItem.IsEqual(Slot)) - { - return; - } - if ((DraggingItem.m_ItemCount + Slot.m_ItemCount) > Slot.GetMaxStackSize()) - { - return; - } + DraggingItem = Slot.CopyOne(); + DraggingItem.m_ItemCount = static_cast<char>(static_cast<float>(Slot.m_ItemCount) / 2.f + 0.5f); + Slot.m_ItemCount -= DraggingItem.m_ItemCount; - DraggingItem.m_ItemCount += Slot.m_ItemCount; - HandleSmeltItem(Slot, a_Player); - Slot.Empty(); - } - else - { - switch (a_ClickAction) - { - case caDblClick: - { - DblClicked(a_Player, a_SlotNum); - return; - } - case caLeftClick: + if (Slot.m_ItemCount <= 0) { - DraggingItem = Slot; - HandleSmeltItem(Slot, a_Player); Slot.Empty(); - break; - } - case caRightClick: - { - DraggingItem = Slot.CopyOne(); - DraggingItem.m_ItemCount = static_cast<char>(static_cast<float>(Slot.m_ItemCount) / 2.f + 0.5f); - Slot.m_ItemCount -= DraggingItem.m_ItemCount; - - if (Slot.m_ItemCount <= 0) - { - Slot.Empty(); - } - HandleSmeltItem(DraggingItem, a_Player); - break; - } - default: - { - ASSERT(!"Unhandled click type!"); } + HandleSmeltItem(DraggingItem, a_Player); + break; + } + default: + { + ASSERT(!"Unhandled click type!"); } } + } - SetSlot(a_SlotNum, a_Player, Slot); - if (bAsync) - { - m_ParentWindow.BroadcastWholeWindow(); - } - return; + SetSlot(a_SlotNum, a_Player, Slot); + if (bAsync) + { + m_ParentWindow.BroadcastWholeWindow(); } + return; } Super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); |