Skip to content

Commit

Permalink
standardize formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
loganmc10 committed Jun 19, 2024
1 parent 5e29959 commit 2e6fb1e
Show file tree
Hide file tree
Showing 42 changed files with 607 additions and 506 deletions.
32 changes: 16 additions & 16 deletions cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ CheatsDialog::CheatsDialog(QString gameName, QWidget *parent)
QJsonObject cheats = gameData.value(keys.at(i)).toObject();
QLabel *name = new QLabel(keys.at(i), this);
QString helper = cheats.value("note").toString();
if (!helper.isEmpty()) {
if (!helper.isEmpty())
{
helper.prepend("<span style=\"color:black;\">");
helper.append("</span>");
name->setToolTip(helper);
Expand All @@ -47,7 +48,7 @@ CheatsDialog::CheatsDialog(QString gameName, QWidget *parent)
{
row++;
QJsonObject options = cheats.value("options").toObject();
QButtonGroup* optionButtons = new QButtonGroup(this);
QButtonGroup *optionButtons = new QButtonGroup(this);
optionButtons->setExclusive(true);
QStringList optionsKeys = options.keys();
for (int j = 0; j < optionsKeys.size(); ++j)
Expand Down Expand Up @@ -91,9 +92,8 @@ CheatsTextEdit::CheatsTextEdit(QString _game, QWidget *parent)

setPlainText(w->getSettings()->value(prefix + "cheat").toString());

connect(this, &QPlainTextEdit::textChanged, [=]{
w->getSettings()->setValue(prefix + "cheat", toPlainText());
});
connect(this, &QPlainTextEdit::textChanged, [=]
{ w->getSettings()->setValue(prefix + "cheat", toPlainText()); });
}

CheatsCheckBox::CheatsCheckBox(QString _game, QString _cheat, QWidget *parent)
Expand All @@ -102,28 +102,28 @@ CheatsCheckBox::CheatsCheckBox(QString _game, QString _cheat, QWidget *parent)
m_game = _game;
m_cheatName = _cheat;

connect(this, &QAbstractButton::pressed, [=]{
connect(this, &QAbstractButton::pressed, [=]
{
if (m_group != nullptr && checkState() == Qt::Checked)
{
m_group->setExclusive(false);
}
});
} });

connect(this, &QAbstractButton::released, [=]{
connect(this, &QAbstractButton::released, [=]
{
if (m_group != nullptr)
{
m_group->setExclusive(true);
}
});
} });

connect(this, &QCheckBox::stateChanged, [=](int state){
connect(this, &QCheckBox::stateChanged, [=](int state)
{
QString prefix = "Cheats/" + m_game + "/" + m_cheatName + "/";
if (m_optionName != "")
{
w->getSettings()->setValue(prefix + "option", m_optionName);
}
w->getSettings()->setValue(prefix + "enabled", state == Qt::Checked ? true : false);
});
w->getSettings()->setValue(prefix + "enabled", state == Qt::Checked ? true : false); });
}

