Skip to content

Commit

Permalink
Fix picking a gender and init randomly
Browse files Browse the repository at this point in the history
Picking a gender was not working because the radio buttons weren't
synchronized with the internal variable holding the information. Discard
the internal variable and use the buttons as the source of truth.
Always make sure that one of the buttons is selected. Pick one randomly
on startup, as choosing one would be offensive towards half of
humankind.

Reported by Hawk on Discord.
  • Loading branch information
lmoureaux committed Nov 23, 2023
1 parent 4fc1b38 commit e15e2d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
17 changes: 8 additions & 9 deletions client/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <QKeyEvent>
#include <QPainter>
#include <QRadioButton>
#include <QRandomGenerator>
#include <QVBoxLayout>
#include <QtMath>
// utility
Expand Down Expand Up @@ -389,7 +390,6 @@ races_dialog::races_dialog(struct player *pplayer, QWidget *parent)

selected_nation = -1;
selected_style = -1;
selected_sex = -1;
setWindowTitle(_("Select Nation"));
selected_nation_tabs->setRowCount(0);
selected_nation_tabs->setColumnCount(1);
Expand Down Expand Up @@ -432,6 +432,9 @@ races_dialog::races_dialog(struct player *pplayer, QWidget *parent)
qgroupbox_layout->addWidget(is_female, 2, 0);
is_female->setText(_("Female"));
is_male->setText(_("Male"));
// Select a default fairly
is_male->setChecked(QRandomGenerator::global()->generate() % 2 == 0);
is_female->setChecked(!is_male->isChecked());
no_name->setLayout(qgroupbox_layout);

description = new QTextEdit;
Expand Down Expand Up @@ -699,7 +702,8 @@ void races_dialog::nation_selected(const QItemSelection &selected,
description->setPlainText(buf);
leader_name->clear();
if (client.conn.playing == tplayer) {
leader_name->addItem(client.conn.playing->name, true);
// Add username preserving gender information
leader_name->addItem(client.conn.playing->name, is_male->isChecked());
}
nation_leader_list_iterate(
nation_leaders(nation_by_number(selected_nation)), pleader)
Expand Down Expand Up @@ -753,11 +757,9 @@ void races_dialog::leader_selected(int index)
if (leader_name->itemData(index).toBool()) {
is_male->setChecked(true);
is_female->setChecked(false);
selected_sex = 0;
} else {
is_male->setChecked(false);
is_female->setChecked(true);
selected_sex = 1;
}
}

Expand All @@ -773,10 +775,7 @@ void races_dialog::ok_pressed()
return;
}

if (selected_sex == -1) {
output_window_append(ftc_client, _("You must select your sex."));
return;
}
fc_assert_ret(is_male->isChecked() || is_female->isChecked());

if (selected_style == -1) {
output_window_append(ftc_client, _("You must select your style."));
Expand All @@ -795,7 +794,7 @@ void races_dialog::ok_pressed()
}
ln_bytes = leader_name->currentText().toUtf8();
dsend_packet_nation_select_req(&client.conn, player_number(tplayer),
selected_nation, selected_sex,
selected_nation, is_male->isChecked(),
ln_bytes.data(), selected_style);
close();
deleteLater();
Expand Down
1 change: 0 additions & 1 deletion client/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ private slots:
private:
int selected_nation;
int selected_style;
int selected_sex;
struct player *tplayer;
int last_index;
};
Expand Down

0 comments on commit e15e2d5

Please sign in to comment.