From 96fcb75c4c836887c80af3ddc1b4c8e1d4622abb Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 12 Jan 2021 13:46:39 +0300 Subject: [PATCH 1/3] Make sure blankposts are properly displayed unless repeats, playing nice with view desync --- include/courtroom.h | 1 + src/courtroom.cpp | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index 92b5a03..46da7a3 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -349,6 +349,7 @@ private: QVector arup_locks; QVector ic_chatlog_history; + int ic_chatlog_current = -1; QQueue chatmessage_queue; diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 99a330c..51f9dbd 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2067,8 +2067,7 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show } // If the chat message isn't a blankpost, or the chatlog history is empty, or its last message isn't a blankpost - if (!f_message.isEmpty() || - ic_chatlog_history.isEmpty() || ic_chatlog_history.last().get_message() != "") { + if (!f_message.isEmpty() || ic_chatlog_history.isEmpty() || ic_chatlog_history.last().get_showname() != f_showname) { // Add the message to the logs file log_ic_text(f_showname, f_displayname, f_message, "", f_color); @@ -2140,6 +2139,7 @@ void Courtroom::display_log_chatmessage(QString f_message, int f_char_id, QStrin break; } append_ic_text(shout_message, f_displayname, tr("shouts")); + ic_chatlog_current += 1; } // Obtain evidence ID we're trying to work with @@ -2150,15 +2150,16 @@ void Courtroom::display_log_chatmessage(QString f_message, int f_char_id, QStrin QString f_evi_name = local_evidence_list.at(f_evi_id - 1).name; // Append the message to the IC chatlogs in client append_ic_text(f_evi_name, f_displayname, tr("has presented evidence")); + ic_chatlog_current += 1; } } // If the chat message isn't a blankpost, or the chatlog history is empty, or its last message isn't a blankpost - if (!f_message.isEmpty() || - ic_chatlog_history.isEmpty() || ic_chatlog_history.last().get_message() != "") { + if (!f_message.isEmpty() || ic_chatlog_current == -1 || ic_chatlog_history[ic_chatlog_current].get_showname() != f_showname) { // Append the message to the IC chatlogs in client append_ic_text(f_message, f_displayname, "", - f_color); + f_color); + ic_chatlog_current += 1; } } @@ -3678,10 +3679,12 @@ void Courtroom::handle_song(QStringList *p_contents) if (f_song == "~stop.mp3") { log_ic_text(str_char, str_show, "", tr("has stopped the music")); append_ic_text("", str_show, tr("has stopped the music")); + ic_chatlog_current += 1; } else { log_ic_text(str_char, str_show, f_song, tr("has played a song")); append_ic_text(f_song_clear, str_show, tr("has played a song")); + ic_chatlog_current += 1; } music_player->play(f_song, channel, looping, effect_flags); if (f_song == "~stop.mp3") @@ -5243,12 +5246,14 @@ void Courtroom::on_showname_enable_clicked() void Courtroom::regenerate_ic_chatlog() { ui_ic_chatlog->clear(); + ic_chatlog_current = -1; foreach (chatlogpiece item, ic_chatlog_history) { append_ic_text(item.get_message(), ui_showname_enable->isChecked() ? item.get_showname() : item.get_name(), item.get_action(), item.get_chat_color(), item.get_datetime().toLocalTime()); + ic_chatlog_current += 1; } } From ea94644cf5bbd11f507b318677a7360433a0ae92 Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 18 Jan 2021 17:56:21 +0300 Subject: [PATCH 2/3] Attempt a theoretically safer method of tracking last displayed message --- include/courtroom.h | 1 - src/courtroom.cpp | 11 ++--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index 46da7a3..92b5a03 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -349,7 +349,6 @@ private: QVector arup_locks; QVector ic_chatlog_history; - int ic_chatlog_current = -1; QQueue chatmessage_queue; diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 51f9dbd..24d8c5f 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2139,7 +2139,6 @@ void Courtroom::display_log_chatmessage(QString f_message, int f_char_id, QStrin break; } append_ic_text(shout_message, f_displayname, tr("shouts")); - ic_chatlog_current += 1; } // Obtain evidence ID we're trying to work with @@ -2150,16 +2149,14 @@ void Courtroom::display_log_chatmessage(QString f_message, int f_char_id, QStrin QString f_evi_name = local_evidence_list.at(f_evi_id - 1).name; // Append the message to the IC chatlogs in client append_ic_text(f_evi_name, f_displayname, tr("has presented evidence")); - ic_chatlog_current += 1; } } - + int current = ic_chatlog_history.size() - chatmessage_queue.size() - 1; // If the chat message isn't a blankpost, or the chatlog history is empty, or its last message isn't a blankpost - if (!f_message.isEmpty() || ic_chatlog_current == -1 || ic_chatlog_history[ic_chatlog_current].get_showname() != f_showname) { + if (!f_message.isEmpty() || current <= -1 || ic_chatlog_history[current].get_showname() != f_showname) { // Append the message to the IC chatlogs in client append_ic_text(f_message, f_displayname, "", f_color); - ic_chatlog_current += 1; } } @@ -3679,12 +3676,10 @@ void Courtroom::handle_song(QStringList *p_contents) if (f_song == "~stop.mp3") { log_ic_text(str_char, str_show, "", tr("has stopped the music")); append_ic_text("", str_show, tr("has stopped the music")); - ic_chatlog_current += 1; } else { log_ic_text(str_char, str_show, f_song, tr("has played a song")); append_ic_text(f_song_clear, str_show, tr("has played a song")); - ic_chatlog_current += 1; } music_player->play(f_song, channel, looping, effect_flags); if (f_song == "~stop.mp3") @@ -5246,14 +5241,12 @@ void Courtroom::on_showname_enable_clicked() void Courtroom::regenerate_ic_chatlog() { ui_ic_chatlog->clear(); - ic_chatlog_current = -1; foreach (chatlogpiece item, ic_chatlog_history) { append_ic_text(item.get_message(), ui_showname_enable->isChecked() ? item.get_showname() : item.get_name(), item.get_action(), item.get_chat_color(), item.get_datetime().toLocalTime()); - ic_chatlog_current += 1; } } From 78777391467556b1312a00bdf1618619f771476e Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 18 Jan 2021 18:54:11 +0300 Subject: [PATCH 3/3] Simplify the logic behind last message = blankpost detection I need to stop overcomplicating things. --- include/courtroom.h | 1 + src/courtroom.cpp | 39 +++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/courtroom.h b/include/courtroom.h index 92b5a03..4cf42e1 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -349,6 +349,7 @@ private: QVector arup_locks; QVector ic_chatlog_history; + QString last_ic_message = ""; QQueue chatmessage_queue; diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 24d8c5f..443fb30 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -2066,12 +2066,13 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show } } - // If the chat message isn't a blankpost, or the chatlog history is empty, or its last message isn't a blankpost - if (!f_message.isEmpty() || ic_chatlog_history.isEmpty() || ic_chatlog_history.last().get_showname() != f_showname) { - // Add the message to the logs file - log_ic_text(f_showname, f_displayname, f_message, "", - f_color); - } + // If our current message is a blankpost, the chat log isn't empty, the chat log's last message is a blank post, and the blankpost's showname is the same as ours + if (f_message.isEmpty() && !ic_chatlog_history.isEmpty() && ic_chatlog_history.last().get_message().isEmpty() && ic_chatlog_history.last().get_showname() == f_displayname) + return; // Skip adding message + + // Add the message to the logs file + log_ic_text(f_showname, f_displayname, f_message, "", + f_color); } void Courtroom::display_log_chatmessage(QString f_message, int f_char_id, QString f_showname, int f_color) @@ -2151,13 +2152,15 @@ void Courtroom::display_log_chatmessage(QString f_message, int f_char_id, QStrin append_ic_text(f_evi_name, f_displayname, tr("has presented evidence")); } } - int current = ic_chatlog_history.size() - chatmessage_queue.size() - 1; - // If the chat message isn't a blankpost, or the chatlog history is empty, or its last message isn't a blankpost - if (!f_message.isEmpty() || current <= -1 || ic_chatlog_history[current].get_showname() != f_showname) { - // Append the message to the IC chatlogs in client - append_ic_text(f_message, f_displayname, "", - f_color); - } + + // If our current message is a blankpost, the chat log isn't empty, the chat log's last message is a blank post, and the blankpost's showname is the same as ours + if (f_message.isEmpty() && last_ic_message == f_displayname + ":") + return; // Skip adding message + + last_ic_message = f_displayname + ":" + f_message; + // Append the message to the IC chatlogs in client + append_ic_text(f_message, f_displayname, "", + f_color); } bool Courtroom::handle_objection() @@ -5241,12 +5244,16 @@ void Courtroom::on_showname_enable_clicked() void Courtroom::regenerate_ic_chatlog() { ui_ic_chatlog->clear(); + last_ic_message = ""; foreach (chatlogpiece item, ic_chatlog_history) { - append_ic_text(item.get_message(), - ui_showname_enable->isChecked() ? item.get_showname() - : item.get_name(), + QString message = item.get_message(); + QString name = ui_showname_enable->isChecked() ? item.get_showname() + : item.get_name(); + append_ic_text(message, + name, item.get_action(), item.get_chat_color(), item.get_datetime().toLocalTime()); + last_ic_message = name + ":" + message; } }