]> git.lizzy.rs Git - minetest.git/blobdiff - src/guiFormSpecMenu.cpp
Clear list rings when loading a new formspec
[minetest.git] / src / guiFormSpecMenu.cpp
index 73fef9a692a39b8b5ff4c72f937ec126fbc0de7b..dca7618b9852f794aadea571cde6db73a7d6eb51 100644 (file)
@@ -381,6 +381,7 @@ void GUIFormSpecMenu::parseListRing(parserData* data, std::string element)
                const ListDrawSpec &spb = m_inventorylists[siz - 1];
                m_inventory_rings.push_back(ListRingSpec(spa.inventoryloc, spa.listname));
                m_inventory_rings.push_back(ListRingSpec(spb.inventoryloc, spb.listname));
+               return;
        }
        errorstream<< "Invalid list ring element(" << parts.size() << ", "
                << m_inventorylists.size() << "): '" << element << "'"  << std::endl;
@@ -1019,6 +1020,7 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
                if (g_settings->getBool("freetype")) {
                        e = (gui::IGUIElement *) new gui::intlGUIEditBox(spec.fdefault.c_str(),
                                true, Environment, this, spec.fid, rect);
+                       e->drop();
                } else {
 #else
                {
@@ -1118,6 +1120,7 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,
                if (g_settings->getBool("freetype")) {
                        e = (gui::IGUIEditBox *) new gui::intlGUIEditBox(spec.fdefault.c_str(),
                                true, Environment, this, spec.fid, rect);
+                       e->drop();
                } else {
 #else
                {
@@ -1877,6 +1880,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
        m_fields.clear();
        m_boxes.clear();
        m_tooltips.clear();
+       m_inventory_rings.clear();
 
        // Set default values (fits old formspec values)
        m_bgcolor = video::SColor(140,0,0,0);
@@ -2100,7 +2104,7 @@ bool GUIFormSpecMenu::getAndroidUIInput()
        }
 
        for(std::vector<FieldSpec>::iterator iter =  m_fields.begin();
-                       iter != m_fields.end(); iter++) {
+                       iter != m_fields.end(); ++iter) {
 
                if (iter->fname != fieldname) {
                        continue;
@@ -2470,7 +2474,7 @@ void GUIFormSpecMenu::drawMenu()
 
                if (id != -1 && delta >= m_tooltip_show_delay) {
                        for(std::vector<FieldSpec>::iterator iter =  m_fields.begin();
-                                       iter != m_fields.end(); iter++) {
+                                       iter != m_fields.end(); ++iter) {
                                if ( (iter->fid == id) && (m_tooltips[iter->fname].tooltip != "") ){
                                        if (m_old_tooltip != m_tooltips[iter->fname].tooltip) {
                                                m_old_tooltip = m_tooltips[iter->fname].tooltip;
@@ -3383,31 +3387,42 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
                                        break;
                                ItemStack stack_from = list_from->getItem(s.i);
                                assert(shift_move_amount <= stack_from.count);
-
-                               // find a place (or more than one) to add the new item
-                               u32 ilt_size = list_to->getSize();
-                               ItemStack leftover;
-                               for (u32 slot_to = 0; slot_to < ilt_size
-                                               && shift_move_amount > 0; slot_to++) {
-                                       list_to->itemFits(slot_to, stack_from, &leftover);
-                                       if (leftover.count < stack_from.count) {
-                                               infostream << "Handing IACTION_MOVE to manager" << std::endl;
-                                               IMoveAction *a = new IMoveAction();
-                                               a->count = MYMIN(shift_move_amount,
-                                                       (u32) (stack_from.count - leftover.count));
-                                               shift_move_amount -= a->count;
-                                               a->from_inv = s.inventoryloc;
-                                               a->from_list = s.listname;
-                                               a->from_i = s.i;
-                                               a->to_inv = to_inv_sp.inventoryloc;
-                                               a->to_list = to_inv_sp.listname;
-                                               a->to_i = slot_to;
-                                               m_invmgr->inventoryAction(a);
-                                               stack_from = leftover;
+                               if (m_client->getProtoVersion() >= 25) {
+                                       infostream << "Handing IACTION_MOVE to manager" << std::endl;
+                                       IMoveAction *a = new IMoveAction();
+                                       a->count = shift_move_amount;
+                                       a->from_inv = s.inventoryloc;
+                                       a->from_list = s.listname;
+                                       a->from_i = s.i;
+                                       a->to_inv = to_inv_sp.inventoryloc;
+                                       a->to_list = to_inv_sp.listname;
+                                       a->move_somewhere = true;
+                                       m_invmgr->inventoryAction(a);
+                               } else {
+                                       // find a place (or more than one) to add the new item
+                                       u32 ilt_size = list_to->getSize();
+                                       ItemStack leftover;
+                                       for (u32 slot_to = 0; slot_to < ilt_size
+                                                       && shift_move_amount > 0; slot_to++) {
+                                               list_to->itemFits(slot_to, stack_from, &leftover);
+                                               if (leftover.count < stack_from.count) {
+                                                       infostream << "Handing IACTION_MOVE to manager" << std::endl;
+                                                       IMoveAction *a = new IMoveAction();
+                                                       a->count = MYMIN(shift_move_amount,
+                                                               (u32) (stack_from.count - leftover.count));
+                                                       shift_move_amount -= a->count;
+                                                       a->from_inv = s.inventoryloc;
+                                                       a->from_list = s.listname;
+                                                       a->from_i = s.i;
+                                                       a->to_inv = to_inv_sp.inventoryloc;
+                                                       a->to_list = to_inv_sp.listname;
+                                                       a->to_i = slot_to;
+                                                       m_invmgr->inventoryAction(a);
+                                                       stack_from = leftover;
+                                               }
                                        }
                                }
                        } while (0);
-
                } else if (drop_amount > 0) {
                        m_selected_content_guess = ItemStack(); // Clear
 
@@ -3595,7 +3610,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
 std::string GUIFormSpecMenu::getNameByID(s32 id)
 {
        for(std::vector<FieldSpec>::iterator iter =  m_fields.begin();
-                               iter != m_fields.end(); iter++) {
+                               iter != m_fields.end(); ++iter) {
                if (iter->fid == id) {
                        return iter->fname;
                }
@@ -3611,7 +3626,7 @@ std::string GUIFormSpecMenu::getNameByID(s32 id)
 std::wstring GUIFormSpecMenu::getLabelByID(s32 id)
 {
        for(std::vector<FieldSpec>::iterator iter =  m_fields.begin();
-                               iter != m_fields.end(); iter++) {
+                               iter != m_fields.end(); ++iter) {
                if (iter->fid == id) {
                        return iter->flabel;
                }