Skip to content

Commit

Permalink
Merge pull request #24 from Bollos00/dev
Browse files Browse the repository at this point in the history
Upgrade to version 1.6.1
  • Loading branch information
Bollos00 authored Apr 24, 2021
2 parents 7980bba + 6822a41 commit ee80d21
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
message(STATUS "Using CMake version ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.1.0)
project(libremines
VERSION "1.6.0"
VERSION "1.6.1"
DESCRIPTION "A Qt based Minesweeper game"
HOMEPAGE_URL "https://github.com/Bollos00/LibreMines"
LANGUAGES "CXX"
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@ For activate the keyboard controller mode, press one of the following keys: **A|

* **P**: Flag/Unflag Current Cell;

* **Space**: Locate current cell on middle of the scroll bar;

* **CTRL + R**: Retart the game;

* **CTRL + SHIFT + P**: Save minefield as image;

If you do not feel comfortable with those keys, you can edit them going to the main menu, then Options > Preferences.

Tip: hold the **Control Key** while moving to move faster.
Tip: hold the **CTRL** modifier while moving in order to move faster.


## Contributing
Expand All @@ -143,7 +149,7 @@ All kinds of contributions are welcome on this project. You can help:
* Packaging the software for other distributions;
* Increasing the playability and adding new features by making changes on the source code.

# Third party Repositories
# Third party Repositories used in this software
* [BreezeStyleSheets](https://github.com/Alexhuszagh/BreezeStyleSheets)
* [GTRONICK/QSS](https://github.com/GTRONICK/QSS)
* [QDarkStyleSheet](https://github.com/ColinDuquesnoy/QDarkStyleSheet)
Expand Down
2 changes: 2 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ struct KeyboardController
int keyUp;
int keyReleaseCell;
int keyFlagCell;
int keyCenterCell;

bool valid;
};

Expand Down
115 changes: 96 additions & 19 deletions src/libreminesgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <QShortcut>
#include <QMessageBox>
#include <QTranslator>
#include <QStandardPaths>

#include "libreminesgui.h"
#include "libreminesscoresdialog.h"
Expand All @@ -57,6 +58,8 @@ LibreMinesGui::LibreMinesGui(QWidget *parent, const int thatWidth, const int tha
difficult( NONE ),
preferences( new LibreMinesPreferencesDialog(this) )
{
this->resize(800, 600);

connect(preferences, &LibreMinesPreferencesDialog::SIGNAL_optionChanged,
this, &LibreMinesGui::SLOT_optionChanged);

Expand All @@ -70,13 +73,9 @@ LibreMinesGui::LibreMinesGui(QWidget *parent, const int thatWidth, const int tha
});

// Quit the application with Ctrl + Q
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this), &QShortcut::activated,
connect(new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this), &QShortcut::activated,
this, &LibreMinesGui::SLOT_quitApplication);

// Restart the game with Ctrl + R
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_R), this), &QShortcut::activated,
this, &LibreMinesGui::SLOT_RestartGame);

