Stop iniswapping from modifying the char.ini file (#712)

* Stop iniswapping from modifying the char.ini (which can potentially remove comments such as credits, charmaker notes, etc.)
* Fix iniswaps.ini and soundlist.ini not using vpath
* Deprecate get_char_name, making "name=" part in the char.ini no longer a thing
* Fix iniswap and emote dropdowns not getting properly updated when theme is reloaded
* Prevent reload theme from resetting your emote to the first one
* Fallback soundlist.ini

Co-authored-by: stonedDiscord <Tukz@gmx.de>
Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
This commit is contained in:
Crystalwarrior 2022-07-30 03:45:42 +03:00 committed by GitHub
parent e36d79f749
commit f896475de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 23 deletions

View File

@ -435,9 +435,6 @@ public:
// Returns whether the given pos is a judge position // Returns whether the given pos is a judge position
bool get_pos_is_judge(const QString &p_pos); bool get_pos_is_judge(const QString &p_pos);
// Returns the name of p_char
QString get_char_name(QString p_char);
// Returns the total amount of emotes of p_char // Returns the total amount of emotes of p_char
int get_emote_number(QString p_char); int get_emote_number(QString p_char);

View File

@ -213,7 +213,8 @@ public:
QString get_current_background() { return current_background; } QString get_current_background() { return current_background; }
// updates character to p_cid and updates necessary ui elements // updates character to p_cid and updates necessary ui elements
void update_character(int p_cid); // Optional "char_name" is the iniswap we're using
void update_character(int p_cid, QString char_name = "", bool reset_emote = false);
// properly sets up some varibles: resets user state // properly sets up some varibles: resets user state
void enter_courtroom(); void enter_courtroom();

View File

@ -1469,7 +1469,7 @@ void Courtroom::set_pos_dropdown(QStringList pos_dropdowns)
set_side(current_side); set_side(current_side);
} }
void Courtroom::update_character(int p_cid) void Courtroom::update_character(int p_cid, QString char_name, bool reset_emote)
{ {
bool newchar = m_cid != p_cid; bool newchar = m_cid != p_cid;
@ -1483,7 +1483,10 @@ void Courtroom::update_character(int p_cid)
f_char = ""; f_char = "";
} }
else { else {
f_char = ao_app->get_char_name(char_list.at(m_cid).name); f_char = char_name;
if (char_name.isEmpty()) {
f_char = char_list.at(m_cid).name;
}
if (ao_app->is_discord_enabled()) if (ao_app->is_discord_enabled())
ao_app->discord->state_character(f_char.toStdString()); ao_app->discord->state_character(f_char.toStdString());
@ -1494,8 +1497,11 @@ void Courtroom::update_character(int p_cid)
set_text_color_dropdown(); set_text_color_dropdown();
current_emote_page = 0; // If our cid changed or we're being told to reset
current_emote = 0; if (newchar || reset_emote) {
current_emote_page = 0;
current_emote = 0;
}
if (m_cid == -1) if (m_cid == -1)
ui_emotes->hide(); ui_emotes->hide();
@ -4476,9 +4482,6 @@ void Courtroom::set_iniswap_dropdown()
ao_app->get_list_file(ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini")) + ao_app->get_list_file(ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini")) +
ao_app->get_list_file(VPath("iniswaps.ini")); ao_app->get_list_file(VPath("iniswaps.ini"));
if (ao_app->get_char_name(char_list.at(m_cid).name) != char_list.at(m_cid).name)
iniswaps.append(ao_app->get_char_name(char_list.at(m_cid).name));
iniswaps.prepend(char_list.at(m_cid).name); iniswaps.prepend(char_list.at(m_cid).name);
iniswaps.removeDuplicates(); iniswaps.removeDuplicates();
if (iniswaps.size() <= 0) { if (iniswaps.size() <= 0) {
@ -4507,7 +4510,6 @@ void Courtroom::on_iniswap_dropdown_changed(int p_index)
{ {
ui_ic_chat_message->setFocus(); ui_ic_chat_message->setFocus();
QString iniswap = ui_iniswap_dropdown->itemText(p_index); QString iniswap = ui_iniswap_dropdown->itemText(p_index);
ao_app->set_char_ini(char_list.at(m_cid).name, iniswap, "name", "Options");
QStringList swaplist; QStringList swaplist;
QStringList defswaplist = ao_app->get_list_file(ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini")); QStringList defswaplist = ao_app->get_list_file(ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini"));
@ -4524,7 +4526,7 @@ void Courtroom::on_iniswap_dropdown_changed(int p_index)
ui_iniswap_dropdown->blockSignals(true); ui_iniswap_dropdown->blockSignals(true);
ui_iniswap_dropdown->setCurrentIndex(p_index); ui_iniswap_dropdown->setCurrentIndex(p_index);
ui_iniswap_dropdown->blockSignals(false); ui_iniswap_dropdown->blockSignals(false);
update_character(m_cid); update_character(m_cid, iniswap, true);
QString icon_path = ao_app->get_image_suffix(ao_app->get_character_path( QString icon_path = ao_app->get_image_suffix(ao_app->get_character_path(
iniswap, "char_icon")); iniswap, "char_icon"));
ui_iniswap_dropdown->setItemIcon(p_index, QIcon(icon_path)); ui_iniswap_dropdown->setItemIcon(p_index, QIcon(icon_path));
@ -5407,7 +5409,7 @@ void Courtroom::on_reload_theme_clicked()
set_courtroom_size(); set_courtroom_size();
set_widgets(); set_widgets();
update_character(m_cid); update_character(m_cid, ui_iniswap_dropdown->itemText(ui_iniswap_dropdown->currentIndex()));
enter_courtroom(); enter_courtroom();
gen_char_rgb_list(ao_app->get_chat(current_char)); gen_char_rgb_list(ao_app->get_chat(current_char));

View File

@ -173,6 +173,9 @@ void Courtroom::set_emote_dropdown()
current_char, "emotions/button" + QString::number(n + 1) + "_off")); current_char, "emotions/button" + QString::number(n + 1) + "_off"));
ui_emote_dropdown->setItemIcon(n, QIcon(icon_path)); ui_emote_dropdown->setItemIcon(n, QIcon(icon_path));
} }
if (current_emote > -1 && current_emote < ui_emote_dropdown->count()) {
ui_emote_dropdown->setCurrentIndex(current_emote);
}
} }
void Courtroom::select_emote(int p_id) void Courtroom::select_emote(int p_id)

View File

@ -600,6 +600,7 @@ void AOApplication::set_char_ini(QString p_char, QString value,
{ {
QSettings settings(get_real_path(get_character_path(p_char, "char.ini")), QSettings settings(get_real_path(get_character_path(p_char, "char.ini")),
QSettings::IniFormat); QSettings::IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup(target_tag); settings.beginGroup(target_tag);
settings.setValue(p_search_line, value); settings.setValue(p_search_line, value);
settings.endGroup(); settings.endGroup();
@ -623,15 +624,6 @@ QStringList AOApplication::read_ini_tags(VPath p_path, QString target_tag)
return r_values; return r_values;
} }
QString AOApplication::get_char_name(QString p_char)
{
QString f_result = read_char_ini(p_char, "name", "Options");
if (f_result == "")
return p_char;
return f_result;
}
QString AOApplication::get_showname(QString p_char) QString AOApplication::get_showname(QString p_char)
{ {
QString f_result = read_char_ini(p_char, "showname", "Options"); QString f_result = read_char_ini(p_char, "showname", "Options");