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); void set_background(QString p_background, bool display = false);
// sets the local character pos/side to use. // 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 // sets the pos dropdown
void set_pos_dropdown(QStringList pos_dropdowns); void set_pos_dropdown(QStringList pos_dropdowns);
@ -659,6 +659,7 @@ private:
QComboBox *ui_emote_dropdown; QComboBox *ui_emote_dropdown;
QComboBox *ui_pos_dropdown; QComboBox *ui_pos_dropdown;
AOButton *ui_pos_remove;
QComboBox *ui_iniswap_dropdown; QComboBox *ui_iniswap_dropdown;
AOButton *ui_iniswap_remove; AOButton *ui_iniswap_remove;
@ -836,6 +837,7 @@ private slots:
void on_emote_dropdown_changed(int p_index); void on_emote_dropdown_changed(int p_index);
void on_pos_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 on_iniswap_dropdown_changed(int p_index);
void set_iniswap_dropdown(); void set_iniswap_dropdown();

View File

@ -165,6 +165,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
initialize_emotes(); initialize_emotes();
ui_pos_dropdown = new QComboBox(this); ui_pos_dropdown = new QComboBox(this);
ui_pos_remove = new AOButton(this, ao_app);
ui_iniswap_dropdown = new QComboBox(this); ui_iniswap_dropdown = new QComboBox(this);
ui_iniswap_dropdown->setContextMenuPolicy(Qt::CustomContextMenu); 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, connect(ui_pos_dropdown, SIGNAL(currentIndexChanged(int)), this,
SLOT(on_pos_dropdown_changed(int))); 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, connect(ui_iniswap_dropdown, SIGNAL(currentIndexChanged(int)), this,
SLOT(on_iniswap_dropdown_changed(int))); SLOT(on_iniswap_dropdown_changed(int)));
@ -726,6 +728,15 @@ void Courtroom::set_widgets()
ui_pos_dropdown->setToolTip( ui_pos_dropdown->setToolTip(
tr("Set your character's supplementary background.")); 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"); set_size_and_pos(ui_iniswap_dropdown, "iniswap_dropdown");
ui_iniswap_dropdown->setEditable(true); ui_iniswap_dropdown->setEditable(true);
ui_iniswap_dropdown->setInsertPolicy(QComboBox::InsertAtBottom); 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 == "") if (p_side == "")
current_side = ao_app->get_char_side(current_char); f_side = ao_app->get_char_side(current_char);
else 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) { for (int i = 0; i < ui_pos_dropdown->count(); ++i) {
QString pos = ui_pos_dropdown->itemText(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 // Block the signals to prevent setCurrentIndex from triggering a pos
// change // 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 // Set the index on dropdown ui element to let you know what pos you're on
// right now // right now
ui_pos_dropdown->setCurrentIndex(i); ui_pos_dropdown->setCurrentIndex(i);
// Unblock the signals so the element can be used for setting pos again // 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 // alright we dun, jobs done here boyos
break; break;
@ -1321,6 +1356,7 @@ void Courtroom::set_pos_dropdown(QStringList pos_dropdowns)
ui_pos_dropdown->addItems(pos_dropdown_list); ui_pos_dropdown->addItems(pos_dropdown_list);
// Unblock the signals so the element can be used for setting pos again // Unblock the signals so the element can be used for setting pos again
ui_pos_dropdown->blockSignals(false); ui_pos_dropdown->blockSignals(false);
set_side(current_side);
} }
void Courtroom::update_character(int p_cid) void Courtroom::update_character(int p_cid)
@ -1344,7 +1380,7 @@ void Courtroom::update_character(int p_cid)
} }
current_char = f_char; current_char = f_char;
current_side = ao_app->get_char_side(current_char); set_side(current_side);
set_text_color_dropdown(); set_text_color_dropdown();
@ -1366,27 +1402,6 @@ void Courtroom::update_character(int p_cid)
if (newchar) // Avoid infinite loop of death and suffering if (newchar) // Avoid infinite loop of death and suffering
set_iniswap_dropdown(); 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(); ui_custom_objection->hide();
if (ao_app->custom_objection_enabled) // if setting is enabled if (ao_app->custom_objection_enabled) // if setting is enabled
{ {
@ -1693,9 +1708,12 @@ void Courtroom::on_chat_return_pressed()
// immediate_preanim#% // immediate_preanim#%
QStringList packet_contents; QStringList packet_contents;
QString f_side;
if (current_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"; 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(ui_ic_chat_message->text());
packet_contents.append(current_side); packet_contents.append(f_side);
packet_contents.append(get_char_sfx()); packet_contents.append(get_char_sfx());
@ -4269,12 +4287,36 @@ void Courtroom::on_pos_dropdown_changed(int p_index)
if (f_pos == "jud") if (f_pos == "jud")
toggle_judge_buttons(true); toggle_judge_buttons(true);
ui_pos_remove->show();
current_side = f_pos;
// YEAH SENDING LIKE 20 PACKETS IF THE USER SCROLLS THROUGH, GREAT IDEA // YEAH SENDING LIKE 20 PACKETS IF THE USER SCROLLS THROUGH, GREAT IDEA
// how about this instead // how about this instead
set_side(f_pos); 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() void Courtroom::set_iniswap_dropdown()
{ {
ui_iniswap_dropdown->blockSignals(true); 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 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)); append_to_demofile(p_packet->to_string(true));
} }
} }