// Create interface with the passed dimensions
vCreateGUI(thatWidth, thatHeight);
vShowMainMenu();
Expand Down Expand Up @@ -228,6 +227,11 @@ bool LibreMinesGui::eventFilter(QObject* object, QEvent* event)
Q_EMIT SIGNAL_addOrRemoveFlag(controller.currentX, controller.currentY);
return true;
}
if(key == Qt::Key_Space)
{
vKeyboardControllerCenterCurrentCell();
return true;
}
if(key == Qt::Key_Escape)
{
controller.active = false;
Expand Down Expand Up @@ -287,6 +291,7 @@ void LibreMinesGui::vNewGame(const uchar _X,

buttonQuitInGame->setEnabled(false);
buttonRestartInGame->setEnabled(false);
buttonSaveMinefieldAsImage->setEnabled(false);

// Create the game engine instance
gameEngine.reset(new LibreMinesGameEngine());
Expand Down Expand Up @@ -363,6 +368,7 @@ void LibreMinesGui::vNewGame(const uchar _X,

buttonQuitInGame->setEnabled(true);
buttonRestartInGame->setEnabled(true);
buttonSaveMinefieldAsImage->setEnabled(true);

// Set the correct state of each cell
vAttributeAllCells();
Expand Down Expand Up @@ -527,6 +533,7 @@ void LibreMinesGui::vCreateGUI(const int width, const int height)
progressBarGameCompleteInGame = new QProgressBar(centralWidget());
buttonRestartInGame = new QPushButton(centralWidget());
buttonQuitInGame = new QPushButton(centralWidget());
buttonSaveMinefieldAsImage = new QPushButton(centralWidget());
labelYouWonYouLost = new QLabel(centralWidget());
labelStatisLastMatch = new QLabel(centralWidget());

Expand All @@ -537,17 +544,23 @@ void LibreMinesGui::vCreateGUI(const int width, const int height)
layoutBoard->setSpacing(0);

widgetBoardContents->setLayout(layoutBoard);
widgetBoardContents->setFocusPolicy(Qt::NoFocus);
scrollAreaBoard->setWidget(widgetBoardContents);
scrollAreaBoard->setFocusPolicy(Qt::NoFocus);

labelTimerInGame->setFont(QFont("Liberation Sans", 40));
labelTimerInGame->setNum(0);
lcd_numberMinesLeft->setDecMode();
lcd_numberMinesLeft->display(0);
progressBarGameCompleteInGame->setTextVisible(false);
buttonQuitInGame->setText(tr("Quit"));
buttonRestartInGame->setText(tr("Restart"));
buttonQuitInGame->setText(tr("Quit"));
buttonSaveMinefieldAsImage->setText(tr("Save Minefield as Image"));
labelYouWonYouLost->setFont(QFont("Liberation Sans", 15));

buttonSaveMinefieldAsImage->setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_P));
buttonRestartInGame->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));

vAdjustInterfaceInGame();
vHideInterfaceInGame();
// Interface In Game
Expand Down Expand Up @@ -630,6 +643,9 @@ void LibreMinesGui::vCreateGUI(const int width, const int height)
connect(buttonQuitInGame, &QPushButton::released,
this, &LibreMinesGui::SLOT_QuitGame);

connect(buttonSaveMinefieldAsImage, &QPushButton::released,
this, &LibreMinesGui::SLOT_saveMinefieldAsImage);

connect(actionPreferences, &QAction::triggered,
preferences, &QDialog::show);

Expand Down Expand Up @@ -706,6 +722,7 @@ void LibreMinesGui::vCreateGUI(const int width, const int height)
setTabOrder(sbCustomizedX, sbCustomizedY);
setTabOrder(sbCustomizedY, buttonRestartInGame);
setTabOrder(buttonRestartInGame, buttonQuitInGame);
setTabOrder(buttonQuitInGame, buttonSaveMinefieldAsImage);

