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
This commit is contained in:
Crystalwarrior 2021-01-11 17:38:08 +03:00
parent 62532f0b64
commit 45c78ea5ca
3 changed files with 62 additions and 32 deletions

View File

@ -255,12 +255,12 @@ 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);
void start_clock(int id);
void start_clock(int id, qint64 msecs);
void set_clock(int id, qint64 msecs);
void pause_clock(int id);
void stop_clock(int id);
void set_clock_visibility(int id, bool visible);
qint64 pong();
// Truncates text so it fits within theme-specified boundaries and sets the tooltip to the full string
@ -563,7 +563,8 @@ private:
ScrollText *ui_music_name;
AOMovie *ui_music_display;
AOClockLabel *ui_clock;
static const int max_clocks = 5;
AOClockLabel *ui_clock[max_clocks];
AOButton *ui_pair_button;
QListWidget *ui_pair_list;

View File

@ -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<int>(msecs));
if (id < max_clocks && ui_clock[id] != nullptr)
{
ui_clock[id]->start(static_cast<int>(msecs));
}
}
void Courtroom::set_clock(qint64 msecs)
void Courtroom::set_clock(int id, qint64 msecs)
{
ui_clock->set(static_cast<int>(msecs), true);
if (id < max_clocks && ui_clock[id] != nullptr)
{
ui_clock[id]->set(static_cast<int>(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)

View File

@ -578,7 +578,12 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (!courtroom_constructed || f_contents.size() < 2)
goto end;
// Note: timer ID is reserved as argument 0
// Timer ID is reserved as argument 0
int id = f_contents.at(0).toInt();
// ID is invalid
if (id < 0 || id >= w_courtroom->max_clocks)
goto end;
// Type 0 = start/resume/sync timer at time
// Type 1 = pause timer at time
@ -600,23 +605,23 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (type == 0)
{
timer_value -= latency / 2;
w_courtroom->start_clock(timer_value);
w_courtroom->start_clock(id, timer_value);
}
else
{
w_courtroom->pause_clock();
w_courtroom->set_clock(timer_value);
w_courtroom->pause_clock(id);
w_courtroom->set_clock(id, timer_value);
}
}
else
{
w_courtroom->stop_clock();
w_courtroom->stop_clock(id);
}
}
else if (type == 2)
w_courtroom->set_clock_visibility(true);
w_courtroom->set_clock_visibility(id, true);
else if (type == 3)
w_courtroom->set_clock_visibility(false);
w_courtroom->set_clock_visibility(id, false);
}
else if (header == "CHECK") {
if (!courtroom_constructed)