Streamlined ini swapping so the user can set up multiple character folders associated with a character.

This will save to the character folder's iniswaps.ini. You can click on the dropdown and edit the text inside to add an iniswap, and press the [X] button that'll appear next to it to remove the ini swap.
Recode the enter_courtroom and add a new update_character feature - the two are now separate and responsible for different things. The courtroom will reload the whole theme and widgets while the character is only responsible for all ui elements related to the character. This drastically improves performance when switching characters using /switch or something
Add a set_char_ini helper function that allows you to modify the character variables. For now only used to set name= field when iniswapping
This commit is contained in:
Crystalwarrior 2019-09-17 18:51:40 +03:00
parent 6747bfdd5e
commit 9d20cf0322
6 changed files with 141 additions and 29 deletions

View File

@ -202,6 +202,9 @@ public:
//Returns the list of words in callwords.ini
QStringList get_call_words();
//returns all of the file's lines in a QStringList
QStringList get_list_file(QString p_file);
//Process a file and return its text as a QString
QString read_file(QString filename);
@ -259,6 +262,8 @@ public:
//Returns a QStringList of all key=value definitions on a given tag.
QStringList read_char_ini_tag(QString p_char, QString target_tag);
//Sets the char.ini p_search_line key under tag target_tag to value.
void set_char_ini(QString p_char, QString value, QString p_search_line, QString target_tag);
//Returns the text between target_tag and terminator_tag in p_file
QString get_stylesheet(QString p_file);

View File

@ -184,8 +184,11 @@ public:
QString get_current_char() {return current_char;}
QString get_current_background() {return current_background;}
//updates character to p_cid and updates necessary ui elements
void update_character(int p_cid);
//properly sets up some varibles: resets user state
void enter_courtroom(int p_cid);
void enter_courtroom();
//helper function that populates ui_music_list with the contents of music_list
void list_music();
@ -461,6 +464,9 @@ private:
QComboBox *ui_emote_dropdown;
QComboBox *ui_pos_dropdown;
QComboBox *ui_iniswap_dropdown;
AOButton *ui_iniswap_remove;
AOImage *ui_defense_bar;
AOImage *ui_prosecution_bar;
@ -602,6 +608,10 @@ private slots:
void on_emote_dropdown_changed(int p_index);
void on_pos_dropdown_changed(int p_index);
void on_iniswap_dropdown_changed(int p_index);
void set_iniswap_dropdown();
void on_iniswap_remove_clicked();
void on_evidence_name_edited(QString text);
void on_evidence_image_name_edited();

View File

@ -64,7 +64,7 @@ void Courtroom::set_char_select()
if (f_charselect.width < 0 || f_charselect.height < 0)
{
qDebug() << "W: did not find courtroom width or height in courtroom_design.ini!";
qDebug() << "W: did not find char_select width or height in courtroom_design.ini!";
this->resize(714, 668);
}
else
@ -129,15 +129,13 @@ void Courtroom::char_clicked(int n_char)
return;
}
if (n_char == m_cid)
{
enter_courtroom(m_cid);
}
else
if (n_char != m_cid)
{
ao_app->send_server_packet(new AOPacket("PW#" + ui_char_password->text() + "#%"));
ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_char) + "#" + get_hdid() + "#%"));
}
update_character(n_char);
enter_courtroom();
ui_ic_chat_name->setPlaceholderText(char_list.at(n_char).name);
}

View File

