X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mainwindow.cpp;fp=mainwindow.cpp;h=bb6883f7cf58918f50f4e1e6f0a8c7c7ce77140a;hb=a8b643f686d812de920091153b5409b5eeca8aa8;hp=bf0ec2bcc80addab23e00ab393feabb49ba0567c;hpb=478618b4599c98d75c5b7af3f9bd38f1a958b548;p=pkanalytics diff --git a/mainwindow.cpp b/mainwindow.cpp index bf0ec2b..bb6883f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -263,7 +263,7 @@ MainWindow::MainWindow(EventsModel *events, PlayersModel *players, if (s.attack_state == EventsModel::Status::DEFENSE && s.pull_state == EventsModel::Status::PULL_IN_AIR) { insert_noplayer_event("pull_oob"); } else { - set_current_event_type("throwaway"); + insert_throwaway(); } }); connect(ui->drop, &QPushButton::clicked, [this] { set_current_event_type("drop"); }); @@ -425,6 +425,36 @@ void MainWindow::set_current_event_type(const string &type) update_ui_from_time(ui->video->get_position()); } +void MainWindow::insert_throwaway() +{ + uint64_t t = ui->video->get_position(); + + QItemSelectionModel *select = ui->event_view->selectionModel(); + if (select->hasSelection()) { + int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior. + // We could want to modify this catch event into a throwaway. See if that is the case. + int last_catching_player = events->get_status_at(events->get_time(row) - 1).last_catching_player; + if (last_catching_player != -1 && last_catching_player == events->get_player_id(row)) { + // Last event was that this player caught the disc, so yes, make this a throwaway. + events->set_event_type(row, "throwaway"); + update_ui_from_time(t); + return; + } + // It doesn't make sense that the player throws it away without holding the disc first, + // so we insert a new event where the person holding the disc throws it away. + // (In other words, fall back to inserting a new one based on time.) + } + + int last_catching_player = events->get_status_at(t - 1).last_catching_player; + if (last_catching_player == -1) { + return; + } + + ui->event_view->selectionModel()->blockSignals(true); + ui->event_view->selectRow(events->insert_event(t, last_catching_player, nullopt, "throwaway")); + ui->event_view->selectionModel()->blockSignals(false); +} + // Formation buttons either modify the existing formation (if we've selected // a formation change event), or insert a new one (if not). void MainWindow::insert_or_change_formation(bool offense) @@ -668,7 +698,7 @@ void MainWindow::update_action_buttons(uint64_t t) ui->pull_or_was_d->setEnabled(true); ui->catch_->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player); - ui->throwaway->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player); + ui->throwaway->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && s.last_catching_player != -1); ui->drop->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player); ui->goal->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player); ui->stallout->setEnabled(s.attack_state == EventsModel::Status::OFFENSE && has_selection_with_player);