Add two ways of controlling judge buttons that aren't hardcoded nonsense (networked and local) (#537)

* add both network and local ways to show judge buttons on pos other than jud

* hide judge buttons when pos_removing to a non-judge position

* alter packet header

* Only use pos jud hardcoding if no design.ini

if design.ini does not define judges= then we fall back to pos jud garbage

* Fix judge buttons being disabled if default_side pos is judge (logic poopy)
Fix positions.isEmpty() returning False cuz a split of an empty string returns the list with an empty string by default

* Expand JD packet to be able to send -1, 0 and 1. If -1 is received, fall back on client-sided judge button behavior. If 0 or 1 is received, treat it as "absolute override" and adhere to that packet.

* alter check for empty qstringlist to support old qt versions

* heehoo

* trigger client side behavior when jd -1 is sent

* less confusing variable names

* remove useless code, trim some fat

Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>

* use an enum dammit! & warn on malformed auth

* use an enum dammit! pt. 2

* appease clang, rewrite ugly judge controls function

* please squash this its so bad

Co-authored-by: Crystalwarrior <Varsash@Gmail.com>
Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
This commit is contained in:
Rosemary Witchaven 2022-03-29 09:37:02 -05:00 committed by GitHub
parent 18412cc930
commit 68d0b838cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 27 deletions

View File

@ -421,6 +421,9 @@ public:
// Returns the custom realisation used by the character. // Returns the custom realisation used by the character.
QString get_custom_realization(QString p_char); QString get_custom_realization(QString p_char);
// Returns whether the given pos is a judge position
bool get_pos_is_judge(const QString &p_pos);
// Returns the name of p_char // Returns the name of p_char
QString get_char_name(QString p_char); QString get_char_name(QString p_char);

View File

@ -304,7 +304,7 @@ public:
void set_hp_bar(int p_bar, int p_state); void set_hp_bar(int p_bar, int p_state);
// Toggles the judge buttons, whether they should appear or not. // Toggles the judge buttons, whether they should appear or not.
void toggle_judge_buttons(bool is_on); void show_judge_controls(bool visible);
void announce_case(QString title, bool def, bool pro, bool jud, bool jur, void announce_case(QString title, bool def, bool pro, bool jud, bool jur,
bool steno); bool steno);
@ -325,6 +325,16 @@ public:
void on_authentication_state_received(int p_state); void on_authentication_state_received(int p_state);
enum JudgeState {
POS_DEPENDENT = -1,
HIDE_CONTROLS = 0,
SHOW_CONTROLS = 1
};
JudgeState get_judge_state() { return judge_state; }
void set_judge_state(JudgeState new_state) { judge_state = new_state; }
void set_judge_buttons() { show_judge_controls(ao_app->get_pos_is_judge(current_side)); }
~Courtroom(); ~Courtroom();
private: private:
AOApplication *ao_app; AOApplication *ao_app;
@ -480,6 +490,8 @@ private:
bool is_muted = false; bool is_muted = false;
JudgeState judge_state = POS_DEPENDENT;
// state of animation, 0 = objecting, 1 = preanim, 2 = talking, 3 = idle, 4 = // state of animation, 0 = objecting, 1 = preanim, 2 = talking, 3 = idle, 4 =
// noniterrupting preanim, 5 = (c) animation // noniterrupting preanim, 5 = (c) animation
int anim_state = 3; int anim_state = 3;

View File

