Skip to content

Commit

Permalink
add options for bots & player visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodCoder666 committed Dec 8, 2024
1 parent 6425e80 commit e8399ad
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
39 changes: 36 additions & 3 deletions src/localGameDialog/localGameDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
LocalGameDialog::LocalGameDialog(QWidget* parent) :
QDialog(parent), ui(new Ui::LocalGameDialog) {
ui->setupUi(this);
// connect slots
connect(ui->btnStartGame, &QPushButton::clicked, this, &LocalGameDialog::on_btnStartGame_clicked);
connect(ui->btnCancel, &QPushButton::clicked, this, &LocalGameDialog::on_btnCancel_clicked);
on_spinBox_numPlayers_valueChanged(ui->spinBox_numPlayers->value());
}

LocalGameDialog::~LocalGameDialog() {
Expand All @@ -20,3 +18,38 @@ void LocalGameDialog::on_btnStartGame_clicked() {
void LocalGameDialog::on_btnCancel_clicked() {
this->done(QDialog::Rejected);
}

void LocalGameDialog::on_spinBox_numPlayers_valueChanged(int numPlayers) {
QLayout* layout = ui->groupBox_players->layout();
int requiredCount = numPlayers + 1;
while(layout->count() > requiredCount) {
layout->takeAt(layout->count() - 1)->widget()->deleteLater();
}
// Bot names from v5, for demonstration only.
const QStringList botNames = { "ktqBot", "lcwBot", "smartRandomBot", "xrzBot", "zlyBot" };
const QFont& font = ui->labNumPlayers->font();
QFont comboFont = font;
comboFont.setPointSize(comboFont.pointSize() - 2);
while(layout->count() < requiredCount) {
QLabel* playerLabel = new QLabel(tr("Player %1").arg(layout->count()));
playerLabel->setFont(font);
QComboBox* playerCombo = new QComboBox();
if(layout->count() == 1) playerCombo->addItem(tr("Human"));
playerCombo->addItems(botNames);
playerCombo->setCurrentIndex(0);
playerCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
playerCombo->setStyleSheet("color: teal;");
playerCombo->setFont(comboFont);
QCheckBox* visibleChkbox = new QCheckBox(tr("Visible"));
visibleChkbox->setChecked(layout->count() == 1);
visibleChkbox->setFont(font);
QHBoxLayout* playerLayout = new QHBoxLayout();
playerLayout->addWidget(playerLabel);
playerLayout->addWidget(playerCombo);
playerLayout->addWidget(visibleChkbox);
playerLayout->setContentsMargins(0, 0, 0, 0);
QWidget* playerWidget = new QWidget();
playerWidget->setLayout(playerLayout);
layout->addWidget(playerWidget);
}
}
3 changes: 2 additions & 1 deletion src/localGameDialog/localGameDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class LocalGameDialog : public QDialog {
LocalGameDialog(QWidget* parent = nullptr);
~LocalGameDialog();

// slots
public slots:
void on_btnStartGame_clicked();
void on_btnCancel_clicked();
void on_spinBox_numPlayers_valueChanged(int);

private:
Ui::LocalGameDialog* ui;
Expand Down
4 changes: 2 additions & 2 deletions src/localGameDialog/localGameDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<property name="font">
<font>
<family>Quicksand</family>
<pointsize>15</pointsize>
<pointsize>13</pointsize>
</font>
</property>
<property name="styleSheet">
Expand Down Expand Up @@ -325,7 +325,7 @@
<number>2</number>
</property>
<property name="maximum">
<number>1000</number>
<number>12</number>
</property>
</widget>
</item>
Expand Down
2 changes: 0 additions & 2 deletions src/mainWindow/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
MainWindow::MainWindow(QWidget* parent) :
QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
// connect slots
connect(ui->btnLocalGame, &QPushButton::clicked, this, &MainWindow::on_btnLocalGame_clicked);
}

MainWindow::~MainWindow() {
Expand Down
2 changes: 1 addition & 1 deletion src/mainWindow/mainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MainWindow : public QMainWindow {
MainWindow(QWidget* parent = nullptr);
~MainWindow();

// slots
public slots:
void on_btnLocalGame_clicked();

private:
Expand Down

0 comments on commit e8399ad

Please sign in to comment.