From fbd1f838ae5767f86385207632574c2c89a3b28b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 1 May 2023 23:13:35 +0200 Subject: [PATCH] Disable irrelevant buttons. --- events.h | 1 + main.cpp | 44 ++++++++++++++++++++++++++++++++++++++++---- mainwindow.h | 1 + 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/events.h b/events.h index 3574cc6..fe5bd6d 100644 --- a/events.h +++ b/events.h @@ -29,6 +29,7 @@ public: void delete_event(unsigned row); void set_event_type(unsigned row, const std::string &type); uint64_t get_time(unsigned row) { return events[row].t; } + std::optional get_player_id(unsigned row) { return events[row].player_id; } struct Status { unsigned our_score, their_score; diff --git a/main.cpp b/main.cpp index 3c44f94..9b9f630 100644 --- a/main.cpp +++ b/main.cpp @@ -89,7 +89,6 @@ MainWindow::MainWindow(EventsModel *events, PlayersModel *players) : events(even connect(ui->player_7, &QPushButton::clicked, [this]() { insert_event(7); }); // Offensive events - // TODO: disable if nothing is selected connect(ui->catch_, &QPushButton::clicked, [this]() { set_current_event_type("catch"); }); connect(ui->throwaway, &QPushButton::clicked, [this]() { set_current_event_type("throwaway"); }); connect(ui->drop, &QPushButton::clicked, [this]() { set_current_event_type("drop"); }); @@ -103,9 +102,9 @@ MainWindow::MainWindow(EventsModel *events, PlayersModel *players) : events(even connect(ui->their_throwaway, &QPushButton::clicked, [this]() { insert_noplayer_event("their_throwaway"); }); connect(ui->their_goal, &QPushButton::clicked, [this]() { insert_noplayer_event("their_goal"); }); connect(ui->their_pull, &QPushButton::clicked, [this]() { insert_noplayer_event("their_pull"); }); - connect(ui->our_defense, &QPushButton::clicked, [this]() { set_current_event_type("defense"); }); // TODO: player-connected - connect(ui->defensive_soft_plus, &QPushButton::clicked, [this]() { set_current_event_type("defensive_soft_plus"); }); // TODO: player-connected - connect(ui->defensive_soft_minus, &QPushButton::clicked, [this]() { set_current_event_type("defensive_soft_minus"); }); // TODO: player-connected + connect(ui->our_defense, &QPushButton::clicked, [this]() { set_current_event_type("defense"); }); + connect(ui->defensive_soft_plus, &QPushButton::clicked, [this]() { set_current_event_type("defensive_soft_plus"); }); + connect(ui->defensive_soft_minus, &QPushButton::clicked, [this]() { set_current_event_type("defensive_soft_minus"); }); // Misc. events connect(ui->substitution, &QPushButton::clicked, [this]() { make_substitution(); }); @@ -230,6 +229,7 @@ void MainWindow::update_ui_from_time(uint64_t t) { update_status(t); update_player_buttons(t); + update_action_buttons(t); } void MainWindow::update_status(uint64_t t) @@ -274,6 +274,42 @@ void MainWindow::update_player_buttons(uint64_t t) } } +void MainWindow::update_action_buttons(uint64_t t) +{ + EventsModel::Status s = events->get_status_at(t); + bool has_selection = false; + bool has_selection_with_player = false; + + QItemSelectionModel *select = ui->event_view->selectionModel(); + if (select->hasSelection()) { + has_selection = true; + int row = select->selectedRows().front().row(); // Should only be one, due to our selection behavior. + has_selection_with_player = events->get_player_id(row).has_value(); + } + + ui->catch_->setEnabled(s.offense && has_selection_with_player); + ui->throwaway->setEnabled(s.offense && has_selection_with_player); + ui->drop->setEnabled(s.offense && has_selection_with_player); + ui->goal->setEnabled(s.offense && has_selection_with_player); + ui->offensive_soft_plus->setEnabled(s.offense && has_selection_with_player); + ui->offensive_soft_minus->setEnabled(s.offense && has_selection_with_player); + + // TODO: be stricter + ui->pull->setEnabled(s.offense && has_selection_with_player); + ui->pull_landed->setEnabled(s.offense && has_selection_with_player); + + ui->interception->setEnabled(!s.offense && has_selection_with_player); + ui->their_throwaway->setEnabled(!s.offense); + ui->our_defense->setEnabled(!s.offense && has_selection_with_player); + ui->their_goal->setEnabled(!s.offense); + ui->defensive_soft_plus->setEnabled(!s.offense && has_selection_with_player); + ui->defensive_soft_minus->setEnabled(!s.offense && has_selection_with_player); + ui->their_pull->setEnabled(!s.offense); + ui->our_foul->setEnabled(!s.offense && has_selection_with_player); + + ui->delete_->setEnabled(has_selection); +} + sqlite3 *open_db(const char *filename) { sqlite3 *db; diff --git a/mainwindow.h b/mainwindow.h index d3f834c..805fb12 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,6 +27,7 @@ private: void update_ui_from_time(uint64_t t); void update_status(uint64_t t); void update_player_buttons(uint64_t t); + void update_action_buttons(uint64_t t); Ui::MainWindow *ui; EventsModel *events; -- 2.39.2