Overhaul sound lists to introduce aliases, rethink editing behavior (#389)

* Resolve https://github.com/AttorneyOnline/AO2-Client/issues/275 by adding a "Nothing" option to play no SFX even when playing a preanimation that behaves similar to the Default option

* Overhaul sound list:
* Allow aliases. .ini file syntax is "filename = alias".
* Do not allow editing the .ini files from the client anymore.
* The sound list dropdown is still editable, but all it does is play your custom sfx without adding it to any files.
* Overhaul get_char_sfx

* Fix aliases not working properly with a rather tricky solution

* save character soundlist in base and drop the character_ from the filename

Co-authored-by: stonedDiscord <10584181+stonedDiscord@users.noreply.github.com>
This commit is contained in:
Crystalwarrior 2021-01-14 01:34:20 +03:00 committed by GitHub
parent 8fb87c9f3a
commit 147892bae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 84 deletions

View File

@ -503,6 +503,12 @@ private:
// List of all currently available pos // List of all currently available pos
QStringList pos_dropdown_list; QStringList pos_dropdown_list;
// Current list file sorted line by line
QStringList sound_list;
// Current SFX the user put in for the sfx dropdown list
QString custom_sfx = "";
// is the message we're about to send supposed to present evidence? // is the message we're about to send supposed to present evidence?
bool is_presenting_evidence = false; bool is_presenting_evidence = false;
@ -804,6 +810,7 @@ private slots:
void on_iniswap_remove_clicked(); void on_iniswap_remove_clicked();
void on_sfx_dropdown_changed(int p_index); void on_sfx_dropdown_changed(int p_index);
void on_sfx_dropdown_custom(QString p_sfx);
void set_sfx_dropdown(); void set_sfx_dropdown();
void on_sfx_context_menu_requested(const QPoint &pos); void on_sfx_context_menu_requested(const QPoint &pos);
void on_sfx_edit_requested(); void on_sfx_edit_requested();

View File

@ -299,6 +299,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
connect(ui_sfx_dropdown, SIGNAL(currentIndexChanged(int)), this, connect(ui_sfx_dropdown, SIGNAL(currentIndexChanged(int)), this,
SLOT(on_sfx_dropdown_changed(int))); SLOT(on_sfx_dropdown_changed(int)));
connect(ui_sfx_dropdown, SIGNAL(editTextChanged(QString)), this,
SLOT(on_sfx_dropdown_custom(QString)));
connect(ui_sfx_dropdown, SIGNAL(customContextMenuRequested(QPoint)), this, connect(ui_sfx_dropdown, SIGNAL(customContextMenuRequested(QPoint)), this,
SLOT(on_sfx_context_menu_requested(QPoint))); SLOT(on_sfx_context_menu_requested(QPoint)));
connect(ui_sfx_remove, SIGNAL(clicked()), this, connect(ui_sfx_remove, SIGNAL(clicked()), this,
@ -731,7 +733,7 @@ void Courtroom::set_widgets()
set_size_and_pos(ui_sfx_dropdown, "sfx_dropdown"); set_size_and_pos(ui_sfx_dropdown, "sfx_dropdown");
ui_sfx_dropdown->setEditable(true); ui_sfx_dropdown->setEditable(true);
ui_sfx_dropdown->setInsertPolicy(QComboBox::InsertAtBottom); ui_sfx_dropdown->setInsertPolicy(QComboBox::NoInsert);
ui_sfx_dropdown->setToolTip( ui_sfx_dropdown->setToolTip(
tr("Set a sound effect to play on your next 'Preanim'. Leaving it on " tr("Set a sound effect to play on your next 'Preanim'. Leaving it on "
"Default will use the emote-defined sound (if any).\n" "Default will use the emote-defined sound (if any).\n"
@ -1625,7 +1627,7 @@ void Courtroom::on_chat_return_pressed()
return; return;
ui_ic_chat_message->blockSignals(true); ui_ic_chat_message->blockSignals(true);
QTimer::singleShot(200, this, QTimer::singleShot(600, this,
[=] { ui_ic_chat_message->blockSignals(false); }); [=] { ui_ic_chat_message->blockSignals(false); });
// MS# // MS#
// deskmod# // deskmod#
@ -1684,12 +1686,6 @@ void Courtroom::on_chat_return_pressed()
packet_contents.append(current_side); packet_contents.append(current_side);
packet_contents.append(get_char_sfx()); packet_contents.append(get_char_sfx());
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);
ui_sfx_remove->hide();
}
int f_emote_mod = ao_app->get_emote_mod(current_char, current_emote); int f_emote_mod = ao_app->get_emote_mod(current_char, current_emote);
@ -1865,8 +1861,6 @@ void Courtroom::reset_ui()
realization_state = 0; realization_state = 0;
screenshake_state = 0; screenshake_state = 0;
is_presenting_evidence = false; is_presenting_evidence = false;
if (!ao_app->is_stickypres_enabled())
ui_pre->setChecked(false);
ui_hold_it->set_image("holdit"); ui_hold_it->set_image("holdit");
ui_objection->set_image("objection"); ui_objection->set_image("objection");
ui_take_that->set_image("takethat"); ui_take_that->set_image("takethat");
@ -1874,6 +1868,14 @@ void Courtroom::reset_ui()
ui_realization->set_image("realization"); ui_realization->set_image("realization");
ui_screenshake->set_image("screenshake"); ui_screenshake->set_image("screenshake");
ui_evidence_present->set_image("present"); ui_evidence_present->set_image("present");
if (ui_pre->isChecked() && !ao_app->is_stickysounds_enabled()) {
ui_sfx_dropdown->setCurrentIndex(0);
ui_sfx_remove->hide();
custom_sfx = "";
}
if (!ao_app->is_stickypres_enabled())
ui_pre->setChecked(false);
} }
void Courtroom::chatmessage_enqueue(QStringList p_contents) void Courtroom::chatmessage_enqueue(QStringList p_contents)
@ -4322,28 +4324,28 @@ void Courtroom::set_sfx_dropdown()
ui_sfx_remove->hide(); ui_sfx_remove->hide();
return; return;
} }
QStringList soundlist = ao_app->get_list_file( sound_list = ao_app->get_list_file(
ao_app->get_character_path(current_char, "soundlist.ini")); ao_app->get_character_path(current_char, "soundlist.ini"));
if (soundlist.size() <= 0) { if (sound_list.size() <= 0) {
soundlist = ao_app->get_list_file( sound_list = ao_app->get_list_file(
ao_app->get_theme_path("character_soundlist.ini")); ao_app->get_base_path() + "soundlist.ini");
if (soundlist.size() <= 0) {
soundlist = ao_app->get_list_file(
ao_app->get_default_theme_path("character_soundlist.ini"));
}
} }
if (soundlist.size() <= 0) { QStringList display_sounds;
ui_sfx_dropdown->hide(); for (QString sound : sound_list) {
ui_sfx_remove->hide(); QStringList unpacked = sound.split("=");
return; QString display = unpacked[0].trimmed();
if (unpacked.size() > 1)
display = unpacked[1].trimmed();
display_sounds.append(display);
} }
soundlist.prepend("Nothing"); display_sounds.prepend("Nothing");
soundlist.prepend("Default"); display_sounds.prepend("Default");
ui_sfx_dropdown->show(); ui_sfx_dropdown->show();
ui_sfx_dropdown->addItems(soundlist); ui_sfx_dropdown->addItems(display_sounds);
ui_sfx_dropdown->setCurrentIndex(0); ui_sfx_dropdown->setCurrentIndex(0);
ui_sfx_remove->hide(); ui_sfx_remove->hide();
ui_sfx_dropdown->blockSignals(false); ui_sfx_dropdown->blockSignals(false);
@ -4352,36 +4354,14 @@ void Courtroom::set_sfx_dropdown()
void Courtroom::on_sfx_dropdown_changed(int p_index) void Courtroom::on_sfx_dropdown_changed(int p_index)
{ {
ui_ic_chat_message->setFocus(); ui_ic_chat_message->setFocus();
QStringList soundlist;
for (int i = 2; i < ui_sfx_dropdown->count(); ++i) {
QString entry = ui_sfx_dropdown->itemText(i);
if (!soundlist.contains(entry))
soundlist.append(entry);
}
QStringList defaultlist =
ao_app->get_list_file(ao_app->get_theme_path("character_soundlist.ini"));
if (defaultlist.size() <= 0) {
defaultlist = ao_app->get_list_file(
ao_app->get_default_theme_path("character_soundlist.ini"));
}
if (defaultlist.size() > 0 &&
defaultlist.toSet().subtract(soundlist.toSet()).size() >
0) // There's a difference from the default configuration
ao_app->write_to_file(
soundlist.join("\n"),
ao_app->get_character_path(current_char,
"soundlist.ini")); // Create a new sound list
ui_sfx_dropdown->blockSignals(true);
ui_sfx_dropdown->setCurrentIndex(p_index);
ui_sfx_dropdown->blockSignals(false);
if (p_index > 1)
ui_sfx_remove->show();
else
ui_sfx_remove->hide(); ui_sfx_remove->hide();
custom_sfx = "";
}
void Courtroom::on_sfx_dropdown_custom(QString p_sfx)
{
ui_sfx_remove->show();
custom_sfx = p_sfx;
} }
void Courtroom::on_sfx_context_menu_requested(const QPoint &pos) void Courtroom::on_sfx_context_menu_requested(const QPoint &pos)
@ -4394,40 +4374,27 @@ void Courtroom::on_sfx_context_menu_requested(const QPoint &pos)
menu->addAction(QString("Edit " + current_char + "/soundlist.ini"), this, menu->addAction(QString("Edit " + current_char + "/soundlist.ini"), this,
SLOT(on_sfx_edit_requested())); SLOT(on_sfx_edit_requested()));
else else
menu->addAction(QString("Edit theme's character_soundlist.ini"), this, menu->addAction(QString("Edit global soundlist.ini"), this,
SLOT(on_sfx_edit_requested())); SLOT(on_sfx_edit_requested()));
if (ui_sfx_dropdown->currentIndex() > 1) if (!custom_sfx.isEmpty())
menu->addAction(QString("Remove " + ui_sfx_dropdown->itemText( menu->addAction(QString("Clear Edit Text"), this, SLOT(on_sfx_remove_clicked()));
ui_sfx_dropdown->currentIndex())),
this, SLOT(on_sfx_remove_clicked()));
menu->popup(ui_sfx_dropdown->mapToGlobal(pos)); menu->popup(ui_sfx_dropdown->mapToGlobal(pos));
} }
void Courtroom::on_sfx_edit_requested() void Courtroom::on_sfx_edit_requested()
{ {
QString p_path = ao_app->get_character_path(current_char, "soundlist.ini"); QString p_path = ao_app->get_character_path(current_char, "soundlist.ini");
if (!file_exists(p_path)) { if (!file_exists(p_path)) {
p_path = ao_app->get_theme_path("character_soundlist.ini"); p_path = ao_app->get_base_path() + "soundlist.ini";
if (!file_exists(p_path)) {
p_path = ao_app->get_default_theme_path("character_soundlist.ini");
if (!file_exists(p_path)) {
return;
}
}
} }
QDesktopServices::openUrl(QUrl::fromLocalFile(p_path)); QDesktopServices::openUrl(QUrl::fromLocalFile(p_path));
} }
void Courtroom::on_sfx_remove_clicked() void Courtroom::on_sfx_remove_clicked()
{ {
if (ui_sfx_dropdown->count() <= 0) { ui_sfx_remove->hide();
ui_sfx_remove->hide(); // We're not supposed to see it. Do this or the ui_sfx_dropdown->setCurrentIndex(0);
// client will crash custom_sfx = "";
return;
}
if (ui_sfx_dropdown->currentIndex() > 1) {
ui_sfx_dropdown->removeItem(ui_sfx_dropdown->currentIndex());
on_sfx_dropdown_changed(0); // Reset back to original
}
} }
void Courtroom::set_effects_dropdown() void Courtroom::set_effects_dropdown()
@ -4530,19 +4497,21 @@ bool Courtroom::effects_dropdown_find_and_set(QString effect)
QString Courtroom::get_char_sfx() QString Courtroom::get_char_sfx()
{ {
QString sfx = ui_sfx_dropdown->itemText(ui_sfx_dropdown->currentIndex()); if (!custom_sfx.isEmpty())
if (sfx == "Nothing") return custom_sfx;
return "1"; int index = ui_sfx_dropdown->currentIndex();
if (sfx != "" && sfx != "Default") if (index == 0) // Default
return sfx;
return ao_app->get_sfx_name(current_char, current_emote); return ao_app->get_sfx_name(current_char, current_emote);
if (index == 1) // Nothing
return "1";
QString sfx = sound_list[index-2].split("=")[0].trimmed();
if (sfx == "")
return "1";
return sfx;
} }
int Courtroom::get_char_sfx_delay() int Courtroom::get_char_sfx_delay()
{ {
// QString sfx = ui_sfx_dropdown->itemText(ui_sfx_dropdown->currentIndex());
// if (sfx != "" && sfx != "Default")
// return 0; //todo: a way to define this
return ao_app->get_sfx_delay(current_char, current_emote); return ao_app->get_sfx_delay(current_char, current_emote);
} }