Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop iniswapping from modifying the char.ini file #712

Merged
merged 17 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ class Courtroom : public QMainWindow {
QString get_current_background() { return current_background; }

// updates character to p_cid and updates necessary ui elements
void update_character(int p_cid);
// Otptional "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
void enter_courtroom();
Expand Down
19 changes: 12 additions & 7 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ void Courtroom::set_pos_dropdown(QStringList pos_dropdowns)
set_side(current_side);
}

void Courtroom::update_character(int p_cid)
void Courtroom::update_character(int p_cid, QString char_name, bool reset_emote)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does cid matter if we know that char_name is going to override it? I think this CID thing is really a vestigial part of the protocol at this point and we should seclude it to some packet handler.

Likewise, instead of adding reset_emote we can extract a method for that.

Crystalwarrior marked this conversation as resolved.
Show resolved Hide resolved
Crystalwarrior marked this conversation as resolved.
Show resolved Hide resolved
{
bool newchar = m_cid != p_cid;

Expand All @@ -1478,7 +1478,10 @@ void Courtroom::update_character(int p_cid)
f_char = "";
}
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())
ao_app->discord->state_character(f_char.toStdString());
Expand All @@ -1489,8 +1492,11 @@ void Courtroom::update_character(int p_cid)

set_text_color_dropdown();

current_emote_page = 0;
current_emote = 0;
// If our cid changed or we're being told to reset
if (newchar || reset_emote) {
current_emote_page = 0;
current_emote = 0;
}

if (m_cid == -1)
ui_emotes->hide();
Expand Down Expand Up @@ -4400,7 +4406,6 @@ void Courtroom::on_iniswap_dropdown_changed(int p_index)
{
ui_ic_chat_message->setFocus();
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 defswaplist = ao_app->get_list_file(ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini"));
Expand All @@ -4415,7 +4420,7 @@ void Courtroom::on_iniswap_dropdown_changed(int p_index)
ui_iniswap_dropdown->blockSignals(true);
ui_iniswap_dropdown->setCurrentIndex(p_index);
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(
iniswap, "char_icon"));
ui_iniswap_dropdown->setItemIcon(p_index, QIcon(icon_path));
Expand Down Expand Up @@ -5287,7 +5292,7 @@ void Courtroom::on_reload_theme_clicked()

set_courtroom_size();
set_widgets();
update_character(m_cid);
update_character(m_cid, ui_iniswap_dropdown->itemText(ui_iniswap_dropdown->currentIndex()));
enter_courtroom();
gen_char_rgb_list(ao_app->get_chat(current_char));

Expand Down
3 changes: 3 additions & 0 deletions src/emotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ void Courtroom::set_emote_dropdown()
current_char, "emotions/button" + QString::number(n + 1) + "_off"));
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)
Expand Down
10 changes: 1 addition & 9 deletions src/text_file_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ void AOApplication::set_char_ini(QString p_char, QString value,
{
QSettings settings(get_real_path(get_character_path(p_char, "char.ini")),
QSettings::IniFormat);
settings.setIniCodec("UTF-8");
settings.beginGroup(target_tag);
settings.setValue(p_search_line, value);
settings.endGroup();
Expand All @@ -588,15 +589,6 @@ QStringList AOApplication::read_ini_tags(VPath p_path, QString target_tag)
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;
}

Crystalwarrior marked this conversation as resolved.
Show resolved Hide resolved
QString AOApplication::get_showname(QString p_char)
{
QString f_result = read_char_ini(p_char, "showname", "Options");
Expand Down