connect(ui->pull, &QPushButton::clicked, [this]() { set_current_event_type("pull"); });
connect(ui->pull_landed, &QPushButton::clicked, [this]() { set_current_event_type("pull_landed"); });
+ connect(ui->substitution, &QPushButton::clicked, [this]() { make_substitution(); });
+
QShortcut *key_delete = new QShortcut(QKeySequence(Qt::Key_Delete), this);
connect(key_delete, &QShortcut::activated, [this]() { ui->delete_->animateClick(); });
connect(ui->delete_, &QPushButton::clicked, [this]() { delete_current_event(); });
update_status();
}
+void MainWindow::make_substitution()
+{
+ QItemSelectionModel *select = ui->player_view->selectionModel();
+
+ // FIXME: we should backdate t to start of point (last goal, or 0) if:
+ // - no players we're removing have had actions yet
+ // - there have been no other in/out events
+ //
+ // ...but if so, we might need to modify in/out events that are already there
+ // (perhaps just overwrite them all?)
+ uint64_t t = player->position();
+
+ set<int> old_team = events->get_team_at(t);
+ set<int> new_team;
+
+ for (QModelIndex row : select->selectedRows()) {
+ new_team.insert(players->get_player_id(row.row()));
+ }
+
+ for (int player_id : old_team) {
+ if (!new_team.count(player_id)) {
+ events->insert_event(t, player_id, "out");
+ }
+ }
+ for (int player_id : new_team) {
+ if (!old_team.count(player_id)) {
+ events->insert_event(t, player_id, "in");
+ }
+ }
+}
+
void MainWindow::update_status()
{
EventsModel::Status s = events->get_status_at(player->position());