s.defensive_formation = 0;
s.stoppage = false;
s.pull_state = Status::SHOULD_PULL;
+ s.last_catching_player = -1;
uint64_t last_gained_possession = 0;
uint64_t last_stoppage = 0;
uint64_t time_spent_in_stoppage = 0;
unsigned num_touches = 0;
- auto set_offense = [&s] { s.attack_state = Status::OFFENSE; };
- auto set_defense = [&s] { s.attack_state = Status::DEFENSE; };
+ auto set_offense = [&s] { s.attack_state = Status::OFFENSE; s.last_catching_player = -1; };
+ auto set_defense = [&s] { s.attack_state = Status::DEFENSE; s.last_catching_player = -1; };
for (const Event &e : events) {
if (e.t > t) {
// No effect on pull status.
} else if (e.type == EventType::PULL) {
s.pull_state = Status::PULL_IN_AIR;
+ s.last_catching_player = -1; // Just to be sure.
} else {
s.pull_state = Status::NOT_PULLING; // Includes pull_landed and pull_oob.
}
time_spent_in_stoppage = 0;
}
++num_touches;
+ s.last_catching_player = *e.player_id;
}
if (e.type == EventType::INTERCEPTION) {
num_touches = 1;
set_offense();
+ s.last_catching_player = *e.player_id;
last_gained_possession = e.t;
time_spent_in_stoppage = 0;
}
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"); });
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)
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);