@ -1406,10 +1406,7 @@ void Courtroom::set_side(QString p_side)
ui_pos_remove->show(); ui_pos_remove->show();
} }
toggle_judge_buttons(false); set_judge_buttons();
if (f_side == "jud")
toggle_judge_buttons(true);
// Block the signals to prevent setCurrentIndex from triggering a pos // Block the signals to prevent setCurrentIndex from triggering a pos
// change // change
@ -4042,27 +4039,28 @@ void Courtroom::set_hp_bar(int p_bar, int p_state)
} }
} }
void Courtroom::toggle_judge_buttons(bool is_on) void Courtroom::show_judge_controls(bool visible)
{ {
if (is_on) { if (judge_state != POS_DEPENDENT) {
ui_witness_testimony->show(); visible = judge_state == SHOW_CONTROLS; // Server-side override
ui_cross_examination->show();
ui_guilty->show();
ui_not_guilty->show();
ui_defense_minus->show();
ui_defense_plus->show();
ui_prosecution_minus->show();
ui_prosecution_plus->show();
} }
else { QList<QWidget*> judge_controls =
ui_witness_testimony->hide(); {
ui_cross_examination->hide(); ui_witness_testimony,
ui_guilty->hide(); ui_cross_examination,
ui_not_guilty->hide(); ui_guilty,
ui_defense_minus->hide(); ui_not_guilty,
ui_defense_plus->hide(); ui_defense_minus,
ui_prosecution_minus->hide(); ui_defense_plus,
ui_prosecution_plus->hide(); ui_prosecution_minus,
ui_prosecution_plus
};
for (QWidget* control : judge_controls) {
if (visible)
control->show();
else
control->hide();
} }
} }
@ -4093,10 +4091,10 @@ void Courtroom::on_ooc_return_pressed()
//Using an arbitrary 2.8 feature flag certainly won't cause issues someday. //Using an arbitrary 2.8 feature flag certainly won't cause issues someday.
if (ooc_message.startsWith("/pos") & !ao_app->effects_enabled) { if (ooc_message.startsWith("/pos") & !ao_app->effects_enabled) {
if (ooc_message == "/pos jud") { if (ooc_message == "/pos jud") {
toggle_judge_buttons(true); show_judge_controls(true);
} }
else { else {
toggle_judge_buttons(false); show_judge_controls(false);
} }
} }
@ -4373,6 +4371,8 @@ void Courtroom::on_pos_remove_clicked()
ui_pos_dropdown->blockSignals(true); ui_pos_dropdown->blockSignals(true);
QString default_side = ao_app->get_char_side(current_char); QString default_side = ao_app->get_char_side(current_char);
show_judge_controls(ao_app->get_pos_is_judge(default_side));
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 == default_side) { if (pos == default_side) {

View File

@ -606,10 +606,31 @@ void AOApplication::server_packet_received(AOPacket *p_packet)
else if (header == "AUTH") { else if (header == "AUTH") {
if (!courtroom_constructed || !auth_packet_enabled || f_contents.size() < 1) if (!courtroom_constructed || !auth_packet_enabled || f_contents.size() < 1)
goto end; goto end;
int authenticated = f_contents.at(0).toInt(); bool ok;
int authenticated = f_contents.at(0).toInt(&ok);
if (!ok) {
qWarning() << "Malformed AUTH packet! Contents:" << f_contents.at(0);
}
w_courtroom->on_authentication_state_received(authenticated); w_courtroom->on_authentication_state_received(authenticated);
} }
else if (header == "JD") {
if (!courtroom_constructed || f_contents.empty()) {
goto end;
}
bool ok;
Courtroom::JudgeState state = static_cast<Courtroom::JudgeState>(f_contents.at(0).toInt(&ok));
if (!ok) {
goto end; // ignore malformed packet
}
w_courtroom->set_judge_state(state);
if (w_courtroom->get_judge_state() != Courtroom::POS_DEPENDENT) { // If we receive JD -1, it means the server asks us to fall back to client-side judge buttons behavior
w_courtroom->show_judge_controls(w_courtroom->get_judge_state() == Courtroom::SHOW_CONTROLS);
}
else {
w_courtroom->set_judge_buttons(); // client-side judge behavior
}
}
//AssetURL Packet //AssetURL Packet
else if (header == "ASS") { else if (header == "ASS") {

View File

@ -912,6 +912,15 @@ QString AOApplication::get_custom_realization(QString p_char)
return get_sfx_suffix(get_sounds_path(f_result)); return get_sfx_suffix(get_sounds_path(f_result));
} }
bool AOApplication::get_pos_is_judge(const QString &p_pos)
{
QStringList positions = read_design_ini("judges", get_background_path("design.ini")).split(",");
if (positions.size() == 1 && positions[0] == "") {
return p_pos == "jud"; //Hardcoded BS only if we have no judges= defined
}
return positions.contains(p_pos.trimmed());
}
bool AOApplication::get_blank_blip() bool AOApplication::get_blank_blip()
{ {
QString result = configini->value("blank_blip", "false").value<QString>(); QString result = configini->value("blank_blip", "false").value<QString>();