From f27f210efeb13a5ac29727fef271f8249e3e8c5d Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Fri, 21 Aug 2020 18:01:24 +0300 Subject: Proof of concept complete. The timer will now take int msecs to start, and will properly display the time remaining until target time in hh:mm:ss.zzz Clock can be defined in courtroom_config.ini and its font set in courtroom_fonts.ini Pause and resume functions will not work as expected atm. --- src/courtroom.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/courtroom.cpp') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 2484bcb0..e2b372c5 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -112,6 +112,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_music_name->setText(tr("None")); ui_music_name->setAttribute(Qt::WA_TransparentForMouseEvents); + ui_clock = new AOClockLabel(this); + ui_clock->setAttribute(Qt::WA_TransparentForMouseEvents); + ui_ic_chat_name = new QLineEdit(this); ui_ic_chat_name->setFrame(false); ui_ic_chat_name->setPlaceholderText(tr("Showname")); @@ -619,6 +622,9 @@ void Courtroom::set_widgets() ui_music_display->play("music_display"); ui_music_display->set_play_once(false); + set_size_and_pos(ui_clock, "clock"); + ui_clock->start(30000); + if (is_ao2_bg) { set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); set_size_and_pos(ui_vp_chatbox, "ao2_chatbox"); @@ -943,6 +949,7 @@ void Courtroom::set_fonts(QString p_char) set_font(ui_music_list, "", "music_list", p_char); set_font(ui_area_list, "", "area_list", p_char); set_font(ui_music_name, "", "music_name", p_char); + set_font(ui_clock, "", "clock", p_char); set_dropdowns(); } -- cgit From febfbeafc11ecad57d6e9a06575c28f1b13da8da Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 25 Aug 2020 12:18:49 +0300 Subject: Actually make use of the completely useless CHECK and CH keepalive timer and use them to determine the client's ping. Display ping in the application window title. keepalive timer now fires every second instead of every minute Remove meme clock starting on set_widgets() implement get_ping() on w_courtroom --- src/courtroom.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/courtroom.cpp') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index e2b372c5..ec1fc994 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -8,7 +8,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() qsrand(static_cast(QDateTime::currentMSecsSinceEpoch() / 1000)); keepalive_timer = new QTimer(this); - keepalive_timer->start(60000); + keepalive_timer->start(1000); chat_tick_timer = new QTimer(this); @@ -623,7 +623,6 @@ void Courtroom::set_widgets() ui_music_display->set_play_once(false); set_size_and_pos(ui_clock, "clock"); - ui_clock->start(30000); if (is_ao2_bg) { set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); @@ -4672,6 +4671,7 @@ void Courtroom::on_switch_area_music_clicked() void Courtroom::ping_server() { + ping_timer.start(); ao_app->send_server_packet( new AOPacket("CH#" + QString::number(m_cid) + "#%")); } -- cgit From 7e9c5726e02a65023d9563f49e833525bf8f4bae Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 25 Aug 2020 12:21:10 +0300 Subject: Introduce the timer packet - "TI". This timer will start the clock accounting for latency! Cool, right? Remove useless qDebug() for music looping --- src/courtroom.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/courtroom.cpp') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index ec1fc994..6bd2bd2d 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -4715,6 +4715,16 @@ void Courtroom::announce_case(QString title, bool def, bool pro, bool jud, } } +void Courtroom::start_clock(qint64 msecs) +{ + ui_clock->start(static_cast(msecs)); +} + +void Courtroom::stop_clock() +{ + ui_clock->stop(); +} + Courtroom::~Courtroom() { delete music_player; -- cgit From ee3bad44c72329d61a2cb0c4064c22512451372d Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 25 Aug 2020 12:48:09 +0300 Subject: Implement clock pausing Implement clock setting w/o starting or stopping Both of these should make it possible for the server to start/stop/pause/resume the clock with perfect synchronization to the true time. --- src/courtroom.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/courtroom.cpp') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 6bd2bd2d..f4e31647 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -4715,11 +4715,26 @@ void Courtroom::announce_case(QString title, bool def, bool pro, bool jud, } } +void Courtroom::start_clock() +{ + ui_clock->start(); +} + void Courtroom::start_clock(qint64 msecs) { ui_clock->start(static_cast(msecs)); } +void Courtroom::set_clock(qint64 msecs) +{ + ui_clock->set(static_cast(msecs), true); +} + +void Courtroom::pause_clock() +{ + ui_clock->pause(); +} + void Courtroom::stop_clock() { ui_clock->stop(); -- cgit From de3533fbf2615a40efc60c9ed2e96f1a3b5da3c1 Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Sat, 9 Jan 2021 01:18:19 -0600 Subject: Rework timer and ping logic The timer's time as received by the server is clarified to be the actual numerical time, in milliseconds, to be shown on the clock. --- src/courtroom.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/courtroom.cpp') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index f4e31647..c2fcf9b8 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -8,7 +8,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() qsrand(static_cast(QDateTime::currentMSecsSinceEpoch() / 1000)); keepalive_timer = new QTimer(this); - keepalive_timer->start(1000); + keepalive_timer->start(45000); chat_tick_timer = new QTimer(this); @@ -114,6 +114,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_clock = new AOClockLabel(this); ui_clock->setAttribute(Qt::WA_TransparentForMouseEvents); + ui_clock->hide(); ui_ic_chat_name = new QLineEdit(this); ui_ic_chat_name->setFrame(false); @@ -4672,10 +4673,20 @@ void Courtroom::on_switch_area_music_clicked() void Courtroom::ping_server() { ping_timer.start(); + is_pinging = true; ao_app->send_server_packet( new AOPacket("CH#" + QString::number(m_cid) + "#%")); } +qint64 Courtroom::pong() +{ + if (!is_pinging) + return -1; + + is_pinging = false; + return ping_timer.elapsed(); +} + void Courtroom::on_casing_clicked() { if (ao_app->casing_alerts_enabled) { @@ -4740,6 +4751,11 @@ void Courtroom::stop_clock() ui_clock->stop(); } +void Courtroom::set_clock_visibility(bool visible) +{ + ui_clock->setVisible(visible); +} + Courtroom::~Courtroom() { delete music_player; -- cgit From 45c78ea5caf58b6b8494decc6021540c755fabd7 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 11 Jan 2021 17:38:08 +0300 Subject: Add "id" variable to the clock functions and properly parse the ID Implement scalable maximum clock count, right now it's at 5 clocks a theme can have max Theme "clock_" starts from 1 instead of 0 since users don't know when stuff starts at index 0 TODO: testing lol --- src/courtroom.cpp | 60 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 18 deletions(-) (limited to 'src/courtroom.cpp') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 962c04f3..d997c91e 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -115,10 +115,12 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_music_name = new ScrollText(ui_music_display); ui_music_name->setText(tr("None")); ui_music_name->setAttribute(Qt::WA_TransparentForMouseEvents); - - ui_clock = new AOClockLabel(this); - ui_clock->setAttribute(Qt::WA_TransparentForMouseEvents); - ui_clock->hide(); + + for (int i = 0; i < max_clocks; i++) { + ui_clock[i] = new AOClockLabel(this); + ui_clock[i]->setAttribute(Qt::WA_TransparentForMouseEvents); + ui_clock[i]->hide(); + } ui_ic_chat_name = new QLineEdit(this); ui_ic_chat_name->setFrame(false); @@ -645,7 +647,9 @@ void Courtroom::set_widgets() ui_music_display->play("music_display"); ui_music_display->set_play_once(false); - set_size_and_pos(ui_clock, "clock"); + for (int i = 0; i < max_clocks; i++) { + set_size_and_pos(ui_clock[i], "clock_" + QString::number(i+1)); + } if (is_ao2_bg) { set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); @@ -994,7 +998,9 @@ void Courtroom::set_fonts(QString p_char) set_font(ui_music_list, "", "music_list", p_char); set_font(ui_area_list, "", "area_list", p_char); set_font(ui_music_name, "", "music_name", p_char); - set_font(ui_clock, "", "clock", p_char); + + for (int i = 0; i < max_clocks; i++) + set_font(ui_clock[i], "", "clock_" + QString::number(i+1), p_char); set_dropdowns(); } @@ -5066,34 +5072,52 @@ void Courtroom::announce_case(QString title, bool def, bool pro, bool jud, } } -void Courtroom::start_clock() +void Courtroom::start_clock(int id) { - ui_clock->start(); + if (id < max_clocks && ui_clock[id] != nullptr) + { + ui_clock[id]->start(); + } } -void Courtroom::start_clock(qint64 msecs) +void Courtroom::start_clock(int id, qint64 msecs) { - ui_clock->start(static_cast(msecs)); + if (id < max_clocks && ui_clock[id] != nullptr) + { + ui_clock[id]->start(static_cast(msecs)); + } } -void Courtroom::set_clock(qint64 msecs) +void Courtroom::set_clock(int id, qint64 msecs) { - ui_clock->set(static_cast(msecs), true); + if (id < max_clocks && ui_clock[id] != nullptr) + { + ui_clock[id]->set(static_cast(msecs), true); + } } -void Courtroom::pause_clock() +void Courtroom::pause_clock(int id) { - ui_clock->pause(); + if (id < max_clocks && ui_clock[id] != nullptr) + { + ui_clock[id]->pause(); + } } -void Courtroom::stop_clock() +void Courtroom::stop_clock(int id) { - ui_clock->stop(); + if (id < max_clocks && ui_clock[id] != nullptr) + { + ui_clock[id]->stop(); + } } -void Courtroom::set_clock_visibility(bool visible) +void Courtroom::set_clock_visibility(int id, bool visible) { - ui_clock->setVisible(visible); + if (id < max_clocks && ui_clock[id] != nullptr) + { + ui_clock[id]->setVisible(visible); + } } void Courtroom::truncate_label_text(QWidget *p_widget, QString p_identifier) -- cgit From 98da2698a603c2dd131e523e305a961e805affd7 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 11 Jan 2021 17:52:23 +0300 Subject: Screw it, let there be clock_0 --- src/courtroom.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/courtroom.cpp') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index d997c91e..361f08fa 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -648,7 +648,7 @@ void Courtroom::set_widgets() ui_music_display->set_play_once(false); for (int i = 0; i < max_clocks; i++) { - set_size_and_pos(ui_clock[i], "clock_" + QString::number(i+1)); + set_size_and_pos(ui_clock[i], "clock_" + QString::number(i)); } if (is_ao2_bg) { @@ -1000,7 +1000,7 @@ void Courtroom::set_fonts(QString p_char) set_font(ui_music_name, "", "music_name", p_char); for (int i = 0; i < max_clocks; i++) - set_font(ui_clock[i], "", "clock_" + QString::number(i+1), p_char); + set_font(ui_clock[i], "", "clock_" + QString::number(i), p_char); set_dropdowns(); } -- cgit From 07993a621b046985ee39ddef1427d8b4cc6042b1 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 12 Jan 2021 12:02:07 +0300 Subject: Better place to check invalid ID's --- src/courtroom.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/courtroom.cpp') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 4ed47355..0c36215f 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -5336,7 +5336,7 @@ void Courtroom::announce_case(QString title, bool def, bool pro, bool jud, void Courtroom::start_clock(int id) { - if (id < max_clocks && ui_clock[id] != nullptr) + if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr) { ui_clock[id]->start(); } @@ -5344,7 +5344,7 @@ void Courtroom::start_clock(int id) void Courtroom::start_clock(int id, qint64 msecs) { - if (id < max_clocks && ui_clock[id] != nullptr) + if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr) { ui_clock[id]->start(static_cast(msecs)); } @@ -5352,7 +5352,7 @@ void Courtroom::start_clock(int id, qint64 msecs) void Courtroom::set_clock(int id, qint64 msecs) { - if (id < max_clocks && ui_clock[id] != nullptr) + if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr) { ui_clock[id]->set(static_cast(msecs), true); } @@ -5360,7 +5360,7 @@ void Courtroom::set_clock(int id, qint64 msecs) void Courtroom::pause_clock(int id) { - if (id < max_clocks && ui_clock[id] != nullptr) + if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr) { ui_clock[id]->pause(); } @@ -5368,7 +5368,7 @@ void Courtroom::pause_clock(int id) void Courtroom::stop_clock(int id) { - if (id < max_clocks && ui_clock[id] != nullptr) + if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr) { ui_clock[id]->stop(); } @@ -5376,7 +5376,7 @@ void Courtroom::stop_clock(int id) void Courtroom::set_clock_visibility(int id, bool visible) { - if (id < max_clocks && ui_clock[id] != nullptr) + if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr) { ui_clock[id]->setVisible(visible); } -- cgit