From 6bbb45a6d14fa8ff18cf4b145a8b2bb76ca6bdc2 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Sun, 1 Aug 2021 11:13:52 -0500 Subject: handle expanded desk mods on chat ticking start --- src/courtroom.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 25f256a..1fb8ce0 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -3284,6 +3284,22 @@ void Courtroom::preanim_done() if (anim_state != 1 && anim_state != 4) return; anim_state = 1; + + handle_ic_speaking(); +} + +void Courtroom::start_chat_ticking() +{ + text_delay_timer->stop(); + // we need to ensure that the text isn't already ticking because this function + // can be called by two logic paths + if (text_state != 0) + return; + + // Display the evidence + display_evidence_image(); + + // handle expanded desk mods switch(m_chatmessage[DESK_MOD].toInt()) { case 4: set_self_offset(m_chatmessage[SELF_OFFSET]); @@ -3302,19 +3318,6 @@ void Courtroom::preanim_done() set_scene(m_chatmessage[DESK_MOD], m_chatmessage[SIDE]); break; } - handle_ic_speaking(); -} - -void Courtroom::start_chat_ticking() -{ - text_delay_timer->stop(); - // we need to ensure that the text isn't already ticking because this function - // can be called by two logic paths - if (text_state != 0) - return; - - // Display the evidence - display_evidence_image(); if (m_chatmessage[EFFECTS] != "") { QStringList fx_list = m_chatmessage[EFFECTS].split("|"); -- cgit From 26851be53600483a4a35f14d7096ce85a64af97d Mon Sep 17 00:00:00 2001 From: Pyraqq <46277816+Pyraqq@users.noreply.github.com> Date: Thu, 23 Dec 2021 23:53:26 +0100 Subject: Add version to window title (#613) Also updated the translation files for missing strings and updated the Polish translation. --- src/lobby.cpp | 3 ++- src/packet_distribution.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lobby.cpp b/src/lobby.cpp index 08fcaae..54e4c70 100644 --- a/src/lobby.cpp +++ b/src/lobby.cpp @@ -12,8 +12,9 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; + // - this->setWindowTitle(tr("Attorney Online 2")); + this->setWindowTitle(tr("Attorney Online %1").arg(ao_app->applicationVersion())); this->setWindowIcon(QIcon(":/logo.png")); this->setWindowFlags( (this->windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowMaximizeButtonHint); diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index bcbc667..7d2eafc 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -268,7 +268,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) courtroom_loaded = false; - window_title = tr("Attorney Online 2"); + window_title = tr("Attorney Online %1").arg(applicationVersion()); int selected_server = w_lobby->get_selected_server(); QString server_address = "", server_name = ""; -- cgit From bcbe9a8a67356ae4f82a1020afb5c3cfa51ca79d Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Thu, 23 Dec 2021 17:05:11 -0600 Subject: Remove client-side send waiting This piece of code from another era is not needed anymore thanks to the message queue and decent server-side anti-flooding. Player input won't be thrown away since the client waits for an acknowledgement from the server before clearing the input box. --- src/courtroom.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 8c59f1d..fe92362 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1787,9 +1787,6 @@ void Courtroom::on_chat_return_pressed() if (is_muted) return; - if (text_state < 2 && objection_state == 0) - return; - ui_ic_chat_message->blockSignals(true); QTimer::singleShot(ao_app->get_chat_ratelimit(), this, [=] { ui_ic_chat_message->blockSignals(false); }); -- cgit From 2eed786c776ba31e464e5929a6a0299a19897192 Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Thu, 23 Dec 2021 17:29:17 -0600 Subject: Split logging option into text and demo Apparently, people don't like logging demos because it takes up too much space. It's possible to enable NTFS compression for demo files (or the entire demos folder), though. --- src/aooptionsdialog.cpp | 41 ++++++++++++++++++++++++++--------------- src/courtroom.cpp | 4 ++-- src/packet_distribution.cpp | 4 ++-- src/text_file_functions.cpp | 9 ++++++++- 4 files changed, 38 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/aooptionsdialog.cpp b/src/aooptionsdialog.cpp index 1b9342c..b752038 100644 --- a/src/aooptionsdialog.cpp +++ b/src/aooptionsdialog.cpp @@ -583,6 +583,28 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_category_stop_cb); + //Check whether mass logging is enabled + row += 1; + ui_log_text_lbl = new QLabel(ui_form_layout_widget); + ui_log_text_lbl->setText(tr("Log to Text Files:")); + ui_log_text_lbl->setToolTip( + tr("Text logs of gameplay will be automatically written in the /logs folder.")); + ui_gameplay_form->setWidget(row, QFormLayout::LabelRole, ui_log_text_lbl); + + ui_log_text_cb = new QCheckBox(ui_form_layout_widget); + ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_log_text_cb); + + row += 1; + ui_log_demo_lbl = new QLabel(ui_form_layout_widget); + ui_log_demo_lbl->setText(tr("Log to Demo Files:")); + ui_log_demo_lbl->setToolTip( + tr("Gameplay will be automatically recorded as demos in the /logs folder.")); + ui_gameplay_form->setWidget(row, QFormLayout::LabelRole, ui_log_demo_lbl); + + ui_log_demo_cb = new QCheckBox(ui_form_layout_widget); + ui_gameplay_form->setWidget(row, QFormLayout::FieldRole, ui_log_demo_cb); + + // Finish gameplay tab QScrollArea *scroll = new QScrollArea(this); scroll->setWidget(ui_form_layout_widget); ui_gameplay_tab->setLayout(new QVBoxLayout); @@ -921,19 +943,6 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) ui_casing_layout->setWidget(row, QFormLayout::FieldRole, ui_casing_cm_cases_textbox); - //Check whether mass logging is enabled - row += 1; - ui_log_lbl = new QLabel(ui_casing_widget); - ui_log_lbl->setText(tr("Automatic Logging:")); - ui_log_lbl->setToolTip( - tr("If checked, all logs will be automatically written in the " - "/logs folder.")); - - ui_casing_layout->setWidget(row, QFormLayout::LabelRole, ui_log_lbl); - - ui_log_cb = new QCheckBox(ui_casing_widget); - - ui_casing_layout->setWidget(row, QFormLayout::FieldRole, ui_log_cb); // Assets tab ui_assets_tab = new QWidget(this); @@ -1123,7 +1132,8 @@ void AOOptionsDialog::update_values() { ui_casing_jur_cb->setChecked(ao_app->get_casing_juror_enabled()); ui_casing_steno_cb->setChecked(ao_app->get_casing_steno_enabled()); ui_casing_cm_cb->setChecked(ao_app->get_casing_cm_enabled()); - ui_log_cb->setChecked(ao_app->get_auto_logging_enabled()); + ui_log_text_cb->setChecked(ao_app->get_text_logging_enabled()); + ui_log_demo_cb->setChecked(ao_app->get_demo_logging_enabled()); ui_length_spinbox->setValue(ao_app->get_max_log_size()); ui_log_margin_spinbox->setValue(ao_app->get_log_margin()); ui_stay_time_spinbox->setValue(ao_app->stay_time()); @@ -1181,7 +1191,8 @@ void AOOptionsDialog::save_pressed() configini->setValue("stickypres", ui_stickypres_cb->isChecked()); configini->setValue("customchat", ui_customchat_cb->isChecked()); configini->setValue("sticker", ui_sticker_cb->isChecked()); - configini->setValue("automatic_logging_enabled", ui_log_cb->isChecked()); + configini->setValue("automatic_logging_enabled", ui_log_text_cb->isChecked()); + configini->setValue("demo_logging_enabled", ui_log_demo_cb->isChecked()); configini->setValue("continuous_playback", ui_continuous_cb->isChecked()); configini->setValue("category_stop", ui_category_stop_cb->isChecked()); QFile *callwordsini = new QFile(ao_app->get_base_path() + "callwords.ini"); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 8c59f1d..d64e5b0 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1761,7 +1761,7 @@ void Courtroom::append_server_chatmessage(QString p_name, QString p_message, ui_server_chatlog->append_chatmessage(p_name, p_message, color); - if (ao_app->get_auto_logging_enabled() && !ao_app->log_filename.isEmpty()) { + if (ao_app->get_text_logging_enabled() && !ao_app->log_filename.isEmpty()) { QString full = "[OOC][" + QDateTime::currentDateTimeUtc().toString() + "] " + p_name + ": " + p_message; ao_app->append_to_file(full, ao_app->log_filename, true); } @@ -3091,7 +3091,7 @@ void Courtroom::log_ic_text(QString p_name, QString p_showname, { chatlogpiece log_entry(p_name, p_showname, p_message, p_action, p_color); ic_chatlog_history.append(log_entry); - if (ao_app->get_auto_logging_enabled() && !ao_app->log_filename.isEmpty()) + if (ao_app->get_text_logging_enabled() && !ao_app->log_filename.isEmpty()) ao_app->append_to_file(log_entry.get_full(), ao_app->log_filename, true); while (ic_chatlog_history.size() > log_maximum_blocks && diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index bcbc667..066ed63 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -107,7 +107,7 @@ end: void AOApplication::append_to_demofile(QString packet_string) { - if (get_auto_logging_enabled() && !log_filename.isEmpty()) + if (get_demo_logging_enabled() && !log_filename.isEmpty()) { QString path = log_filename.left(log_filename.size()).replace(".log", ".demo"); if (!demo_timer.isValid()) @@ -304,7 +304,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) // Remove any characters not accepted in folder names for the server_name // here - if (AOApplication::get_auto_logging_enabled() && server_name != "Demo playback") { + if (AOApplication::get_demo_logging_enabled() && server_name != "Demo playback") { this->log_filename = QDateTime::currentDateTime().toUTC().toString( "'logs/" + server_name.remove(QRegExp("[\\\\/:*?\"<>|\']")) + "/'yyyy-MM-dd hh-mm-ss t'.log'"); diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index d873b3c..af96b3d 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -1067,13 +1067,20 @@ QString AOApplication::get_casing_can_host_cases() return result; } -bool AOApplication::get_auto_logging_enabled() +bool AOApplication::get_text_logging_enabled() { QString result = configini->value("automatic_logging_enabled", "true").value(); return result.startsWith("true"); } +bool AOApplication::get_demo_logging_enabled() +{ + QString result = + configini->value("demo_logging_enabled", "true").value(); + return result.startsWith("true"); +} + QString AOApplication::get_subtheme() { QString result = -- cgit From 3c7f5619dbd2702c4234e085604139569c000eb3 Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Thu, 23 Dec 2021 20:45:57 -0600 Subject: Fix emote buttons not generating due to bad VPath lookup --- src/aoemotebutton.cpp | 48 ++++++++++++++++++++++++++---------------------- src/emotes.cpp | 8 ++++---- 2 files changed, 30 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/aoemotebutton.cpp b/src/aoemotebutton.cpp index 638d49d..82149af 100644 --- a/src/aoemotebutton.cpp +++ b/src/aoemotebutton.cpp @@ -25,11 +25,27 @@ void AOEmoteButton::set_image(QString p_image, QString p_emote_comment) "\") 0 0 0 0 stretch stretch; }" "QToolTip { color: #000000; background-color: #ffffff; border: 0px; }"); } - else if ((p_image.contains("_on") && - file_exists(tmp_p_image.replace("_on", "_off"))) || - (p_image.contains("_off") && - file_exists(tmp_p_image.replace("_off", "_on")))) { - QImage tmpImage(tmp_p_image); + else { + this->setText(p_emote_comment); + this->setStyleSheet("QPushButton { border-image: url(); }" + "QToolTip { background-image: url(); color: #000000; " + "background-color: #ffffff; border: 0px; }"); + } +} + +void AOEmoteButton::set_char_image(QString p_char, int p_emote, bool on) +{ + QString emotion_number = QString::number(p_emote + 1); + QStringList suffixes { "_off", "_on" }; + QStringList suffixedPaths; + for (const QString &suffix : suffixes) { + suffixedPaths.append(ao_app->get_image_suffix(ao_app->get_character_path( + p_char, "emotions/button" + emotion_number + suffix))); + } + + QString emoteComment = ao_app->get_emote_comment(p_char, p_emote); + if (!file_exists(suffixedPaths[on]) && file_exists(suffixedPaths[!on])) { + QImage tmpImage(suffixedPaths[!on]); tmpImage = tmpImage.convertToFormat(QImage::Format_ARGB32); QPoint p1, p2; p2.setY(tmpImage.height()); @@ -46,25 +62,13 @@ void AOEmoteButton::set_image(QString p_image, QString p_emote_comment) p.fillRect(0, 0, tmpImage.width(), tmpImage.height(), gradient); p.end(); - tmpImage.save(p_image, "png"); - set_image(p_image, p_emote_comment); - } - else { - this->setText(p_emote_comment); - this->setStyleSheet("QPushButton { border-image: url(); }" - "QToolTip { background-image: url(); color: #000000; " - "background-color: #ffffff; border: 0px; }"); - } -} -void AOEmoteButton::set_char_image(QString p_char, int p_emote, QString suffix) -{ - QString emotion_number = QString::number(p_emote + 1); - QString image_path = - ao_app->get_image_suffix(ao_app->get_character_path( - p_char, "emotions/button" + emotion_number + suffix)); + // Original suffixed path may be empty, so create the path again + suffixedPaths[on] = QString(suffixedPaths[!on]).replace(suffixes[!on], suffixes[on]); + tmpImage.save(suffixedPaths[on], "png"); + } - this->set_image(image_path, ao_app->get_emote_comment(p_char, p_emote)); + set_image(suffixedPaths[on], emoteComment); } void AOEmoteButton::on_clicked() { emit emote_clicked(m_id); } diff --git a/src/emotes.cpp b/src/emotes.cpp index 541a6e2..67a243b 100644 --- a/src/emotes.cpp +++ b/src/emotes.cpp @@ -126,9 +126,9 @@ void Courtroom::set_emote_page() AOEmoteButton *f_emote = ui_emote_list.at(n_emote); if (n_real_emote == current_emote) - f_emote->set_char_image(current_char, n_real_emote, "_on"); + f_emote->set_char_image(current_char, n_real_emote, true); else - f_emote->set_char_image(current_char, n_real_emote, "_off"); + f_emote->set_char_image(current_char, n_real_emote, false); f_emote->show(); f_emote->setToolTip(QString::number(n_real_emote + 1) + ": " + @@ -158,7 +158,7 @@ void Courtroom::select_emote(int p_id) if (current_emote >= min && current_emote <= max) ui_emote_list.at(current_emote % max_emotes_on_page) - ->set_char_image(current_char, current_emote, "_off"); + ->set_char_image(current_char, current_emote, false); int old_emote = current_emote; @@ -166,7 +166,7 @@ void Courtroom::select_emote(int p_id) if (current_emote >= min && current_emote <= max) ui_emote_list.at(current_emote % max_emotes_on_page) - ->set_char_image(current_char, current_emote, "_on"); + ->set_char_image(current_char, current_emote, true); int emote_mod = ao_app->get_emote_mod(current_char, current_emote); -- cgit From 5ce0e6416e9e821be69219cc8a949c00e2cb462c Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Fri, 24 Dec 2021 21:05:01 +0100 Subject: Fix animation freeze when loading music files (#609) * Implement async music loading * Simplify music filename parsing and fix "missing" on streams Co-authored-by: oldmud0 --- src/aomusicplayer.cpp | 39 ++++++++++++++++++++++++++++++++++----- src/courtroom.cpp | 47 +++++++++++++++++++++-------------------------- 2 files changed, 55 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp index d0d9563..16d6df7 100644 --- a/src/aomusicplayer.cpp +++ b/src/aomusicplayer.cpp @@ -13,12 +13,13 @@ AOMusicPlayer::~AOMusicPlayer() } } -int AOMusicPlayer::play(QString p_song, int channel, bool loop, +QString AOMusicPlayer::play(QString p_song, int channel, bool loop, int effect_flags) { + QFuture invoking_future = music_watcher.future(); channel = channel % m_channelmax; if (channel < 0) // wtf? - return BASS_ERROR_NOCHAN; + return "[ERROR] Invalid Channel"; QString f_path = ao_app->get_real_path(ao_app->get_music_path(p_song)); unsigned int flags = BASS_STREAM_PRESCAN | BASS_STREAM_AUTOFREE | @@ -43,6 +44,14 @@ int AOMusicPlayer::play(QString p_song, int channel, bool loop, newstream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, flags); } + int error_code = BASS_ErrorGetCode(); + + if (invoking_future.isCanceled() && channel == 0) { + // Target future has changed. This stream has become irrelevant. + // So even if the stream manages to finish after the latest one, we don't run + // into order issues. + return QString(); + } if (ao_app->get_audio_output_device() != "default") BASS_ChannelSetDevice(m_stream_list[channel], BASS_GetDevice()); @@ -109,7 +118,7 @@ int AOMusicPlayer::play(QString p_song, int channel, bool loop, BASS_ChannelStop(m_stream_list[channel]); m_stream_list[channel] = newstream; - BASS_ChannelPlay(m_stream_list[channel], false); + BASS_ChannelPlay(newstream, false); if (effect_flags & FADE_IN) { // Fade in our sample BASS_ChannelSetAttribute(newstream, BASS_ATTRIB_VOL, 0); @@ -120,12 +129,32 @@ int AOMusicPlayer::play(QString p_song, int channel, bool loop, else this->set_volume(m_volume[channel], channel); - BASS_ChannelSetSync(m_stream_list[channel], BASS_SYNC_DEV_FAIL, 0, + BASS_ChannelSetSync(newstream, BASS_SYNC_DEV_FAIL, 0, ao_app->BASSreset, 0); this->set_looping(loop, channel); // Have to do this here due to any // crossfading-related changes, etc. - return BASS_ErrorGetCode(); + + bool is_stop = (p_song == "~stop.mp3"); + QString p_song_clear = QUrl(p_song).fileName(); + p_song_clear = p_song_clear.left(p_song_clear.lastIndexOf('.')); + + if (is_stop) { + return QObject::tr("None"); + } + + if (error_code == BASS_ERROR_HANDLE) { // Cheap hack to see if file missing + return QObject::tr("[MISSING] %1").arg(p_song_clear); + } + + if (p_song.startsWith("http") && channel == 0) { + return QObject::tr("[STREAM] %1").arg(p_song_clear); + } + + if (channel == 0) + return p_song_clear; + + return ""; } void AOMusicPlayer::stop(int channel) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 3eda163..a9f2da6 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -27,6 +27,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() music_player = new AOMusicPlayer(this, ao_app); music_player->set_volume(0); + connect(&music_player->music_watcher, &QFutureWatcher::finished, + this, &Courtroom::update_ui_music_name, Qt::QueuedConnection); sfx_player = new AOSfxPlayer(this, ao_app); sfx_player->set_volume(0); @@ -3807,13 +3809,8 @@ void Courtroom::handle_song(QStringList *p_contents) int effect_flags = 0; // No effects by default - vanilla functionality QString f_song = f_contents.at(0); - QString f_song_clear = f_song.left(f_song.lastIndexOf(".")); - if (f_song.startsWith("http")) { - QByteArray f_song_bytearray = f_song.toUtf8(); - QString f_song_decoded = QUrl::fromPercentEncoding(f_song_bytearray); - f_song_clear = f_song_decoded.left(f_song_decoded.lastIndexOf(".")); - } - f_song_clear = f_song_clear.right(f_song_clear.length() - (f_song_clear.lastIndexOf("/") + 1)); + QString f_song_clear = QUrl(f_song).fileName(); + f_song_clear = f_song_clear.left(f_song_clear.lastIndexOf('.')); int n_char = f_contents.at(1).toInt(&ok); if (!ok) @@ -3862,27 +3859,25 @@ void Courtroom::handle_song(QStringList *p_contents) } } - int error_code = music_player->play(f_song, channel, looping, effect_flags); - - if (is_stop) { - ui_music_name->setText(tr("None")); - return; - } - - if (error_code == BASS_ERROR_HANDLE) { // Cheap hack to see if file missing - ui_music_name->setText(tr("[MISSING] %1").arg(f_song_clear)); - return; - } - - if (f_song.startsWith("http") && channel == 0) { - ui_music_name->setText(tr("[STREAM] %1").arg(f_song_clear)); - return; + QFuture future = QtConcurrent::run(music_player, &AOMusicPlayer::play, f_song, channel, + looping, effect_flags); + if (channel == 0) { + // Current song UI only displays the song playing, not other channels. + // Any other music playing is irrelevant. + if (music_player->music_watcher.isRunning()) { + music_player->music_watcher.cancel(); + } + music_player->music_watcher.setFuture(future); + ui_music_name->setText(tr("[LOADING] %1").arg(f_song_clear)); } +} - if (channel == 0){ - ui_music_name->setText(f_song_clear); - return; - } +void Courtroom::update_ui_music_name() +{ + QString result = music_player->music_watcher.result(); + if (result.isEmpty()) + return; + ui_music_name->setText(result); } void Courtroom::handle_wtce(QString p_wtce, int variant) -- cgit From c57afe821e637fe08467848190a83553d913aaa6 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Fri, 24 Dec 2021 21:36:41 +0100 Subject: Sanity check before removing the ui element (#612) Co-authored-by: oldmud0 --- src/courtroom.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/courtroom.cpp b/src/courtroom.cpp index a9f2da6..f909526 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -4436,10 +4436,11 @@ void Courtroom::set_sfx_dropdown() void Courtroom::on_sfx_dropdown_changed(int p_index) { - Q_UNUSED(p_index); ui_ic_chat_message->setFocus(); - ui_sfx_remove->hide(); - custom_sfx = ""; + if (p_index == 0) { + ui_sfx_remove->hide(); + custom_sfx = ""; + } } void Courtroom::on_sfx_dropdown_custom(QString p_sfx) -- cgit From ecfe6f2542d73e9559b75a502f6eebffe63a76cf Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Sat, 25 Dec 2021 19:17:27 -0600 Subject: Change master chat in courtroom to debug log Since the MS chat has been disabled for quite some time now (and we aren't planning on bringing it back since Discord, Guilded etc. have better chat features), I decided to go ahead and change the pane into a debug log to keep it useful and avoid creating a gaping hole in themes. Though, maybe it is worth removing the whole switcher and keeping the debug log hidden away where it can't scare people. --- src/aoapplication.cpp | 25 ++++++++++++---- src/aoimage.cpp | 2 +- src/aolayer.cpp | 4 +-- src/aotextarea.cpp | 17 +++++++---- src/charselect.cpp | 2 +- src/courtroom.cpp | 73 ++++++++++++++++++++++++++++----------------- src/lobby.cpp | 4 +-- src/main.cpp | 2 ++ src/networkmanager.cpp | 4 +-- src/packet_distribution.cpp | 8 +++-- src/text_file_functions.cpp | 10 +++---- 11 files changed, 96 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/aoapplication.cpp b/src/aoapplication.cpp index 4a5ed52..b50cc7a 100644 --- a/src/aoapplication.cpp +++ b/src/aoapplication.cpp @@ -8,6 +8,15 @@ #include "aocaseannouncerdialog.h" #include "aooptionsdialog.h" +static QtMessageHandler original_message_handler; +static AOApplication *message_handler_context; +void message_handler(QtMsgType type, const QMessageLogContext &context, + const QString &msg) +{ + emit message_handler_context->qt_log_message(type, context, msg); + original_message_handler(type, context, msg); +} + AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) { // Create the QSettings class that points to the config.ini. @@ -20,6 +29,9 @@ AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) this, &AOApplication::ms_connect_finished); asset_lookup_cache.reserve(2048); + + message_handler_context = this; + original_message_handler = qInstallMessageHandler(message_handler); } AOApplication::~AOApplication() @@ -28,12 +40,13 @@ AOApplication::~AOApplication() destruct_courtroom(); delete discord; delete configini; + qInstallMessageHandler(original_message_handler); } void AOApplication::construct_lobby() { if (lobby_constructed) { - qDebug() << "W: lobby was attempted constructed when it already exists"; + qWarning() << "lobby was attempted constructed when it already exists"; return; } @@ -58,7 +71,7 @@ void AOApplication::construct_lobby() void AOApplication::destruct_lobby() { if (!lobby_constructed) { - qDebug() << "W: lobby was attempted destructed when it did not exist"; + qWarning() << "lobby was attempted destructed when it did not exist"; return; } @@ -70,7 +83,7 @@ void AOApplication::destruct_lobby() void AOApplication::construct_courtroom() { if (courtroom_constructed) { - qDebug() << "W: courtroom was attempted constructed when it already exists"; + qWarning() << "courtroom was attempted constructed when it already exists"; return; } @@ -87,14 +100,14 @@ void AOApplication::construct_courtroom() w_courtroom, &Courtroom::skip_clocks); } else { - qDebug() << "W: demo server did not exist during courtroom construction"; + qWarning() << "demo server did not exist during courtroom construction"; } } void AOApplication::destruct_courtroom() { if (!courtroom_constructed) { - qDebug() << "W: courtroom was attempted destructed when it did not exist"; + qWarning() << "courtroom was attempted destructed when it did not exist"; return; } @@ -232,7 +245,7 @@ void AOApplication::initBASS() BASS_Init(static_cast(a), 48000, BASS_DEVICE_LATENCY, nullptr, nullptr); load_bass_opus_plugin(); - qDebug() << info.name << "was set as the default audio output device."; + qInfo() << info.name << "was set as the default audio output device."; return; } } diff --git a/src/aoimage.cpp b/src/aoimage.cpp index 82e17b9..b84a279 100644 --- a/src/aoimage.cpp +++ b/src/aoimage.cpp @@ -30,7 +30,7 @@ bool AOImage::set_image(QString p_image, QString p_misc) ao_app->default_theme, p_misc, "", "", is_static || !ao_app->get_animated_theme()); if (!file_exists(p_image)) { - qDebug() << "Warning: Image" << p_image << "not found! Can't set!"; + qWarning() << "Image" << p_image << "not found! Can't set!"; return false; } path = p_image; diff --git a/src/aolayer.cpp b/src/aolayer.cpp index dd1fe76..1587d28 100644 --- a/src/aolayer.cpp +++ b/src/aolayer.cpp @@ -437,7 +437,7 @@ void CharLayer::load_network_effects() continue; int f_frame = frame_split.at(0).toInt(); if (f_frame >= max_frames || f_frame < 0) { - qDebug() << "Warning: out of bounds" << effects_list[i] << "frame" + qWarning() << "out of bounds" << effects_list[i] << "frame" << f_frame << "out of" << max_frames << "for" << m_emote; continue; } @@ -461,7 +461,7 @@ void CharLayer::load_network_effects() void CharLayer::play_frame_effect(int p_frame) { if (p_frame >= movie_effects.size()) { - qDebug() << "W: Attempted to play a frame effect bigger than the size of movie_effects"; + qWarning() << "Attempted to play a frame effect bigger than the size of movie_effects"; return; } if (p_frame < max_frames) { diff --git a/src/aotextarea.cpp b/src/aotextarea.cpp index 52e32f5..3513d22 100644 --- a/src/aotextarea.cpp +++ b/src/aotextarea.cpp @@ -11,7 +11,7 @@ void AOTextArea::append_linked(QString p_message) } void AOTextArea::append_chatmessage(QString p_name, QString p_message, - QString p_colour) + QString p_name_colour, QString p_color) { const QTextCursor old_cursor = this->textCursor(); const int old_scrollbar_value = this->verticalScrollBar()->value(); @@ -21,15 +21,22 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message, this->moveCursor(QTextCursor::End); this->append(""); - this->insertHtml("" + p_name.toHtmlEscaped() + - ": "); + if (!p_name.isEmpty()) { + this->insertHtml("" + p_name.toHtmlEscaped() + + ": "); + + // cheap workarounds ahoy + p_message += " "; + } - // cheap workarounds ahoy - p_message += " "; QString result = p_message.toHtmlEscaped() .replace("\n", "
") .replace(url_parser_regex, "\\1"); + if (!p_color.isEmpty()) { + result = "" + result + ""; + } + this->insertHtml(result); this->auto_scroll(old_cursor, old_scrollbar_value, is_scrolled_down); diff --git a/src/charselect.cpp b/src/charselect.cpp index 8928f44..3109558 100644 --- a/src/charselect.cpp +++ b/src/charselect.cpp @@ -82,7 +82,7 @@ void Courtroom::set_char_select() ao_app->get_element_dimensions("char_select", filename); if (f_charselect.width < 0 || f_charselect.height < 0) { - qDebug() << "W: did not find char_select width or height in " + qWarning() << "did not find char_select width or height in " "courtroom_design.ini!"; this->setFixedSize(714, 668); } diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 3eda163..b3272d9 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -111,11 +111,13 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() log_timestamp = ao_app->get_log_timestamp(); log_timestamp_format = ao_app->get_log_timestamp_format(); - ui_ms_chatlog = new AOTextArea(this); - ui_ms_chatlog->setReadOnly(true); - ui_ms_chatlog->setOpenExternalLinks(true); - ui_ms_chatlog->hide(); - ui_ms_chatlog->setObjectName("ui_ms_chatlog"); + ui_debug_log = new AOTextArea(this); + ui_debug_log->setReadOnly(true); + ui_debug_log->setOpenExternalLinks(true); + ui_debug_log->hide(); + ui_debug_log->setObjectName("ui_debug_log"); + connect(ao_app, &AOApplication::qt_log_message, + this, &Courtroom::debug_message_handler); ui_server_chatlog = new AOTextArea(this); ui_server_chatlog->setReadOnly(true); @@ -560,7 +562,7 @@ void Courtroom::set_courtroom_size() ao_app->get_element_dimensions("courtroom", filename); if (f_courtroom.width < 0 || f_courtroom.height < 0) { - qDebug() << "W: did not find courtroom width or height in " << filename; + qWarning() << "did not find courtroom width or height in " << filename; this->setFixedSize(714, 668); } @@ -679,7 +681,7 @@ void Courtroom::set_widgets() ao_app->get_element_dimensions("chat_arrow", "courtroom_design.ini"); if (design_ini_result.width < 0 || design_ini_result.height < 0) { - qDebug() << "W: could not find \"chat_arrow\" in courtroom_design.ini"; + qWarning() << "could not find \"chat_arrow\" in courtroom_design.ini"; ui_vp_chat_arrow->hide(); } else { @@ -725,8 +727,9 @@ void Courtroom::set_widgets() ui_ic_chatlog->setPlaceholderText(log_goes_downwards ? "▼ " + tr("Log goes down") + " ▼" : "▲ " + tr("Log goes up") + " ▲"); - set_size_and_pos(ui_ms_chatlog, "ms_chatlog"); - ui_ms_chatlog->setFrameShape(QFrame::NoFrame); + set_size_and_pos(ui_debug_log, "ms_chatlog"); // Old name + set_size_and_pos(ui_debug_log, "debug_log"); // New name + ui_debug_log->setFrameShape(QFrame::NoFrame); set_size_and_pos(ui_server_chatlog, "server_chatlog"); ui_server_chatlog->setFrameShape(QFrame::NoFrame); @@ -786,7 +789,7 @@ void Courtroom::set_widgets() ao_app->get_element_dimensions("music_display", "courtroom_design.ini"); if (design_ini_result.width < 0 || design_ini_result.height < 0) { - qDebug() << "W: could not find \"music_display\" in courtroom_design.ini"; + qWarning() << "could not find \"music_display\" in courtroom_design.ini"; ui_music_display->hide(); } else { @@ -1139,7 +1142,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_ms_chatlog, "", "ms_chatlog", 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); set_font(ui_area_list, "", "area_list", p_char); @@ -1248,7 +1251,7 @@ void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier, QStrin ao_app->get_element_dimensions(p_identifier, filename, p_misc); if (design_ini_result.width < 0 || design_ini_result.height < 0) { - qDebug() << "W: could not find \"" << p_identifier << "\" in " << filename; + qWarning() << "could not find \"" << p_identifier << "\" in " << filename; p_widget->hide(); } else { @@ -1282,7 +1285,7 @@ QPoint Courtroom::get_theme_pos(QString p_identifier) ao_app->get_element_dimensions(p_identifier, filename); if (design_ini_result.width < 0 || design_ini_result.height < 0) { - qDebug() << "W: could not find \"" << p_identifier << "\" in " << filename; + qWarning() << "could not find \"" << p_identifier << "\" in " << filename; return QPoint(0, 0); } else { @@ -1733,12 +1736,27 @@ void Courtroom::list_areas() } } -void Courtroom::append_ms_chatmessage(QString f_name, QString f_message) +void Courtroom::debug_message_handler(QtMsgType type, const QMessageLogContext &context, + const QString &msg) { - ui_ms_chatlog->append_chatmessage( - f_name, f_message, - ao_app->get_color("ms_chatlog_sender_color", "courtroom_fonts.ini") - .name()); + const QMap colors = { + {QtDebugMsg, "debug"}, + {QtInfoMsg, "info"}, + {QtWarningMsg, "warn"}, + {QtCriticalMsg, "critical"}, + {QtFatalMsg, "fatal"} + }; + const QString color_id = QString("debug_log_%1_color").arg(colors.value(type, "info")); + ui_debug_log->append_chatmessage( + QString(), qFormatLogMessage(type, context, msg), + QString(), ao_app->get_color(color_id, "courtroom_fonts.ini").name()); +} + +void Courtroom::append_debug_message(QString f_message) +{ + ui_debug_log->append_chatmessage( + QString(), f_message, + ao_app->get_color("debug_log_color", "courtroom_fonts.ini").name()); } void Courtroom::append_server_chatmessage(QString p_name, QString p_message, @@ -1758,7 +1776,6 @@ void Courtroom::append_server_chatmessage(QString p_name, QString p_message, on_authentication_state_received(1); } - ui_server_chatlog->append_chatmessage(p_name, p_message, color); if (ao_app->get_text_logging_enabled() && !ao_app->log_filename.isEmpty()) { @@ -2492,7 +2509,7 @@ void Courtroom::handle_emote_mod(int emote_mod, bool p_immediate) break; default: // This should never happen, but if it does anyway, yell in the console about it. - qDebug() << "W: invalid emote mod: " << QString::number(emote_mod); + qWarning() << "invalid emote mod: " << QString::number(emote_mod); } } @@ -2732,7 +2749,7 @@ void Courtroom::initialize_chatbox() pos_size_type design_ini_result = ao_app->get_element_dimensions( "chat_arrow", "courtroom_design.ini", p_misc); if (design_ini_result.width < 0 || design_ini_result.height < 0) { - qDebug() << "W: could not find \"chat_arrow\" in courtroom_design.ini"; + qWarning() << "could not find \"chat_arrow\" in courtroom_design.ini"; ui_vp_chat_arrow->hide(); } else { @@ -3246,7 +3263,7 @@ void Courtroom::play_preanim(bool immediate) else anim_state = 1; preanim_done(); - qDebug() << "W: could not find " + anim_to_find; + qWarning() << "could not find " + anim_to_find; return; } ui_vp_player_char->set_static_duration(preanim_duration); @@ -4199,14 +4216,14 @@ void Courtroom::on_ooc_return_pressed() void Courtroom::on_ooc_toggle_clicked() { if (server_ooc) { - ui_ms_chatlog->show(); + ui_debug_log->show(); ui_server_chatlog->hide(); - ui_ooc_toggle->setText(tr("Master")); + ui_ooc_toggle->setText(tr("Debug")); server_ooc = false; } else { - ui_ms_chatlog->hide(); + ui_debug_log->hide(); ui_server_chatlog->show(); ui_ooc_toggle->setText(tr("Server")); @@ -4623,7 +4640,7 @@ void Courtroom::on_mute_list_clicked(QModelIndex p_index) } if (f_cid < 0 || f_cid >= char_list.size()) { - qDebug() << "W: " << real_char << " not present in char_list"; + qWarning() << "" << real_char << " not present in char_list"; return; } @@ -4657,7 +4674,7 @@ void Courtroom::on_pair_list_clicked(QModelIndex p_index) } if (f_cid < -2 || f_cid >= char_list.size()) { - qDebug() << "W: " << real_char << " not present in char_list"; + qWarning() << "" << real_char << " not present in char_list"; return; } @@ -5104,7 +5121,7 @@ void Courtroom::on_text_color_changed(int p_color) int c = color_row_to_number.at(p_color); QString markdown_start = color_markdown_start_list.at(c); if (markdown_start.isEmpty()) { - qDebug() << "W: Color list dropdown selected a non-existent markdown " + qWarning() << "Color list dropdown selected a non-existent markdown " "start character"; return; } diff --git a/src/lobby.cpp b/src/lobby.cpp index 54e4c70..e9d95e0 100644 --- a/src/lobby.cpp +++ b/src/lobby.cpp @@ -116,7 +116,7 @@ void Lobby::set_widgets() pos_size_type f_lobby = ao_app->get_element_dimensions("lobby", filename); if (f_lobby.width < 0 || f_lobby.height < 0) { - qDebug() << "W: did not find lobby width or height in " << filename; + qWarning() << "did not find lobby width or height in " << filename; // Most common symptom of bad config files and missing assets. call_notice( @@ -205,7 +205,7 @@ void Lobby::set_size_and_pos(QWidget *p_widget, QString p_identifier) ao_app->get_element_dimensions(p_identifier, filename); if (design_ini_result.width < 0 || design_ini_result.height < 0) { - qDebug() << "W: could not find " << p_identifier << " in " << filename; + qWarning() << "could not find " << p_identifier << " in " << filename; p_widget->hide(); } else { diff --git a/src/main.cpp b/src/main.cpp index ef61bca..d7bbed1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,8 @@ int main(int argc, char *argv[]) { + qSetMessagePattern("%{type}: %{if-category}%{category}: %{endif}%{message}"); + #if QT_VERSION > QT_VERSION_CHECK(5, 6, 0) // High-DPI support is for Qt version >=5.6. // However, many Linux distros still haven't brought their stable/LTS diff --git a/src/networkmanager.cpp b/src/networkmanager.cpp index 08d0124..b302cea 100644 --- a/src/networkmanager.cpp +++ b/src/networkmanager.cpp @@ -149,8 +149,8 @@ void NetworkManager::on_srv_lookup() ms_socket->state() != QAbstractSocket::HostLookupState && ms_socket->error() != -1) { qDebug() << ms_socket->error(); - qWarning() << "Error connecting to master server:" - << ms_socket->errorString(); + qCritical() << "Error connecting to master server:" + << ms_socket->errorString(); ms_socket->abort(); ms_socket->close(); break; diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 1590608..bc7ae82 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -29,7 +29,7 @@ void AOApplication::ms_packet_received(AOPacket *p_packet) QStringList sub_contents = i_string.split("&"); if (sub_contents.size() < 4) { - qDebug() << "W: malformed packet"; + qWarning() << "malformed packet"; continue; } @@ -63,7 +63,8 @@ void AOApplication::ms_packet_received(AOPacket *p_packet) w_lobby->append_chatmessage(f_name, f_message); } if (courtroom_constructed && courtroom_loaded) { - w_courtroom->append_ms_chatmessage(f_name, f_message); + w_courtroom->append_server_chatmessage(tr("[Global] %1").arg(f_name), + f_message, "0"); } } else if (header == "AO2CHECK") { @@ -453,7 +454,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) goto end; if (lobby_constructed) - w_courtroom->append_ms_chatmessage("", w_lobby->get_chatlog()); + w_courtroom->append_server_chatmessage(tr("[Global log]"), + w_lobby->get_chatlog(), "0"); w_courtroom->character_loading_finished(); w_courtroom->done_received(); diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index af96b3d..6ea82f5 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -167,7 +167,7 @@ QString AOApplication::read_file(QString filename) QFile f_log(filename); if (!f_log.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << "Couldn't open" << filename; + qWarning() << "Couldn't open" << filename; return ""; } @@ -699,7 +699,7 @@ QString AOApplication::get_emote_comment(QString p_char, int p_emote) QStringList result_contents = f_result.split("#"); if (result_contents.size() < 4) { - qDebug() << "W: misformatted char.ini: " << p_char << ", " << p_emote; + qWarning() << "misformatted char.ini: " << p_char << ", " << p_emote; return "normal"; } return result_contents.at(0); @@ -713,7 +713,7 @@ QString AOApplication::get_pre_emote(QString p_char, int p_emote) QStringList result_contents = f_result.split("#"); if (result_contents.size() < 4) { - qDebug() << "W: misformatted char.ini: " << p_char << ", " << p_emote; + qWarning() << "misformatted char.ini: " << p_char << ", " << p_emote; return ""; } return result_contents.at(1); @@ -727,7 +727,7 @@ QString AOApplication::get_emote(QString p_char, int p_emote) QStringList result_contents = f_result.split("#"); if (result_contents.size() < 4) { - qDebug() << "W: misformatted char.ini: " << p_char << ", " << p_emote; + qWarning() << "misformatted char.ini: " << p_char << ", " << p_emote; return "normal"; } return result_contents.at(2); @@ -741,7 +741,7 @@ int AOApplication::get_emote_mod(QString p_char, int p_emote) QStringList result_contents = f_result.split("#"); if (result_contents.size() < 4) { - qDebug() << "W: misformatted char.ini: " << p_char << ", " + qWarning() << "misformatted char.ini: " << p_char << ", " << QString::number(p_emote); return 0; } -- cgit From dcff063f19fbcfa698a8f703fabaa92c2c7fc428 Mon Sep 17 00:00:00 2001 From: oldmud0 Date: Sat, 25 Dec 2021 20:40:39 -0600 Subject: Don't hide "OK" on message timer, just disable it --- src/debug_functions.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/debug_functions.cpp b/src/debug_functions.cpp index 456aee8..f4f7b3a 100644 --- a/src/debug_functions.cpp +++ b/src/debug_functions.cpp @@ -1,7 +1,10 @@ #include +#include #include #include +#include #include + #include #include "debug_functions.h" @@ -22,16 +25,38 @@ void call_error(QString p_message) void call_notice(QString p_message) { - QMessageBox *msgBox = new QMessageBox; + auto *msgBox = new QMessageBox; msgBox->setAttribute(Qt::WA_DeleteOnClose); msgBox->setText(p_message); msgBox->setWindowTitle( QCoreApplication::translate("debug_functions", "Notice")); - msgBox->setStandardButtons(QMessageBox::NoButton); - - QTimer::singleShot(3000, msgBox, std::bind(&QMessageBox::setStandardButtons,msgBox,QMessageBox::Ok)); + msgBox->setStandardButtons(QMessageBox::Ok); + msgBox->setDefaultButton(QMessageBox::Ok); + msgBox->defaultButton()->setEnabled(false); + + QTimer intervalTimer; + intervalTimer.setInterval(1000); + + int counter = 3; + const auto updateCounter = [msgBox, &counter] { + if (counter <= 0) + return; + msgBox->defaultButton()->setText( + QString("%1 (%2)").arg(QDialogButtonBox::tr("OK")).arg(counter)); + counter--; + }; + + QObject::connect(&intervalTimer, &QTimer::timeout, msgBox, updateCounter); + intervalTimer.start(); + updateCounter(); + + QTimer::singleShot(3000, msgBox, [msgBox, &intervalTimer] { + msgBox->defaultButton()->setEnabled(true); + msgBox->defaultButton()->setText(QDialogButtonBox::tr("OK")); + intervalTimer.stop(); + }); msgBox->exec(); -- cgit