void CheatsCheckBox::loadState()
Expand Down Expand Up @@ -167,7 +167,7 @@ QJsonObject getCheatsFromSettings(QString gameName, QJsonObject gameData)
else if (w->getSettings()->value("enabled").toBool())
{
QJsonArray cheat_codes = gameData.value(childGroups.at(i)).toObject().value("data").toArray();
if(w->getSettings()->contains("option"))
if (w->getSettings()->contains("option"))
{
for (int j = 0; j < cheat_codes.size(); ++j)
{
Expand Down Expand Up @@ -195,7 +195,7 @@ bool loadCheats(QJsonObject cheatsData)
for (int i = 0; i < cheatsData.size(); ++i)
{
QJsonArray cheat_codes = cheatsData.value(cheatsData.keys().at(i)).toArray();
QList <m64p_cheat_code> codes;
QList<m64p_cheat_code> codes;
for (int j = 0; j < cheat_codes.size(); ++j)
{
QStringList data = cheat_codes.at(j).toString().split(" ");
Expand Down
11 changes: 8 additions & 3 deletions cheats.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CheatsTextEdit : public QPlainTextEdit
{
public:
explicit CheatsTextEdit(QString _game, QWidget *parent = 0);

private:
QString m_game = "";
};
Expand All @@ -21,14 +22,17 @@ class CheatsCheckBox : public QCheckBox
public:
explicit CheatsCheckBox(QString _game, QString _cheat, QWidget *parent = 0);
void loadState();
void setGroup(QButtonGroup* group) {
void setGroup(QButtonGroup *group)
{
m_group = group;
}
void setOptionName(QString name) {
void setOptionName(QString name)
{
m_optionName = name;
}

private:
QButtonGroup* m_group = nullptr;
QButtonGroup *m_group = nullptr;
QString m_cheatName = "";
QString m_optionName = "";
QString m_game = "";
Expand All @@ -39,6 +43,7 @@ class CheatsDialog : public QDialog
Q_OBJECT
public:
CheatsDialog(QString gameName, QWidget *parent = nullptr);

private:
QGridLayout *m_layout;
};
Expand Down
54 changes: 31 additions & 23 deletions hotkeydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@

static void paramListCallback(void *context, const char *ParamName, m64p_type ParamType)
{
HotkeyDialog* dialog = (HotkeyDialog*)context;
HotkeyDialog *dialog = (HotkeyDialog *)context;

if (strcmp((char*)ParamName, "Version") == 0) return;
else if (strncmp((char*)ParamName, "Joy Mapping", 11) == 0) return;
if (strcmp((char *)ParamName, "Version") == 0)
return;
else if (strncmp((char *)ParamName, "Joy Mapping", 11) == 0)
return;

int l_ParamInt;
bool l_ParamBool;
float l_ParamFloat;
QString l_ParamString;
QString helper = (*ConfigGetParameterHelp)(dialog->getHandle(), ParamName);
QLabel *desc = new QLabel(ParamName, dialog->getLayout()->parentWidget());
if (!helper.isEmpty()) {
helper.prepend("<span style=\"color:black;\">");
helper.append("</span>");
desc->setToolTip(helper);
if (!helper.isEmpty())
{
helper.prepend("<span style=\"color:black;\">");
helper.append("</span>");
desc->setToolTip(helper);
}
desc->setStyleSheet("padding: 10px");
dialog->getLayout()->addWidget(desc, *dialog->getLayoutRow(), 0);
Expand All @@ -37,9 +40,9 @@ static void paramListCallback(void *context, const char *ParamName, m64p_type Pa
l_ParamInt = (*ConfigGetParamInt)(dialog->getHandle(), ParamName);
my_Widget->setText(QKeySequence(SDL22QT(sdl_keysym2scancode(l_ParamInt))).toString());

dialog->getLayout()->addWidget((QWidget*)my_Widget, *dialog->getLayoutRow(), 1);
dialog->getLayout()->addWidget((QWidget *)my_Widget, *dialog->getLayoutRow(), 1);

ClearButton* clear_Widget = new ClearButton(dialog->getLayout()->parentWidget());
ClearButton *clear_Widget = new ClearButton(dialog->getLayout()->parentWidget());
clear_Widget->setConfigHandle(dialog->getHandle());
clear_Widget->setParamType(ParamType);
clear_Widget->setParamName(ParamName);
Expand All @@ -48,21 +51,23 @@ static void paramListCallback(void *context, const char *ParamName, m64p_type Pa
l_ParamInt = (*ConfigGetParamInt)(dialog->getHandle(), ParamName);
clear_Widget->setText("Clear");

dialog->getLayout()->addWidget((QWidget*)clear_Widget, *dialog->getLayoutRow(), 2);
dialog->getLayout()->addWidget((QWidget *)clear_Widget, *dialog->getLayoutRow(), 2);
++*dialog->getLayoutRow();
}

void HotkeyDialog::handleResetButton()
{
int value;
(*CoreDoCommand)(M64CMD_CORE_STATE_QUERY, M64CORE_EMU_STATE, &value);
if (value == M64EMU_STOPPED) {
if (value == M64EMU_STOPPED)
{
(*ConfigDeleteSection)("CoreEvents");
(*ConfigSaveFile)();
w->resetCore();
this->close();
}
else {
else
{
QMessageBox msgBox;
msgBox.setText("Emulator must be stopped.");
msgBox.exec();
Expand Down Expand Up @@ -96,15 +101,16 @@ HotkeyDialog::HotkeyDialog(QWidget *parent)
mainLayout->addWidget(coreEventsScroll);
QPushButton *resetButton = new QPushButton("Reset All Settings", this);
resetButton->setAutoDefault(false);
connect(resetButton, &QPushButton::released,this, &HotkeyDialog::handleResetButton);
connect(resetButton, &QPushButton::released, this, &HotkeyDialog::handleResetButton);
mainLayout->addWidget(resetButton);
setLayout(mainLayout);
}

void HotkeyDialog::keyReleaseEvent(QKeyEvent *event)
{
int keyValue = sdl_scancode2keysym(QT2SDL2(event->key()));
if (m_activeButton != nullptr) {
if (m_activeButton != nullptr)
{
killTimer(m_timer);
(*ConfigSetParameter)(m_configHandle, m_activeButton->getParamName(), m_activeButton->getParamType(), &keyValue);
(*ConfigSaveFile)();
Expand All @@ -117,43 +123,45 @@ void HotkeyDialog::keyReleaseEvent(QKeyEvent *event)

void HotkeyDialog::timerEvent(QTimerEvent *)
{
if (m_buttonTimer == 0) {
if (m_buttonTimer == 0)
{
killTimer(m_timer);
m_activeButton->setText(m_activeButton->getOrigText());
m_activeButton = nullptr;
for (int i = 0; i < m_coreEventsButtonList.size(); ++i) {
for (int i = 0; i < m_coreEventsButtonList.size(); ++i)
{
m_coreEventsButtonList.at(i)->setDisabled(0);
}
return;
}
--m_buttonTimer;
m_activeButton->setText(QString::number(ceil(m_buttonTimer/10.0)));
m_activeButton->setText(QString::number(ceil(m_buttonTimer / 10.0)));
}

CustomButton::CustomButton(QWidget *parent)
: QPushButton(parent)
{
connect(this, &QPushButton::released, [=]{
connect(this, &QPushButton::released, [=]
{
int buttonTimer = 50;
for (int i = 0; i < ((HotkeyDialog*)m_dialog)->getButtonList()->size(); ++i)
((HotkeyDialog*)m_dialog)->getButtonList()->at(i)->setDisabled(1);
((HotkeyDialog*)m_dialog)->setActiveButton(this);
((HotkeyDialog*)m_dialog)->setButtonTimer(buttonTimer);
origText = text();
setText(QString::number(buttonTimer/10));
((HotkeyDialog*)m_dialog)->setTimer(100);
});
((HotkeyDialog*)m_dialog)->setTimer(100); });
}

ClearButton::ClearButton(QWidget *parent)
: QPushButton(parent)
{
connect(this, &QPushButton::released, [=]{
connect(this, &QPushButton::released, [=]
{
if (((HotkeyDialog*)m_dialog)->getActiveButton() == m_MainButton)
return;
int value = 0;
(*ConfigSetParameter)(m_CurrentHandle, m_ParamName.toUtf8().constData(), m_ParamType, &value);
(*ConfigSaveFile)();
m_MainButton->setText("");
});
m_MainButton->setText(""); });
}
Loading

0 comments on commit 2e6fb1e

Please sign in to comment.