Merge lp:~widelands-dev/widelands/bug-1791891-key-modifier-inputqueue into lp:widelands

Proposed by Notabilis
Status: Merged
Merged at revision: 9079
Proposed branch: lp:~widelands-dev/widelands/bug-1791891-key-modifier-inputqueue
Merge into: lp:widelands
Diff against target: 167 lines (+74/-16)
2 files modified
src/wui/inputqueuedisplay.cc (+72/-15)
src/wui/inputqueuedisplay.h (+2/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1791891-key-modifier-inputqueue
Reviewer Review Type Date Requested Status
GunChleoc Approve
Benedikt Straub code Approve
Review via email: mp+354732@code.launchpad.net

Commit message

Adding support for Ctrl and Shift keys when using the increase/decrease buttons of input queues.

Description of the change

Adding keyboard modifiers for faster adaption of input queue settings (see bug report).

Slight disadvantage of this branch: To allow a "decreasing" shift-click on an input queue that is already at minimum (and vice versa), the code to disable the buttons had to be removed. That means that the increase/decrease buttons will always look the same, even when a "normal" click on them won't change anything.

To post a comment you must log in.
Revision history for this message
Benedikt Straub (nordfriese) wrote :

Code LGTM, not tested.
Thanks!

review: Approve (code)
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3943. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/427411087.
Appveyor build 3741. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1791891_key_modifier_inputqueue-3741.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Tested.

Now, how will the user find out about this feature? There should be additional info in the tooltip and/or in the helptexts explaining the keyboard shortcuts.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have added the info to the tooltips.

@bunnybot merge

review: Approve
Revision history for this message
Notabilis (notabilis27) wrote :

Sorry, I wasn't able to work on this the last days. Your solution looks good, though, thanks!

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 3981. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/428918967.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Can you merge trunk please, so that we can get this in and call the feature freeze?

Revision history for this message
GunChleoc (gunchleoc) wrote :

Since there is now a complication with this feature (see https://bugs.launchpad.net/widelands/+bug/1792774), let's postpone this - I'm calling the feature freeze now.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Perhaps it might be good to notice Bug #1792774 before merging

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Using a different key might be a solution to have this quickly.
Don't know whether ALT is currently used.

Revision history for this message
GunChleoc (gunchleoc) wrote :

What is the usual Mac keyboard combination for Middle-click? If that's not CTRL-click, it might be better to change the window minimize shortcut.

Revision history for this message
Benedikt Straub (nordfriese) wrote :

Alt-Click often doesn´t work on my linux, as it´s a system key combination. Shift-Click for minimizing would be good imho. Super-Click would be better, but that wouldn´t work on Windows.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Shift-Click will gain us nothing, because we'll get the same misclick conflict as we have with Ctrl-Click.

Revision history for this message
Benedikt Straub (nordfriese) wrote :

Well the capacity buttons are larger and somewhat harder to miss than the priority buttons…
But Alt-click should be fine since it´s just an alternative to a middleclick (without modifiers) anyway.

Revision history for this message
Notabilis (notabilis27) wrote :

Personally, I would prefer to keep the modifiers in this branch as they are and modify the minimize feature, e.g., by only minimizing on clicking the window title.
The bug report only mentions the priority buttons, but we have the same problem with the dismantle and burn buttons. Admittedly the latter ones already are in build19 and nobody complained about them yet. But that would also mean that the big buttons of this branch will probably be fine independent of the bug report.

Unfortunately I am unable to merge trunk in this branch, since I am currently in a "secure" WiFi where only web and mail is allowed. So no bzr for me at the moment.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Hm, perhaps the problem really only arises for the priority buttons.
What about having them displayed bigger and horizontally instaead of vertically behind the inputs that would allow for better precision in clicking them.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I think the priority buttons make a really tiny click target anyway, so making them bigger is a good idea.

I'm also OK with minimizing by clicking on the window title only.

Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 3981. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/428918967.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4769. State: canceled. Details: https://travis-ci.org/widelands/widelands/builds/523574258.
Appveyor build 3779. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1791891_key_modifier_inputqueue-3779.

Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 4769. State: canceled. Details: https://travis-ci.org/widelands/widelands/builds/523574258.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4787. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/524095891.
Appveyor build 4568. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1791891_key_modifier_inputqueue-4568.

Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/wui/inputqueuedisplay.cc'
--- src/wui/inputqueuedisplay.cc 2019-02-23 11:00:49 +0000
+++ src/wui/inputqueuedisplay.cc 2019-04-24 15:17:48 +0000
@@ -21,6 +21,8 @@
2121
22#include <algorithm>22#include <algorithm>
2323
24#include <boost/format.hpp>
25
24#include "economy/input_queue.h"26#include "economy/input_queue.h"
25#include "economy/request.h"27#include "economy/request.h"
26#include "graphic/graphic.h"28#include "graphic/graphic.h"
@@ -240,18 +242,35 @@
240 uint32_t x = Border;242 uint32_t x = Border;
241 uint32_t y = Border + (total_height_ - 2 * Border - WARE_MENU_PIC_WIDTH) / 2;243 uint32_t y = Border + (total_height_ - 2 * Border - WARE_MENU_PIC_WIDTH) / 2;
242244
245 boost::format tooltip_format("%s<br><p><font size=%d bold=0>%s<br>%s</font></p>");
246
243 decrease_max_fill_ = new UI::Button(247 decrease_max_fill_ = new UI::Button(
244 this, "decrease_max_fill", x, y, WARE_MENU_PIC_WIDTH, WARE_MENU_PIC_HEIGHT,248 this, "decrease_max_fill", x, y, WARE_MENU_PIC_WIDTH, WARE_MENU_PIC_HEIGHT,
245 UI::ButtonStyle::kWuiMenu, g_gr->images().get("images/ui_basic/scrollbar_left.png"),249 UI::ButtonStyle::kWuiMenu, g_gr->images().get("images/ui_basic/scrollbar_left.png"),
246 _("Decrease the number of wares you want to be stored here."));250 (tooltip_format
251 /** TRANSLATORS: Button tooltip in in a building's wares input queue */
252 % _("Decrease the number of wares you want to be stored here")
253 % UI_FONT_SIZE_MESSAGE
254 /** TRANSLATORS: Button tooltip in in a building's wares input queue - option explanation */
255 % _("Hold down Shift to decrease all ware types at the same time")
256 /** TRANSLATORS: Button tooltip in in a building's wares input queue - option explanation */
257 % _("Hold down Ctrl to allow none of this ware")).str());
247 decrease_max_fill_->sigclicked.connect(258 decrease_max_fill_->sigclicked.connect(
248 boost::bind(&InputQueueDisplay::decrease_max_fill_clicked, boost::ref(*this)));259 boost::bind(&InputQueueDisplay::decrease_max_fill_clicked, boost::ref(*this)));
249260
250 x = Border + (cache_size_ + 1) * (CellWidth + CellSpacing);261 x = Border + (cache_size_ + 1) * (CellWidth + CellSpacing);
262
251 increase_max_fill_ = new UI::Button(263 increase_max_fill_ = new UI::Button(
252 this, "increase_max_fill", x, y, WARE_MENU_PIC_WIDTH, WARE_MENU_PIC_HEIGHT,264 this, "increase_max_fill", x, y, WARE_MENU_PIC_WIDTH, WARE_MENU_PIC_HEIGHT,
253 UI::ButtonStyle::kWuiMenu, g_gr->images().get("images/ui_basic/scrollbar_right.png"),265 UI::ButtonStyle::kWuiMenu, g_gr->images().get("images/ui_basic/scrollbar_right.png"),
254 _("Increase the number of wares you want to be stored here."));266 (tooltip_format
267 /** TRANSLATORS: Button tooltip in a building's wares input queue */
268 % _("Increase the number of wares you want to be stored here")
269 % UI_FONT_SIZE_MESSAGE
270 /** TRANSLATORS: Button tooltip in in a building's wares input queue - option explanation */
271 % _("Hold down Shift to increase all ware types at the same time")
272 /** TRANSLATORS: Button tooltip in in a building's wares input queue - option explanation */
273 % _("Hold down Ctrl to allow all of this ware")).str());
255 increase_max_fill_->sigclicked.connect(274 increase_max_fill_->sigclicked.connect(
256 boost::bind(&InputQueueDisplay::increase_max_fill_clicked, boost::ref(*this)));275 boost::bind(&InputQueueDisplay::increase_max_fill_clicked, boost::ref(*this)));
257276
@@ -285,7 +304,7 @@
285 return;304 return;
286 }305 }
287 if (SDL_GetModState() & KMOD_CTRL) {306 if (SDL_GetModState() & KMOD_CTRL) {
288 update_siblings(state);307 update_siblings_priority(state);
289 }308 }
290 igb_.game().send_player_set_ware_priority(building_, type_, index_, priority);309 igb_.game().send_player_set_ware_priority(building_, type_, index_, priority);
291}310}
@@ -294,11 +313,11 @@
294 // Already set option has been clicked again313 // Already set option has been clicked again
295 // Unimportant for this queue, but update other queues314 // Unimportant for this queue, but update other queues
296 if (SDL_GetModState() & KMOD_CTRL) {315 if (SDL_GetModState() & KMOD_CTRL) {
297 update_siblings(priority_radiogroup_->get_state());316 update_siblings_priority(priority_radiogroup_->get_state());
298 }317 }
299}318}
300319
301void InputQueueDisplay::update_siblings(int32_t state) {320void InputQueueDisplay::update_siblings_priority(int32_t state) {
302 // "Release" the CTRL key to avoid recursion321 // "Release" the CTRL key to avoid recursion
303 const SDL_Keymod old_modifiers = SDL_GetModState();322 const SDL_Keymod old_modifiers = SDL_GetModState();
304 SDL_SetModState(KMOD_NONE);323 SDL_SetModState(KMOD_NONE);
@@ -340,19 +359,63 @@
340 * stored here has been clicked359 * stored here has been clicked
341 */360 */
342void InputQueueDisplay::decrease_max_fill_clicked() {361void InputQueueDisplay::decrease_max_fill_clicked() {
343 assert(cache_max_fill_ > 0);
344 if (!igb_.can_act(building_.owner().player_number())) {362 if (!igb_.can_act(building_.owner().player_number())) {
345 return;363 return;
346 }364 }
347 igb_.game().send_player_set_input_max_fill(building_, index_, type_, cache_max_fill_ - 1);365
366 // Update the value of this queue if required
367 if (cache_max_fill_ > 0) {
368 igb_.game().send_player_set_input_max_fill(building_, index_, type_,
369 ((SDL_GetModState() & KMOD_CTRL) ? 0 : cache_max_fill_ - 1));
370 }
371
372 // Update other queues of this building
373 if (SDL_GetModState() & KMOD_SHIFT) {
374 // Using int16_t instead of int32_t on purpose to avoid over-/underflows
375 update_siblings_fill(
376 ((SDL_GetModState() & KMOD_CTRL) ? std::numeric_limits<int16_t>::min() : -1));
377 }
348}378}
349379
350void InputQueueDisplay::increase_max_fill_clicked() {380void InputQueueDisplay::increase_max_fill_clicked() {
351 assert(cache_max_fill_ < queue_.get_max_size());
352 if (!igb_.can_act(building_.owner().player_number())) {381 if (!igb_.can_act(building_.owner().player_number())) {
353 return;382 return;
354 }383 }
355 igb_.game().send_player_set_input_max_fill(building_, index_, type_, cache_max_fill_ + 1);384
385 if (cache_max_fill_ < cache_size_) {
386 igb_.game().send_player_set_input_max_fill(building_, index_, type_,
387 ((SDL_GetModState() & KMOD_CTRL) ? cache_size_ : cache_max_fill_ + 1));
388 }
389
390 if (SDL_GetModState() & KMOD_SHIFT) {
391 update_siblings_fill(
392 ((SDL_GetModState() & KMOD_CTRL) ? std::numeric_limits<int16_t>::max() : 1));
393 }
394}
395
396void InputQueueDisplay::update_siblings_fill(int32_t delta) {
397 Panel* sibling = get_parent()->get_first_child();
398 // Well, at least we should be a child of our parent
399 assert(sibling != nullptr);
400 do {
401 if (sibling == this) {
402 // We already have been set
403 continue;
404 }
405 InputQueueDisplay* display = dynamic_cast<InputQueueDisplay*>(sibling);
406 if (display == nullptr) {
407 // Cast failed. Sibling is no InputQueueDisplay
408 continue;
409 }
410 uint32_t new_fill = std::max(0,
411 std::min<int32_t>(
412 static_cast<int32_t>(display->cache_max_fill_) + delta,
413 display->cache_size_));
414 if (new_fill != display->cache_max_fill_) {
415 igb_.game().send_player_set_input_max_fill(
416 building_, display->index_, display->type_, new_fill);
417 }
418 } while ((sibling = sibling->get_next_sibling()));
356}419}
357420
358void InputQueueDisplay::compute_max_fill_buttons_enabled_state() {421void InputQueueDisplay::compute_max_fill_buttons_enabled_state() {
@@ -364,11 +427,5 @@
364 increase_max_fill_->set_enabled(false);427 increase_max_fill_->set_enabled(false);
365 if (decrease_max_fill_)428 if (decrease_max_fill_)
366 decrease_max_fill_->set_enabled(false);429 decrease_max_fill_->set_enabled(false);
367 } else {
368
369 if (decrease_max_fill_)
370 decrease_max_fill_->set_enabled(cache_max_fill_ > 0);
371 if (increase_max_fill_)
372 increase_max_fill_->set_enabled(cache_max_fill_ < queue_.get_max_size());
373 }430 }
374}431}
375432
=== modified file 'src/wui/inputqueuedisplay.h'
--- src/wui/inputqueuedisplay.h 2019-02-23 11:00:49 +0000
+++ src/wui/inputqueuedisplay.h 2019-04-24 15:17:48 +0000
@@ -87,7 +87,8 @@
87 void increase_max_fill_clicked();87 void increase_max_fill_clicked();
88 void radiogroup_changed(int32_t);88 void radiogroup_changed(int32_t);
89 void radiogroup_clicked();89 void radiogroup_clicked();
90 void update_siblings(int32_t);90 void update_siblings_priority(int32_t);
91 void update_siblings_fill(int32_t);
9192
92 void compute_max_fill_buttons_enabled_state();93 void compute_max_fill_buttons_enabled_state();
93};94};

Subscribers

People subscribed via source and target branches

to status/vote changes: