aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/aoapplication.h4
-rw-r--r--include/aoclocklabel.h29
-rw-r--r--include/courtroom.h21
-rw-r--r--src/aoclocklabel.cpp59
-rw-r--r--src/aomusicplayer.cpp1
-rw-r--r--src/courtroom.cpp50
-rw-r--r--src/packet_distribution.cpp55
7 files changed, 213 insertions, 6 deletions
diff --git a/include/aoapplication.h b/include/aoapplication.h
index a0121f2..b17ac4a 100644
--- a/include/aoapplication.h
+++ b/include/aoapplication.h
@@ -26,6 +26,7 @@
#include <QScreen>
#include <QStringList>
#include <QTextStream>
+#include <QTime>
class NetworkManager;
class Lobby;
@@ -61,6 +62,9 @@ public:
void call_settings_menu();
void call_announce_menu(Courtroom *court);
+ qint64 latency = 0;
+ QString window_title;
+
/////////////////server metadata//////////////////
bool yellow_text_enabled = false;
diff --git a/include/aoclocklabel.h b/include/aoclocklabel.h
new file mode 100644
index 0000000..b5d0794
--- /dev/null
+++ b/include/aoclocklabel.h
@@ -0,0 +1,29 @@
+#ifndef AOCLOCKLABEL_H
+#define AOCLOCKLABEL_H
+
+#include <QLabel>
+#include <QBasicTimer>
+#include <QTimerEvent>
+#include <QTime>
+#include <QDebug>
+
+class AOClockLabel : public QLabel {
+ Q_OBJECT
+
+public:
+ AOClockLabel(QWidget *parent);
+ void start();
+ void start(int msecs);
+ void set(int msecs, bool update_text = false);
+ void pause();
+ void stop();
+
+protected:
+ void timerEvent(QTimerEvent *event) override;
+
+private:
+ QBasicTimer timer;
+ QTime target_time;
+};
+
+#endif // AOCLOCKLABEL_H
diff --git a/include/courtroom.h b/include/courtroom.h
index cb1c458..e0db719 100644
--- a/include/courtroom.h
+++ b/include/courtroom.h
@@ -6,6 +6,7 @@
#include "aobutton.h"
#include "aocharbutton.h"
#include "aocharmovie.h"
+#include "aoclocklabel.h"
#include "aoemotebutton.h"
#include "aoevidencebutton.h"
#include "aoevidencedisplay.h"
@@ -56,7 +57,7 @@
#include <QScrollBar>
#include <QTextBoundaryFinder>
#include <QTextCharFormat>
-//#include <QRandomGenerator>
+#include <QElapsedTimer>
#include <algorithm>
#include <stack>
@@ -254,11 +255,18 @@ public:
void check_connection_received();
+ void start_clock();
+ void start_clock(qint64 msecs);
+ void set_clock(qint64 msecs);
+ void pause_clock();
+ void stop_clock();
+ void set_clock_visibility(bool visible);
+
+ qint64 pong();
// Truncates text so it fits within theme-specified boundaries and sets the tooltip to the full string
void truncate_label_text(QWidget* p_widget, QString p_identifier);
~Courtroom();
-
private:
AOApplication *ao_app;
@@ -308,11 +316,16 @@ private:
QVector<chatlogpiece> ic_chatlog_history;
- // triggers ping_server() every 60 seconds
+ // triggers ping_server() every 1 second
QTimer *keepalive_timer;
// determines how fast messages tick onto screen
QTimer *chat_tick_timer;
+
+ // count up timer to check how long it took for us to get a response from ping_server()
+ QElapsedTimer ping_timer;
+ bool is_pinging = false;
+
// int chat_tick_interval = 60;
// which tick position(character in chat message) we are at
int tick_pos = 0;
@@ -550,6 +563,8 @@ private:
ScrollText *ui_music_name;
AOMovie *ui_music_display;
+ AOClockLabel *ui_clock;
+
AOButton *ui_pair_button;
QListWidget *ui_pair_list;
QSpinBox *ui_pair_offset_spinbox;
diff --git a/src/aoclocklabel.cpp b/src/aoclocklabel.cpp
new file mode 100644
index 0000000..4c9c481
--- /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 585a7f4..6219edf 100644
--- a/src/aomusicplayer.cpp
+++ b/src/aomusicplayer.cpp
@@ -157,7 +157,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 0f807c3..962c04f 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);
@@ -116,6 +116,10 @@ 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_clock->hide();
+
ui_ic_chat_name = new QLineEdit(this);
ui_ic_chat_name->setFrame(false);
ui_ic_chat_name->setPlaceholderText(tr("Showname"));
@@ -641,6 +645,8 @@ void Courtroom::set_widgets()
ui_music_display->play("music_display");
ui_music_display->set_play_once(false);
+ set_size_and_pos(ui_clock, "clock");
+
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");
@@ -988,6 +994,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();
}
@@ -5005,10 +5012,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) {
@@ -5048,6 +5066,36 @@ 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<int>(msecs));
+}
+
+void Courtroom::set_clock(qint64 msecs)
+{
+ ui_clock->set(static_cast<int>(msecs), true);
+}
+
+void Courtroom::pause_clock()
+{
+ ui_clock->pause();
+}
+
+void Courtroom::stop_clock()
+{
+ ui_clock->stop();
+}
+
+void Courtroom::set_clock_visibility(bool visible)
+{
+ ui_clock->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 7146e6e..0bc3814 100644
--- a/src/packet_distribution.cpp
+++ b/src/packet_distribution.cpp
@@ -245,7 +245,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 = "";
@@ -574,6 +574,59 @@ 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;
+
+ // Note: timer ID is reserved as argument 0
+
+ // 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(timer_value);
+ }
+ else
+ {
+ w_courtroom->pause_clock();
+ w_courtroom->set_clock(timer_value);
+ }
+ }
+ else
+ {
+ w_courtroom->stop_clock();
+ }
+ }
+ else if (type == 2)
+ w_courtroom->set_clock_visibility(true);
+ else if (type == 3)
+ w_courtroom->set_clock_visibility(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: