aboutsummaryrefslogtreecommitdiff
path: root/src/courtroom.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/courtroom.cpp')
-rw-r--r--src/courtroom.cpp127
1 files changed, 70 insertions, 57 deletions
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index 3eda1635..486cb1c2 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,7 +1778,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 +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);
}
}
@@ -2732,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 {
@@ -3246,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);
@@ -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)
@@ -4199,14 +4211,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"));
@@ -4441,10 +4453,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)
@@ -4623,7 +4636,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 +4670,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 +5117,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;
}