Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions launcher/ui/dialogs/ChooseOfflineNameDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <QPushButton>
#include <QRegularExpression>
#include <QRandomGenerator>

#include "ui_ChooseOfflineNameDialog.h"

Expand Down Expand Up @@ -73,3 +74,32 @@ void ChooseOfflineNameDialog::on_allowInvalidUsernames_checkStateChanged(const Q
ui->usernameTextBox->setValidator(checkState == Qt::Checked ? nullptr : m_usernameValidator);
updateAcceptAllowed(getUsername());
}

void ChooseOfflineNameDialog::on_randomCharUser_clicked()
{
const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
const int randomStringLength = 14;
QString randomString;
for(int i=0; i<randomStringLength; ++i)
{
int index = QRandomGenerator::global()->generate() % possibleCharacters.length();
QChar nextChar = possibleCharacters.at(index);
randomString.append(nextChar);
}
ui->usernameTextBox->setText(randomString);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}

void ChooseOfflineNameDialog::on_randomFullUser_clicked()
{
//todo: maybe make this words configurable and not hardcoded, smh.
QList<QString> PossibleUsernameHalves = {"Cookie", "Clicker", "Licker", "Lenny", "Super", "Sakupen", "Sonic", "Geometry", "Mining", "Chicken", "Sculpted", "Random", "Painted", "Fainted", "MadeIn", "Chinese", "Bing", "Hell", "Circles", "Wave", "Dash", "Crafting", "Smelting", "Jockey", "Vase", "Heaven", "Pudding", "Chilling"};
int UsernameArrayLength = PossibleUsernameHalves.count();
//int indexPossibleHalf = QRandomGenerator::global()->bounded(22);
int indexFirstPossibleHalf = QRandomGenerator::global()->bounded(UsernameArrayLength);
int indexSecondPossibleHalf = QRandomGenerator::global()->bounded(UsernameArrayLength);
QString GeneratedUsername = PossibleUsernameHalves[indexFirstPossibleHalf] + PossibleUsernameHalves[indexSecondPossibleHalf];
ui->usernameTextBox->setText(GeneratedUsername);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}

4 changes: 4 additions & 0 deletions launcher/ui/dialogs/ChooseOfflineNameDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class ChooseOfflineNameDialog final : public QDialog {
void on_usernameTextBox_textEdited(const QString& newText) const;
void on_allowInvalidUsernames_checkStateChanged(Qt::CheckState checkState) const;

private slots:
void on_randomCharUser_clicked();
void on_randomFullUser_clicked();

private:
Ui::ChooseOfflineNameDialog* ui;
QRegularExpressionValidator* m_usernameValidator;
Expand Down
14 changes: 14 additions & 0 deletions launcher/ui/dialogs/ChooseOfflineNameDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="randomCharUser">
<property name="text">
<string>Random Characters</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="randomFullUser">
<property name="text">
<string>Random Username</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
Expand Down
Loading