@ -163,6 +163,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_pos_dropdown->addItem("jur");
ui_pos_dropdown->addItem("sea");
ui_iniswap_dropdown = new QComboBox(this);
ui_iniswap_remove = new AOButton(this, ao_app);
ui_defense_bar = new AOImage(this, ao_app);
ui_prosecution_bar = new AOImage(this, ao_app);
@ -282,6 +285,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
connect(ui_emote_dropdown, SIGNAL(activated(int)), this, SLOT(on_emote_dropdown_changed(int)));
connect(ui_pos_dropdown, SIGNAL(currentIndexChanged(int)), this, SLOT(on_pos_dropdown_changed(int)));
connect(ui_iniswap_dropdown, SIGNAL(activated(int)), this, SLOT(on_iniswap_dropdown_changed(int)));
connect(ui_iniswap_remove, SIGNAL(clicked()), this, SLOT(on_iniswap_remove_clicked()));
connect(ui_mute_list, SIGNAL(clicked(QModelIndex)), this, SLOT(on_mute_list_clicked(QModelIndex)));
connect(ui_ic_chat_message, SIGNAL(returnPressed()), this, SLOT(on_chat_return_pressed()));
@ -571,6 +577,13 @@ void Courtroom::set_widgets()
set_size_and_pos(ui_emote_dropdown, "emote_dropdown");
set_size_and_pos(ui_pos_dropdown, "pos_dropdown");
set_size_and_pos(ui_iniswap_dropdown, "iniswap_dropdown");
ui_iniswap_dropdown->setEditable(true);
ui_iniswap_dropdown->setInsertPolicy(QComboBox::InsertAtBottom);
set_size_and_pos(ui_iniswap_remove, "iniswap_remove");
// ui_iniswap_remove->setText("X");
ui_iniswap_remove->set_image("evidencex");
set_size_and_pos(ui_defense_bar, "defense_bar");
ui_defense_bar->set_image("defensebar" + QString::number(defense_bar_state));
@ -585,10 +598,15 @@ void Courtroom::set_widgets()
ui_blip_label->setText(tr("Blips"));
set_size_and_pos(ui_hold_it, "hold_it");
// ui_hold_it->setText(tr("Hold It!"));
ui_hold_it->set_image("holdit");
set_size_and_pos(ui_objection, "objection");
// ui_objection->setText(tr("Objection!"));
ui_objection->set_image("objection");
set_size_and_pos(ui_take_that, "take_that");
// ui_take_that->setText(tr("Take That!"));
ui_take_that->set_image("takethat");
set_size_and_pos(ui_ooc_toggle, "ooc_toggle");
@ -876,8 +894,10 @@ void Courtroom::set_background(QString p_background)
}
}
void Courtroom::enter_courtroom(int p_cid)
void Courtroom::update_character(int p_cid)
{
bool newchar = m_cid != p_cid;
m_cid = p_cid;
QString f_char;
@ -909,11 +929,6 @@ void Courtroom::enter_courtroom(int p_cid)
set_emote_page();
set_emote_dropdown();
current_evidence_page = 0;
current_evidence = 0;
set_evidence_page();
QString side = ao_app->get_char_side(f_char);
if (side == "jud")
@ -947,6 +962,21 @@ void Courtroom::enter_courtroom(int p_cid)
else
ui_custom_objection->hide();
ui_char_select_background->hide();
ui_ic_chat_message->setEnabled(m_cid != -1);
ui_ic_chat_message->setFocus();
if (newchar)
set_iniswap_dropdown();
}
void Courtroom::enter_courtroom()
{
current_evidence_page = 0;
current_evidence = 0;
set_evidence_page();
if (ao_app->flipping_enabled)
ui_flip->show();
else
@ -975,11 +1005,6 @@ void Courtroom::enter_courtroom(int p_cid)
set_widgets();
//ui_server_chatlog->setHtml(ui_server_chatlog->toHtml());
ui_char_select_background->hide();
ui_ic_chat_message->setEnabled(m_cid != -1);
ui_ic_chat_message->setFocus();
}
void Courtroom::list_music()
@ -3224,6 +3249,70 @@ void Courtroom::on_pos_dropdown_changed(int p_index)
ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/pos " + f_pos + "#%"));
}
void Courtroom::set_iniswap_dropdown()
{
ui_iniswap_dropdown->clear();
if (m_cid == -1)
{
ui_iniswap_dropdown->hide();
return;
}
QStringList iniswaps = ao_app->get_list_file(ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini"));
iniswaps.prepend(char_list.at(m_cid).name);
if (iniswaps.size() <= 0)
{
ui_iniswap_dropdown->hide();
return;
}
ui_iniswap_dropdown->show();
ui_iniswap_dropdown->addItems(iniswaps);
for (int i = 0; i < iniswaps.size(); ++i)
{
if (iniswaps.at(i) == current_char)
{
ui_iniswap_dropdown->setCurrentIndex(i);
if (i != 0)
ui_iniswap_remove->show();
else
ui_iniswap_remove->hide();
break;
}
}
}
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;
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)
swaplist.append(entry);
}
ao_app->write_to_file(swaplist.join("\n"), ao_app->get_character_path(char_list.at(m_cid).name, "iniswaps.ini"));
ui_iniswap_dropdown->setCurrentIndex(p_index);
update_character(m_cid);
if (p_index != 0)
ui_iniswap_remove->show();
else
ui_iniswap_remove->hide();
}
void Courtroom::on_iniswap_remove_clicked()
{
if (ui_iniswap_dropdown->itemText(ui_iniswap_dropdown->currentIndex()) != char_list.at(m_cid).name)
{
ui_iniswap_dropdown->removeItem(ui_iniswap_dropdown->currentIndex());
on_iniswap_dropdown_changed(0); //Reset back to original
update_character(m_cid);
}
}
void Courtroom::on_mute_list_clicked(QModelIndex p_index)
{
QListWidgetItem *f_item = ui_mute_list->item(p_index.row());
@ -3607,7 +3696,8 @@ void Courtroom::on_reload_theme_clicked()
//to update status on the background
set_background(current_background);
enter_courtroom(m_cid);
update_character(m_cid);
enter_courtroom();
anim_state = 4;
text_state = 3;
@ -3633,11 +3723,7 @@ void Courtroom::on_char_select_right_clicked()
void Courtroom::on_spectator_clicked()
{
enter_courtroom(-1);
ui_emotes->hide();
ui_char_select_background->hide();
update_character(-1);
}
void Courtroom::on_call_mod_clicked()

View File

@ -601,7 +601,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
goto end;
if (courtroom_constructed)
w_courtroom->enter_courtroom(f_contents.at(2).toInt());
w_courtroom->update_character(f_contents.at(2).toInt());
}
else if (header == "MS")
{

View File

@ -74,17 +74,22 @@ QString AOApplication::get_audio_output_device()
}
QStringList AOApplication::get_call_words()
{
return get_list_file(get_base_path() + "callwords.ini");
}
QStringList AOApplication::get_list_file(QString p_file)
{
QStringList return_value;
QFile callwords_ini;
QFile p_ini;
callwords_ini.setFileName(get_base_path() + "callwords.ini");
p_ini.setFileName(p_file);
if (!callwords_ini.open(QIODevice::ReadOnly))
if (!p_ini.open(QIODevice::ReadOnly))
return return_value;
QTextStream in(&callwords_ini);
QTextStream in(&p_ini);
while (!in.atEnd())
{
@ -555,6 +560,14 @@ QString AOApplication::read_char_ini(QString p_char, QString p_search_line, QStr
return value;
}
void AOApplication::set_char_ini(QString p_char, QString value, QString p_search_line, QString target_tag)
{
QSettings settings(get_character_path(p_char, "char.ini"), QSettings::IniFormat);
settings.beginGroup(target_tag);
settings.setValue(p_search_line, value);
settings.endGroup();
}
//returns all the values of target_tag
QStringList AOApplication::read_char_ini_tag(QString p_char, QString target_tag)
{