From e1a495ee306290b3bec2de9aa298aac1528e9243 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 2 Sep 2012 22:51:38 +0300 Subject: Make inventory GUI do sane things when server-side inventory acts unusually --- src/guiFormSpecMenu.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) (limited to 'src/guiFormSpecMenu.cpp') diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index 41ec0f3da..ed44e441b 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -733,6 +733,54 @@ void GUIFormSpecMenu::drawMenu() void GUIFormSpecMenu::updateSelectedItem() { + // WARNING: BLACK MAGIC + // See if there is a stack suited for our current guess. + // If such stack does not exist, clear the guess. + if(m_selected_content_guess.name != "") + { + bool found = false; + for(u32 i=0; igetInventory(s.inventoryloc); + if(!inv) + continue; + InventoryList *list = inv->getList(s.listname); + if(!list) + continue; + for(s32 i=0; i= list->getSize()) + continue; + ItemStack stack = list->getItem(item_i); + if(stack.name == m_selected_content_guess.name && + stack.count == m_selected_content_guess.count){ + found = true; + if(m_selected_item){ + // If guessed stack is already selected, all is fine + if(m_selected_item->inventoryloc == s.inventoryloc && + m_selected_item->listname == s.listname && + m_selected_item->i == (s32)item_i && + m_selected_amount == stack.count){ + break; + } + delete m_selected_item; + m_selected_item = NULL; + } + infostream<<"Client: Changing selected content guess to " + <idef()); - if(leftover.count == stack_from.count) + // If source stack cannot be added to destination stack at all, + // they are swapped + if(leftover.count == stack_from.count && leftover.name == stack_from.name) { - // Swap the stacks m_selected_amount = stack_to.count; + // In case the server doesn't directly swap them but instead + // moves stack_to somewhere else, set this + m_selected_content_guess = stack_to; + m_selected_content_guess_inventory = s.inventoryloc; } + // Source stack goes fully into destination stack else if(leftover.empty()) { - // Item fits m_selected_amount -= move_amount; + m_selected_content_guess = ItemStack(); // Clear } + // Source stack goes partly into destination stack else { - // Item only fits partially move_amount -= leftover.count; m_selected_amount -= move_amount; + m_selected_content_guess = ItemStack(); // Clear } infostream<<"Handing IACTION_MOVE to manager"< 0) { + m_selected_content_guess = ItemStack(); // Clear + // Send IACTION_DROP assert(m_selected_item && m_selected_item->isValid()); @@ -1107,6 +1164,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) } else if(craft_amount > 0) { + m_selected_content_guess = ItemStack(); // Clear + // Send IACTION_CRAFT assert(s.isValid()); @@ -1126,6 +1185,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) m_selected_item = NULL; m_selected_amount = 0; m_selected_dragging = false; + m_selected_content_guess = ItemStack(); } } if(event.EventType==EET_GUI_EVENT) -- cgit v1.2.3