aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoroldmud0 <oldmud0@users.noreply.github.com>2021-12-30 20:31:44 -0600
committeroldmud0 <oldmud0@users.noreply.github.com>2021-12-30 20:31:44 -0600
commitee76c2ce61f6996bfae3ef027eaee8485d455c95 (patch)
treec70e266cad00d0adf27be8fa51a07e13de9828db /src
parentecfb791e483234308b1edacb87e499860a63e510 (diff)
parent593bd54000be14c9a1455914285c1b2549b0fa51 (diff)
Merge branch 'master' into feature/http-ms
# Conflicts: # src/networkmanager.cpp
Diffstat (limited to 'src')
-rw-r--r--src/aoapplication.cpp25
-rw-r--r--src/aoemotebutton.cpp48
-rw-r--r--src/aoimage.cpp2
-rw-r--r--src/aolayer.cpp4
-rw-r--r--src/aomusicplayer.cpp39
-rw-r--r--src/aooptionsdialog.cpp41
-rw-r--r--src/aotextarea.cpp17
-rw-r--r--src/charselect.cpp2
-rw-r--r--src/courtroom.cpp163
-rw-r--r--src/debug_functions.cpp33
-rw-r--r--src/emotes.cpp8
-rw-r--r--src/lobby.cpp7
-rw-r--r--src/main.cpp2
-rw-r--r--src/packet_distribution.cpp14
-rw-r--r--src/text_file_functions.cpp19
15 files changed, 269 insertions, 155 deletions
diff --git a/src/aoapplication.cpp b/src/aoapplication.cpp
index 3d37c32f..3a91aece 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.
@@ -18,6 +27,9 @@ AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv)
discord = new AttorneyOnline::Discord();
asset_lookup_cache.reserve(2048);
+
+ message_handler_context = this;
+ original_message_handler = qInstallMessageHandler(message_handler);
}
AOApplication::~AOApplication()
@@ -26,12 +38,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;
}
@@ -56,7 +69,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;
}
@@ -68,7 +81,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;
}
@@ -85,14 +98,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;
}
@@ -203,7 +216,7 @@ void AOApplication::initBASS()
BASS_Init(static_cast<int>(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/aoemotebutton.cpp b/src/aoemotebutton.cpp
index 638d49da..82149aff 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/aoimage.cpp b/src/aoimage.cpp
index 82e17b98..b84a279f 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 dd1fe76c..1587d289 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/aomusicplayer.cpp b/src/aomusicplayer.cpp
index d0d95635..16d6df7a 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<QString> 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/aooptionsdialog.cpp b/src/aooptionsdialog.cpp
index 7413db3a..5fd80b70 100644
--- a/src/aooptionsdialog.cpp
+++ b/src/aooptionsdialog.cpp
@@ -584,6 +584,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);
@@ -922,19 +944,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);
@@ -1148,7 +1157,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());
@@ -1215,7 +1225,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/aotextarea.cpp b/src/aotextarea.cpp
index 52e32f55..3513d221 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("<b><font color=" + p_colour + ">" + p_name.toHtmlEscaped() +
- "</font></b>:&nbsp;");
+ if (!p_name.isEmpty()) {
+ this->insertHtml("<b><font color=" + p_name_colour + ">" + p_name.toHtmlEscaped() +
+ "</font></b>:&nbsp;");
+
+ // cheap workarounds ahoy
+ p_message += " ";
+ }
- // cheap workarounds ahoy
- p_message += " ";
QString result = p_message.toHtmlEscaped()
.replace("\n", "<br>")
.replace(url_parser_regex, "<a href='\\1'>\\1</a>");
+ if (!p_color.isEmpty()) {
+ result = "<font color=" + p_color + ">" + result + "</font>";
+ }
+
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 8928f446..3109558e 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 e5495266..1f8b3dac 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<QString>::finished,
+ this, &Courtroom::update_ui_music_name, Qt::QueuedConnection);
sfx_player = new AOSfxPlayer(this, ao_app);
sfx_player->set_volume(0);
@@ -111,11 +113,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 +564,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 +683,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 +729,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 +791,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 +1144,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 +1253,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 +1287,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 +1738,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<QtMsgType, QString> 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,10 +1778,9 @@ 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_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);
}
@@ -1787,9 +1806,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); });
@@ -2495,7 +2511,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);
}
}
@@ -2735,7 +2751,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 {
@@ -3091,7 +3107,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 &&
@@ -3249,7 +3265,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);
@@ -3290,6 +3306,22 @@ void Courtroom::preanim_done()
if (anim_state != 1 && anim_state != 4 && anim_state != 5)
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]);
@@ -3308,19 +3340,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("|");
@@ -3807,13 +3826,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 +3876,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<QString> 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)
@@ -4197,14 +4209,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"));
@@ -4439,10 +4451,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)
@@ -4621,7 +4634,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;
}
@@ -4655,7 +4668,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;
}
@@ -5102,7 +5115,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/debug_functions.cpp b/src/debug_functions.cpp
index 456aee8a..f4f7b3a7 100644
--- a/src/debug_functions.cpp
+++ b/src/debug_functions.cpp
@@ -1,7 +1,10 @@
#include <QCoreApplication>
+#include <QDialogButtonBox>
#include <QElapsedTimer>
#include <QMessageBox>
+#include <QPushButton>
#include <QTimer>
+
#include <functional>
#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();
diff --git a/src/emotes.cpp b/src/emotes.cpp
index 541a6e20..67a243ba 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);
diff --git a/src/lobby.cpp b/src/lobby.cpp
index 39b63e55..44496032 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);
@@ -117,7 +118,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(
@@ -206,7 +207,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 e6e977c7..6edefa49 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/packet_distribution.cpp b/src/packet_distribution.cpp
index 37f58c8b..9b56fae3 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") {
@@ -104,7 +105,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())
@@ -265,7 +266,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 = "";
@@ -301,7 +302,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'");
@@ -450,7 +451,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 07a93935..71da85ec 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;
}
@@ -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<QString>();
return result.startsWith("true");
}
+bool AOApplication::get_demo_logging_enabled()
+{
+ QString result =
+ configini->value("demo_logging_enabled", "true").value<QString>();
+ return result.startsWith("true");
+}
+
QString AOApplication::get_subtheme()
{
QString result =