aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/aoclocklabel.cpp59
-rw-r--r--src/aomusicplayer.cpp1
-rw-r--r--src/courtroom.cpp74
-rw-r--r--src/packet_distribution.cpp56
4 files changed, 187 insertions, 3 deletions
diff --git a/src/aoclocklabel.cpp b/src/aoclocklabel.cpp
new file mode 100644
index 00000000..4c9c4819
--- /dev/null
+++ b/src/aoclocklabel.cpp
@@ -0,0 +1,59 @@
+#include "aoclocklabel.h"
+
+AOClockLabel::AOClockLabel(QWidget *parent) : QLabel(parent) {}
+
+void AOClockLabel::start()
+{
+ timer.start(1000 / 60, this);
+}
+
+void AOClockLabel::start(int msecs)
+{
+ this->set(msecs);
+ this->start();
+}
+
+void AOClockLabel::set(int msecs, bool update_text)
+{
+ target_time = QTime::currentTime().addMSecs(msecs);
+ if (update_text)
+ {
+ if (QTime::currentTime() >= target_time)
+ {
+ this->setText("00:00:00.000");
+ }
+ else
+ {
+ QTime timeleft = QTime(0,0).addMSecs(QTime::currentTime().msecsTo(target_time));
+ QString timestring = timeleft.toString("hh:mm:ss.zzz");
+ this->setText(timestring);
+ }
+ }
+}
+
+void AOClockLabel::pause()
+{
+ timer.stop();
+}
+
+void AOClockLabel::stop()
+{
+ this->setText("00:00:00.000");
+ timer.stop();
+}
+
+void AOClockLabel::timerEvent(QTimerEvent *event)
+{
+ if (event->timerId() == timer.timerId()) {
+ if (QTime::currentTime() >= target_time)
+ {
+ this->stop();
+ return;
+ }
+ QTime timeleft = QTime(0,0).addMSecs(QTime::currentTime().msecsTo(target_time));
+ QString timestring = timeleft.toString("hh:mm:ss.zzz");
+ this->setText(timestring);
+ } else {
+ QWidget::timerEvent(event);
+ }
+}
diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp
index be9d7632..b36de486 100644
--- a/src/aomusicplayer.cpp
+++ b/src/aomusicplayer.cpp
@@ -161,7 +161,6 @@ void CALLBACK loopProc(HSYNC handle, DWORD channel, DWORD data, void *user)
void AOMusicPlayer::set_looping(bool toggle, int channel)
{
- qDebug() << "Setting looping for channel" << channel << "to" << toggle;
m_looping = toggle;
if (!m_looping) {
if (BASS_ChannelFlags(m_stream_list[channel], 0, 0) & BASS_SAMPLE_LOOP)
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index 7a4cc3b7..4b37e6f9 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -12,7 +12,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
qsrand(static_cast<uint>(QDateTime::currentMSecsSinceEpoch() / 1000));
keepalive_timer = new QTimer(this);
- keepalive_timer->start(60000);
+ keepalive_timer->start(45000);
chat_tick_timer = new QTimer(this);
@@ -120,6 +120,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);
+
+ 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);
@@ -663,6 +669,10 @@ void Courtroom::set_widgets()
ui_music_display->load_image("music_display", "");
+ for (int i = 0; i < max_clocks; i++) {
+ set_size_and_pos(ui_clock[i], "clock_" + QString::number(i));
+ }
+
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");
@@ -1016,6 +1026,9 @@ void Courtroom::set_fonts(QString p_char)
set_font(ui_area_list, "", "area_list", 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), p_char);
+
set_dropdowns();
}
@@ -5266,10 +5279,21 @@ 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) {
@@ -5309,6 +5333,54 @@ void Courtroom::announce_case(QString title, bool def, bool pro, bool jud,
}
}
+void Courtroom::start_clock(int id)
+{
+ if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr)
+ {
+ ui_clock[id]->start();
+ }
+}
+
+void Courtroom::start_clock(int id, qint64 msecs)
+{
+ if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr)
+ {
+ ui_clock[id]->start(static_cast<int>(msecs));
+ }
+}
+
+void Courtroom::set_clock(int id, qint64 msecs)
+{
+ if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr)
+ {
+ ui_clock[id]->set(static_cast<int>(msecs), true);
+ }
+}
+
+void Courtroom::pause_clock(int id)
+{
+ if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr)
+ {
+ ui_clock[id]->pause();
+ }
+}
+
+void Courtroom::stop_clock(int id)
+{
+ if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr)
+ {
+ ui_clock[id]->stop();
+ }
+}
+
+void Courtroom::set_clock_visibility(int id, bool visible)
+{
+ if (id >= 0 && id < max_clocks && ui_clock[id] != nullptr)
+ {
+ ui_clock[id]->setVisible(visible);
+ }
+}
+
void Courtroom::truncate_label_text(QWidget *p_widget, QString p_identifier)
{
QString filename = "courtroom_design.ini";
diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp
index 822b2dc9..2da6981c 100644
--- a/src/packet_distribution.cpp
+++ b/src/packet_distribution.cpp
@@ -260,7 +260,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
courtroom_loaded = false;
- QString window_title = tr("Attorney Online 2");
+ window_title = tr("Attorney Online 2");
int selected_server = w_lobby->get_selected_server();
QString server_address = "", server_name = "";
@@ -604,6 +604,60 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
f_contents.at(4) == "1",
f_contents.at(5) == "1");
}
+ else if (header == "TI") { // Timer packet
+ if (!courtroom_constructed || f_contents.size() < 2)
+ goto end;
+
+ // Timer ID is reserved as argument 0
+ int id = f_contents.at(0).toInt();
+
+ // Type 0 = start/resume/sync timer at time
+ // Type 1 = pause timer at time
+ // Type 2 = show timer
+ // Type 3 = hide timer
+ int type = f_contents.at(1).toInt();
+
+ if (type == 0 || type == 1)
+ {
+ if (f_contents.size() < 2)
+ goto end;
+
+ // The time as displayed on the clock, in milliseconds.
+ // If the number received is negative, stop the timer.
+ qint64 timer_value = f_contents.at(2).toLongLong();
+ qDebug() << "timer:" << timer_value;
+ if (timer_value > 0)
+ {
+ if (type == 0)
+ {
+ timer_value -= latency / 2;
+ w_courtroom->start_clock(id, timer_value);
+ }
+ else
+ {
+ w_courtroom->pause_clock(id);
+ w_courtroom->set_clock(id, timer_value);
+ }
+ }
+ else
+ {
+ w_courtroom->stop_clock(id);
+ }
+ }
+ else if (type == 2)
+ w_courtroom->set_clock_visibility(id, true);
+ else if (type == 3)
+ w_courtroom->set_clock_visibility(id, false);
+ }
+ else if (header == "CHECK") {
+ if (!courtroom_constructed)
+ goto end;
+
+ qint64 ping_time = w_courtroom->pong();
+ qDebug() << "ping:" << ping_time;
+ if (ping_time != -1)
+ latency = ping_time;
+ }
end: