From 0571ac694a3411f218b80ea4f77451dab3f78cf3 Mon Sep 17 00:00:00 2001
From: Dev <90421310+EstatoDeviato@users.noreply.github.com>
Date: Tue, 28 May 2024 16:09:24 +0200
Subject: [PATCH 1/5] Update ms maximum
---
include/courtroom.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/courtroom.h b/include/courtroom.h
index a8942efe2..ae19423d5 100644
--- a/include/courtroom.h
+++ b/include/courtroom.h
@@ -561,7 +561,7 @@ class Courtroom : public QMainWindow {
// Minumum and maximum number of parameters in the MS packet
static const int MS_MINIMUM = 15;
- static const int MS_MAXIMUM = 35;
+ static const int MS_MAXIMUM = 40;
QString m_chatmessage[MS_MAXIMUM];
QString previous_ic_message = "";
From d083e647eff8b8b8b0cf45fd600d827f04a39fd6 Mon Sep 17 00:00:00 2001
From: Dev <90421310+EstatoDeviato@users.noreply.github.com>
Date: Sun, 9 Jun 2024 10:26:53 +0200
Subject: [PATCH 2/5] Update courtroom.h
---
include/courtroom.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/courtroom.h b/include/courtroom.h
index ae19423d5..a8942efe2 100644
--- a/include/courtroom.h
+++ b/include/courtroom.h
@@ -561,7 +561,7 @@ class Courtroom : public QMainWindow {
// Minumum and maximum number of parameters in the MS packet
static const int MS_MINIMUM = 15;
- static const int MS_MAXIMUM = 40;
+ static const int MS_MAXIMUM = 35;
QString m_chatmessage[MS_MAXIMUM];
QString previous_ic_message = "";
From 3373c5f498bc2a0355d26f631e7ecd1ca909256c Mon Sep 17 00:00:00 2001
From: Dev <90421310+EstatoDeviato@users.noreply.github.com>
Date: Sat, 15 Jun 2024 12:19:57 +0200
Subject: [PATCH 3/5] Add PM packet (pinned message) and CPM (clear pinned
message)
---
src/packet_distribution.cpp | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp
index 2e6c63bc2..51d7526ee 100644
--- a/src/packet_distribution.cpp
+++ b/src/packet_distribution.cpp
@@ -436,6 +436,17 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
w_courtroom->chatmessage_enqueue(p_packet->get_contents());
}
}
+ else if (header == "PM") {
+ if (courtroom_constructed && courtroom_loaded) {
+ w_courtroom->append_pinned_text(f_contents.at(0), f_contents.at(1),
+ f_contents.at(2));
+ }
+ }
+ else if (header == "CPM") {
+ if (courtroom_constructed && courtroom_loaded) {
+ w_courtroom->clear_pinned_message();
+ }
+ }
else if (header == "MC") {
if (courtroom_constructed && courtroom_loaded)
{
From 3161cececfef59b4e33cd69bafe0ba1e48e85a63 Mon Sep 17 00:00:00 2001
From: Dev <90421310+EstatoDeviato@users.noreply.github.com>
Date: Sat, 15 Jun 2024 12:25:20 +0200
Subject: [PATCH 4/5] add append pinned message function
---
include/courtroom.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/courtroom.h b/include/courtroom.h
index a8942efe2..bc20d16df 100644
--- a/include/courtroom.h
+++ b/include/courtroom.h
@@ -311,6 +311,9 @@ class Courtroom : public QMainWindow {
int color = 0, bool selfname = false, QDateTime timestamp = QDateTime::currentDateTime(),
bool ghost = false);
+ void append_pinned_text(QString p_text, QString p_name = "", QString action = "", int color = 0, bool selfname = false, QDateTime timestamp = QDateTime::currentDateTime());
+ void clear_pinned_message();
+
// clear sent messages that appear on the IC log but haven't been delivered
// yet to other players
void pop_ic_ghost();
@@ -762,6 +765,7 @@ class Courtroom : public QMainWindow {
SplashLayer *ui_vp_objection;
QTextEdit *ui_ic_chatlog;
+ QTextEdit *ui_ic_chatlog_pinned;
AOTextArea *ui_debug_log;
AOTextArea *ui_server_chatlog;
@@ -840,6 +844,7 @@ class Courtroom : public QMainWindow {
AOButton *ui_call_mod;
AOButton *ui_settings;
AOButton *ui_switch_area_music;
+ AOButton *ui_switch_logs;
QCheckBox *ui_pre;
QCheckBox *ui_flip;
@@ -1129,6 +1134,7 @@ private slots:
void on_spectator_clicked();
void on_switch_area_music_clicked();
+ void on_switch_logs_clicked();
void on_application_state_changed(Qt::ApplicationState state);
From 10db287a11defcf42c14f589c9768bdce656d341 Mon Sep 17 00:00:00 2001
From: Dev <90421310+EstatoDeviato@users.noreply.github.com>
Date: Sat, 15 Jun 2024 12:34:08 +0200
Subject: [PATCH 5/5] add append pinned message function
---
src/courtroom.cpp | 185 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 185 insertions(+)
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index a09b5dbc4..e90266990 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -153,6 +153,11 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_ic_chatlog->setReadOnly(true);
ui_ic_chatlog->setObjectName("ui_ic_chatlog");
+ ui_ic_chatlog_pinned = new QTextEdit(this);
+ ui_ic_chatlog_pinned->setReadOnly(true);
+ ui_ic_chatlog_pinned->setObjectName("ui_ic_chatlog_pinned");
+ ui_ic_chatlog_pinned->hide();
+
log_maximum_blocks = Options::getInstance().maxLogSize();
log_goes_downwards = Options::getInstance().logDirectionDownwards();
log_colors = Options::getInstance().colorLogEnabled();
@@ -336,6 +341,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_switch_area_music = new AOButton(this, ao_app);
ui_switch_area_music->setObjectName("ui_switch_area_music");
+ ui_switch_logs = new AOButton(this, ao_app);
+ ui_switch_logs->setObjectName("ui_switch_logs");
+
ui_pre = new QCheckBox(this);
ui_pre->setText(tr("Pre"));
ui_pre->setObjectName("ui_pre");
@@ -834,6 +842,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
connect(ui_settings, &AOButton::clicked, this, &Courtroom::on_settings_clicked);
connect(ui_switch_area_music, &AOButton::clicked, this,
&Courtroom::on_switch_area_music_clicked);
+ connect(ui_switch_logs, &AOButton::clicked, this,
+ &Courtroom::on_switch_logs_clicked);
connect(ui_pre, &AOButton::clicked, this, &Courtroom::on_pre_clicked);
connect(ui_flip, &AOButton::clicked, this, &Courtroom::on_flip_clicked);
@@ -1085,6 +1095,12 @@ void Courtroom::set_widgets()
ui_ic_chatlog->setPlaceholderText(log_goes_downwards ? "▼ " + tr("Log goes down") + " ▼"
: "▲ " + tr("Log goes up") + " ▲");
+ set_size_and_pos(ui_ic_chatlog_pinned, "ic_chatlog");
+ ui_ic_chatlog_pinned->setFrameShape(QFrame::NoFrame);
+ ui_ic_chatlog_pinned->setPlaceholderText(log_goes_downwards
+ ? "▼📌 " + tr("Pinned Message") + " 📌▼"
+ : "▲📌 " + tr("Pinned Message") + " 📌▲");
+
set_size_and_pos(ui_debug_log, "ms_chatlog"); // Old name, still use it to not break compatibility
ui_debug_log->setFrameShape(QFrame::NoFrame);
@@ -1331,6 +1347,11 @@ void Courtroom::set_widgets()
ui_switch_area_music->set_image("switch_area_music");
ui_switch_area_music->setToolTip(tr("Switch between Areas and Music lists"));
+ set_size_and_pos(ui_switch_logs, "switch_logs");
+ ui_switch_logs->setText(tr("L/P"));
+ ui_switch_logs->set_image("switch_logs");
+ ui_switch_logs->setToolTip(tr("Switch between Log message chat and Log pinned chat"));
+
set_size_and_pos(ui_pre, "pre");
ui_pre->setText(tr("Preanim"));
ui_pre->setToolTip(
@@ -1476,6 +1497,7 @@ void Courtroom::set_fonts(QString p_char)
set_font(ui_vp_showname, "", "showname", p_char);
set_font(ui_vp_message, "", "message", p_char);
set_font(ui_ic_chatlog, "", "ic_chatlog", p_char);
+ set_font(ui_ic_chatlog_pinned, "", "ic_chatlog_pinned", p_char);
set_font(ui_debug_log, "", "debug_log", p_char);
set_font(ui_server_chatlog, "", "server_chatlog", p_char);
set_font(ui_music_list, "", "music_list", p_char);
@@ -4008,6 +4030,157 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
}
}
+void Courtroom::append_pinned_text(QString p_text, QString p_name, QString p_action, int color, bool selfname, QDateTime timestamp)
+{
+ QColor chatlog_color = ao_app->get_color("ic_chatlog_color", "courtroom_fonts.ini");
+ QTextCharFormat bold;
+ QTextCharFormat normal;
+ QTextCharFormat italics;
+ QTextCharFormat own_name;
+ QTextCharFormat other_name;
+ QTextCharFormat timestamp_format;
+ QTextCharFormat selftimestamp_format;
+ QTextBlockFormat format;
+ bold.setFontWeight(QFont::Bold);
+ normal.setFontWeight(QFont::Normal);
+ italics.setFontItalic(true);
+ own_name.setFontWeight(QFont::Bold);
+ own_name.setForeground(
+ ao_app->get_color("ic_chatlog_selfname_color", "courtroom_fonts.ini"));
+ other_name.setFontWeight(QFont::Bold);
+ other_name.setForeground(
+ ao_app->get_color("ic_chatlog_showname_color", "courtroom_fonts.ini"));
+ timestamp_format.setForeground(
+ ao_app->get_color("ic_chatlog_timestamp_color", "courtroom_fonts.ini"));
+ selftimestamp_format.setForeground(ao_app->get_color(
+ "ic_chatlog_selftimestamp_color", "courtroom_fonts.ini"));
+ format.setTopMargin(log_margin);
+ const QTextCursor old_cursor = ui_ic_chatlog_pinned->textCursor();
+ const int old_scrollbar_value = ui_ic_chatlog_pinned->verticalScrollBar()->value();
+ const bool need_newline = !ui_ic_chatlog_pinned->document()->isEmpty();
+ const int scrollbar_target_value =
+ log_goes_downwards ? ui_ic_chatlog_pinned->verticalScrollBar()->maximum()
+ : ui_ic_chatlog_pinned->verticalScrollBar()->minimum();
+
+
+ ui_ic_chatlog_pinned->moveCursor(log_goes_downwards ? QTextCursor::End
+ : QTextCursor::Start);
+
+ // Only prepend with newline if log goes downwards
+ if (log_goes_downwards && need_newline) {
+ ui_ic_chatlog_pinned->textCursor().insertBlock(format);
+ }
+
+ // Timestamp if we're doing that meme
+ if (log_timestamp) {
+ // Format the timestamp
+ QTextCharFormat format = selfname ? selftimestamp_format : timestamp_format;
+ if (timestamp.isValid()) {
+ ui_ic_chatlog_pinned->textCursor().insertText(
+ "[" + timestamp.toString(log_timestamp_format) + "] ", format);
+ }
+ else {
+ qCritical() << "could not insert invalid timestamp" << timestamp;
+ }
+ }
+
+ // Format the name of the actor
+ QTextCharFormat name_format = selfname ? own_name : other_name;
+ ui_ic_chatlog_pinned->textCursor().insertText("📌" + p_name + "📌", name_format);
+ // Special case for stopping the music
+ if (p_action == tr("has stopped the music")) {
+ ui_ic_chatlog_pinned->textCursor().insertText(" " + p_action + ".", normal);
+ }
+ // Make shout text bold
+ else if (p_action == tr("shouts") && log_ic_actions) {
+ ui_ic_chatlog_pinned->textCursor().insertText(" " + p_action + " ", normal);
+ if (log_colors) {
+ ui_ic_chatlog_pinned->textCursor().insertHtml(
+ "" +
+ filter_ic_text(p_text, true, -1, 0)
+ .replace("$c0", chatlog_color.name(QColor::HexArgb)) +
+ "");
+ }
+ else
+ ui_ic_chatlog_pinned->textCursor().insertText(" " + p_text, italics);
+ }
+ // If action not blank:
+ else if (p_action != "" && log_ic_actions) {
+ // Format the action in normal
+ ui_ic_chatlog_pinned->textCursor().insertText(" " + p_action, normal);
+ if (log_newline)
+ // For some reason, we're forced to use
instead of the more sensible
+ // \n. Why? Because \n is treated as a new Block instead of a soft newline
+ // within a paragraph!
+ ui_ic_chatlog_pinned->textCursor().insertHtml("
");
+ else
+ ui_ic_chatlog_pinned->textCursor().insertText(": ", normal);
+ // Format the result in italics
+ ui_ic_chatlog->textCursor().insertText(p_text + ".", italics);
+ }
+ else {
+ if (log_newline) {
+ // For some reason, we're forced to use
instead of the more sensible
+ // \n. Why? Because \n is treated as a new Block instead of a soft newline
+ // within a paragraph!
+ ui_ic_chatlog_pinned->textCursor().insertHtml("
");
+ }
+ else {
+ ui_ic_chatlog_pinned->textCursor().insertText(": ", normal);
+ }
+ // Format the result according to html
+ if (log_colors) {
+ QString p_text_filtered = filter_ic_text(p_text, true, -1, color);
+ p_text_filtered =
+ p_text_filtered.replace("$c0", chatlog_color.name(QColor::HexArgb));
+ for (int c = 1; c < max_colors; ++c) {
+ QColor color_result = default_color_rgb_list.at(c);
+ p_text_filtered = p_text_filtered.replace(
+ "$c" + QString::number(c), color_result.name(QColor::HexArgb));
+ }
+ ui_ic_chatlog_pinned->textCursor().insertHtml(p_text_filtered);
+ }
+ else {
+ ui_ic_chatlog_pinned->textCursor().insertText(filter_ic_text(p_text, false),
+ normal);
+ }
+ }
+
+ // Only append with newline if log goes upwards
+ if (!log_goes_downwards && need_newline) {
+ ui_ic_chatlog_pinned->textCursor().insertBlock(format);
+ }
+
+ // If we got too many blocks in the current log, delete some.
+ while (ui_ic_chatlog_pinned->document()->blockCount() > log_maximum_blocks &&
+ log_maximum_blocks > 0) {
+ QTextCursor temp_curs = ui_ic_chatlog_pinned->textCursor();
+ temp_curs.movePosition(log_goes_downwards ? QTextCursor::Start
+ : QTextCursor::End);
+ temp_curs.select(QTextCursor::BlockUnderCursor);
+ temp_curs.removeSelectedText();
+ if (log_goes_downwards)
+ temp_curs.deleteChar();
+ else
+ temp_curs.deletePreviousChar();
+ }
+
+ // Finally, scroll the scrollbar to the correct position.
+ if (old_cursor.hasSelection() ||
+ old_scrollbar_value != scrollbar_target_value) {
+ // The user has selected text or scrolled away from the bottom: maintain
+ // position.
+ ui_ic_chatlog_pinned->setTextCursor(old_cursor);
+ ui_ic_chatlog_pinned->verticalScrollBar()->setValue(old_scrollbar_value);
+ }
+ else {
+ ui_ic_chatlog_pinned->verticalScrollBar()->setValue(
+ log_goes_downwards ? ui_ic_chatlog->verticalScrollBar()->maximum() : 0);
+ }
+}
+
+void Courtroom::clear_pinned_message() { ui_ic_chatlog_pinned->clear(); }
+
void Courtroom::pop_ic_ghost()
{
QTextCursor ghost = ui_ic_chatlog->textCursor();
@@ -6651,6 +6824,18 @@ void Courtroom::on_switch_area_music_clicked()
}
+void Courtroom::on_switch_logs_clicked()
+{
+ if (ui_ic_chatlog->isHidden()) {
+ ui_ic_chatlog->show();
+ ui_ic_chatlog_pinned->hide();
+ }
+ else {
+ ui_ic_chatlog->hide();
+ ui_ic_chatlog_pinned->show();
+ }
+}
+
void Courtroom::ping_server()
{
ping_timer.start();