From 96a511ed5406bf94743854aa8fa99b4137935574 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 29 May 2023 15:38:53 +0200 Subject: [PATCH 1/1] Show formation name in the status bar. --- events.cpp | 16 ++++++++++++++++ events.h | 1 + formations.h | 9 ++++++++- main.cpp | 16 ++++++++++++---- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/events.cpp b/events.cpp index ad70407..9826f0e 100644 --- a/events.cpp +++ b/events.cpp @@ -314,6 +314,8 @@ EventsModel::Status EventsModel::get_status_at(uint64_t t) s.our_score = 0; s.their_score = 0; s.attack_state = Status::NOT_STARTED; + s.offensive_formation = 0; + s.defensive_formation = 0; s.stoppage = false; s.pull_state = Status::SHOULD_PULL; uint64_t last_gained_possession = 0; @@ -388,6 +390,20 @@ EventsModel::Status EventsModel::get_status_at(uint64_t t) last_stoppage = 0; } } + if (e.type == "formation_offense") { + if (e.formation_id) { + s.offensive_formation = *e.formation_id; + } else { + s.offensive_formation = 0; + } + } + if (e.type == "formation_defense") { + if (e.formation_id) { + s.defensive_formation = *e.formation_id; + } else { + s.defensive_formation = 0; + } + } } if (s.stoppage && last_stoppage != 0) { time_spent_in_stoppage += (t - last_stoppage); diff --git a/events.h b/events.h index 6dc2faf..8922496 100644 --- a/events.h +++ b/events.h @@ -38,6 +38,7 @@ public: struct Status { unsigned our_score, their_score; enum { NOT_STARTED, OFFENSE, DEFENSE } attack_state; + unsigned offensive_formation, defensive_formation; bool stoppage; enum { NOT_PULLING, SHOULD_PULL, PULL_IN_AIR } pull_state; unsigned num_passes; diff --git a/formations.h b/formations.h index aa85c79..c023173 100644 --- a/formations.h +++ b/formations.h @@ -29,7 +29,14 @@ public: } return formations[row - 1].formation_id; } - std::string get_formation_name_by_id(unsigned formation_id); + std::string get_formation_name_by_id(unsigned formation_id) { + for (unsigned i = 0; i < formations.size(); ++i) { + if (formations[i].formation_id == formation_id) { + return formations[i].name; + } + } + abort(); + } unsigned get_row_from_id(unsigned formation_id) { for (unsigned i = 0; i < formations.size(); ++i) { if (formations[i].formation_id == formation_id) { diff --git a/main.cpp b/main.cpp index 42d42cc..01b1583 100644 --- a/main.cpp +++ b/main.cpp @@ -301,15 +301,23 @@ void MainWindow::update_status(uint64_t t) { EventsModel::Status s = events->get_status_at(t); char buf[256]; - const char *offense = "not started"; + std::string formation = "Not started"; if (s.attack_state == EventsModel::Status::OFFENSE) { - offense = "offense"; + if (s.offensive_formation != 0) { + formation = offensive_formations->get_formation_name_by_id(s.offensive_formation); + } else { + formation = "Offense"; + } } else if (s.attack_state == EventsModel::Status::DEFENSE) { - offense = "defense"; + if (s.defensive_formation != 0) { + formation = defensive_formations->get_formation_name_by_id(s.defensive_formation); + } else { + formation = "Defense"; + } } snprintf(buf, sizeof(buf), "%d–%d | %s | %d passes, %d sec possession", - s.our_score, s.their_score, offense, s.num_passes, s.possession_sec); + s.our_score, s.their_score, formation.c_str(), s.num_passes, s.possession_sec); if (s.stoppage_sec > 0) { char buf2[256]; snprintf(buf2, sizeof(buf2), "%s (plus %d sec stoppage)", buf, s.stoppage_sec); -- 2.39.2