~widelands-dev/widelands/fix-bug-1735980-related-problems

« back to all changes in this revision

Viewing changes to src/wui/inputqueuedisplay.cc

  • Committer: Wideland's Bunnybot
  • Date: 2017-12-18 10:45:01 UTC
  • mfrom: (8528.1.4 ctrl-priorities)
  • Revision ID: bunnybot@widelands.org-20171218104501-abi4nr6ul01fn3w1
Merged lp:~widelands-dev/widelands/ctrl-priorities:
Updating all ware priorities of a building when CTRL is pressed while clicking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
208
208
 
209
209
        priority_radiogroup_->changedto.connect(
210
210
           boost::bind(&InputQueueDisplay::radiogroup_changed, this, _1));
 
211
        priority_radiogroup_->clicked.connect(boost::bind(&InputQueueDisplay::radiogroup_clicked, this));
211
212
 
212
213
        bool const can_act = igb_.can_act(building_.owner().player_number());
213
214
        if (!can_act)
275
276
        default:
276
277
                return;
277
278
        }
 
279
        if (SDL_GetModState() & KMOD_CTRL) {
 
280
                update_siblings(state);
 
281
        }
278
282
        igb_.game().send_player_set_ware_priority(building_, type_, index_, priority);
279
283
}
280
284
 
 
285
void InputQueueDisplay::radiogroup_clicked() {
 
286
        // Already set option has been clicked again
 
287
        // Unimportant for this queue, but update other queues
 
288
        if (SDL_GetModState() & KMOD_CTRL) {
 
289
                update_siblings(priority_radiogroup_->get_state());
 
290
        }
 
291
}
 
292
 
 
293
void InputQueueDisplay::update_siblings(int32_t state) {
 
294
        // "Release" the CTRL key to avoid recursion
 
295
        const SDL_Keymod old_modifiers = SDL_GetModState();
 
296
        SDL_SetModState(KMOD_NONE);
 
297
 
 
298
        Panel* sibling = get_parent()->get_first_child();
 
299
        // Well, at least we should be a child of our parent
 
300
        assert(sibling != nullptr);
 
301
        do {
 
302
                if (sibling == this) {
 
303
                        // We already have been set
 
304
                        continue;
 
305
                }
 
306
                InputQueueDisplay* display = dynamic_cast<InputQueueDisplay*>(sibling);
 
307
                if (display == nullptr) {
 
308
                        // Cast failed. Sibling is no InputQueueDisplay
 
309
                        continue;
 
310
                }
 
311
                if (display->priority_radiogroup_->get_state() == state) {
 
312
                        // Nothing to do for this queue
 
313
                        continue;
 
314
                }
 
315
                // Calling set_state() leads to radiogroup_changed()) getting called, which does the real
 
316
                // change
 
317
                // TODO(Notabilis): When bug 1738485 is fixed probably replace with
 
318
                // send_player_set_ware_priority()
 
319
                display->priority_radiogroup_->set_state(state);
 
320
        } while ((sibling = sibling->get_next_sibling()));
 
321
 
 
322
        SDL_SetModState(old_modifiers);
 
323
}
 
324
 
281
325
/**
282
326
 * One of the buttons to increase or decrease the amount of wares
283
327
 * stored here has been clicked