Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/aotimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <QDebug>
#include <QTimer>

const int AOTimer::TIMER_COUNT = 20;

AOTimer::AOTimer(QWidget *p_parent) : DRTextEdit(p_parent)
{
// Adapted from:
Expand Down
1 change: 1 addition & 0 deletions src/aotimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AOTimer : public DRTextEdit

public:
AOTimer(QWidget *p_parent);
static const int TIMER_COUNT;

public slots:
void update_time();
Expand Down
8 changes: 8 additions & 0 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions src/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
int adapt_numbered_items(QVector<T *> &item_vector, QString config_item_number, QString item_name);
Expand Down Expand Up @@ -605,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();

Expand Down
24 changes: 23 additions & 1 deletion src/courtroom_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions src/server_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down