diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index be405fe..940dd4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" - build-linux: + build-linux-qt5: # The type of runner that the job will run on runs-on: ubuntu-20.04 @@ -30,6 +30,9 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 + - name: "Apt update" + run: "sudo apt-get update" + - name: "Install dependencies" run: "sudo apt-get install build-essential qt5-default cmake libqt5svg5-dev" @@ -38,7 +41,24 @@ jobs: - name: "Build" run: "cd build && make" - + + build-linux-qt6: + runs-on: ubuntu-20.04 + container: + image: archlinux:latest + options: --privileged + steps: + - uses: actions/checkout@v2 + + - name: "Install dependencies" + run: "pacman -Syu --noconfirm base-devel qt6-base qt6-svg cmake" + + - name: "Create build directory and run CMake" + run: "mkdir build && cd build && cmake -DUSE_QT6='YES' .." + + - name: "Build" + run: "cd build && make" + build-windows: runs-on: windows-2019 steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index c3053ff..9ca2a65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ message(STATUS "Using CMake version ${CMAKE_VERSION}") cmake_minimum_required(VERSION 3.1.0) project(libremines - VERSION "1.6.3" + VERSION "1.7.0" DESCRIPTION "A Qt based Minesweeper game" HOMEPAGE_URL "https://github.com/Bollos00/LibreMines" LANGUAGES "CXX" diff --git a/src/libreminesgameengine.cpp b/src/libreminesgameengine.cpp index 2533697..7902ea9 100644 --- a/src/libreminesgameengine.cpp +++ b/src/libreminesgameengine.cpp @@ -287,15 +287,17 @@ void LibreMinesGameEngine::vResetPrincipalMatrix() principalMatrix.clear(); } -void LibreMinesGameEngine::vCleanCell(const uchar _X, const uchar _Y) +bool LibreMinesGameEngine::bCleanCell(const uchar _X, const uchar _Y) { if(!principalMatrix[_X][_Y].hasFlag && principalMatrix[_X][_Y].state == MINE) { // If the user tried to unlock an unflaged mined cell, (s)he lose vGameLost(_X, _Y); + return false; } - else if(principalMatrix[_X][_Y].isHidden && + + if(principalMatrix[_X][_Y].isHidden && !principalMatrix[_X][_Y].hasFlag) { // Unlock the cell @@ -309,140 +311,140 @@ void LibreMinesGameEngine::vCleanCell(const uchar _X, const uchar _Y) _Y == 0) { if(principalMatrix[_X+1][_Y].isHidden) - vCleanCell(_X+1, _Y); + bCleanCell(_X+1, _Y); if(principalMatrix[_X][_Y+1].isHidden) - vCleanCell(_X, _Y+1); + bCleanCell(_X, _Y+1); if(principalMatrix[_X+1][_Y+1].isHidden) - vCleanCell(_X+1, _Y+1); + bCleanCell(_X+1, _Y+1); } else if(_X == 0 && _Y == iY-1) { if(principalMatrix[_X+1][_Y].isHidden) - vCleanCell(_X+1, _Y); + bCleanCell(_X+1, _Y); if(principalMatrix[_X][_Y-1].isHidden) - vCleanCell(_X, _Y-1); + bCleanCell(_X, _Y-1); if(principalMatrix[_X+1][_Y-1].isHidden) - vCleanCell(_X+1, _Y-1); + bCleanCell(_X+1, _Y-1); } else if(_X == iX-1 && _Y == 0) { if(principalMatrix[_X-1][_Y].isHidden) - vCleanCell(_X-1, _Y); + bCleanCell(_X-1, _Y); if(principalMatrix[_X][_Y+1].isHidden) - vCleanCell(_X, _Y+1); + bCleanCell(_X, _Y+1); if(principalMatrix[_X-1][_Y+1].isHidden) - vCleanCell(_X-1, _Y+1); + bCleanCell(_X-1, _Y+1); } else if(_X == iX-1 && _Y == iY-1) { if(principalMatrix[_X-1][_Y].isHidden) - vCleanCell(_X-1, _Y); + bCleanCell(_X-1, _Y); if(principalMatrix[_X][_Y-1].isHidden) - vCleanCell(_X, _Y-1); + bCleanCell(_X, _Y-1); if(principalMatrix[_X-1][_Y-1].isHidden) - vCleanCell(_X-1, _Y-1); + bCleanCell(_X-1, _Y-1); } else if(_X == iX-1 && _Y == 0) { if(principalMatrix[_X-1][_Y].isHidden) - vCleanCell(_X-1, _Y); + bCleanCell(_X-1, _Y); if(principalMatrix[_X][_Y+1].isHidden) - vCleanCell(_X, _Y+1); + bCleanCell(_X, _Y+1); if(principalMatrix[_X-1][_Y+1].isHidden) - vCleanCell(_X-1, _Y+1); + bCleanCell(_X-1, _Y+1); } else if(_X == iX-1 && _Y == iY-1) { if(principalMatrix[_X-1][_Y].isHidden) - vCleanCell(_X-1, _Y); + bCleanCell(_X-1, _Y); if(principalMatrix[_X][_Y-1].isHidden) - vCleanCell(_X, _Y-1); + bCleanCell(_X, _Y-1); if(principalMatrix[_X-1][_Y-1].isHidden) - vCleanCell(_X-1, _Y-1); + bCleanCell(_X-1, _Y-1); } else if(_X == 0 && _Y > 0 && _Y < iY-1) { if(principalMatrix[_X+1][_Y].isHidden) - vCleanCell(_X+1, _Y); + bCleanCell(_X+1, _Y); if(principalMatrix[_X][_Y+1].isHidden) - vCleanCell(_X, _Y+1); + bCleanCell(_X, _Y+1); if(principalMatrix[_X+1][_Y+1].isHidden) - vCleanCell(_X+1, _Y+1); + bCleanCell(_X+1, _Y+1); if(principalMatrix[_X][_Y-1].isHidden) - vCleanCell(_X, _Y-1); + bCleanCell(_X, _Y-1); if(principalMatrix[_X+1][_Y-1].isHidden) - vCleanCell(_X+1, _Y-1); + bCleanCell(_X+1, _Y-1); } else if(_X == iX-1 && _Y > 0 && _Y < iY-1) { if(principalMatrix[_X-1][_Y].isHidden) - vCleanCell(_X-1, _Y); + bCleanCell(_X-1, _Y); if(principalMatrix[_X][_Y+1].isHidden) - vCleanCell(_X, _Y+1); + bCleanCell(_X, _Y+1); if(principalMatrix[_X-1][_Y+1].isHidden) - vCleanCell(_X-1, _Y+1); + bCleanCell(_X-1, _Y+1); if(principalMatrix[_X][_Y-1].isHidden) - vCleanCell(_X, _Y-1); + bCleanCell(_X, _Y-1); if(principalMatrix[_X-1][_Y-1].isHidden) - vCleanCell(_X-1, _Y-1); + bCleanCell(_X-1, _Y-1); } else if(_X > 0 && _X < iX-1 && _Y == 0) { if(principalMatrix[_X-1][_Y].isHidden) - vCleanCell(_X-1, _Y); + bCleanCell(_X-1, _Y); if(principalMatrix[_X+1][_Y].isHidden) - vCleanCell(_X+1, _Y); + bCleanCell(_X+1, _Y); if(principalMatrix[_X-1][_Y+1].isHidden) - vCleanCell(_X-1, _Y+1); + bCleanCell(_X-1, _Y+1); if(principalMatrix[_X][_Y+1].isHidden) - vCleanCell(_X, _Y+1); + bCleanCell(_X, _Y+1); if(principalMatrix[_X+1][_Y+1].isHidden) - vCleanCell(_X+1, _Y+1); + bCleanCell(_X+1, _Y+1); } else if(_X > 0 && _X < iX-1 && _Y == iY-1) { if(principalMatrix[_X+1][_Y].isHidden) - vCleanCell(_X+1, _Y); + bCleanCell(_X+1, _Y); if(principalMatrix[_X-1][_Y].isHidden) - vCleanCell(_X-1, _Y); + bCleanCell(_X-1, _Y); if(principalMatrix[_X-1][_Y-1].isHidden) - vCleanCell(_X-1, _Y-1); + bCleanCell(_X-1, _Y-1); if(principalMatrix[_X][_Y-1].isHidden) - vCleanCell(_X, _Y-1); + bCleanCell(_X, _Y-1); if(principalMatrix[_X+1][_Y-1].isHidden) - vCleanCell(_X+1, _Y-1); + bCleanCell(_X+1, _Y-1); } else { if(principalMatrix[_X-1][_Y-1].isHidden) - vCleanCell(_X-1, _Y-1); + bCleanCell(_X-1, _Y-1); if(principalMatrix[_X-1][_Y].isHidden) - vCleanCell(_X-1, _Y); + bCleanCell(_X-1, _Y); if(principalMatrix[_X-1][_Y+1].isHidden) - vCleanCell(_X-1, _Y+1); + bCleanCell(_X-1, _Y+1); if(principalMatrix[_X][_Y-1].isHidden) - vCleanCell(_X, _Y-1); + bCleanCell(_X, _Y-1); if(principalMatrix[_X][_Y+1].isHidden) - vCleanCell(_X, _Y+1); + bCleanCell(_X, _Y+1); if(principalMatrix[_X+1][_Y-1].isHidden) - vCleanCell(_X+1, _Y-1); + bCleanCell(_X+1, _Y-1); if(principalMatrix[_X+1][_Y].isHidden) - vCleanCell(_X+1, _Y); + bCleanCell(_X+1, _Y); if(principalMatrix[_X+1][_Y+1].isHidden) - vCleanCell(_X+1, _Y+1); + bCleanCell(_X+1, _Y+1); } } @@ -453,6 +455,8 @@ void LibreMinesGameEngine::vCleanCell(const uchar _X, const uchar _Y) vGameWon(); } } + + return true; } void LibreMinesGameEngine::vGameLost(const uchar _X, const uchar _Y) @@ -476,8 +480,12 @@ void LibreMinesGameEngine::vGameWon() } -void LibreMinesGameEngine::vGenerateEndGameScore(qint64 iTimeInNs) +void LibreMinesGameEngine::vGenerateEndGameScore(qint64 iTimeInNs, bool ignorePreferences) { + static qint64 timeLastGame = -1; + + if(iTimeInNs != -1) + timeLastGame = iTimeInNs; int iCorrectFlags = 0, iWrongFlags = 0, @@ -497,14 +505,14 @@ void LibreMinesGameEngine::vGenerateEndGameScore(qint64 iTimeInNs) } } - double timeInSecs = (double)iTimeInNs*1e-9; + double timeInSecs = (double)timeLastGame*1e-9; double dFlagsPerSecond = (double)iCorrectFlags/timeInSecs, dCellsPerSecond = (double)iUnlockedCells/timeInSecs, dPercentageGameComplete = (double)100*iUnlockedCells/iCellsToUnlock; LibreMinesScore score; - score.iTimeInNs = iTimeInNs; + score.iTimeInNs = timeLastGame; score.gameDifficulty = NONE; score.width = iX; score.heigth = iY; @@ -512,7 +520,8 @@ void LibreMinesGameEngine::vGenerateEndGameScore(qint64 iTimeInNs) score.bGameCompleted = iUnlockedCells == iCellsToUnlock; score.dPercentageGameCompleted = dPercentageGameComplete; - Q_EMIT SIGNAL_endGameScore(score, iCorrectFlags, iWrongFlags, iUnlockedCells, dFlagsPerSecond, dCellsPerSecond); + Q_EMIT SIGNAL_endGameScore(score, iCorrectFlags, iWrongFlags, iUnlockedCells, + dFlagsPerSecond, dCellsPerSecond, ignorePreferences); } const std::vector >& LibreMinesGameEngine::getPrincipalMatrix() const @@ -569,7 +578,7 @@ void LibreMinesGameEngine::SLOT_cleanCell(const uchar _X, const uchar _Y) SLOT_startTimer(); bFirst = false; } - vCleanCell(_X, _Y); + bCleanCell(_X, _Y); } void LibreMinesGameEngine::SLOT_addOrRemoveFlag(const uchar _X, const uchar _Y) @@ -628,12 +637,18 @@ void LibreMinesGameEngine::SLOT_cleanNeighborCells(const uchar _X, const uchar _ if(cell.isHidden && !cell.hasFlag) { - vCleanCell(i, j); + if(!bCleanCell(i, j)) + return; } } } } +void LibreMinesGameEngine::SLOT_generateEndGameScoreAgain() +{ + vGenerateEndGameScore(-1, true); +} + void LibreMinesGameEngine::SLOT_UpdateTime() { iTimeInSeconds++; diff --git a/src/libreminesgameengine.h b/src/libreminesgameengine.h index ef2bc5e..6623e7a 100644 --- a/src/libreminesgameengine.h +++ b/src/libreminesgameengine.h @@ -61,11 +61,11 @@ class LibreMinesGameEngine: public QObject void setFirstCellClean(const bool x); private: void vResetPrincipalMatrix(); - void vCleanCell(const uchar _X, const uchar _Y); + bool bCleanCell(const uchar _X, const uchar _Y); void vGameLost(const uchar _X, const uchar _Y); void vGameWon(); - void vGenerateEndGameScore(qint64 iTimeInNs); + void vGenerateEndGameScore(qint64 iTimeInNs = -1, bool ignorePreferences=false); std::vector< std::vector > principalMatrix; /**< TODO: describe */ @@ -93,7 +93,8 @@ class LibreMinesGameEngine: public QObject int iWrongFlags, int iUnlockedCells, double dFlagsPerSecond, - double dCellsPerSecond); + double dCellsPerSecond, + bool ignorePreferences=false); void SIGNAL_currentTime(const ushort); void SIGNAL_minesLeft(const ushort); void SIGNAL_flagCell(const uchar _X, const uchar _Y); @@ -108,6 +109,7 @@ public Q_SLOTS: void SLOT_stop(); void SLOT_startTimer(); void SLOT_cleanNeighborCells(const uchar _X, const uchar _Y); + void SLOT_generateEndGameScoreAgain(); private Q_SLOTS: void SLOT_UpdateTime(); diff --git a/src/libreminesgui.cpp b/src/libreminesgui.cpp index 9c5daa1..b703fd0 100644 --- a/src/libreminesgui.cpp +++ b/src/libreminesgui.cpp @@ -316,6 +316,7 @@ void LibreMinesGui::vNewGame(const uchar _X, buttonQuitInGame->setEnabled(false); buttonRestartInGame->setEnabled(false); buttonSaveMinefieldAsImage->setEnabled(false); + buttonSaveScore->hide(); // Create the game engine instance gameEngine.reset(new LibreMinesGameEngine()); @@ -435,6 +436,10 @@ void LibreMinesGui::vNewGame(const uchar _X, connect(this, &LibreMinesGui::SIGNAL_stopGame, gameEngine.get(), &LibreMinesGameEngine::SLOT_stop); + connect(buttonSaveScore, &QPushButton::released, + gameEngine.get(), &LibreMinesGameEngine::SLOT_generateEndGameScoreAgain); + + if(preferences->optionProgressBar()) { progressBarGameCompleteInGame->setRange(-gameEngine->cellsToUnlock(), 0); @@ -565,6 +570,7 @@ void LibreMinesGui::vCreateGUI(const int width, const int height) buttonRestartInGame = new QPushButton(centralWidget()); buttonQuitInGame = new QPushButton(centralWidget()); buttonSaveMinefieldAsImage = new QPushButton(centralWidget()); + buttonSaveScore = new QPushButton(centralWidget()); labelYouWonYouLost = new QLabel(centralWidget()); labelStatisLastMatch = new QLabel(centralWidget()); @@ -587,6 +593,7 @@ void LibreMinesGui::vCreateGUI(const int width, const int height) buttonRestartInGame->setText(tr("Restart")); buttonQuitInGame->setText(tr("Quit")); buttonSaveMinefieldAsImage->setText(tr("Save Minefield as Image")); + buttonSaveScore->setText(tr("Save Score")); labelYouWonYouLost->setFont(QFont("Liberation Sans", 15)); buttonSaveMinefieldAsImage->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_P)); @@ -757,6 +764,7 @@ void LibreMinesGui::vCreateGUI(const int width, const int height) setTabOrder(sbCustomizedY, buttonRestartInGame); setTabOrder(buttonRestartInGame, buttonQuitInGame); setTabOrder(buttonQuitInGame, buttonSaveMinefieldAsImage); + setTabOrder(buttonSaveMinefieldAsImage, buttonSaveScore); if(width == -1 || height == -1) { @@ -949,7 +957,9 @@ void LibreMinesGui::vAdjustInterfaceInGame() buttonRestartInGame->width(), buttonRestartInGame->height()); buttonSaveMinefieldAsImage->setGeometry(buttonRestartInGame->x(), buttonRestartInGame->y() + buttonRestartInGame->height()*1.1, progressBarGameCompleteInGame->width(), progressBarGameCompleteInGame->height()); - labelYouWonYouLost->setGeometry(lcd_numberMinesLeft->x(), buttonRestartInGame->y()+buttonRestartInGame->height()+h /20, + buttonSaveScore->setGeometry(buttonSaveMinefieldAsImage->x(), buttonSaveMinefieldAsImage->y() + buttonSaveMinefieldAsImage->height()*1.1, + buttonSaveMinefieldAsImage->width(), buttonSaveMinefieldAsImage->height()); + labelYouWonYouLost->setGeometry(buttonSaveScore->x(), buttonSaveScore->y()+buttonSaveScore->height()*1.1, lcd_numberMinesLeft->width(), lcd_numberMinesLeft->height()); labelStatisLastMatch->setGeometry(labelYouWonYouLost->x(), labelYouWonYouLost->y() + labelYouWonYouLost->height(), labelYouWonYouLost->width(), h /5); @@ -965,6 +975,7 @@ void LibreMinesGui::vHideInterfaceInGame() buttonRestartInGame->hide(); buttonQuitInGame->hide(); buttonSaveMinefieldAsImage->hide(); + buttonSaveScore->hide(); labelYouWonYouLost->hide(); labelStatisLastMatch->hide(); widgetBoardContents->hide(); @@ -1176,7 +1187,8 @@ void LibreMinesGui::SLOT_endGameScore(LibreMinesScore score, int iWrongFlags, int iUnlockedCells, double dFlagsPerSecond, - double dCellsPerSecond) + double dCellsPerSecond, + bool ignorePreferences) { QString QS_Statics = tr("Total time: ") + QString::number(score.iTimeInNs*1e-9, 'f', 3) + tr(" secs") + '\n' @@ -1285,18 +1297,26 @@ void LibreMinesGui::SLOT_endGameScore(LibreMinesScore score, QString::number(score.mines); } - // open the dialog - LibreMinesScoresDialog dialog(this, scores.size() + 1); - dialog.setWindowTitle(strGameDiffuclty); - dialog.setWindowIcon(QIcon(":/icons_rsc/icons/libremines.svg")); + AskToSaveMatchScore behaviour = preferences->optionAskToSaveMatchScoreBehaviour(); - dialog.setScores(scores, &score, index); - int result = dialog.exec(); Q_UNUSED(result); - - if(dialog.bSaveEditableScore()) + if(ignorePreferences || + behaviour == LibreMines::SaveAlways || + ((behaviour & LibreMines::SaveWhenGameCompleted) && score.bGameCompleted) || + ((behaviour & LibreMines::SaveWhenNewHighScore) && index == 0)) { - score.username = dialog.stringUserName(); - saveScore = true; + // open the dialog + LibreMinesScoresDialog dialog(this, scores.size() + 1); + dialog.setWindowTitle(strGameDiffuclty); + dialog.setWindowIcon(QIcon(":/icons_rsc/icons/libremines.svg")); + + dialog.setScores(scores, &score, index); + int result = dialog.exec(); Q_UNUSED(result); + + if(dialog.bSaveEditableScore()) + { + score.username = dialog.stringUserName(); + saveScore = true; + } } } @@ -1317,7 +1337,10 @@ void LibreMinesGui::SLOT_endGameScore(LibreMinesScore score, stream << score; } + + buttonSaveScore->setVisible(!saveScore); } + } void LibreMinesGui::SLOT_currentTime(const ushort time) @@ -2200,6 +2223,13 @@ void LibreMinesGui::vLastSessionLoadConfigurationFile() preferences->setOptionMinefieldGenerationAnimation(terms.at(1)); } + else if(terms.at(0).compare("AskToSaveMatchScoreBehaviour", Qt::CaseInsensitive) == 0) + { + if(terms.size() != 2) + continue; + + preferences->setOptionAskToSaveMatchScoreBehaviour(terms.at(1).toUInt()); + } } } @@ -2261,7 +2291,8 @@ void LibreMinesGui::vLastSessionSaveConfigurationFile() << "MaximumCellLength" << ' ' << preferences->optionMaximumCellLength() << '\n' << "FacesReaction" << ' ' << preferences->optionFacesReaction() << '\n' << "ProgressBar" << ' ' << (preferences->optionProgressBar() ? "On" : "Off") << '\n' - << "MinefieldGenerationAnimation" << ' ' << preferences->optionMinefieldGenerationAnimationString() << '\n'; + << "MinefieldGenerationAnimation" << ' ' << preferences->optionMinefieldGenerationAnimationString() << '\n' + << "AskToSaveMatchScoreBehaviour" << ' ' << (uchar)preferences->optionAskToSaveMatchScoreBehaviour() << '\n'; } { diff --git a/src/libreminesgui.h b/src/libreminesgui.h index dbc10eb..c06ba96 100644 --- a/src/libreminesgui.h +++ b/src/libreminesgui.h @@ -190,7 +190,8 @@ private Q_SLOTS: int iWrongFlags, int iUnlockedCells, double dFlagsPerSecond, - double dCellsPerSecond); + double dCellsPerSecond, + bool ignorePreferences=false); void SLOT_currentTime(const ushort time); void SLOT_minesLeft(const ushort minesLeft); void SLOT_flagCell(const uchar _X, const uchar _Y); @@ -255,6 +256,7 @@ private Q_SLOTS: QPushButton *buttonRestartInGame; /**< TODO: describe */ QPushButton *buttonQuitInGame; /**< TODO: describe */ QPushButton* buttonSaveMinefieldAsImage; + QPushButton* buttonSaveScore; QScrollArea* scrollAreaBoard; QWidget* widgetBoardContents; diff --git a/src/libreminespreferencesdialog.cpp b/src/libreminespreferencesdialog.cpp index d61d270..cf54706 100644 --- a/src/libreminespreferencesdialog.cpp +++ b/src/libreminespreferencesdialog.cpp @@ -176,6 +176,21 @@ QString LibreMinesPreferencesDialog::optionMinefieldGenerationAnimationString() return ui->comboBoxMinefieldGenerationAnimation->currentText(); } +AskToSaveMatchScore LibreMinesPreferencesDialog::optionAskToSaveMatchScoreBehaviour() const +{ + if(ui->rbSaveScoreNever->isChecked()) + return LibreMines::SaveNever; + if(ui->rbSaveScoreAlways->isChecked()) + return LibreMines::SaveAlways; + if(ui->rbSaveScoreWhenHighScore->isChecked()) + return LibreMines::SaveWhenNewHighScore; + if(ui->rbSaveScoreWhenGameCompleted->isChecked()) + return LibreMines::SaveWhenGameCompleted; + if(ui->rbSaveScoreWhenHighScoreAndGameCompleted->isChecked()) + return LibreMines::SaveWhenGameCompleted | LibreMines::SaveWhenNewHighScore; + return LibreMines::SaveNever; +} + void LibreMinesPreferencesDialog::setOptionFirstCellClean(const QString &option) { ui->cbFirstCellClean->setChecked(option.compare("On", Qt::CaseInsensitive) == 0); @@ -268,6 +283,25 @@ void LibreMinesPreferencesDialog::setOptionMinefieldGenerationAnimation(const QS ui->comboBoxMinefieldGenerationAnimation->setCurrentText(option); } +void LibreMinesPreferencesDialog::setOptionAskToSaveMatchScoreBehaviour(const uchar option) +{ + switch(option) + { + case LibreMines::SaveNever: + return ui->rbSaveScoreNever->setChecked(true); + case LibreMines::SaveWhenNewHighScore: + return ui->rbSaveScoreWhenHighScore->setChecked(true); + case LibreMines::SaveWhenGameCompleted: + return ui->rbSaveScoreWhenGameCompleted->setChecked(true); + case LibreMines::SaveWhenGameCompleted | LibreMines::SaveWhenNewHighScore: + return ui->rbSaveScoreWhenHighScoreAndGameCompleted->setChecked(true); + case LibreMines::SaveAlways: + return ui->rbSaveScoreAlways->setChecked(true); + } + + return ui->rbSaveScoreNever->setChecked(true); +} + QList LibreMinesPreferencesDialog::optionKeyboardControllerKeys() const { return diff --git a/src/libreminespreferencesdialog.h b/src/libreminespreferencesdialog.h index 603036d..f7b7c99 100644 --- a/src/libreminespreferencesdialog.h +++ b/src/libreminespreferencesdialog.h @@ -44,7 +44,18 @@ enum MinefieldGenerationAnimation : uchar AnimationLimited = 1, AnimationOff = 2 }; + +enum AskToSaveMatchScore : uchar +{ + SaveNever = 0x00, + SaveWhenNewHighScore = 0x01, + SaveWhenGameCompleted = 0x02, + SaveAlways = 0x04 +}; + } +Q_DECLARE_FLAGS(AskToSaveMatchScore, LibreMines::AskToSaveMatchScore) +Q_DECLARE_OPERATORS_FOR_FLAGS(AskToSaveMatchScore) class LibreMinesPreferencesDialog : public QDialog { @@ -67,6 +78,7 @@ class LibreMinesPreferencesDialog : public QDialog QString optionsLanguage()const; uchar optionMinefieldGenerationAnimation()const; QString optionMinefieldGenerationAnimationString()const; + AskToSaveMatchScore optionAskToSaveMatchScoreBehaviour()const; void setOptionFirstCellClean(const QString& option); void setOptionCleanNeighborCellsWhenClickedOnShowedCell(const QString& option); @@ -81,6 +93,7 @@ class LibreMinesPreferencesDialog : public QDialog void setOptionLanguage(const QString& option); void setOptionMinefieldGenerationAnimation(const uchar option); void setOptionMinefieldGenerationAnimation(const QString& option); + void setOptionAskToSaveMatchScoreBehaviour(const uchar option); QList optionKeyboardControllerKeys()const; QString optionKeyboardControllerKeysString()const; diff --git a/src/libreminespreferencesdialog.ui b/src/libreminespreferencesdialog.ui index 92be729..475bad3 100644 --- a/src/libreminespreferencesdialog.ui +++ b/src/libreminespreferencesdialog.ui @@ -6,8 +6,8 @@ 0 0 - 680 - 522 + 757 + 679 @@ -148,8 +148,8 @@ Animation - - + + Keyboard Controller @@ -403,6 +403,81 @@ Animation + + + Scores + + + + + + true + + + + + 0 + 0 + 609 + 213 + + + + + + + Ask to save the match score: + + + + + + Always + + + true + + + + + + + When a new high score is achieved or when the game is completed + + + + + + + When a new high score is achieved + + + + + + + When the game is completed + + + + + + + Never + + + + + + + + + + + + + + Appearance