From f8bd91331cdef3c4e9d9d343414ba3cc49cbe1d0 Mon Sep 17 00:00:00 2001 From: Chrezm Date: Wed, 1 Jun 2022 16:13:08 -0400 Subject: [PATCH 1/2] Basic implementation of revealing/hiding timer --- src/courtroom.cpp | 8 ++++++++ src/courtroom.h | 1 + src/server_socket.cpp | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 09d42714d..f96946443 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2334,3 +2334,11 @@ void Courtroom::pause_timer(int p_id) AOTimer *l_timer = ui_timers.at(p_id); l_timer->pause(); } + +void Courtroom::reveal_timer(int p_id, bool p_reveal) +{ + if (p_id < 0 || p_id >= ui_timers.length()) + return; + AOTimer *l_timer = ui_timers.at(p_id); + l_timer->setVisible(p_reveal); +} diff --git a/src/courtroom.h b/src/courtroom.h index 4cde32df1..079864fff 100644 --- a/src/courtroom.h +++ b/src/courtroom.h @@ -214,6 +214,7 @@ class Courtroom : public QMainWindow void set_timer_timestep(int timer_id, int timestep_length); void set_timer_firing(int timer_id, int firing_interval); void pause_timer(int timer_id); + void reveal_timer(int timer_id, bool reveal); template int adapt_numbered_items(QVector &item_vector, QString config_item_number, QString item_name); diff --git a/src/server_socket.cpp b/src/server_socket.cpp index 61bd45203..604818190 100644 --- a/src/server_socket.cpp +++ b/src/server_socket.cpp @@ -436,6 +436,17 @@ void AOApplication::_p_handle_server_packet(DRPacket p_packet) int timer_id = l_content.at(0).toInt(); m_courtroom->pause_timer(timer_id); } + else if (l_header == "TV") + { + // Timer visible + if (l_content.size() != 2) + return; + if (!is_courtroom_constructed) + return; + int timer_id = l_content.at(0).toInt(); + bool reveal = l_content.at(1).toInt() == 1; + m_courtroom->reveal_timer(timer_id, reveal); + } else if (l_header == "SP") { // Set position From 8d8484af113ecce2c0bb4c3589708833979f2d62 Mon Sep 17 00:00:00 2001 From: Chrezm Date: Tue, 7 Jun 2022 16:50:49 -0400 Subject: [PATCH 2/2] Deprecate timer_number in favor of always having 20 timers --- src/aotimer.cpp | 2 ++ src/aotimer.h | 1 + src/courtroom.h | 1 + src/courtroom_widgets.cpp | 24 +++++++++++++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/aotimer.cpp b/src/aotimer.cpp index 31ca10eab..c5d30b6b5 100644 --- a/src/aotimer.cpp +++ b/src/aotimer.cpp @@ -3,6 +3,8 @@ #include #include +const int AOTimer::TIMER_COUNT = 20; + AOTimer::AOTimer(QWidget *p_parent) : DRTextEdit(p_parent) { // Adapted from: diff --git a/src/aotimer.h b/src/aotimer.h index 96c71d5d3..539c96145 100644 --- a/src/aotimer.h +++ b/src/aotimer.h @@ -43,6 +43,7 @@ class AOTimer : public DRTextEdit public: AOTimer(QWidget *p_parent); + static const int TIMER_COUNT; public slots: void update_time(); diff --git a/src/courtroom.h b/src/courtroom.h index 079864fff..b91f85c7c 100644 --- a/src/courtroom.h +++ b/src/courtroom.h @@ -606,6 +606,7 @@ private slots: void load_shouts(); void load_effects(); void load_wtce(); + void load_timers(); void load_free_blocks(); void reset_shout_buttons(); diff --git a/src/courtroom_widgets.cpp b/src/courtroom_widgets.cpp index 5434ac205..d7bc0222e 100644 --- a/src/courtroom_widgets.cpp +++ b/src/courtroom_widgets.cpp @@ -1005,7 +1005,7 @@ void Courtroom::set_widgets() set_stylesheet(f_line, "[LINE EDIT]", COURTROOM_STYLESHEETS_CSS, ao_app); } - adapt_numbered_items(ui_timers, "timer_number", "timer"); + load_timers(); set_fonts(); Q_EMIT loaded_theme(); @@ -1248,6 +1248,28 @@ void Courtroom::load_free_blocks() } } +void Courtroom::load_timers() +{ + // Close any existing timers to prevent memory leaks + for (QWidget *widget : qAsConst(ui_timers)) + delete_widget(widget); + + // And create new free block buttons + int timer_number = AOTimer::TIMER_COUNT; + // Create new items + ui_timers.resize(timer_number); + for (int i = 0; i < timer_number; i++) + { + ui_timers[i] = new AOTimer(this); + } + + for (int i = 0; i < timer_number; i++) + { + ui_timers[i]->show(); + set_size_and_pos(ui_timers[i], "timer_" + QString::number(i), COURTROOM_DESIGN_INI, ao_app); + } +} + void Courtroom::load_shouts() { for (QWidget *widget : qAsConst(ui_shouts))