Improvements to the way the position dropdown is handled (#428)

* it works

* woops

* oops 2 electric boogaloo

* fix "SP" packet not working properly
This commit is contained in:
in1tiate 2021-01-28 15:38:15 -06:00 committed by GitHub
parent 3683e54501
commit 639d4738db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 32 deletions

View File

@ -165,7 +165,7 @@ public:
void set_background(QString p_background, bool display = false);
// sets the local character pos/side to use.
void set_side(QString p_side);
void set_side(QString p_side, bool block_signals=true);
// sets the pos dropdown
void set_pos_dropdown(QStringList pos_dropdowns);
@ -659,6 +659,7 @@ private:
QComboBox *ui_emote_dropdown;
QComboBox *ui_pos_dropdown;
AOButton *ui_pos_remove;
QComboBox *ui_iniswap_dropdown;
AOButton *ui_iniswap_remove;
@ -836,6 +837,7 @@ private slots:
void on_emote_dropdown_changed(int p_index);
void on_pos_dropdown_changed(int p_index);
void on_pos_remove_clicked();
void on_iniswap_dropdown_changed(int p_index);
void set_iniswap_dropdown();

View File

@ -165,6 +165,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
initialize_emotes();
ui_pos_dropdown = new QComboBox(this);
ui_pos_remove = new AOButton(this, ao_app);
ui_iniswap_dropdown = new QComboBox(this);
ui_iniswap_dropdown->setContextMenuPolicy(Qt::CustomContextMenu);
@ -301,6 +302,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
connect(ui_pos_dropdown, SIGNAL(currentIndexChanged(int)), this,
SLOT(on_pos_dropdown_changed(int)));
connect(ui_pos_remove, SIGNAL(clicked()), this, SLOT(on_pos_remove_clicked()));
connect(ui_iniswap_dropdown, SIGNAL(currentIndexChanged(int)), this,
SLOT(on_iniswap_dropdown_changed(int)));
@ -726,6 +728,15 @@ void Courtroom::set_widgets()
ui_pos_dropdown->setToolTip(
tr("Set your character's supplementary background."));
set_size_and_pos(ui_pos_remove, "pos_remove");
ui_pos_remove->setText("X");
ui_pos_remove->set_image("evidencex");
ui_pos_remove->setToolTip(tr("Reset your character's supplementary background to its default."));
if (current_side == "")
ui_pos_remove->hide();
else
ui_pos_remove->show();
set_size_and_pos(ui_iniswap_dropdown, "iniswap_dropdown");
ui_iniswap_dropdown->setEditable(true);
ui_iniswap_dropdown->setInsertPolicy(QComboBox::InsertAtBottom);
@ -1285,26 +1296,50 @@ void Courtroom::set_background(QString p_background, bool display)
}
}
void Courtroom::set_side(QString p_side)
void Courtroom::set_side(QString p_side, bool block_signals)
{
QString f_side;
if (p_side == "")
current_side = ao_app->get_char_side(current_char);
f_side = ao_app->get_char_side(current_char);
else
current_side = p_side;
f_side = p_side;
if (f_side == "jud") {
ui_witness_testimony->show();
ui_cross_examination->show();
ui_not_guilty->show();
ui_guilty->show();
ui_defense_minus->show();
ui_defense_plus->show();
ui_prosecution_minus->show();
ui_prosecution_plus->show();
}
else {
ui_witness_testimony->hide();
ui_cross_examination->hide();
ui_guilty->hide();
ui_not_guilty->hide();
ui_defense_minus->hide();
ui_defense_plus->hide();
ui_prosecution_minus->hide();
ui_prosecution_plus->hide();
}
for (int i = 0; i < ui_pos_dropdown->count(); ++i) {
QString pos = ui_pos_dropdown->itemText(i);
if (pos == current_side) {
if (pos == f_side) {
// Block the signals to prevent setCurrentIndex from triggering a pos
// change
ui_pos_dropdown->blockSignals(true);
if (block_signals)
ui_pos_dropdown->blockSignals(true);
// Set the index on dropdown ui element to let you know what pos you're on
// right now
ui_pos_dropdown->setCurrentIndex(i);
// Unblock the signals so the element can be used for setting pos again
ui_pos_dropdown->blockSignals(false);
if (block_signals)
ui_pos_dropdown->blockSignals(false);
// alright we dun, jobs done here boyos
break;
@ -1321,6 +1356,7 @@ void Courtroom::set_pos_dropdown(QStringList pos_dropdowns)
ui_pos_dropdown->addItems(pos_dropdown_list);
// Unblock the signals so the element can be used for setting pos again
ui_pos_dropdown->blockSignals(false);
set_side(current_side);
}
void Courtroom::update_character(int p_cid)
@ -1344,7 +1380,7 @@ void Courtroom::update_character(int p_cid)
}
current_char = f_char;
current_side = ao_app->get_char_side(current_char);
set_side(current_side);
set_text_color_dropdown();
@ -1366,27 +1402,6 @@ void Courtroom::update_character(int p_cid)
if (newchar) // Avoid infinite loop of death and suffering
set_iniswap_dropdown();
if (current_side == "jud") {
ui_witness_testimony->show();
ui_cross_examination->show();
ui_not_guilty->show();
ui_guilty->show();
ui_defense_minus->show();
ui_defense_plus->show();
ui_prosecution_minus->show();
ui_prosecution_plus->show();
}
else {
ui_witness_testimony->hide();
ui_cross_examination->hide();
ui_guilty->hide();
ui_not_guilty->hide();
ui_defense_minus->hide();
ui_defense_plus->hide();
ui_prosecution_minus->hide();
ui_prosecution_plus->hide();
}
ui_custom_objection->hide();
if (ao_app->custom_objection_enabled) // if setting is enabled
{
@ -1693,9 +1708,12 @@ void Courtroom::on_chat_return_pressed()
// immediate_preanim#%
QStringList packet_contents;
QString f_side;
if (current_side == "")
current_side = ao_app->get_char_side(current_char);
f_side = ao_app->get_char_side(current_char);
else
f_side = current_side;
QString f_desk_mod = "chat";
@ -1722,7 +1740,7 @@ void Courtroom::on_chat_return_pressed()
packet_contents.append(ui_ic_chat_message->text());
packet_contents.append(current_side);
packet_contents.append(f_side);
packet_contents.append(get_char_sfx());
@ -4269,12 +4287,36 @@ void Courtroom::on_pos_dropdown_changed(int p_index)
if (f_pos == "jud")
toggle_judge_buttons(true);
ui_pos_remove->show();
current_side = f_pos;
// YEAH SENDING LIKE 20 PACKETS IF THE USER SCROLLS THROUGH, GREAT IDEA
// how about this instead
set_side(f_pos);
}
void Courtroom::on_pos_remove_clicked()
{
QString default_side = ao_app->get_char_side(current_char);
for (int i = 0; i < ui_pos_dropdown->count(); ++i) {
QString pos = ui_pos_dropdown->itemText(i);
if (pos == default_side) {
ui_pos_dropdown->setCurrentIndex(i);
break;
}
}
int wit_index = ui_pos_dropdown->findText("wit");
if ((ui_pos_dropdown->currentText() != default_side) & (wit_index != -1)) //i.e. this bg doesn't have our pos
ui_pos_dropdown->setCurrentIndex(wit_index); // fall back to "wit"
else if (ui_pos_dropdown->currentText() != default_side) // we don't have "wit" either?
ui_pos_dropdown->setCurrentIndex(0); // as a last resort, choose the first item in the dropdown
current_side = "";
ui_pos_remove->hide();
}
void Courtroom::set_iniswap_dropdown()
{
ui_iniswap_dropdown->blockSignals(true);

View File

@ -475,7 +475,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
if (courtroom_constructed) // We were sent a "set position" packet
{
w_courtroom->set_side(f_contents.at(0));
w_courtroom->set_side(f_contents.at(0), false);
append_to_demofile(p_packet->to_string(true));
}
}