Skip to content

Commit

Permalink
Right mouse button behaviour for craft/inventory If right mousebutton…
Browse files Browse the repository at this point in the history
… clicked once then don't drop single items into slots. If right mouse button has been clicked and held a second time, drop items as the mouse is moved. In the second case (automatically drop/place items as mouse is moved) only auto-drop into blank slots, or slots that contain the same item.
  • Loading branch information
Zeno- committed Dec 4, 2014
1 parent d7b3046 commit f6912f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/guiFormSpecMenu.cpp
Expand Up @@ -124,6 +124,7 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
m_tooltip_element(NULL),
m_hovered_time(0),
m_old_tooltip_id(-1),
m_rmouse_auto_place(false),
m_allowclose(true),
m_lock(false),
m_form_src(fsrc),
Expand Down Expand Up @@ -3153,6 +3154,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
m_selected_amount = s_count;

m_selected_dragging = true;
m_rmouse_auto_place = false;
}
}
else { // m_selected_item != NULL
Expand Down Expand Up @@ -3205,6 +3207,11 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
}

m_selected_dragging = false;
// Keep count of how many times right mouse button has been
// clicked. One click is drag without dropping. Click + release
// + click changes to drop one item when moved mode
if(button == 1 && m_selected_item != NULL)
m_rmouse_auto_place = !m_rmouse_auto_place;
}
else if(updown == -1) {
// Mouse has been moved and rmb is down and mouse pointer just
Expand All @@ -3213,7 +3220,18 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if(m_selected_item != NULL && s.isValid()){
// Move 1 item
// TODO: middle mouse to move 10 items might be handy
move_amount = 1;
if (m_rmouse_auto_place) {
// Only move an item if the destination slot is empty
// or contains the same item type as what is going to be
// moved
InventoryList *list_from = inv_selected->getList(m_selected_item->listname);
InventoryList *list_to = inv_s->getList(s.listname);
assert(list_from && list_to);
ItemStack stack_from = list_from->getItem(m_selected_item->i);
ItemStack stack_to = list_to->getItem(s.i);
if (stack_to.empty() || stack_to.name == stack_from.name)
move_amount = 1;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/guiFormSpecMenu.h
Expand Up @@ -328,6 +328,8 @@ class GUIFormSpecMenu : public GUIModalMenu
s32 m_old_tooltip_id;
std::string m_old_tooltip;

bool m_rmouse_auto_place;

bool m_allowclose;
bool m_lock;
v2u32 m_lockscreensize;
Expand Down

0 comments on commit f6912f4

Please sign in to comment.