Fix shownames toggle not being respected in several places, clean up implementation (#1080)

* Move showname switch to settings and fix it

* let the append function handle shownames
This commit is contained in:
in1tiate 2025-02-09 09:53:36 -06:00 committed by GitHub
parent 494eb6ca1b
commit a8156ed1b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 49 deletions

View File

@ -128,6 +128,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app)
log_timestamp = Options::getInstance().logTimestampEnabled(); log_timestamp = Options::getInstance().logTimestampEnabled();
log_timestamp_format = Options::getInstance().logTimestampFormat(); log_timestamp_format = Options::getInstance().logTimestampFormat();
custom_shownames = Options::getInstance().customShownameEnabled();
ui_debug_log = new AOTextArea(Options::getInstance().maxLogSize(), this); ui_debug_log = new AOTextArea(Options::getInstance().maxLogSize(), this);
ui_debug_log->setReadOnly(true); ui_debug_log->setReadOnly(true);
ui_debug_log->setOpenExternalLinks(true); ui_debug_log->setOpenExternalLinks(true);
@ -320,11 +322,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app)
ui_additive->hide(); ui_additive->hide();
ui_additive->setObjectName("ui_additive"); ui_additive->setObjectName("ui_additive");
ui_showname_enable = new QCheckBox(this);
ui_showname_enable->setChecked(Options::getInstance().customShownameEnabled());
ui_showname_enable->setText(tr("Shownames"));
ui_showname_enable->setObjectName("ui_showname_enable");
ui_slide_enable = new QCheckBox(this); ui_slide_enable = new QCheckBox(this);
ui_slide_enable->setChecked(false); ui_slide_enable->setChecked(false);
ui_slide_enable->setText(tr("Slide")); ui_slide_enable->setText(tr("Slide"));
@ -507,8 +504,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app)
connect(ui_guard, &AOButton::clicked, this, &Courtroom::focus_ic_input); connect(ui_guard, &AOButton::clicked, this, &Courtroom::focus_ic_input);
connect(ui_slide_enable, &AOButton::clicked, this, &Courtroom::focus_ic_input); connect(ui_slide_enable, &AOButton::clicked, this, &Courtroom::focus_ic_input);
connect(ui_showname_enable, &AOButton::clicked, this, &Courtroom::on_showname_enable_clicked);
connect(ui_pair_button, &AOButton::clicked, this, &Courtroom::on_pair_clicked); connect(ui_pair_button, &AOButton::clicked, this, &Courtroom::on_pair_clicked);
connect(ui_pair_list, &QListWidget::clicked, this, &Courtroom::on_pair_list_clicked); connect(ui_pair_list, &QListWidget::clicked, this, &Courtroom::on_pair_list_clicked);
connect(ui_pair_offset_spinbox, QOverload<int>::of(&QSpinBox::valueChanged), this, &Courtroom::on_pair_offset_changed); connect(ui_pair_offset_spinbox, QOverload<int>::of(&QSpinBox::valueChanged), this, &Courtroom::on_pair_offset_changed);
@ -750,7 +745,6 @@ void Courtroom::set_widgets()
{ {
ui_pair_button->show(); ui_pair_button->show();
ui_immediate->show(); ui_immediate->show();
ui_showname_enable->show();
ui_ic_chat_name->show(); ui_ic_chat_name->show();
ui_ic_chat_name->setEnabled(true); ui_ic_chat_name->setEnabled(true);
} }
@ -758,7 +752,6 @@ void Courtroom::set_widgets()
{ {
ui_pair_button->hide(); ui_pair_button->hide();
ui_immediate->hide(); ui_immediate->hide();
ui_showname_enable->hide();
ui_ic_chat_name->hide(); ui_ic_chat_name->hide();
ui_ic_chat_name->setEnabled(false); ui_ic_chat_name->setEnabled(false);
} }
@ -814,13 +807,15 @@ void Courtroom::set_widgets()
log_maximum_blocks = Options::getInstance().maxLogSize(); log_maximum_blocks = Options::getInstance().maxLogSize();
bool regenerate = log_goes_downwards != Options::getInstance().logDirectionDownwards() || log_colors != Options::getInstance().colorLogEnabled() || log_newline != Options::getInstance().logNewline() || log_margin != Options::getInstance().logMargin() || log_timestamp != Options::getInstance().logTimestampEnabled() || log_timestamp_format != Options::getInstance().logTimestampFormat(); bool regenerate = log_goes_downwards != Options::getInstance().logDirectionDownwards() || log_colors != Options::getInstance().colorLogEnabled() || log_newline != Options::getInstance().logNewline() || log_margin != Options::getInstance().logMargin() || log_timestamp != Options::getInstance().logTimestampEnabled() || log_timestamp_format != Options::getInstance().logTimestampFormat() || custom_shownames != Options::getInstance().customShownameEnabled();
log_goes_downwards = Options::getInstance().logDirectionDownwards(); log_goes_downwards = Options::getInstance().logDirectionDownwards();
log_colors = Options::getInstance().colorLogEnabled(); log_colors = Options::getInstance().colorLogEnabled();
log_newline = Options::getInstance().logNewline(); log_newline = Options::getInstance().logNewline();
log_margin = Options::getInstance().logMargin(); log_margin = Options::getInstance().logMargin();
log_timestamp = Options::getInstance().logTimestampEnabled(); log_timestamp = Options::getInstance().logTimestampEnabled();
log_timestamp_format = Options::getInstance().logTimestampFormat(); log_timestamp_format = Options::getInstance().logTimestampFormat();
custom_shownames = Options::getInstance().customShownameEnabled();
if (regenerate) if (regenerate)
{ {
regenerate_ic_chatlog(); regenerate_ic_chatlog();
@ -1095,9 +1090,6 @@ void Courtroom::set_widgets()
ui_guard->setToolTip(tr("Do not listen to mod calls when checked, preventing them from " ui_guard->setToolTip(tr("Do not listen to mod calls when checked, preventing them from "
"playing sounds or focusing attention on the window.")); "playing sounds or focusing attention on the window."));
set_size_and_pos(ui_showname_enable, "showname_enable");
ui_showname_enable->setToolTip(tr("Display customized shownames for all users when checked."));
set_size_and_pos(ui_slide_enable, "slide_enable"); set_size_and_pos(ui_slide_enable, "slide_enable");
ui_slide_enable->setToolTip(tr("Allow your messages to trigger slide animations when checked.")); ui_slide_enable->setToolTip(tr("Allow your messages to trigger slide animations when checked."));
ui_slide_enable->show(); ui_slide_enable->show();
@ -1172,7 +1164,6 @@ void Courtroom::set_widgets()
truncate_label_text(ui_guard, "guard"); truncate_label_text(ui_guard, "guard");
truncate_label_text(ui_pre, "pre"); truncate_label_text(ui_pre, "pre");
truncate_label_text(ui_flip, "flip"); truncate_label_text(ui_flip, "flip");
truncate_label_text(ui_showname_enable, "showname_enable");
truncate_label_text(ui_slide_enable, "slide_enable"); truncate_label_text(ui_slide_enable, "slide_enable");
// QLabel // QLabel
@ -2397,7 +2388,7 @@ void Courtroom::chatmessage_enqueue(QStringList p_contents)
if (sender || Options::getInstance().desynchronisedLogsEnabled()) if (sender || Options::getInstance().desynchronisedLogsEnabled())
{ {
// Initialize operation "message queue ghost" // Initialize operation "message queue ghost"
log_chatmessage(p_contents[MESSAGE], p_contents[CHAR_ID].toInt(), p_contents[SHOWNAME], p_contents[CHAR_NAME], p_contents[OBJECTION_MOD], p_contents[EVIDENCE_ID].toInt(), p_contents[TEXT_COLOR].toInt(), QUEUED, sender || Options::getInstance().desynchronisedLogsEnabled()); log_chatmessage(p_contents[MESSAGE], f_char_id, p_contents[SHOWNAME], p_contents[CHAR_NAME], p_contents[OBJECTION_MOD], p_contents[EVIDENCE_ID].toInt(), p_contents[TEXT_COLOR].toInt(), QUEUED, sender || Options::getInstance().desynchronisedLogsEnabled());
} }
bool is_objection = false; bool is_objection = false;
@ -2414,7 +2405,7 @@ void Courtroom::chatmessage_enqueue(QStringList p_contents)
} }
} }
// Log the IO file // Log the IO file
log_chatmessage(p_contents[MESSAGE], f_char_id, showname, p_contents[CHAR_NAME], p_contents[OBJECTION_MOD], p_contents[EVIDENCE_ID].toInt(), p_contents[TEXT_COLOR].toInt(), log_mode, sender); log_chatmessage(p_contents[MESSAGE], f_char_id, p_contents[SHOWNAME], p_contents[CHAR_NAME], p_contents[OBJECTION_MOD], p_contents[EVIDENCE_ID].toInt(), p_contents[TEXT_COLOR].toInt(), log_mode, sender);
// Send this boi into the queue // Send this boi into the queue
chatmessage_queue.enqueue(p_contents); chatmessage_queue.enqueue(p_contents);
@ -2482,7 +2473,7 @@ void Courtroom::unpack_chatmessage(QStringList p_contents)
bool sender = Options::getInstance().desynchronisedLogsEnabled() || m_chatmessage[CHAR_ID].toInt() == m_cid; bool sender = Options::getInstance().desynchronisedLogsEnabled() || m_chatmessage[CHAR_ID].toInt() == m_cid;
// We have logs displaying as soon as we reach the message in our queue, which is a less confusing but also less accurate experience for the user. // We have logs displaying as soon as we reach the message in our queue, which is a less confusing but also less accurate experience for the user.
log_chatmessage(m_chatmessage[MESSAGE], m_chatmessage[CHAR_ID].toInt(), m_chatmessage[SHOWNAME], m_chatmessage[CHAR_NAME], m_chatmessage[OBJECTION_MOD], m_chatmessage[EVIDENCE_ID].toInt(), m_chatmessage[TEXT_COLOR].toInt(), DISPLAY_ONLY, sender); log_chatmessage(m_chatmessage[MESSAGE], m_chatmessage[CHAR_ID].toInt(), p_contents[SHOWNAME], m_chatmessage[CHAR_NAME], m_chatmessage[OBJECTION_MOD], m_chatmessage[EVIDENCE_ID].toInt(), m_chatmessage[TEXT_COLOR].toInt(), DISPLAY_ONLY, sender);
// Process the callwords for this message // Process the callwords for this message
handle_callwords(); handle_callwords();
@ -2597,7 +2588,7 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show
break; break;
case DISPLAY_AND_IO: case DISPLAY_AND_IO:
log_ic_text(f_char, f_displayname, shout_message, tr("shouts")); log_ic_text(f_char, f_displayname, shout_message, tr("shouts"));
append_ic_text(shout_message, f_displayname, tr("shouts"), 0, selfname, QDateTime::currentDateTime(), false); append_ic_text(shout_message, f_displayname, f_char, tr("shouts"), 0, selfname, QDateTime::currentDateTime(), false);
break; break;
case DISPLAY_ONLY: case DISPLAY_ONLY:
case QUEUED: case QUEUED:
@ -2605,7 +2596,7 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show
{ {
pop_ic_ghost(); pop_ic_ghost();
} }
append_ic_text(shout_message, f_displayname, tr("shouts"), 0, selfname, QDateTime::currentDateTime(), ghost); append_ic_text(shout_message, f_displayname, f_char, tr("shouts"), 0, selfname, QDateTime::currentDateTime(), ghost);
break; break;
} }
} }
@ -2619,11 +2610,11 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show
switch (f_log_mode) switch (f_log_mode)
{ {
case IO_ONLY: case IO_ONLY:
log_ic_text(f_showname, f_displayname, f_evi_name, tr("has presented evidence"), 0, selfname); log_ic_text(f_char, f_displayname, f_evi_name, tr("has presented evidence"), 0, selfname);
break; break;
case DISPLAY_AND_IO: case DISPLAY_AND_IO:
log_ic_text(f_showname, f_displayname, f_evi_name, tr("has presented evidence")); log_ic_text(f_char, f_displayname, f_evi_name, tr("has presented evidence"));
append_ic_text(f_evi_name, f_displayname, tr("has presented evidence"), 0, selfname, QDateTime::currentDateTime(), false); append_ic_text(f_evi_name, f_displayname, f_char, tr("has presented evidence"), 0, selfname, QDateTime::currentDateTime(), false);
break; break;
case DISPLAY_ONLY: case DISPLAY_ONLY:
case QUEUED: case QUEUED:
@ -2631,7 +2622,7 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show
{ {
pop_ic_ghost(); pop_ic_ghost();
} }
append_ic_text(f_evi_name, f_displayname, tr("has presented evidence"), 0, selfname, QDateTime::currentDateTime(), ghost); append_ic_text(f_evi_name, f_displayname, f_char, tr("has presented evidence"), 0, selfname, QDateTime::currentDateTime(), ghost);
break; break;
} }
} }
@ -2651,11 +2642,11 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show
switch (f_log_mode) switch (f_log_mode)
{ {
case IO_ONLY: case IO_ONLY:
log_ic_text(f_showname, f_displayname, f_message, "", f_color, selfname); log_ic_text(f_char, f_displayname, f_message, "", f_color, selfname);
break; break;
case DISPLAY_AND_IO: case DISPLAY_AND_IO:
log_ic_text(f_showname, f_displayname, f_message, "", f_color, selfname); log_ic_text(f_char, f_displayname, f_message, "", f_color, selfname);
append_ic_text(f_message, f_displayname, "", f_color, selfname, QDateTime::currentDateTime(), false); append_ic_text(f_message, f_displayname, f_char, "", f_color, selfname, QDateTime::currentDateTime(), false);
break; break;
case DISPLAY_ONLY: case DISPLAY_ONLY:
case QUEUED: case QUEUED:
@ -2663,7 +2654,7 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show
{ {
pop_ic_ghost(); pop_ic_ghost();
} }
append_ic_text(f_message, f_displayname, "", f_color, selfname, QDateTime::currentDateTime(), ghost); append_ic_text(f_message, f_displayname, f_char, "", f_color, selfname, QDateTime::currentDateTime(), ghost);
break; break;
} }
} }
@ -3261,7 +3252,7 @@ void Courtroom::play_char_sfx(QString sfx_name)
void Courtroom::initialize_chatbox() void Courtroom::initialize_chatbox()
{ {
int f_charid = m_chatmessage[CHAR_ID].toInt(); int f_charid = m_chatmessage[CHAR_ID].toInt();
if (f_charid >= 0 && f_charid < char_list.size() && (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked())) if (f_charid >= 0 && f_charid < char_list.size() && (m_chatmessage[SHOWNAME].isEmpty() || !custom_shownames))
{ {
QString real_name = char_list.at(f_charid).name; QString real_name = char_list.at(f_charid).name;
QString f_showname = ao_app->get_showname(real_name); QString f_showname = ao_app->get_showname(real_name);
@ -3790,7 +3781,7 @@ void Courtroom::log_ic_text(QString p_name, QString p_showname, QString p_messag
} }
} }
void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action, int color, bool selfname, QDateTime timestamp, bool ghost) void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_char, QString p_action, int color, bool selfname, QDateTime timestamp, bool ghost)
{ {
QColor chatlog_color = ao_app->get_color("ic_chatlog_color", "courtroom_fonts.ini"); QColor chatlog_color = ao_app->get_color("ic_chatlog_color", "courtroom_fonts.ini");
QTextCharFormat bold; QTextCharFormat bold;
@ -3816,6 +3807,8 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
const bool need_newline = !ui_ic_chatlog->document()->isEmpty(); const bool need_newline = !ui_ic_chatlog->document()->isEmpty();
const int scrollbar_target_value = log_goes_downwards ? ui_ic_chatlog->verticalScrollBar()->maximum() : ui_ic_chatlog->verticalScrollBar()->minimum(); const int scrollbar_target_value = log_goes_downwards ? ui_ic_chatlog->verticalScrollBar()->maximum() : ui_ic_chatlog->verticalScrollBar()->minimum();
QString displayname = custom_shownames ? p_name : ao_app->get_showname(p_char);
if (ghost) if (ghost)
{ {
ghost_blocks++; ghost_blocks++;
@ -3826,7 +3819,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
} }
else else
{ {
last_ic_message = p_name + ":" + p_text; last_ic_message = displayname + ":" + p_text;
} }
ui_ic_chatlog->moveCursor(log_goes_downwards ? QTextCursor::End : QTextCursor::Start); ui_ic_chatlog->moveCursor(log_goes_downwards ? QTextCursor::End : QTextCursor::Start);
@ -3863,7 +3856,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
// Format the name of the actor // Format the name of the actor
QTextCharFormat name_format = selfname ? own_name : other_name; QTextCharFormat name_format = selfname ? own_name : other_name;
ui_ic_chatlog->textCursor().insertText(p_name, name_format); ui_ic_chatlog->textCursor().insertText(displayname, name_format);
// Special case for stopping the music // Special case for stopping the music
if (p_action == tr("has stopped the music")) if (p_action == tr("has stopped the music"))
{ {
@ -4756,12 +4749,12 @@ void Courtroom::handle_song(QStringList *p_contents)
if (is_stop) if (is_stop)
{ {
log_ic_text(str_char, str_show, "", tr("has stopped the music"), 0, selfname); log_ic_text(str_char, str_show, "", tr("has stopped the music"), 0, selfname);
append_ic_text("", str_show, tr("has stopped the music"), 0, selfname); append_ic_text("", str_show, str_char, tr("has stopped the music"), 0, selfname);
} }
else else
{ {
log_ic_text(str_char, str_show, f_song, tr("has played a song"), 0, selfname); log_ic_text(str_char, str_show, f_song, tr("has played a song"), 0, selfname);
append_ic_text(f_song_clear, str_show, tr("has played a song"), 0, selfname); append_ic_text(f_song_clear, str_show, str_char, tr("has played a song"), 0, selfname);
} }
} }
} }
@ -6503,21 +6496,13 @@ void Courtroom::focus_ic_input()
ui_ic_chat_message->setFocus(); ui_ic_chat_message->setFocus();
} }
void Courtroom::on_showname_enable_clicked()
{
regenerate_ic_chatlog();
focus_ic_input();
}
void Courtroom::regenerate_ic_chatlog() void Courtroom::regenerate_ic_chatlog()
{ {
ui_ic_chatlog->clear(); ui_ic_chatlog->clear();
last_ic_message = ""; last_ic_message = "";
foreach (ChatLogPiece item, ic_chatlog_history) foreach (ChatLogPiece item, ic_chatlog_history)
{ {
QString message = item.message; append_ic_text(item.message, item.character_name, item.character, item.action, item.color, item.local_player, item.timestamp.toLocalTime());
QString name = ui_showname_enable->isChecked() ? item.character_name : item.character;
append_ic_text(message, name, item.action, item.color, item.local_player, item.timestamp.toLocalTime());
} }
} }

