~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/wui/interactive_base.cc

Merged lp:~widelands-dev/widelands/expedition_portspace_indicator:
Show a port icon on the field where an expedition ship can build a port

Show diffs side-by-side

added added

removed removed

Lines of Context:
152
152
           });
153
153
        sound_subscriber_ = Notifications::subscribe<NoteSound>(
154
154
           [this](const NoteSound& note) { play_sound_effect(note); });
 
155
        shipnotes_subscriber_ =
 
156
           Notifications::subscribe<Widelands::NoteShip>([this](const Widelands::NoteShip& note) {
 
157
                   if (note.action == Widelands::NoteShip::Action::kWaitingForCommand &&
 
158
                       note.ship->get_ship_state() ==
 
159
                          Widelands::Ship::ShipStates::kExpeditionPortspaceFound) {
 
160
                           expedition_port_spaces_.emplace(note.ship, note.ship->exp_port_spaces().front());
 
161
                   }
 
162
           });
155
163
 
156
164
        toolbar_.set_layout_toplevel(true);
157
165
        map_view_.changeview.connect([this] { mainview_move(); });
304
312
void InteractiveBase::on_buildhelp_changed(bool /* value */) {
305
313
}
306
314
 
 
315
bool InteractiveBase::has_expedition_port_space(const Widelands::Coords& coords) const {
 
316
        for (const auto& pair : expedition_port_spaces_) {
 
317
                if (pair.second == coords) {
 
318
                        return true;
 
319
                }
 
320
        }
 
321
        return false;
 
322
}
 
323
 
307
324
// Show the given workareas at the given coords and returns the overlay job id associated
308
325
void InteractiveBase::show_workarea(const WorkareaInfo& workarea_info, Widelands::Coords coords) {
309
326
        workarea_previews_[coords] = &workarea_info;
457
474
        }
458
475
        egbase().think();  // Call game logic here. The game advances.
459
476
 
 
477
        // Cleanup found port spaces if the ship sailed on or was destroyed
 
478
        for (auto it = expedition_port_spaces_.begin(); it != expedition_port_spaces_.end(); ++it) {
 
479
                if (!egbase().objects().object_still_available(it->first) ||
 
480
                    it->first->get_ship_state() != Widelands::Ship::ShipStates::kExpeditionPortspaceFound) {
 
481
                        expedition_port_spaces_.erase(it);
 
482
                        // If another port space also needs removing, we'll take care of it in the next frame
 
483
                        return;
 
484
                }
 
485
        }
 
486
 
460
487
        UI::Panel::think();
461
488
}
462
489