From: timoph Date: Fri, 9 Apr 2010 16:43:55 +0000 (+0000) Subject: Fine tuning save and restore and adding maemo5 style notifications X-Git-Tag: 0.7.2~17 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=0fc78d2c66458cb9d42890e2b7983b5967ec2f1d;hp=3d0c7311ebed17f81381b264e767374a9e5d0ab4;p=impuzzle Fine tuning save and restore and adding maemo5 style notifications git-svn-id: file:///svnroot/impuzzle/trunk@17 e6bec12f-0854-4cc4-ad26-6875f1509f77 --- diff --git a/debian/changelog b/debian/changelog index 326c3b2..e0ce620 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +impuzzle (0.4-1maemo0) unstable; urgency=low + + * Implemented: Game state save and restore + * Implemented: Maemo5 style notifications + + -- Timo Härkönen Wed, 24 Mar 2010 17:51:13 +0200 + impuzzle (0.3-2maemo1) unstable; urgency=low * Added bug tracking link to control diff --git a/debian/control b/debian/control index c5f80ea..9096698 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ XSBC-Bugtracker: mailto:timop.harkonen@gmail.com Package: impuzzle Architecture: any -Depends: libqt4-core (>= 4.6.0), libqt4-gui (>= 4.6.0) +Depends: libqt4-core (>= 4.6.0), libqt4-gui (>= 4.6.0), libqt4-maemo5 (>= 4.6.0) Description: Image puzzle game impuzzle is a picture puzzle game that let's you use your own pictures as the game board. \ No newline at end of file diff --git a/src/defines.h b/src/defines.h index 9dc6baf..ded9e0e 100644 --- a/src/defines.h +++ b/src/defines.h @@ -34,7 +34,7 @@ #define RANDOM_IMAGE_TXT "Random image" #define SELECT_IMAGE_TXT "Select image..." -#define RESTORE_FILE "impuzzle.restore" +#define RESTORE_FILE "impuzzle.dat" #define HOME_DIRECTORY ".impuzzle" #endif // DEFINES_H diff --git a/src/gameview.cpp b/src/gameview.cpp index ee44f0a..ba9b827 100644 --- a/src/gameview.cpp +++ b/src/gameview.cpp @@ -34,6 +34,12 @@ #include #include #include +#include +#include + +#ifdef Q_WS_MAEMO_5 +#include +#endif #include @@ -58,6 +64,7 @@ GameView::GameView(QWidget *parent) : .arg(QDir::homePath()).arg(HOME_DIRECTORY).arg(RESTORE_FILE))) { if(!restoreGame()) { setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount())); + PuzzleItem::setMoveCount(0); } } else { @@ -187,7 +194,7 @@ void GameView::setEmptyPlace(const QPointF &place) emptyPlace_ = place; } -bool GameView::areAllPiecesOk() const +bool GameView::areAllPiecesOk() { for(int i = 0; i < pieces_.count(); ++i) { // Skip hidden piece @@ -211,6 +218,7 @@ bool GameView::areAllPiecesOk() const // Show dialog with move count QMessageBox::about(const_cast(this), tr("You won"), QString("Puzzle completed with %1 moves").arg(PuzzleItem::moveCount())); + emit gameWon(); return true; } @@ -275,9 +283,25 @@ bool GameView::restoreGame() qDebug() << "restore list count: " << list.count(); if(!list.isEmpty()) { - Settings::instance()->setPieceCount(list.at(0).toInt()); + bool ok = false; + int pieces = list.at(0).toInt(&ok); + if(!ok) { + return false; + } QString im = list.at(1); + if(!QFile::exists(im) && im != "default") { + return false; + } + + int moveCount = list.at(2).toInt(&ok); + if(!ok) { + return false; + } + + Settings::instance()->setPieceCount(pieces); + PuzzleItem::setMoveCount(moveCount); + if(im == "default" || im.isEmpty()) { Settings::instance()->setImage(0); Settings::instance()->setImagePath("default"); @@ -286,7 +310,6 @@ bool GameView::restoreGame() Settings::instance()->setImagePath(im); Settings::instance()->setImage(QPixmap(im)); } - PuzzleItem::setMoveCount(list.at(2).toInt()); setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount()), false); @@ -297,13 +320,26 @@ bool GameView::restoreGame() if(!list.at(j + 3).isNull()) { QStringList points = list.at(j + 3).split("#"); //if(points.count() == 2) - QPointF point(points.at(0).toInt(), points.at(1).toInt()); + int x = points.at(0).toInt(&ok); + if(!ok) { + return false; + } + + int y = points.at(1).toInt(&ok); + if(!ok) { + return false; + } + + QPointF point(x, y); - qDebug() << "Setting piece " << pieces_.at(j)->pieceNumber(); - qDebug() << "x: " << point.x() << " y: " << point.y(); + //qDebug() << "Setting piece " << pieces_.at(j)->pieceNumber(); + //qDebug() << "x: " << point.x() << " y: " << point.y(); pieces_.at(j)->setCurrentPlace(point); } + else { + return false; + } } } else { @@ -318,7 +354,7 @@ bool GameView::restoreGame() for(int m = 0; m < pieces_.count(); ++m) { pieces_.at(m)->setPos(pieces_.at(m)->currentPlace()); if(pieces_.at(m)->pieceNumber() == hidden.at(2).toInt()) { - qDebug() << "Hiding piece number " << hidden; + //qDebug() << "Hiding piece number " << hidden; hiddenIndex_ = m; } } @@ -330,7 +366,6 @@ bool GameView::restoreGame() setMovingPieces(); } else { - // TODO: revert setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount())); file.close(); file.remove(); @@ -344,6 +379,16 @@ bool GameView::restoreGame() return false; } + QFileInfo fileInfo(file); + + QDateTime created = fileInfo.created(); + QString infoTxt = QString("Restored game state from %1") + .arg(created.toString(Qt::TextDate)); + +#ifdef Q_WS_MAEMO_5 + QMaemo5InformationBox::information(this, infoTxt); +#endif + file.close(); file.remove(); @@ -378,16 +423,16 @@ bool GameView::saveGame() QTextStream out(&file); out << Settings::instance()->pieceCount(); - out << ";;"; + out << QString(";;"); if(Settings::instance()->imagePath().isEmpty()) { - out << "default"; + out << QString("default"); } else { out << Settings::instance()->imagePath(); } - out << ";;"; + out << QString(";;"); out << PuzzleItem::moveCount(); - out << ";;"; + out << QString(";;"); // piece positions int number = 0; @@ -397,9 +442,9 @@ bool GameView::saveGame() for(int i = 0; i < pieces_.count(); ++i) { if(pieces_.at(i)->pieceNumber() == number + 1) { out << pieces_.at(i)->currentPlace().x(); - out << "#"; + out << QString("#"); out << pieces_.at(i)->currentPlace().y(); - out << ";;"; + out << QString(";;"); pieces_.at(i)->pieceNumber(); if(!pieces_.at(i)->isVisible()) { hiddenNo = number + 1; diff --git a/src/gameview.h b/src/gameview.h index 54e3393..3eb2d7c 100644 --- a/src/gameview.h +++ b/src/gameview.h @@ -34,7 +34,7 @@ public: QList pieces() const; QPointF emptyPlace(); void setEmptyPlace(const QPointF &place); - bool areAllPiecesOk() const; + bool areAllPiecesOk(); void setMovingPieces(); public slots: @@ -43,6 +43,9 @@ public slots: bool restoreGame(); bool saveGame(); +signals: + void gameWon(); + protected: void closeEvent(QCloseEvent *event); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dbb6910..f9bc5ee 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -37,6 +37,8 @@ MainWindow::MainWindow(QWidget *parent) : settingsDialog_ = new SettingsDialog(this); setWindowTitle(tr("ImPuzzle")); + + connect(GameView::instance(), SIGNAL(gameWon()), this, SLOT(gameEnded())); } void MainWindow::createMenu() @@ -61,6 +63,7 @@ void MainWindow::createActions() saveAction_ = new QAction(tr("Save game"), this); connect(saveAction_, SIGNAL(triggered()), GameView::instance(), SLOT(saveGame())); + saveAction_->setDisabled(true); } void MainWindow::importClicked() @@ -75,9 +78,17 @@ void MainWindow::newGameClicked() settingsDialog_->exec(); GameView::instance()->setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount())); + saveAction_->setEnabled(true); } void MainWindow::settingsClicked() { } + +void MainWindow::gameEnded() +{ + if(saveAction_->isEnabled()) { + saveAction_->setDisabled(true); + } +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 756cb43..6623f9c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -36,6 +36,7 @@ private slots: void newGameClicked(); void importClicked(); void settingsClicked(); + void gameEnded(); private: void createActions(); diff --git a/src/src.pro b/src/src.pro index 71f8d8b..c92dcfd 100644 --- a/src/src.pro +++ b/src/src.pro @@ -4,6 +4,10 @@ DEPENDPATH += . INCLUDEPATH += . DESTDIR = ../bin +maemo5 { + QT += maemo5 +} + # Input HEADERS += gameview.h \ mainwindow.h \