Formspecs: Use mouse wheel to pick up and deposit single items

This commit is contained in:
you 2018-04-02 16:52:07 +02:00 committed by rubenwardy
parent d88c4e1822
commit 12edb200eb

@ -3408,24 +3408,39 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
(m_selected_item->listname == s.listname) && (m_selected_item->listname == s.listname) &&
(m_selected_item->i == s.i); (m_selected_item->i == s.i);
// buttons: 0 = left, 1 = right, 2 = middle // buttons: 0 = left, 1 = right, 2 = middle, 3 = wheeldown, 4 = wheelup
// up/down: 0 = down (press), 1 = up (release), 2 = unknown event, -1 movement // up/down: 0 = down (press or wheel), 1 = up (release),
// 2 = unknown event, -1 = movement
int button = 0; int button = 0;
int updown = 2; int updown = 2;
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) switch (event.MouseInput.Event) {
{ button = 0; updown = 0; } case EMIE_LMOUSE_PRESSED_DOWN:
else if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) button = 0; updown = 0;
{ button = 1; updown = 0; } break;
else if (event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN) case EMIE_RMOUSE_PRESSED_DOWN:
{ button = 2; updown = 0; } button = 1; updown = 0;
else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) break;
{ button = 0; updown = 1; } case EMIE_MMOUSE_PRESSED_DOWN:
else if (event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) button = 2; updown = 0;
{ button = 1; updown = 1; } break;
else if (event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP) case EMIE_MOUSE_WHEEL:
{ button = 2; updown = 1; } button = 3 + (event.MouseInput.Wheel > 0); updown = 0;
else if (event.MouseInput.Event == EMIE_MOUSE_MOVED) break;
{ updown = -1;} case EMIE_LMOUSE_LEFT_UP:
button = 0; updown = 1;
break;
case EMIE_RMOUSE_LEFT_UP:
button = 1; updown = 1;
break;
case EMIE_MMOUSE_LEFT_UP:
button = 2; updown = 1;
break;
case EMIE_MOUSE_MOVED:
updown = -1;
break;
default:
break;
}
// Set this number to a positive value to generate a move action // Set this number to a positive value to generate a move action
// from m_selected_item to s. // from m_selected_item to s.
@ -3442,7 +3457,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
// Set this number to a positive value to generate a craft action at s. // Set this number to a positive value to generate a craft action at s.
u32 craft_amount = 0; u32 craft_amount = 0;
if (updown == 0) { if (!updown) {
// Some mouse button has been pressed // Some mouse button has been pressed
//infostream<<"Mouse button "<<button<<" pressed at p=(" //infostream<<"Mouse button "<<button<<" pressed at p=("
@ -3454,7 +3469,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
// Craft preview has been clicked: craft // Craft preview has been clicked: craft
craft_amount = (button == 2 ? 10 : 1); craft_amount = (button == 2 ? 10 : 1);
} else if (m_selected_item == NULL) { } else if (m_selected_item == NULL) {
if (s_count != 0) { if (s_count && button != 4) {
// Non-empty stack has been clicked: select or shift-move it // Non-empty stack has been clicked: select or shift-move it
m_selected_item = new ItemSpec(s); m_selected_item = new ItemSpec(s);
@ -3463,20 +3478,19 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
count = (s_count + 1) / 2; count = (s_count + 1) / 2;
else if (button == 2) // middle else if (button == 2) // middle
count = MYMIN(s_count, 10); count = MYMIN(s_count, 10);
else if (button == 3) // wheeldown
count = 1;
else // left else // left
count = s_count; count = s_count;
if (!event.MouseInput.Shift) { if (!event.MouseInput.Shift) {
// no shift: select item // no shift: select item
m_selected_amount = count; m_selected_amount = count;
m_selected_dragging = true; m_selected_dragging = button != 3;
m_auto_place = false; m_auto_place = false;
} else { } else {
// shift pressed: move item // shift pressed: move item, right click moves 1
if (button != 1) shift_move_amount = button == 1 ? 1 : count;
shift_move_amount = count;
else // count of 1 at left click like after drag & drop
shift_move_amount = 1;
} }
} }
} else { // m_selected_item != NULL } else { // m_selected_item != NULL
@ -3484,14 +3498,19 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (s.isValid()) { if (s.isValid()) {
// Clicked a slot: move // Clicked a slot: move
if (button == 1) // right if (button == 1 || button == 4) // right or wheelup
move_amount = 1; move_amount = 1;
else if (button == 2) // middle else if (button == 2) // middle
move_amount = MYMIN(m_selected_amount, 10); move_amount = MYMIN(m_selected_amount, 10);
else // left else if (!button) // left
move_amount = m_selected_amount; move_amount = m_selected_amount;
// else wheeldown
if (identical) { if (identical) {
if (button == 3) { // wheeldown
if (m_selected_amount < s_count)
++m_selected_amount;
} else {
if (move_amount >= m_selected_amount) if (move_amount >= m_selected_amount)
m_selected_amount = 0; m_selected_amount = 0;
else else
@ -3499,9 +3518,11 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
move_amount = 0; move_amount = 0;
} }
} }
else if (!getAbsoluteClippingRect().isPointInside(m_pointer)) { }
else if (!getAbsoluteClippingRect().isPointInside(m_pointer)
&& button != 3) {
// Clicked outside of the window: drop // Clicked outside of the window: drop
if (button == 1) // right if (button == 1 || button == 4) // right or wheelup
drop_amount = 1; drop_amount = 1;
else if (button == 2) // middle else if (button == 2) // middle
drop_amount = MYMIN(m_selected_amount, 10); drop_amount = MYMIN(m_selected_amount, 10);
@ -3509,23 +3530,23 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
drop_amount = m_selected_amount; drop_amount = m_selected_amount;
} }
} }
} } else if (updown == 1) {
else if (updown == 1) {
// Some mouse button has been released // Some mouse button has been released
//infostream<<"Mouse button "<<button<<" released at p=(" //infostream<<"Mouse button "<<button<<" released at p=("
// <<p.X<<","<<p.Y<<")"<<std::endl; // <<p.X<<","<<p.Y<<")"<<std::endl;
if (m_selected_item != NULL && m_selected_dragging && s.isValid()) { if (m_selected_dragging && m_selected_item != NULL) {
if (s.isValid()) {
if (!identical) { if (!identical) {
// Dragged to different slot: move all selected // Dragged to different slot: move all selected
move_amount = m_selected_amount; move_amount = m_selected_amount;
} }
} else if (m_selected_item != NULL && m_selected_dragging && } else if (!getAbsoluteClippingRect().isPointInside(m_pointer)) {
!(getAbsoluteClippingRect().isPointInside(m_pointer))) {
// Dragged outside of window: drop all selected // Dragged outside of window: drop all selected
drop_amount = m_selected_amount; drop_amount = m_selected_amount;
} }
}
m_selected_dragging = false; m_selected_dragging = false;
// Keep track of whether the mouse button be released // Keep track of whether the mouse button be released