aboutsummaryrefslogtreecommitdiff
path: root/src/courtroom.cpp
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/courtroom.cpp
parentecfb791e483234308b1edacb87e499860a63e510 (diff)
parent593bd54000be14c9a1455914285c1b2549b0fa51 (diff)
Merge branch 'master' into feature/http-ms
# Conflicts: # src/networkmanager.cpp
Diffstat (limited to 'src/courtroom.cpp')
-rw-r--r--src/courtroom.cpp163
1 files changed, 88 insertions, 75 deletions
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;
}