]> git.sesse.net Git - pkanalytics/commitdiff
Disable irrelevant buttons.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 1 May 2023 21:13:35 +0000 (23:13 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 1 May 2023 21:13:35 +0000 (23:13 +0200)
events.h
main.cpp
mainwindow.h

index 3574cc6736c3d90c587c595a0d4e0bdb58774da5..fe5bd6d47222858720471175760df9b1ff98bcad 100644 (file)
--- 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<int> get_player_id(unsigned row) { return events[row].player_id; }
 
        struct Status {
                unsigned our_score, their_score;
index 3c44f94adbbe8cb034b259747ceaaed215a032cc..9b9f6305ba7db66dc35ccb65da8543346176242f 100644 (file)
--- 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;
index d3f834c85025ffd049401d0ad31ab7582783ee50..805fb125f6c2dc7a056889488cf3c9d2f7777b42 100644 (file)
@@ -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;