View File

@ -252,7 +252,7 @@ public:
// this function keeps the chatlog scrolled to the top unless there's text // this function keeps the chatlog scrolled to the top unless there's text
// selected // selected
// or the user isn't already scrolled to the top // or the user isn't already scrolled to the top
void append_ic_text(QString p_text, QString p_name = QString(), QString action = QString(), int color = 0, bool selfname = false, QDateTime timestamp = QDateTime::currentDateTime(), bool ghost = false); void append_ic_text(QString p_text, QString p_name = QString(), QString p_char = QString(), QString action = QString(), int color = 0, bool selfname = false, QDateTime timestamp = QDateTime::currentDateTime(), bool ghost = false);
// clear sent messages that appear on the IC log but haven't been delivered // clear sent messages that appear on the IC log but haven't been delivered
// yet to other players // yet to other players
@ -409,6 +409,9 @@ private:
// format string for aforementioned log timestamp // format string for aforementioned log timestamp
QString log_timestamp_format; QString log_timestamp_format;
// True, if the log and in-character display should use custom shownames.
bool custom_shownames = true;
// How long in miliseconds should the objection wait before appearing. // How long in miliseconds should the objection wait before appearing.
int objection_threshold = 1500; int objection_threshold = 1500;
@ -939,8 +942,6 @@ private Q_SLOTS:
void focus_ic_input(); void focus_ic_input();
void on_additive_clicked(); void on_additive_clicked();
void on_showname_enable_clicked();
void on_evidence_button_clicked(); void on_evidence_button_clicked();
void on_evidence_context_menu_requested(const QPoint &pos); void on_evidence_context_menu_requested(const QPoint &pos);

View File

@ -56,10 +56,6 @@ Options::Options()
/*! Migrate old configuration keys/values to a relevant format. */ /*! Migrate old configuration keys/values to a relevant format. */
void Options::migrate() void Options::migrate()
{ {
if (config.contains("show_custom_shownames"))
{
config.remove("show_custom_shownames");
}
if (QFile::exists(get_base_path() + "callwords.ini")) if (QFile::exists(get_base_path() + "callwords.ini"))
{ {
migrateCallwords(); migrateCallwords();