diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 7646794da..24164f2d4 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -3506,6 +3506,32 @@ void Courtroom::handle_ic_speaking() start_chat_ticking(); } +struct PauseInfo +{ + int ms; + int digit_count; + bool valid; +}; + +static PauseInfo parse_pause_duration(const QString &text, int start_pos) +{ + static const int max_digits = QString::number(10000).length(); + static const QRegularExpression pause_regex(QString("^([1-9]\\d{0,%1})").arg(max_digits - 1)); + QRegularExpressionMatch match = pause_regex.match(text.mid(start_pos)); + if (!match.hasMatch()) + { + return {0, 0, false}; + } + bool ok = false; + int value = match.captured(1).toInt(&ok); + int length = match.capturedLength(0); + if (!ok || value < 1 || value > 10000) + { + return {0, 0, false}; + } + return {value, length, true}; +} + QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int default_color) { QString p_text_escaped; @@ -3723,6 +3749,14 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int if (f_character == "s" || f_character == "f" || f_character == "p") // screenshake/flash/pause { skip = true; + if (f_character == "p") // also skip any following digits + { + PauseInfo info = parse_pause_duration(p_text, check_pos + f_char_bytes); + if (info.valid) + { + check_pos += info.digit_count; + } + } } parse_escape_seq = false; @@ -4420,6 +4454,14 @@ void Courtroom::chat_tick() if (f_character == "p") { formatting_char = true; + PauseInfo info = parse_pause_duration(f_message, tick_pos); + if (info.valid) + { + tick_pos += info.digit_count; + real_tick_pos += f_char_length; + chat_tick_timer->start(info.ms); + return; + } } next_character_is_not_special = false; } @@ -4441,15 +4483,8 @@ void Courtroom::chat_tick() if ((msg_delay <= 0 && tick_pos < f_message.size() - 1) || formatting_char) { - if (f_character == "p") - { - chat_tick_timer->start(100); // wait the pause lol - } - else - { - chat_tick_timer->start(0); // Don't bother rendering anything out as we're - // doing the SPEED. (there's latency otherwise) - } + chat_tick_timer->start(0); // Don't bother rendering anything out as we're + // doing the SPEED. (there's latency otherwise) if (!formatting_char || f_character == "n" || f_character == "f" || f_character == "s" || f_character == "p") { real_tick_pos += f_char_length; // Adjust the tick position for the diff --git a/src/courtroom.h b/src/courtroom.h index dc8cdf3ae..2a732b9f2 100644 --- a/src/courtroom.h +++ b/src/courtroom.h @@ -450,6 +450,8 @@ class Courtroom : public QMainWindow // amount by which we multiply the delay when we parse punctuation chars const int punctuation_modifier = 3; + const int max_pause_duration = 10000; + // amount of ghost blocks int ghost_blocks = 0;