aboutsummaryrefslogtreecommitdiff
path: root/src/courtroom.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/courtroom.cpp')
-rw-r--r--src/courtroom.cpp707
1 files changed, 558 insertions, 149 deletions
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index c2fcf9b8..962c04f3 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -3,6 +3,10 @@
Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
{
ao_app = p_ao_app;
+
+ this->setWindowFlags((this->windowFlags() | Qt::CustomizeWindowHint) &
+ ~Qt::WindowMaximizeButtonHint);
+
ao_app->initBASS();
qsrand(static_cast<uint>(QDateTime::currentMSecsSinceEpoch() / 1000));
@@ -210,9 +214,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_showname_enable->setChecked(ao_app->get_showname_enabled_by_default());
ui_showname_enable->setText(tr("Shownames"));
- ui_pre_non_interrupt = new QCheckBox(this);
- ui_pre_non_interrupt->setText(tr("No Interrupt"));
- ui_pre_non_interrupt->hide();
+ ui_immediate = new QCheckBox(this);
+ ui_immediate->setText(tr("No Interrupt"));
+ ui_immediate->hide();
ui_custom_objection = new AOButton(this, ao_app);
ui_custom_objection->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -246,7 +250,10 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_pair_list = new QListWidget(this);
ui_pair_offset_spinbox = new QSpinBox(this);
ui_pair_offset_spinbox->setRange(-100, 100);
- ui_pair_offset_spinbox->setSuffix(tr("% offset"));
+ ui_pair_offset_spinbox->setSuffix(tr("% x offset"));
+ ui_pair_vert_offset_spinbox = new QSpinBox(this);
+ ui_pair_vert_offset_spinbox->setRange(-100, 100);
+ ui_pair_vert_offset_spinbox->setSuffix(tr("% y offset"));
ui_pair_order_dropdown = new QComboBox(this);
ui_pair_order_dropdown->addItem(tr("To front"));
@@ -390,6 +397,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
SLOT(on_pair_list_clicked(QModelIndex)));
connect(ui_pair_offset_spinbox, SIGNAL(valueChanged(int)), this,
SLOT(on_pair_offset_changed(int)));
+ connect(ui_pair_vert_offset_spinbox, SIGNAL(valueChanged(int)), this,
+ SLOT(on_pair_vert_offset_changed(int)));
connect(ui_pair_order_dropdown, SIGNAL(currentIndexChanged(int)), this,
SLOT(on_pair_order_dropdown_changed(int)));
@@ -450,13 +459,13 @@ void Courtroom::set_widgets()
if (f_courtroom.width < 0 || f_courtroom.height < 0) {
qDebug() << "W: did not find courtroom width or height in " << filename;
- this->resize(714, 668);
+ this->setFixedSize(714, 668);
}
else {
m_courtroom_width = f_courtroom.width;
m_courtroom_height = f_courtroom.height;
- this->resize(f_courtroom.width, f_courtroom.height);
+ this->setFixedSize(f_courtroom.width, f_courtroom.height);
}
set_fonts();
@@ -472,14 +481,14 @@ void Courtroom::set_widgets()
// if needed.
if (ao_app->cccc_ic_support_enabled) {
ui_pair_button->show();
- ui_pre_non_interrupt->show();
+ ui_immediate->show();
ui_showname_enable->show();
ui_ic_chat_name->show();
ui_ic_chat_name->setEnabled(true);
}
else {
ui_pair_button->hide();
- ui_pre_non_interrupt->hide();
+ ui_immediate->hide();
ui_showname_enable->hide();
ui_ic_chat_name->hide();
ui_ic_chat_name->setEnabled(false);
@@ -556,7 +565,11 @@ void Courtroom::set_widgets()
log_maximum_blocks = ao_app->get_max_log_size();
- bool regenerate = log_goes_downwards != ao_app->get_log_goes_downwards() || log_colors != ao_app->is_colorlog_enabled() || log_newline != ao_app->get_log_newline() || log_margin != ao_app->get_log_margin() || log_timestamp != ao_app->get_log_timestamp();
+ bool regenerate = log_goes_downwards != ao_app->get_log_goes_downwards() ||
+ log_colors != ao_app->is_colorlog_enabled() ||
+ log_newline != ao_app->get_log_newline() ||
+ log_margin != ao_app->get_log_margin() ||
+ log_timestamp != ao_app->get_log_timestamp();
log_goes_downwards = ao_app->get_log_goes_downwards();
log_colors = ao_app->is_colorlog_enabled();
log_newline = ao_app->get_log_newline();
@@ -567,7 +580,8 @@ void Courtroom::set_widgets()
set_size_and_pos(ui_ic_chatlog, "ic_chatlog");
ui_ic_chatlog->setFrameShape(QFrame::NoFrame);
- ui_ic_chatlog->setPlaceholderText(log_goes_downwards ? "▼ Log goes down ▼" : "▲ Log goes up ▲");
+ ui_ic_chatlog->setPlaceholderText(log_goes_downwards ? "▼ Log goes down ▼"
+ : "▲ Log goes up ▲");
set_size_and_pos(ui_ms_chatlog, "ms_chatlog");
ui_ms_chatlog->setFrameShape(QFrame::NoFrame);
@@ -585,12 +599,20 @@ void Courtroom::set_widgets()
set_size_and_pos(ui_pair_offset_spinbox, "pair_offset_spinbox");
ui_pair_offset_spinbox->hide();
ui_pair_offset_spinbox->setToolTip(
- tr("Change the percentage offset of your character's position from the "
+ tr("Change the horizontal percentage offset of your character's position "
+ "from the "
+ "center of the screen."));
+
+ set_size_and_pos(ui_pair_vert_offset_spinbox, "pair_vert_offset_spinbox");
+ ui_pair_vert_offset_spinbox->hide();
+ ui_pair_vert_offset_spinbox->setToolTip(
+ tr("Change the vertical percentage offset of your character's position "
+ "from the "
"center of the screen."));
ui_pair_order_dropdown->hide();
set_size_and_pos(ui_pair_order_dropdown, "pair_order_dropdown");
- ui_pair_offset_spinbox->setToolTip(
+ ui_pair_order_dropdown->setToolTip(
tr("Change the order of appearance for your character."));
set_size_and_pos(ui_pair_button, "pair_button");
@@ -684,7 +706,7 @@ void Courtroom::set_widgets()
tr("Set an 'iniswap', or an alternative character folder to refer to "
"from your current character.\n"
"Edit by typing and pressing Enter, [X] to remove. This saves to your "
- "base/characters/<charname>/iniswaps.ini"));
+ "base/iniswaps.ini"));
set_size_and_pos(ui_iniswap_remove, "iniswap_remove");
ui_iniswap_remove->setText("X");
@@ -706,11 +728,11 @@ void Courtroom::set_widgets()
set_size_and_pos(ui_sfx_remove, "sfx_remove");
ui_sfx_remove->setText("X");
ui_sfx_remove->set_image("evidencex");
- ui_sfx_remove->setToolTip(
- tr("Remove the currently selected iniswap from the list and return to "
- "the original character folder."));
+ ui_sfx_remove->setToolTip(tr("Remove the currently selected sound effect."));
ui_sfx_remove->hide();
+ set_iniswap_dropdown();
+
set_size_and_pos(ui_effects_dropdown, "effects_dropdown");
ui_effects_dropdown->setInsertPolicy(QComboBox::InsertAtBottom);
ui_effects_dropdown->setToolTip(
@@ -823,11 +845,23 @@ void Courtroom::set_widgets()
ui_pre->setToolTip(
tr("Play a single-shot animation as defined by the emote when checked."));
- set_size_and_pos(ui_pre_non_interrupt, "pre_no_interrupt");
- ui_pre_non_interrupt->setToolTip(
+ ui_immediate->setToolTip(
tr("If preanim is checked, display the input text immediately as the "
"animation plays concurrently."));
+ design_ini_result =
+ ao_app->get_element_dimensions("immediate", "courtroom_design.ini");
+ // If we don't have new-style naming, fall back to the old method
+ if (design_ini_result.width < 0 || design_ini_result.height < 0) {
+ set_size_and_pos(ui_immediate, "pre_no_interrupt");
+ truncate_label_text(ui_immediate, "pre_no_interrupt");
+ }
+ else {// Adopt the based new method instead
+ set_size_and_pos(ui_immediate, "immediate");
+ truncate_label_text(ui_immediate, "immediate");
+ }
+
+
set_size_and_pos(ui_flip, "flip");
ui_flip->setToolTip(tr("Mirror your character's emotes when checked."));
@@ -922,6 +956,17 @@ void Courtroom::set_widgets()
ui_spectator->setToolTip(tr("Become a spectator. You won't be able to "
"interact with the in-character screen."));
+ // QCheckBox
+ truncate_label_text(ui_guard, "guard");
+ truncate_label_text(ui_pre, "pre");
+ truncate_label_text(ui_flip, "flip");
+ truncate_label_text(ui_showname_enable, "showname_enable");
+
+ // QLabel
+ truncate_label_text(ui_music_label, "music_label");
+ truncate_label_text(ui_sfx_label, "sfx_label");
+ truncate_label_text(ui_blip_label, "blip_label");
+
free_brush =
QBrush(ao_app->get_color("area_free_color", "courtroom_design.ini"));
lfp_brush =
@@ -1133,14 +1178,18 @@ void Courtroom::set_background(QString p_background, bool display)
// Populate the dropdown list with all pos that exist on this bg
QStringList pos_list = {};
for (QString key : default_pos.keys()) {
- if (file_exists(
- ao_app->get_image_suffix(ao_app->get_background_path(key)))) {
+ if (file_exists(ao_app->get_image_suffix(
+ ao_app->get_background_path(default_pos[key]))) || // if we have 2.8-style positions, e.g. def.png, wit.webp, hld.apng
+ file_exists(
+ ao_app->get_image_suffix(ao_app->get_background_path(key)))) { // if we have pre-2.8-style positions, e.g. defenseempty.png
pos_list.append(default_pos[key]);
}
}
-
- // TODO: search through extra/custom pos and add them to the pos dropdown as
- // well
+ for (QString pos : ao_app->read_design_ini("positions", ao_app->get_background_path("design.ini")).split(",")) {
+ if (file_exists(ao_app->get_image_suffix(ao_app->get_background_path(pos)))) {
+ pos_list.append(pos);
+ }
+ }
set_pos_dropdown(pos_list);
@@ -1287,10 +1336,16 @@ void Courtroom::update_character(int p_cid)
if (ao_app->custom_objection_enabled) // if setting is enabled
{
custom_obj_menu->clear();
+ custom_objections_list.clear();
if (file_exists(ao_app->get_image_suffix(
ao_app->get_character_path(current_char, "custom")))) {
ui_custom_objection->show();
- QAction *action = custom_obj_menu->addAction("Default");
+ QString custom_name = ao_app->read_char_ini(f_char, "custom_name", "Shouts");
+ QAction *action;
+ if (custom_name != "")
+ action = custom_obj_menu->addAction(custom_name);
+ else
+ action = custom_obj_menu->addAction("Default");
custom_obj_menu->setDefaultAction(action);
objection_custom = "";
}
@@ -1305,11 +1360,23 @@ void Courtroom::update_character(int p_cid)
<< "*.webp",
QDir::Files);
for (const QString &filename : custom_obj) {
- QAction *action = custom_obj_menu->addAction(filename);
+ CustomObjection custom_objection;
+ custom_objection.filename = filename;
+ QString custom_name = ao_app->read_char_ini(f_char, filename.split(".")[0] + "_name", "Shouts");
+ QAction *action;
+ if (custom_name != "") {
+ custom_objection.name = custom_name;
+ action = custom_obj_menu->addAction(custom_name);
+ }
+ else {
+ custom_objection.name = filename.split(".")[0];
+ action = custom_obj_menu->addAction(filename.split(".")[0]);
+ }
if (custom_obj_menu->defaultAction() == nullptr) {
custom_obj_menu->setDefaultAction(action);
- objection_custom = action->text();
+ objection_custom = custom_objection.filename;
}
+ custom_objections_list.append(custom_objection);
}
}
}
@@ -1320,6 +1387,9 @@ void Courtroom::update_character(int p_cid)
ui_char_select_background->hide();
ui_ic_chat_message->setEnabled(m_cid != -1);
ui_ic_chat_message->setFocus();
+ // have to call these to make sure sfx and blips don't get accidentally muted forever when we change characters
+ sfx_player->set_volume(ui_sfx_slider->value());
+ blip_player->set_volume(ui_blip_slider->value());
}
void Courtroom::enter_courtroom()
@@ -1532,6 +1602,9 @@ void Courtroom::on_chat_return_pressed()
if ((anim_state < 3 || text_state < 2) && objection_state == 0)
return;
+ ui_ic_chat_message->blockSignals(true);
+ QTimer::singleShot(600, this,
+ [=] { ui_ic_chat_message->blockSignals(false); });
// MS#
// deskmod#
// pre-emote#
@@ -1554,7 +1627,7 @@ void Courtroom::on_chat_return_pressed()
// showname#
// other_charid#
// self_offset#
- // noninterrupting_preanim#%
+ // immediate_preanim#%
QStringList packet_contents;
@@ -1566,6 +1639,12 @@ void Courtroom::on_chat_return_pressed()
if (ao_app->desk_mod_enabled) {
f_desk_mod =
QString::number(ao_app->get_desk_mod(current_char, current_emote));
+ if (!ao_app->expanded_desk_mods_enabled) {
+ if (f_desk_mod == "2" || f_desk_mod == "4")
+ f_desk_mod = "0";
+ else if (f_desk_mod == "3" || f_desk_mod == "5")
+ f_desk_mod = "1";
+ }
if (f_desk_mod == "-1")
f_desk_mod = "chat";
}
@@ -1583,7 +1662,7 @@ void Courtroom::on_chat_return_pressed()
packet_contents.append(current_side);
packet_contents.append(get_char_sfx());
- if (ui_pre->isChecked() && !ao_app->is_stickysounds_enabled()) {
+ if (ui_pre->isChecked() && !ao_app->is_stickysounds_enabled() && ui_sfx_dropdown->currentIndex() > 1) {
ui_sfx_dropdown->blockSignals(true);
ui_sfx_dropdown->setCurrentIndex(0);
ui_sfx_dropdown->blockSignals(false);
@@ -1593,15 +1672,13 @@ void Courtroom::on_chat_return_pressed()
int f_emote_mod = ao_app->get_emote_mod(current_char, current_emote);
// needed or else legacy won't understand what we're saying
- if (objection_state > 0) {
- if (ui_pre->isChecked()) {
- if (f_emote_mod == 4 || f_emote_mod == 5)
- f_emote_mod = 6;
- else
- f_emote_mod = 2;
- }
+ if (objection_state > 0 && ui_pre->isChecked()) {
+ if (f_emote_mod == 4 || f_emote_mod == 5)
+ f_emote_mod = 6;
+ else
+ f_emote_mod = 2;
}
- else if (ui_pre->isChecked() && !ui_pre_non_interrupt->isChecked()) {
+ else if (ui_pre->isChecked() && !ui_immediate->isChecked()) {
if (f_emote_mod == 0)
f_emote_mod = 1;
else if (f_emote_mod == 5 && ao_app->prezoom_enabled)
@@ -1691,10 +1768,13 @@ void Courtroom::on_chat_return_pressed()
packet_contents.append("-1");
}
// Send the offset as it's gonna be used regardless
- packet_contents.append(QString::number(char_offset));
+ if(ao_app->y_offset_enabled)
+ packet_contents.append(QString::number(char_offset) + "&" + QString::number(char_vert_offset));
+ else
+ packet_contents.append(QString::number(char_offset));
// Finally, we send over if we want our pres to not interrupt.
- if (ui_pre_non_interrupt->isChecked() && ui_pre->isChecked()) {
+ if (ui_immediate->isChecked() && ui_pre->isChecked()) {
packet_contents.append("1");
}
else {
@@ -1759,6 +1839,7 @@ void Courtroom::reset_ic()
ui_vp_chat_arrow->stop();
text_state = 0;
anim_state = 0;
+ evidence_presented = false;
ui_vp_objection->stop();
chat_tick_timer->stop();
ui_vp_evidence_display->reset();
@@ -1792,6 +1873,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
if (p_contents->size() < MS_MINIMUM)
return;
+ int prev_char_id = m_chatmessage[CHAR_ID].toInt();
for (int n_string = 0; n_string < MS_MAXIMUM; ++n_string) {
// Note that we have added stuff that vanilla clients and servers simply
// won't send. So now, we have to check if the thing we want even exists
@@ -1859,34 +1941,36 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
{
m_chatmessage[MESSAGE] = ""; // Turn it into true blankpost
}
-
- if (!m_chatmessage[MESSAGE].isEmpty() || ic_chatlog_history.isEmpty() || ic_chatlog_history.last().get_message() != "")
- {
- log_ic_text(f_charname, f_displayname, m_chatmessage[MESSAGE], "",
- m_chatmessage[TEXT_COLOR].toInt());
- append_ic_text(m_chatmessage[MESSAGE], f_displayname, "",
- m_chatmessage[TEXT_COLOR].toInt());
- }
-
+
QString f_char = m_chatmessage[CHAR_NAME];
QString f_custom_theme = ao_app->get_char_shouts(f_char);
// if an objection is used
if (objection_mod <= 4 && objection_mod >= 1) {
+ QString shout_message;
switch (objection_mod) {
case 1:
ui_vp_objection->play("holdit_bubble", f_char, f_custom_theme, 724);
objection_player->play("holdit", f_char, f_custom_theme);
+ shout_message = ao_app->read_char_ini(f_char, "holdit_message", "Shouts");
+ if (shout_message == "")
+ shout_message = tr("HOLD IT!");
break;
case 2:
ui_vp_objection->play("objection_bubble", f_char, f_custom_theme, 724);
objection_player->play("objection", f_char, f_custom_theme);
+ shout_message = ao_app->read_char_ini(f_char, "objection_message", "Shouts");
+ if (shout_message == "")
+ shout_message = tr("OBJECTION!");
if (ao_app->objection_stop_music())
music_player->stop();
break;
case 3:
ui_vp_objection->play("takethat_bubble", f_char, f_custom_theme, 724);
objection_player->play("takethat", f_char, f_custom_theme);
+ shout_message = ao_app->read_char_ini(f_char, "takethat_message", "Shouts");
+ if (shout_message == "")
+ shout_message = tr("TAKE THAT!");
break;
// case 4 is AO2 only
case 4:
@@ -1896,19 +1980,36 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
objection_player->play("custom_objections/" +
custom_objection.split('.')[0],
f_char, f_custom_theme);
+ shout_message = ao_app->read_char_ini(f_char, custom_objection.split('.')[0] + "_message", "Shouts");
+ if (shout_message == "")
+ shout_message = custom_objection.split('.')[0];
}
else {
ui_vp_objection->play("custom", f_char, f_custom_theme,
shout_stay_time);
objection_player->play("custom", f_char, f_custom_theme);
+ shout_message = ao_app->read_char_ini(f_char, "custom_message", "Shouts");
+ if (shout_message == "")
+ shout_message = tr("CUSTOM OBJECTION!");
}
m_chatmessage[EMOTE_MOD] = 1;
break;
}
+ log_ic_text(f_char, f_displayname, shout_message,
+ tr("shouts"),2);
+ append_ic_text(shout_message, f_displayname, tr("shouts"));
sfx_player->clear(); // Objection played! Cut all sfx.
}
else
handle_chatmessage_2();
+
+ if (!m_chatmessage[MESSAGE].isEmpty() || ic_chatlog_history.isEmpty() ||
+ ic_chatlog_history.last().get_message() != "") {
+ log_ic_text(f_charname, f_displayname, m_chatmessage[MESSAGE], "",
+ m_chatmessage[TEXT_COLOR].toInt());
+ append_ic_text(m_chatmessage[MESSAGE], f_displayname, "",
+ m_chatmessage[TEXT_COLOR].toInt());
+ }
}
void Courtroom::objection_done() { handle_chatmessage_2(); }
@@ -2048,8 +2149,6 @@ void Courtroom::handle_chatmessage_2()
f_pointsize = chatsize;
set_font(ui_vp_message, "", "message", customchar, font_name, f_pointsize);
- set_scene(m_chatmessage[DESK_MOD], m_chatmessage[SIDE]);
-
int emote_mod = m_chatmessage[EMOTE_MOD].toInt();
// Deal with invalid emote modifiers
if (emote_mod != 0 && emote_mod != 1 && emote_mod != 2 && emote_mod != 5 &&
@@ -2081,10 +2180,20 @@ void Courtroom::handle_chatmessage_2()
if (got_other_charid > -1) {
// If there is, show them!
ui_vp_sideplayer_char->show();
-
- int other_offset = m_chatmessage[OTHER_OFFSET].toInt();
+ QStringList other_offsets = m_chatmessage[OTHER_OFFSET].split("&");
+ int other_offset;
+ int other_offset_v;
+ if (other_offsets.length() <= 1) {
+ other_offset = m_chatmessage[OTHER_OFFSET].toInt();
+ other_offset_v = 0;
+ }
+ else {
+ other_offset = other_offsets[0].toInt();
+ other_offset_v = other_offsets[1].toInt();
+ }
ui_vp_sideplayer_char->move(ui_viewport->width() * other_offset / 100,
- 0);
+ ui_viewport->height() * other_offset_v /
+ 100);
QStringList args = m_chatmessage[OTHER_CHARID].split("^");
if (args.size() >
@@ -2123,13 +2232,32 @@ void Courtroom::handle_chatmessage_2()
}
// Set ourselves according to SELF_OFFSET
- bool ok;
- int self_offset = m_chatmessage[SELF_OFFSET].toInt(&ok);
- if (ok)
- ui_vp_player_char->move(ui_viewport->width() * self_offset / 100, 0);
+ QStringList self_offsets = m_chatmessage[SELF_OFFSET].split("&");
+ int self_offset = self_offsets[0].toInt();
+ int self_offset_v;
+ if (self_offsets.length() <= 1)
+ self_offset_v = 0;
else
- ui_vp_player_char->move(0, 0);
+ self_offset_v = self_offsets[1].toInt();
+ ui_vp_player_char->move(ui_viewport->width() * self_offset / 100,
+ ui_viewport->height() * self_offset_v / 100);
+ switch(m_chatmessage[DESK_MOD].toInt()) {
+ case 4:
+ ui_vp_sideplayer_char->hide();
+ ui_vp_player_char->move(0, 0);
+ [[fallthrough]];
+ case 2:
+ set_scene("0", m_chatmessage[SIDE]);
+ break;
+ case 5:
+ case 3:
+ set_scene("1", m_chatmessage[SIDE]);
+ break;
+ default:
+ set_scene(m_chatmessage[DESK_MOD], m_chatmessage[SIDE]);
+ break;
+ }
switch (emote_mod) {
case 1:
case 2:
@@ -2138,7 +2266,7 @@ void Courtroom::handle_chatmessage_2()
break;
case 0:
case 5:
- if (m_chatmessage[NONINTERRUPTING_PRE].toInt() == 0)
+ if (m_chatmessage[IMMEDIATE].toInt() == 0)
handle_chatmessage_3();
else
play_preanim(true);
@@ -2251,7 +2379,8 @@ void Courtroom::handle_chatmessage_3()
.isEmpty()) // Pure whitespace showname, get outta here.
f_showname = m_chatmessage[CHAR_NAME];
- if (f_evi_id > 0 && f_evi_id <= local_evidence_list.size()) {
+ if (f_evi_id > 0 && f_evi_id <= local_evidence_list.size() &&
+ !evidence_presented) {
// shifted by 1 because 0 is no evidence per legacy standards
QString f_image = local_evidence_list.at(f_evi_id - 1).image;
QString f_evi_name = local_evidence_list.at(f_evi_id - 1).name;
@@ -2260,16 +2389,38 @@ void Courtroom::handle_chatmessage_3()
f_side == "jud" || f_side == "jur");
ui_vp_evidence_display->show_evidence(f_image, is_left_side,
ui_sfx_slider->value());
-
- log_ic_text(m_chatmessage[CHAR_NAME], m_chatmessage[SHOWNAME], f_evi_name, tr("has presented evidence"),
- m_chatmessage[TEXT_COLOR].toInt());
- append_ic_text(f_evi_name, f_showname, tr("has presented evidence"));
+ if (log_ic_actions) {
+ log_ic_text(m_chatmessage[CHAR_NAME], m_chatmessage[SHOWNAME], f_evi_name,
+ tr("has presented evidence"),
+ m_chatmessage[TEXT_COLOR].toInt());
+ append_ic_text(f_evi_name, f_showname, tr("has presented evidence"));
+ }
+ evidence_presented = true; // we're done presenting evidence, and we
+ // don't want to do it twice
}
int emote_mod = m_chatmessage[EMOTE_MOD].toInt();
QString side = m_chatmessage[SIDE];
+ switch(m_chatmessage[DESK_MOD].toInt()) {
+ case 4:
+ set_self_offset(m_chatmessage[SELF_OFFSET]);
+ [[fallthrough]];
+ case 2:
+ set_scene("1", m_chatmessage[SIDE]);
+ break;
+ case 5:
+ ui_vp_sideplayer_char->hide();
+ ui_vp_player_char->move(0, 0);
+ [[fallthrough]];
+ case 3:
+ set_scene("0", m_chatmessage[SIDE]);
+ break;
+ default:
+ set_scene(m_chatmessage[DESK_MOD], m_chatmessage[SIDE]);
+ break;
+ }
if (emote_mod == 5 || emote_mod == 6) {
ui_vp_desk->hide();
ui_vp_legacy_desk->hide();
@@ -2358,9 +2509,7 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos,
// If html is enabled, prepare this text to be all ready for it.
if (html) {
ic_color_stack.push(default_color);
- QString appendage = "<font color=\"" +
- color_rgb_list.at(default_color).name(QColor::HexRgb) +
- "\">";
+ QString appendage = "<font color=\"$c" + QString::number(default_color) + "\">";
if (!align.isEmpty())
appendage.prepend("<div align=" + align + ">");
@@ -2479,8 +2628,7 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos,
if (!ic_color_stack.empty())
appendage +=
- "<font color=\"" +
- color_rgb_list.at(ic_color_stack.top()).name(QColor::HexRgb) +
+ "<font color=\"$c" + QString::number(ic_color_stack.top()) +
"\">";
if (is_end && !skip) {
@@ -2568,10 +2716,9 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos,
}
void Courtroom::log_ic_text(QString p_name, QString p_showname,
- QString p_message, QString p_action, int p_color)
+ QString p_message, QString p_action, int p_color)
{
- chatlogpiece log_entry(p_name, p_showname, p_message, p_action,
- p_color);
+ 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->append_to_file(log_entry.get_full(), ao_app->log_filename, true);
@@ -2583,7 +2730,7 @@ void Courtroom::log_ic_text(QString p_name, QString p_showname,
}
void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
- int color)
+ int color, QDateTime timestamp)
{
QTextCharFormat bold;
QTextCharFormat normal;
@@ -2596,9 +2743,12 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
const QTextCursor old_cursor = ui_ic_chatlog->textCursor();
const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value();
const bool need_newline = !ui_ic_chatlog->document()->isEmpty();
- const int scrollbar_target_value = log_goes_downwards ? ui_ic_chatlog->verticalScrollBar()->maximum() : ui_ic_chatlog->verticalScrollBar()->minimum();
+ const int scrollbar_target_value =
+ log_goes_downwards ? ui_ic_chatlog->verticalScrollBar()->maximum()
+ : ui_ic_chatlog->verticalScrollBar()->minimum();
- ui_ic_chatlog->moveCursor(log_goes_downwards ? QTextCursor::End : QTextCursor::Start);
+ ui_ic_chatlog->moveCursor(log_goes_downwards ? QTextCursor::End
+ : QTextCursor::Start);
// Only prepend with newline if log goes downwards
if (log_goes_downwards && need_newline) {
@@ -2606,18 +2756,37 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
}
// Timestamp if we're doing that meme
- if (log_timestamp)
- ui_ic_chatlog->textCursor().insertText("[" + QDateTime::currentDateTime().toString("h:mm:ss AP") + "] ", normal);
+ if (log_timestamp) {
+ if (timestamp.isValid()) {
+ ui_ic_chatlog->textCursor().insertText(
+ "[" + timestamp.toString("h:mm:ss AP") + "] ", normal);
+ } else {
+ qDebug() << "could not insert invalid timestamp";
+ }
+ }
// Format the name of the actor
ui_ic_chatlog->textCursor().insertText(p_name, bold);
+ // Special case for stopping the music
+ if (p_action == tr("has stopped the music")) {
+ ui_ic_chatlog->textCursor().insertText(" " + p_action + ".", normal);
+ }
+ // Make shout text bold
+ else if (p_action == tr("shouts") && log_ic_actions) {
+ ui_ic_chatlog->textCursor().insertText(" " + p_action + " ", normal);
+ if (log_colors)
+ ui_ic_chatlog->textCursor().insertHtml("<b>" + filter_ic_text(p_text, true, -1, 0) + "</b>");
+ else
+ ui_ic_chatlog->textCursor().insertText(" " + p_text, italics);
+ }
// If action not blank:
- if (p_action != "") {
+ else if (p_action != "" && log_ic_actions) {
// Format the action in normal
ui_ic_chatlog->textCursor().insertText(" " + p_action, normal);
if (log_newline)
- // For some reason, we're forced to use <br> instead of the more sensible \n.
- // Why? Because \n is treated as a new Block instead of a soft newline within a paragraph!
+ // For some reason, we're forced to use <br> instead of the more sensible
+ // \n. Why? Because \n is treated as a new Block instead of a soft newline
+ // within a paragraph!
ui_ic_chatlog->textCursor().insertHtml("<br>");
else
ui_ic_chatlog->textCursor().insertText(": ", normal);
@@ -2626,14 +2795,21 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
}
else {
if (log_newline)
- // For some reason, we're forced to use <br> instead of the more sensible \n.
- // Why? Because \n is treated as a new Block instead of a soft newline within a paragraph!
+ // For some reason, we're forced to use <br> instead of the more sensible
+ // \n. Why? Because \n is treated as a new Block instead of a soft newline
+ // within a paragraph!
ui_ic_chatlog->textCursor().insertHtml("<br>");
else
ui_ic_chatlog->textCursor().insertText(": ", normal);
// Format the result according to html
- if (log_colors)
- ui_ic_chatlog->textCursor().insertHtml(filter_ic_text(p_text, true, -1, color));
+ if (log_colors) {
+ QString p_text_filtered = filter_ic_text(p_text, true, -1, color);
+ p_text_filtered = p_text_filtered.replace("$c0", ao_app->get_color("ic_chatlog_color", "courtroom_fonts.ini").name(QColor::HexRgb));
+ for (int c = 1; c < max_colors; ++c) {
+ p_text_filtered = p_text_filtered.replace("$c" + QString::number(c), default_color_rgb_list.at(c).name(QColor::HexRgb));
+ }
+ ui_ic_chatlog->textCursor().insertHtml(p_text_filtered);
+ }
else
ui_ic_chatlog->textCursor().insertText(filter_ic_text(p_text, false), normal);
}
@@ -2646,7 +2822,8 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
// If we got too many blocks in the current log, delete some.
while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks &&
log_maximum_blocks > 0) {
- ui_ic_chatlog->moveCursor(log_goes_downwards ? QTextCursor::Start : QTextCursor::End);
+ ui_ic_chatlog->moveCursor(log_goes_downwards ? QTextCursor::Start
+ : QTextCursor::End);
ui_ic_chatlog->textCursor().select(QTextCursor::BlockUnderCursor);
ui_ic_chatlog->textCursor().removeSelectedText();
if (log_goes_downwards)
@@ -2656,7 +2833,8 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
}
// Finally, scroll the scrollbar to the correct position.
- if (old_cursor.hasSelection() || old_scrollbar_value != scrollbar_target_value) {
+ if (old_cursor.hasSelection() ||
+ old_scrollbar_value != scrollbar_target_value) {
// The user has selected text or scrolled away from the bottom: maintain
// position.
ui_ic_chatlog->setTextCursor(old_cursor);
@@ -2665,13 +2843,14 @@ void Courtroom::append_ic_text(QString p_text, QString p_name, QString p_action,
else {
// The user hasn't selected any text and the scrollbar is at the bottom:
// scroll to the bottom.
- ui_ic_chatlog->moveCursor(log_goes_downwards ? QTextCursor::End : QTextCursor::Start);
+ ui_ic_chatlog->moveCursor(log_goes_downwards ? QTextCursor::End
+ : QTextCursor::Start);
ui_ic_chatlog->verticalScrollBar()->setValue(
- ui_ic_chatlog->verticalScrollBar()->maximum());
+ log_goes_downwards ? ui_ic_chatlog->verticalScrollBar()->maximum() : 0);
}
}
-void Courtroom::play_preanim(bool noninterrupting)
+void Courtroom::play_preanim(bool immediate)
{
QString f_char = m_chatmessage[CHAR_NAME];
QString f_preanim = m_chatmessage[PRE_EMOTE];
@@ -2693,7 +2872,7 @@ void Courtroom::play_preanim(bool noninterrupting)
QString anim_to_find =
ao_app->get_image_suffix(ao_app->get_character_path(f_char, f_preanim));
if (!file_exists(anim_to_find)) {
- if (noninterrupting)
+ if (immediate)
anim_state = 4;
else
anim_state = 1;
@@ -2704,7 +2883,7 @@ void Courtroom::play_preanim(bool noninterrupting)
ui_vp_player_char->play_pre(f_char, f_preanim, preanim_duration);
- if (noninterrupting)
+ if (immediate)
anim_state = 4;
else
anim_state = 1;
@@ -2712,7 +2891,7 @@ void Courtroom::play_preanim(bool noninterrupting)
if (text_delay >= 0)
text_delay_timer->start(text_delay);
- if (noninterrupting)
+ if (immediate)
handle_chatmessage_3();
}
@@ -2780,9 +2959,13 @@ void Courtroom::start_chat_ticking()
current_display_speed = 3;
chat_tick_timer->start(0); // Display the first char right away
- QString f_gender = ao_app->get_gender(m_chatmessage[CHAR_NAME]);
+ last_misc = current_misc;
+ current_misc = ao_app->get_char_shouts(m_chatmessage[CHAR_NAME]);
+ if (last_misc != current_misc)
+ gen_char_rgb_list(m_chatmessage[CHAR_NAME]);
- blip_player->set_blips(f_gender);
+ QString f_blips = ao_app->get_blips(m_chatmessage[CHAR_NAME]);
+ blip_player->set_blips(f_blips);
// means text is currently ticking
text_state = 1;
@@ -2814,9 +2997,11 @@ void Courtroom::chat_tick()
ui_vp_chat_arrow->play(
"chat_arrow", f_char,
f_custom_theme); // Chat stopped being processed, indicate that.
- additive_previous =
- additive_previous +
- filter_ic_text(f_message, true, -1, m_chatmessage[TEXT_COLOR].toInt());
+ QString f_message_filtered = filter_ic_text(f_message, true, -1, m_chatmessage[TEXT_COLOR].toInt());
+ for (int c = 0; c < max_colors; ++c) {
+ f_message_filtered = f_message_filtered.replace("$c" + QString::number(c), char_color_rgb_list.at(c).name(QColor::HexRgb));
+ }
+ additive_previous = additive_previous + f_message_filtered;
real_tick_pos = ui_vp_message->toPlainText().size();
return;
}
@@ -2929,9 +3114,11 @@ void Courtroom::chat_tick()
else {
int msg_delay = message_display_speed[current_display_speed];
// Do the colors, gradual showing, etc. in here
- ui_vp_message->setHtml(additive_previous +
- filter_ic_text(f_message, true, tick_pos,
- m_chatmessage[TEXT_COLOR].toInt()));
+ QString f_message_filtered = filter_ic_text(f_message, true, tick_pos, m_chatmessage[TEXT_COLOR].toInt());
+ for (int c = 0; c < max_colors; ++c) {
+ f_message_filtered = f_message_filtered.replace("$c" + QString::number(c), char_color_rgb_list.at(c).name(QColor::HexRgb));
+ }
+ ui_vp_message->setHtml(additive_previous + f_message_filtered);
// This should always be done AFTER setHtml. Scroll the chat window with the
// text.
@@ -2944,17 +3131,42 @@ void Courtroom::chat_tick()
ui_vp_message->ensureCursorVisible();
- // Blip player and real tick pos ticker
- if (!formatting_char && (f_character != ' ' || blank_blip)) {
- if (blip_ticker % blip_rate == 0) {
+ // We blip every "blip rate" letters.
+ // Here's an example with blank_blip being false and blip_rate being 2:
+ // I am you
+ // ! ! ! !
+ // where ! is the blip sound
+ int b_rate = blip_rate;
+ // Earrape prevention without using timers, this method is more consistent.
+ if (msg_delay != 0 && msg_delay <= 25) {
+ // The default blip speed is 40ms, and if current msg_delay is 25ms,
+ // the formula will result in the blip rate of:
+ // 40/25 = 1.6 = 2
+ // And if it's faster than that:
+ // 40/10 = 4
+ b_rate =
+ qMax(b_rate, qRound(static_cast<float>(message_display_speed[3]) /
+ msg_delay));
+ }
+ if (blip_ticker % b_rate == 0) {
+ // ignoring white space unless blank_blip is enabled.
+ if (!formatting_char && (f_character != ' ' || blank_blip)) {
blip_player->blip_tick();
+ ++blip_ticker;
}
+ }
+ else {
+ // Don't fully ignore whitespace still, keep ticking until
+ // we reached the need to play a blip sound - we also just
+ // need to wait for a letter to play it on.
++blip_ticker;
}
- // Punctuation delayer
- if (punctuation_chars.contains(f_character)) {
- msg_delay *= punctuation_modifier;
+ // Punctuation delayer, only kicks in on speed ticks less than }}
+ if (current_display_speed > 1 && punctuation_chars.contains(f_character)) {
+ // Making the user have to wait any longer than 150ms per letter is
+ // downright unreasonable
+ msg_delay = qMin(150, msg_delay * punctuation_modifier);
}
// If this color is talking
@@ -3001,8 +3213,16 @@ void Courtroom::play_sfx()
void Courtroom::set_scene(QString f_desk_mod, QString f_side)
{
// witness is default if pos is invalid
- QString f_background = "witnessempty";
- QString f_desk_image = "stand";
+ QString f_background;
+ QString f_desk_image;
+ if (file_exists(ao_app->get_image_suffix(ao_app->get_background_path("witnessempty")))) {
+ f_background = "witnessempty";
+ f_desk_image = "stand";
+ }
+ else {
+ f_background = "wit";
+ f_desk_image = "wit_overlay";
+ }
if (f_side == "def" && file_exists(ao_app->get_image_suffix(
ao_app->get_background_path("defenseempty")))) {
@@ -3067,6 +3287,17 @@ void Courtroom::set_scene(QString f_desk_mod, QString f_side)
}
}
+void Courtroom::set_self_offset(QString p_list) {
+ QStringList self_offsets = p_list.split("&");
+ int self_offset = self_offsets[0].toInt();
+ int self_offset_v;
+ if (self_offsets.length() <= 1)
+ self_offset_v = 0;
+ else
+ self_offset_v = self_offsets[1].toInt();
+ ui_vp_player_char->move(ui_viewport->width() * self_offset / 100, ui_viewport->height() * self_offset_v / 100);
+}
+
void Courtroom::set_ip_list(QString p_list)
{
QString f_list = p_list.replace("|", ":").replace("*", "\n");
@@ -3141,14 +3372,19 @@ void Courtroom::handle_song(QStringList *p_contents)
{
effect_flags = p_contents->at(5).toInt();
}
-
music_player->play(f_song, channel, looping, effect_flags);
- if (channel == 0)
- ui_music_name->setText(f_song_clear);
+ if (f_song == "~stop.mp3")
+ ui_music_name->setText(tr("None"));
+ else if (channel == 0) {
+ if (file_exists(ao_app->get_sfx_suffix(ao_app->get_music_path(f_song))))
+ ui_music_name->setText(f_song_clear);
+ else
+ ui_music_name->setText(tr("[MISSING] %1").arg(f_song_clear));
+ }
}
else {
QString str_char = char_list.at(n_char).name;
- QString str_show = char_list.at(n_char).name;
+ QString str_show = ao_app->get_showname(str_char);
if (p_contents->length() > 2) {
if (p_contents->at(2) != "") {
@@ -3170,13 +3406,25 @@ void Courtroom::handle_song(QStringList *p_contents)
}
if (!mute_map.value(n_char)) {
- log_ic_text(str_char, str_show, f_song, tr("has played a song"),
- m_chatmessage[TEXT_COLOR].toInt());
- append_ic_text(f_song_clear, str_show, tr("has played a song"));
-
+ if (f_song == "~stop.mp3") {
+ log_ic_text(str_char, str_show, "", tr("has stopped the music"),
+ m_chatmessage[TEXT_COLOR].toInt());
+ append_ic_text("", str_show, tr("has stopped the music"));
+ }
+ else {
+ log_ic_text(str_char, str_show, f_song, tr("has played a song"),
+ m_chatmessage[TEXT_COLOR].toInt());
+ append_ic_text(f_song_clear, str_show, tr("has played a song"));
+ }
music_player->play(f_song, channel, looping, effect_flags);
- if (channel == 0)
- ui_music_name->setText(f_song_clear);
+ if (f_song == "~stop.mp3")
+ ui_music_name->setText(tr("None"));
+ else if (channel == 0) {
+ if (file_exists(ao_app->get_sfx_suffix(ao_app->get_music_path(f_song))))
+ ui_music_name->setText(f_song_clear);
+ else
+ ui_music_name->setText(tr("[MISSING] %1").arg(f_song_clear));
+ }
}
}
}
@@ -3334,9 +3582,8 @@ void Courtroom::on_ooc_return_pressed()
if (ok) {
if (off >= -100 && off <= 100) {
char_offset = off;
- QString msg = tr("You have set your offset to ");
- msg.append(QString::number(off));
- msg.append("%.");
+ QString msg =
+ tr("You have set your offset to %1%%.").arg(QString::number(off));
append_server_chatmessage("CLIENT", msg, "1");
}
else {
@@ -3350,6 +3597,31 @@ void Courtroom::on_ooc_return_pressed()
}
return;
}
+ else if (ooc_message.startsWith("/voffset")) {
+ ui_ooc_chat_message->clear();
+ ooc_message.remove(0, 8);
+
+ bool ok;
+ int off = ooc_message.toInt(&ok);
+ if (ok) {
+ if (off >= -100 && off <= 100) {
+ char_vert_offset = off;
+ QString msg = tr("You have set your vertical offset to %1%%.")
+ .arg(QString::number(off));
+ append_server_chatmessage("CLIENT", msg, "1");
+ }
+ else {
+ append_server_chatmessage(
+ "CLIENT",
+ tr("Your vertical offset must be between -100% and 100%!"), "1");
+ }
+ }
+ else {
+ append_server_chatmessage(
+ "CLIENT", tr("That vertical offset does not look like one."), "1");
+ }
+ return;
+ }
else if (ooc_message.startsWith("/switch_am")) {
append_server_chatmessage(
"CLIENT", tr("You switched your music and area list."), "1");
@@ -3371,13 +3643,13 @@ void Courtroom::on_ooc_return_pressed()
return;
}
else if (ooc_message.startsWith("/non_int_pre")) {
- if (ui_pre_non_interrupt->isChecked())
+ if (ui_immediate->isChecked())
append_server_chatmessage(
"CLIENT", tr("Your pre-animations interrupt again."), "1");
else
append_server_chatmessage(
"CLIENT", tr("Your pre-animations will not interrupt text."), "1");
- ui_pre_non_interrupt->setChecked(!ui_pre_non_interrupt->isChecked());
+ ui_immediate->setChecked(!ui_immediate->isChecked());
ui_ooc_chat_message->clear();
return;
}
@@ -3458,9 +3730,10 @@ void Courtroom::on_ooc_return_pressed()
if (!caseauth.isEmpty())
append_server_chatmessage(tr("CLIENT"),
tr("Case made by %1.").arg(caseauth), "1");
- if (!casedoc.isEmpty())
- ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() +
- "#/doc " + casedoc + "#%"));
+ if (!casedoc.isEmpty()) {
+ QStringList f_contents = {ui_ooc_chat_name->text(), "/doc " + casedoc};
+ ao_app->send_server_packet(new AOPacket("CT", f_contents));
+ }
if (!casestatus.isEmpty())
ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() +
"#/status " + casestatus + "#%"));
@@ -3473,7 +3746,15 @@ void Courtroom::on_ooc_return_pressed()
new AOPacket("DE#" + QString::number(i) + "#%"));
}
- foreach (QString evi, casefile.childGroups()) {
+ // sort the case_evidence numerically
+ QStringList case_evidence = casefile.childGroups();
+ std::sort(case_evidence.begin(), case_evidence.end(),
+ [] (const QString &a, const QString &b) {
+ return a.toInt() < b.toInt();
+ });
+
+ // load evidence
+ foreach (QString evi, case_evidence) {
if (evi == "General")
continue;
@@ -3648,7 +3929,7 @@ void Courtroom::on_music_search_return_pressed()
void Courtroom::on_pos_dropdown_changed(int p_index)
{
- if (p_index < 0 || p_index > 7)
+ if (p_index < 0)
return;
toggle_judge_buttons(false);
@@ -3676,7 +3957,8 @@ void Courtroom::set_iniswap_dropdown()
return;
}
QStringList iniswaps = ao_app->get_list_file(
- ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini"));
+ ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini")) + ao_app->get_list_file(ao_app->get_base_path() + "iniswaps.ini");
+ iniswaps.removeDuplicates();
iniswaps.prepend(char_list.at(m_cid).name);
if (iniswaps.size() <= 0) {
ui_iniswap_dropdown->hide();
@@ -3706,14 +3988,15 @@ void Courtroom::on_iniswap_dropdown_changed(int p_index)
ao_app->set_char_ini(char_list.at(m_cid).name, iniswap, "name", "Options");
QStringList swaplist;
+ QStringList defswaplist = ao_app->get_list_file(ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini"));
for (int i = 0; i < ui_iniswap_dropdown->count(); ++i) {
QString entry = ui_iniswap_dropdown->itemText(i);
- if (!swaplist.contains(entry) && entry != char_list.at(m_cid).name)
+ if (!swaplist.contains(entry) && entry != char_list.at(m_cid).name && !defswaplist.contains(entry))
swaplist.append(entry);
}
ao_app->write_to_file(
swaplist.join("\n"),
- ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini"));
+ ao_app->get_base_path() + "iniswaps.ini");
ui_iniswap_dropdown->blockSignals(true);
ui_iniswap_dropdown->setCurrentIndex(p_index);
ui_iniswap_dropdown->blockSignals(false);
@@ -3728,6 +4011,7 @@ void Courtroom::on_iniswap_context_menu_requested(const QPoint &pos)
{
QMenu *menu = ui_iniswap_dropdown->lineEdit()->createStandardContextMenu();
+ menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addSeparator();
if (file_exists(ao_app->get_character_path(current_char, "char.ini")))
menu->addAction(QString("Edit " + current_char + "/char.ini"), this,
@@ -3787,6 +4071,7 @@ void Courtroom::set_sfx_dropdown()
ui_sfx_remove->hide();
return;
}
+ soundlist.prepend("Nothing");
soundlist.prepend("Default");
ui_sfx_dropdown->show();
@@ -3801,9 +4086,9 @@ void Courtroom::on_sfx_dropdown_changed(int p_index)
ui_ic_chat_message->setFocus();
QStringList soundlist;
- for (int i = 0; i < ui_sfx_dropdown->count(); ++i) {
+ for (int i = 2; i < ui_sfx_dropdown->count(); ++i) {
QString entry = ui_sfx_dropdown->itemText(i);
- if (!soundlist.contains(entry) && entry != "Default")
+ if (!soundlist.contains(entry))
soundlist.append(entry);
}
@@ -3825,7 +4110,7 @@ void Courtroom::on_sfx_dropdown_changed(int p_index)
ui_sfx_dropdown->blockSignals(true);
ui_sfx_dropdown->setCurrentIndex(p_index);
ui_sfx_dropdown->blockSignals(false);
- if (p_index != 0)
+ if (p_index > 1)
ui_sfx_remove->show();
else
ui_sfx_remove->hide();
@@ -3835,6 +4120,7 @@ void Courtroom::on_sfx_context_menu_requested(const QPoint &pos)
{
QMenu *menu = ui_sfx_dropdown->lineEdit()->createStandardContextMenu();
+ menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addSeparator();
if (file_exists(ao_app->get_character_path(current_char, "soundlist.ini")))
menu->addAction(QString("Edit " + current_char + "/soundlist.ini"), this,
@@ -3842,7 +4128,7 @@ void Courtroom::on_sfx_context_menu_requested(const QPoint &pos)
else
menu->addAction(QString("Edit theme's character_soundlist.ini"), this,
SLOT(on_sfx_edit_requested()));
- if (ui_sfx_dropdown->currentIndex() != 0)
+ if (ui_sfx_dropdown->currentIndex() > 1)
menu->addAction(QString("Remove " + ui_sfx_dropdown->itemText(
ui_sfx_dropdown->currentIndex())),
this, SLOT(on_sfx_remove_clicked()));
@@ -3870,7 +4156,7 @@ void Courtroom::on_sfx_remove_clicked()
// client will crash
return;
}
- if (ui_sfx_dropdown->itemText(ui_sfx_dropdown->currentIndex()) != "Default") {
+ if (ui_sfx_dropdown->currentIndex() > 1) {
ui_sfx_dropdown->removeItem(ui_sfx_dropdown->currentIndex());
on_sfx_dropdown_changed(0); // Reset back to original
}
@@ -3891,7 +4177,7 @@ void Courtroom::set_effects_dropdown()
return;
}
- effectslist.prepend("None");
+ effectslist.prepend(tr("None"));
ui_effects_dropdown->show();
ui_effects_dropdown->addItems(effectslist);
@@ -3922,8 +4208,9 @@ void Courtroom::set_effects_dropdown()
void Courtroom::on_effects_context_menu_requested(const QPoint &pos)
{
- QMenu *menu = new QMenu();
+ QMenu *menu = new QMenu(this);
+ menu->setAttribute(Qt::WA_DeleteOnClose);
if (!ao_app->read_char_ini(current_char, "effects", "Options").isEmpty())
menu->addAction(
QString("Open misc/" +
@@ -3976,6 +4263,8 @@ bool Courtroom::effects_dropdown_find_and_set(QString effect)
QString Courtroom::get_char_sfx()
{
QString sfx = ui_sfx_dropdown->itemText(ui_sfx_dropdown->currentIndex());
+ if (sfx == "Nothing")
+ return "1";
if (sfx != "" && sfx != "Default")
return sfx;
return ao_app->get_sfx_name(current_char, current_emote);
@@ -4069,10 +4358,10 @@ void Courtroom::on_music_list_double_clicked(QTreeWidgetItem *p_item,
{
if (is_muted)
return;
-
+ if (p_item->parent() == nullptr) // i.e. we've clicked a category
+ return;
column = 1; // Column 1 is always the metadata (which we want)
QString p_song = p_item->text(column);
-
QStringList packet_contents;
packet_contents.append(p_song);
packet_contents.append(QString::number(m_cid));
@@ -4086,8 +4375,9 @@ void Courtroom::on_music_list_double_clicked(QTreeWidgetItem *p_item,
void Courtroom::on_music_list_context_menu_requested(const QPoint &pos)
{
- QMenu *menu = new QMenu();
-
+ QMenu *menu = new QMenu(this);
+ menu->setAttribute(Qt::WA_DeleteOnClose);
+ menu->addAction(QString(tr("Stop Current Song")), this, SLOT(music_stop()));
menu->addAction(QString(tr("Play Random Song")), this, SLOT(music_random()));
menu->addSeparator();
menu->addAction(QString(tr("Expand All Categories")), this,
@@ -4148,11 +4438,14 @@ void Courtroom::music_random()
QTreeWidgetItemIterator::NotHidden |
QTreeWidgetItemIterator::NoChildren);
while (*it) {
- clist += (*it);
+ if ((*it)->parent()->isExpanded()) {
+ clist += (*it);
+ }
++it;
}
- int i = qrand() % clist.length();
- on_music_list_double_clicked(clist.at(i), 1);
+ if (clist.length() == 0)
+ return;
+ on_music_list_double_clicked(clist.at(qrand() % clist.length()), 1);
}
void Courtroom::music_list_expand_all() { ui_music_list->expandAll(); }
@@ -4165,6 +4458,22 @@ void Courtroom::music_list_collapse_all()
ui_music_list->setCurrentItem(current);
}
+void Courtroom::music_stop()
+{ // send a fake music packet with a nonexistent song
+ if (is_muted) // this requires a special exception for "~stop.mp3" in
+ return; // tsuserver3, as it will otherwise reject songs not on
+ QStringList packet_contents; // its music list
+ packet_contents.append(
+ "~stop.mp3"); // this is our fake song, playing it triggers special code
+ packet_contents.append(QString::number(m_cid));
+ if ((!ui_ic_chat_name->text().isEmpty() && ao_app->cccc_ic_support_enabled) ||
+ ao_app->effects_enabled)
+ packet_contents.append(ui_ic_chat_name->text());
+ if (ao_app->effects_enabled)
+ packet_contents.append(QString::number(music_flags));
+ ao_app->send_server_packet(new AOPacket("MC", packet_contents), false);
+}
+
void Courtroom::on_area_list_double_clicked(QTreeWidgetItem *p_item, int column)
{
column = 0; // The metadata
@@ -4258,10 +4567,16 @@ void Courtroom::show_custom_objection_menu(const QPoint &pos)
ui_take_that->set_image("takethat");
ui_hold_it->set_image("holdit");
ui_custom_objection->set_image("custom_selected");
- if (selecteditem->text() == "Default")
+ if (selecteditem->text() == ao_app->read_char_ini(current_char, "custom_name", "Shouts") || selecteditem->text() == "Default")
objection_custom = "";
- else
- objection_custom = selecteditem->text();
+ else {
+ foreach (CustomObjection custom_objection, custom_objections_list) {
+ if (custom_objection.name == selecteditem->text()) {
+ objection_custom = custom_objection.filename;
+ break;
+ }
+ }
+ }
objection_state = 4;
custom_obj_menu->setDefaultAction(selecteditem);
}
@@ -4306,6 +4621,7 @@ void Courtroom::on_mute_clicked()
ui_mute_list->show();
ui_pair_list->hide();
ui_pair_offset_spinbox->hide();
+ ui_pair_vert_offset_spinbox->hide();
ui_pair_order_dropdown->hide();
ui_pair_button->set_image("pair_button");
ui_mute->set_image("mute_pressed");
@@ -4321,6 +4637,8 @@ void Courtroom::on_pair_clicked()
if (ui_pair_list->isHidden()) {
ui_pair_list->show();
ui_pair_offset_spinbox->show();
+ if(ao_app->y_offset_enabled)
+ ui_pair_vert_offset_spinbox->show();
ui_pair_order_dropdown->show();
ui_mute_list->hide();
ui_mute->set_image("mute");
@@ -4329,6 +4647,7 @@ void Courtroom::on_pair_clicked()
else {
ui_pair_list->hide();
ui_pair_offset_spinbox->hide();
+ ui_pair_vert_offset_spinbox->hide();
ui_pair_order_dropdown->hide();
ui_pair_button->set_image("pair_button");
}
@@ -4383,6 +4702,7 @@ void Courtroom::set_text_color_dropdown()
// Clear the stored optimization information
color_rgb_list.clear();
+ default_color_rgb_list.clear();
color_markdown_start_list.clear();
color_markdown_end_list.clear();
color_markdown_remove_list.clear();
@@ -4419,6 +4739,18 @@ void Courtroom::set_text_color_dropdown()
ui_text_color->setItemIcon(ui_text_color->count() - 1, QIcon(pixmap));
color_row_to_number.append(c);
}
+ for (int c = 0; c < max_colors; ++c) {
+ QColor color = ao_app->get_chat_color("c" + QString::number(c), "default");
+ default_color_rgb_list.append(color);
+ }
+}
+
+void Courtroom::gen_char_rgb_list(QString p_char) {
+ char_color_rgb_list.clear();
+ for (int c = 0; c < max_colors; ++c) {
+ QColor color = ao_app->get_chat_color("c" + QString::number(c), p_char);
+ char_color_rgb_list.append(color);
+ }
}
void Courtroom::on_text_color_changed(int p_color)
@@ -4485,6 +4817,11 @@ void Courtroom::on_log_limit_changed(int value) { log_maximum_blocks = value; }
void Courtroom::on_pair_offset_changed(int value) { char_offset = value; }
+void Courtroom::on_pair_vert_offset_changed(int value)
+{
+ char_vert_offset = value;
+}
+
void Courtroom::on_witness_testimony_clicked()
{
if (is_muted)
@@ -4640,8 +4977,11 @@ void Courtroom::regenerate_ic_chatlog()
{
ui_ic_chatlog->clear();
foreach (chatlogpiece item, ic_chatlog_history) {
- append_ic_text(item.get_message(), ui_showname_enable->isChecked() ? item.get_showname() : item.get_name(),
- item.get_action(), item.get_chat_color());
+ append_ic_text(item.get_message(),
+ ui_showname_enable->isChecked() ? item.get_showname()
+ : item.get_name(),
+ item.get_action(), item.get_chat_color(),
+ item.get_datetime().toLocalTime());
}
}
@@ -4756,6 +5096,75 @@ void Courtroom::set_clock_visibility(bool visible)
ui_clock->setVisible(visible);
}
+void Courtroom::truncate_label_text(QWidget *p_widget, QString p_identifier)
+{
+ QString filename = "courtroom_design.ini";
+ pos_size_type design_ini_result =
+ ao_app->get_element_dimensions(p_identifier, filename);
+ // Get the width of the element as defined by the current theme
+
+ // Cast to make sure we're working with one of the two supported widget types
+ QLabel *p_label = qobject_cast<QLabel *>(p_widget);
+ QCheckBox *p_checkbox = qobject_cast<QCheckBox *>(p_widget);
+
+ if (p_checkbox == nullptr &&
+ p_label ==
+ nullptr) { // i.e. the given p_widget isn't a QLabel or a QCheckBox
+ qWarning() << "W: Tried to truncate an unsupported widget:" << p_identifier;
+ return;
+ }
+ // translate the text for the widget we're working with so we truncate the right string
+ QString label_text_tr =
+ QCoreApplication::translate(p_widget->metaObject()->className(), "%1")
+ .arg((p_label != nullptr ? p_label->text() : p_checkbox->text()));
+ int label_theme_width =
+ (p_label != nullptr
+ ? design_ini_result.width
+ : design_ini_result.width -
+ 18); // 18 is the width of a checkbox on win10 + 5px of
+ // padding, TODO: fetch the actual size
+ int label_px_width =
+ p_widget->fontMetrics().boundingRect(label_text_tr).width(); // pixel width of our translated text
+ p_widget->setToolTip(label_text_tr + "\n" + p_widget->toolTip());
+ // qInfo() << "I: Width of label text: " << label_px_width << "px. Theme's
+ // width: " << label_theme_width << "px.";
+
+ // we can't do much with a 0-width widget, and there's no need to truncate if
+ // the theme gives us enough space
+ if (label_theme_width <= 0 || label_px_width < label_theme_width) {
+ qInfo() << "I: Truncation aborted for label text " << label_text_tr
+ << ", either theme width <= 0 or label width < theme width.";
+ return;
+ }
+
+ QString truncated_label = label_text_tr;
+ int truncated_px_width = label_px_width;
+ while (truncated_px_width > label_theme_width && truncated_label != "…") {
+ truncated_label.chop(2);
+ truncated_label.append("…");
+ // qInfo() << "I: Attempted to truncate label to string: " <<
+ // truncated_label;
+ truncated_px_width =
+ p_widget->fontMetrics().boundingRect(truncated_label).width();
+ }
+ if (truncated_label == "…") {
+ // Safeguard against edge case where label text is shorter in px than '…',
+ // causing an infinite loop. Additionally, having just an ellipse for a
+ // label looks strange, so we don't set the new label.
+ qWarning() << "W: Potential infinite loop prevented: Label text "
+ << label_text_tr
+ << "truncated to '…', so truncation was aborted.";
+ return;
+ }
+ if (p_label != nullptr)
+ p_label->setText(truncated_label);
+ else if (p_checkbox != nullptr)
+ p_checkbox->setText(truncated_label);
+ qInfo() << "I: Truncated label text from " << label_text_tr << " ("
+ << label_px_width << "px ) to " << truncated_label << " ("
+ << truncated_px_width << "px )";
+}
+
Courtroom::~Courtroom()
{
delete music_player;