if(width == -1 || height == -1)
{
Expand Down Expand Up @@ -896,6 +913,8 @@ void LibreMinesGui::vAdjustInterfaceInGame()
progressBarGameCompleteInGame->width()/2, h /20);
buttonQuitInGame->setGeometry(buttonRestartInGame->x()+buttonRestartInGame->width(), buttonRestartInGame->y(),
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,
lcd_numberMinesLeft->width(), lcd_numberMinesLeft->height());
labelStatisLastMatch->setGeometry(labelYouWonYouLost->x(), labelYouWonYouLost->y() + labelYouWonYouLost->height(),
Expand All @@ -911,6 +930,7 @@ void LibreMinesGui::vHideInterfaceInGame()
progressBarGameCompleteInGame->hide();
buttonRestartInGame->hide();
buttonQuitInGame->hide();
buttonSaveMinefieldAsImage->hide();
labelYouWonYouLost->hide();
labelStatisLastMatch->hide();
widgetBoardContents->hide();
Expand All @@ -926,6 +946,7 @@ void LibreMinesGui::vShowInterfaceInGame()
progressBarGameCompleteInGame->show();
buttonRestartInGame->show();
buttonQuitInGame->show();
buttonSaveMinefieldAsImage->show();
labelYouWonYouLost->show();
labelStatisLastMatch->show();
widgetBoardContents->show();
Expand Down Expand Up @@ -1430,7 +1451,8 @@ void LibreMinesGui::SLOT_optionChanged(const QString &name, const QString &value

void LibreMinesGui::SLOT_quitApplication()
{
if(gameEngine && gameEngine->isGameActive())
if(gameEngine && gameEngine->isGameActive() &&
progressBarGameCompleteInGame->value() != progressBarGameCompleteInGame->minimum())
{
QMessageBox messageBox;

Expand Down Expand Up @@ -1538,6 +1560,35 @@ void LibreMinesGui::SLOT_toggleFullScreen()
}
}

void LibreMinesGui::SLOT_saveMinefieldAsImage()
{
if(controller.active)
qApp->restoreOverrideCursor();

QString picturesDirPAth = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
if(picturesDirPAth.isEmpty())
picturesDirPAth = QDir::currentPath();

QString fileName = "libremines_screeshoot" + QDateTime::currentDateTime().toString(Qt::ISODate).replace(':', '_') + ".png";

QString fullFileName = QFileDialog::getSaveFileName(
this,
tr("Save Minefield as image"),
picturesDirPAth + '/' + fileName,
tr("Image (*.bmp *.jpg *png *.jpeg)"));

if(fullFileName.isEmpty())
return;

QImage image(widgetBoardContents->size(), QImage::Format_RGBA64);
QPainter painter(&image);
widgetBoardContents->render(&painter);
image.save(fullFileName);

if(controller.active)
qApp->setOverrideCursor(QCursor(Qt::BlankCursor));
}

void LibreMinesGui::vSetApplicationTheme(const QString& theme)
{
if(theme.compare("FusionDark", Qt::CaseInsensitive) == 0)
Expand Down Expand Up @@ -1742,6 +1793,9 @@ void LibreMinesGui::vKeyboardControllerSetCurrentCell(const uchar x, const uchar

cellGui.label->setPixmap(QPixmap::fromImage(img));
}

scrollAreaBoard->ensureVisible(x*cellLength + cellLength/2, y*cellLength + cellLength/2,
cellLength/2 + 1, cellLength/2 + 1);
}

void LibreMinesGui::vKeyboardControllUnsetCurrentCell()
Expand Down Expand Up @@ -1917,6 +1971,15 @@ void LibreMinesGui::vKeyboardControllerMoveUp()
vKeyboardControllerSetCurrentCell(controller.currentX, destY);
}

void LibreMinesGui::vKeyboardControllerCenterCurrentCell()
{
const uchar x = controller.currentX;
const uchar y = controller.currentY;
scrollAreaBoard->ensureVisible(x*cellLength + cellLength/2, y*cellLength + cellLength/2,
cellLength/2 + scrollAreaBoard->width()/2, cellLength/2 + scrollAreaBoard->height()/2);

}

void LibreMinesGui::vLastSessionLoadConfigurationFile()
{
QDir destDir = QDir::home();
Expand Down Expand Up @@ -2009,18 +2072,31 @@ void LibreMinesGui::vLastSessionLoadConfigurationFile()
}
else if(terms.at(0).compare("KeyboardControllerKeys", Qt::CaseInsensitive) == 0)
{
if(terms.size() != 7)
continue;

preferences->setOptionKeyboardControllerKeys(
{
terms.at(1).toInt(nullptr, 16),
terms.at(2).toInt(nullptr, 16),
terms.at(3).toInt(nullptr, 16),
terms.at(4).toInt(nullptr, 16),
terms.at(5).toInt(nullptr, 16),
terms.at(6).toInt(nullptr, 16),
});
if(terms.size() == 7)
{
preferences->setOptionKeyboardControllerKeys(
{
terms.at(1).toInt(nullptr, 16),
terms.at(2).toInt(nullptr, 16),
terms.at(3).toInt(nullptr, 16),
terms.at(4).toInt(nullptr, 16),
terms.at(5).toInt(nullptr, 16),
terms.at(6).toInt(nullptr, 16)
});
}
else if(terms.size() == 8)
{
preferences->setOptionKeyboardControllerKeys(
{
terms.at(1).toInt(nullptr, 16),
terms.at(2).toInt(nullptr, 16),
terms.at(3).toInt(nullptr, 16),
terms.at(4).toInt(nullptr, 16),
terms.at(5).toInt(nullptr, 16),
terms.at(6).toInt(nullptr, 16),
terms.at(7).toInt(nullptr, 16)
});
}
}
else if(terms.at(0).compare("MinefieldTheme", Qt::CaseInsensitive) == 0)
{
Expand Down Expand Up @@ -2152,6 +2228,7 @@ void LibreMinesGui::vUpdatePreferences()
controller.keyDown = keys.at(3);
controller.keyReleaseCell= keys.at(4);
controller.keyFlagCell = keys.at(5);
controller.keyCenterCell = keys.at(6);

controller.valid = true;
for (int i=0; i<keys.size()-1; ++i)
Expand Down
4 changes: 4 additions & 0 deletions src/libreminesgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class LibreMinesGui : public QMainWindow
void vKeyboardControllerMoveRight();
void vKeyboardControllerMoveDown();
void vKeyboardControllerMoveUp();
void vKeyboardControllerCenterCurrentCell();

void vLastSessionLoadConfigurationFile();
void vLastSessionSaveConfigurationFile();
Expand Down Expand Up @@ -209,6 +210,8 @@ private Q_SLOTS:

void SLOT_toggleFullScreen();

void SLOT_saveMinefieldAsImage();

Q_SIGNALS:
void SIGNAL_cleanCell(const uchar _X, const uchar _Y);
void SIGNAL_cleanNeighborCells(const uchar _X, const uchar _Y);
Expand Down Expand Up @@ -251,6 +254,7 @@ private Q_SLOTS:
QProgressBar* progressBarGameCompleteInGame;
QPushButton *buttonRestartInGame; /**< TODO: describe */
QPushButton *buttonQuitInGame; /**< TODO: describe */
QPushButton* buttonSaveMinefieldAsImage;

QScrollArea* scrollAreaBoard;
QWidget* widgetBoardContents;
Expand Down
10 changes: 9 additions & 1 deletion src/libreminespreferencesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ LibreMinesPreferencesDialog::LibreMinesPreferencesDialog(QWidget *parent) :
ui->keyInputMoveDown->setKey(Qt::Key_S);
ui->keyInputReleaseCell->setKey(Qt::Key_O);
ui->keyInputFlagCell->setKey(Qt::Key_P);
ui->keyInputCenterCell->setKey(Qt::Key_Space);
}

LibreMinesPreferencesDialog::~LibreMinesPreferencesDialog()
Expand Down Expand Up @@ -251,7 +252,8 @@ QList<int> LibreMinesPreferencesDialog::optionKeyboardControllerKeys() const
ui->keyInputMoveRight->currentKey(),
ui->keyInputMoveDown->currentKey(),
ui->keyInputReleaseCell->currentKey(),
ui->keyInputFlagCell->currentKey()
ui->keyInputFlagCell->currentKey(),
ui->keyInputCenterCell->currentKey()
};
}

Expand All @@ -270,6 +272,8 @@ QString LibreMinesPreferencesDialog::optionKeyboardControllerKeysString() const
s += QString::number(ui->keyInputReleaseCell->currentKey(), 16);
s += ' ';
s += QString::number(ui->keyInputFlagCell->currentKey(), 16);
s += ' ';
s += QString::number(ui->keyInputCenterCell->currentKey(), 16);

return s;
}
Expand All @@ -282,6 +286,10 @@ void LibreMinesPreferencesDialog::setOptionKeyboardControllerKeys(const QList<in
ui->keyInputMoveDown->setKey(keys.at(3));
ui->keyInputReleaseCell->setKey(keys.at(4));
ui->keyInputFlagCell->setKey(keys.at(5));
if(keys.size() == 7)
{
ui->keyInputCenterCell->setKey(keys.at(6));
}
}

void LibreMinesPreferencesDialog::closeEvent(QCloseEvent *e)
Expand Down
Loading

0 comments on commit ee80d21

Please sign in to comment.