Changeset View
Changeset View
Standalone View
Standalone View
src/engine/gameplay.cpp
Show All 29 Lines | |||||
30 | #include "texturehelper.h" | 30 | #include "texturehelper.h" | ||
31 | #include "../file-io/puzzle.h" | 31 | #include "../file-io/puzzle.h" | ||
32 | #include "../file-io/components.h" | 32 | #include "../file-io/components.h" | ||
33 | #include "../file-io/collection.h" | 33 | #include "../file-io/collection.h" | ||
34 | #include "../creator/puzzlecreator.h" | 34 | #include "../creator/puzzlecreator.h" | ||
35 | 35 | | |||
36 | #include "../config/configdialog.h" | 36 | #include "../config/configdialog.h" | ||
37 | #include "settings.h" | 37 | #include "settings.h" | ||
38 | #include <KUrl> | 38 | #include <QUrl> | ||
39 | #include <QStackedWidget> | 39 | #include <QStackedWidget> | ||
40 | #include <QPointer> | 40 | #include <QPointer> | ||
41 | #include <QPropertyAnimation> | 41 | #include <QPropertyAnimation> | ||
42 | #include <QFutureWatcher> | 42 | #include <QFutureWatcher> | ||
43 | #include <QtCore/qmath.h> | 43 | #include <QtCore/qmath.h> | ||
44 | #include <QStandardPaths> | ||||
44 | #include <QInputDialog> | 45 | #include <QInputDialog> | ||
45 | #include <QAction> | 46 | #include <QAction> | ||
47 | #include <QFileDialog> | ||||
46 | #include <KActionCollection> | 48 | #include <KActionCollection> | ||
47 | #include <KLocalizedString> | 49 | #include <KLocalizedString> | ||
48 | #include <KMessageBox> | 50 | #include <KMessageBox> | ||
49 | #include <KFileDialog> | | |||
50 | #include <KStandardDirs> | | |||
51 | 51 | | |||
52 | // Use this because comma in type is not possible in foreach macro. | 52 | // Use this because comma in type is not possible in foreach macro. | ||
53 | typedef QPair<int, int> DoubleIntPair; | 53 | typedef QPair<int, int> DoubleIntPair; | ||
54 | 54 | | |||
55 | //TODO: move LoadingWidget into here (stack into m_centralWidget) | 55 | //TODO: move LoadingWidget into here (stack into m_centralWidget) | ||
56 | 56 | | |||
57 | const int Palapeli::GamePlay::LargePuzzle = 300; | 57 | const int Palapeli::GamePlay::LargePuzzle = 300; | ||
58 | 58 | | |||
▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Line(s) | 291 | { | |||
308 | { | 308 | { | ||
309 | coll->deletePuzzle(indexes.at(0)); | 309 | coll->deletePuzzle(indexes.at(0)); | ||
310 | indexes = m_collectionView->selectedIndexes(); | 310 | indexes = m_collectionView->selectedIndexes(); | ||
311 | } | 311 | } | ||
312 | } | 312 | } | ||
313 | 313 | | |||
314 | void Palapeli::GamePlay::actionImport() | 314 | void Palapeli::GamePlay::actionImport() | ||
315 | { | 315 | { | ||
316 | const QString filter = i18nc("Filter for a file dialog", "*.puzzle|Palapeli puzzles (*.puzzle)"); | 316 | const QString filter = i18nc("Filter for a file dialog", "Palapeli puzzles (*.puzzle)"); | ||
317 | const QStringList paths = KFileDialog::getOpenFileNames(KUrl("kfiledialog:///palapeli-import"), filter); | 317 | const QStringList paths = QFileDialog::getOpenFileNames(m_mainWindow, | ||
318 | i18n("Import Palapeli puzzles"), | ||||
319 | QString(), | ||||
320 | filter); | ||||
318 | Palapeli::Collection* coll = Palapeli::Collection::instance(); | 321 | Palapeli::Collection* coll = Palapeli::Collection::instance(); | ||
319 | foreach (const QString& path, paths) | 322 | foreach (const QString& path, paths) | ||
320 | coll->importPuzzle(path); | 323 | coll->importPuzzle(path); | ||
321 | } | 324 | } | ||
322 | 325 | | |||
323 | void Palapeli::GamePlay::actionExport() | 326 | void Palapeli::GamePlay::actionExport() | ||
324 | { | 327 | { | ||
325 | QModelIndexList indexes = m_collectionView->selectedIndexes(); | 328 | QModelIndexList indexes = m_collectionView->selectedIndexes(); | ||
326 | Palapeli::Collection* coll = Palapeli::Collection::instance(); | 329 | Palapeli::Collection* coll = Palapeli::Collection::instance(); | ||
327 | foreach (const QModelIndex& index, indexes) | 330 | foreach (const QModelIndex& index, indexes) | ||
328 | { | 331 | { | ||
329 | Palapeli::Puzzle* puzzle = coll->puzzleFromIndex(index); | 332 | Palapeli::Puzzle* puzzle = coll->puzzleFromIndex(index); | ||
330 | if (!puzzle) | 333 | if (!puzzle) | ||
331 | continue; | 334 | continue; | ||
332 | //get puzzle name (as an initial guess for the file name) | 335 | //get puzzle name (as an initial guess for the file name) | ||
333 | puzzle->get(Palapeli::PuzzleComponent::Metadata).waitForFinished(); | 336 | puzzle->get(Palapeli::PuzzleComponent::Metadata).waitForFinished(); | ||
334 | const Palapeli::MetadataComponent* cmp = puzzle->component<Palapeli::MetadataComponent>(); | 337 | const Palapeli::MetadataComponent* cmp = puzzle->component<Palapeli::MetadataComponent>(); | ||
335 | if (!cmp) | 338 | if (!cmp) | ||
336 | continue; | 339 | continue; | ||
337 | //ask user for target file name | 340 | //ask user for target file name | ||
338 | const QString startLoc = QString::fromLatin1("kfiledialog:///palapeli-export/%1.puzzle").arg(cmp->metadata.name); | 341 | const QString startLoc = QString::fromLatin1("%1.puzzle").arg(cmp->metadata.name); | ||
339 | const QString filter = i18nc("Filter for a file dialog", "*.puzzle|Palapeli puzzles (*.puzzle)"); | 342 | const QString filter = i18nc("Filter for a file dialog", "Palapeli puzzles (*.puzzle)"); | ||
340 | const QString location = KFileDialog::getSaveFileName(KUrl(startLoc), filter); | 343 | const QString location = QFileDialog::getSaveFileName(m_mainWindow, | ||
344 | i18n("Save Palapeli puzzles"), | ||||
345 | startLoc, | ||||
346 | filter); | ||||
341 | if (location.isEmpty()) | 347 | if (location.isEmpty()) | ||
342 | continue; //process aborted by user | 348 | continue; //process aborted by user | ||
343 | //do export | 349 | //do export | ||
344 | coll->exportPuzzle(index, location); | 350 | coll->exportPuzzle(index, location); | ||
345 | } | 351 | } | ||
346 | } | 352 | } | ||
347 | 353 | | |||
348 | void Palapeli::GamePlay::createHolder() | 354 | void Palapeli::GamePlay::createHolder() | ||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Line(s) | |||||
503 | void Palapeli::GamePlay::restartPuzzle() | 509 | void Palapeli::GamePlay::restartPuzzle() | ||
504 | { | 510 | { | ||
505 | if (!m_puzzle) { | 511 | if (!m_puzzle) { | ||
506 | return; // If no puzzle was successfully loaded and started. | 512 | return; // If no puzzle was successfully loaded and started. | ||
507 | } | 513 | } | ||
508 | // Discard the *.save file. | 514 | // Discard the *.save file. | ||
509 | static const QString pathTemplate = | 515 | static const QString pathTemplate = | ||
510 | QString::fromLatin1("collection/%1.save"); | 516 | QString::fromLatin1("collection/%1.save"); | ||
511 | QFile(KStandardDirs::locateLocal("appdata", | 517 | QFile(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, | ||
512 | pathTemplate.arg(m_puzzle->identifier()))).remove(); | 518 | pathTemplate.arg(m_puzzle->identifier()))).remove(); | ||
513 | // Load the puzzle and re-shuffle the pieces. | 519 | // Load the puzzle and re-shuffle the pieces. | ||
514 | loadPuzzle(); | 520 | loadPuzzle(); | ||
515 | } | 521 | } | ||
516 | 522 | | |||
517 | void Palapeli::GamePlay::teleport(Palapeli::Piece* pieceUnderMouse, | 523 | void Palapeli::GamePlay::teleport(Palapeli::Piece* pieceUnderMouse, | ||
518 | const QPointF& scenePos, Palapeli::View* view) | 524 | const QPointF& scenePos, Palapeli::View* view) | ||
519 | { | 525 | { | ||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Line(s) | 723 | { | |||
721 | m_loadingPuzzle = true; | 727 | m_loadingPuzzle = true; | ||
722 | setPalapeliMode(false); | 728 | setPalapeliMode(false); | ||
723 | // Stop autosaving and progress-reporting and start the loading-widget. | 729 | // Stop autosaving and progress-reporting and start the loading-widget. | ||
724 | m_savegameTimer->stop(); // Just in case it is running ... | 730 | m_savegameTimer->stop(); // Just in case it is running ... | ||
725 | emit reportProgress(0, 0); | 731 | emit reportProgress(0, 0); | ||
726 | // Is there a saved game? | 732 | // Is there a saved game? | ||
727 | static const QString pathTemplate = | 733 | static const QString pathTemplate = | ||
728 | QString::fromLatin1("collection/%1.save"); | 734 | QString::fromLatin1("collection/%1.save"); | ||
729 | KConfig savedConfig(KStandardDirs::locateLocal("appdata", | 735 | KConfig savedConfig(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, | ||
730 | pathTemplate.arg(m_puzzle->identifier()))); | 736 | pathTemplate.arg(m_puzzle->identifier()))); | ||
731 | if (savedConfig.hasGroup(AppearanceSaveGroup)) { | 737 | if (savedConfig.hasGroup(AppearanceSaveGroup)) { | ||
732 | // Get settings for background, shadows, etc. in this puzzle. | 738 | // Get settings for background, shadows, etc. in this puzzle. | ||
733 | restorePuzzleSettings(&savedConfig); | 739 | restorePuzzleSettings(&savedConfig); | ||
734 | } | 740 | } | ||
735 | // Return to the event queue to start the loading-widget graphics ASAP. | 741 | // Return to the event queue to start the loading-widget graphics ASAP. | ||
736 | QTimer::singleShot(0, this, SLOT(loadPuzzleFile())); | 742 | QTimer::singleShot(0, this, SLOT(loadPuzzleFile())); | ||
737 | qDebug() << "END loadPuzzle()"; | 743 | qDebug() << "END loadPuzzle()"; | ||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 827 | secondPiece->addLogicalNeighbors(QList<Palapeli::Piece*>() | |||
822 | << firstPiece); | 828 | << firstPiece); | ||
823 | } | 829 | } | ||
824 | calculatePieceAreaSize(); | 830 | calculatePieceAreaSize(); | ||
825 | m_puzzleTableScene->setPieceAreaSize(m_pieceAreaSize); | 831 | m_puzzleTableScene->setPieceAreaSize(m_pieceAreaSize); | ||
826 | 832 | | |||
827 | // Is there a saved game? | 833 | // Is there a saved game? | ||
828 | static const QString pathTemplate = | 834 | static const QString pathTemplate = | ||
829 | QString::fromLatin1("collection/%1.save"); | 835 | QString::fromLatin1("collection/%1.save"); | ||
830 | KConfig savedConfig(KStandardDirs::locateLocal("appdata", | 836 | KConfig savedConfig(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, | ||
831 | pathTemplate.arg(m_puzzle->identifier()))); | 837 | pathTemplate.arg(m_puzzle->identifier()))); | ||
832 | bool oldFormat = false; | 838 | bool oldFormat = false; | ||
833 | m_restoredGame = false; | 839 | m_restoredGame = false; | ||
834 | int nHolders = 0; | 840 | int nHolders = 0; | ||
835 | if (savedConfig.hasGroup(HeaderSaveGroup)) { | 841 | if (savedConfig.hasGroup(HeaderSaveGroup)) { | ||
836 | KConfigGroup headerGroup(&savedConfig, HeaderSaveGroup); | 842 | KConfigGroup headerGroup(&savedConfig, HeaderSaveGroup); | ||
837 | nHolders = headerGroup.readEntry("N_Holders", 0); | 843 | nHolders = headerGroup.readEntry("N_Holders", 0); | ||
838 | m_restoredGame = true; | 844 | m_restoredGame = true; | ||
▲ Show 20 Lines • Show All 348 Lines • ▼ Show 20 Line(s) | 1182 | { | |||
1187 | if (!m_savegameTimer->isActive()) | 1193 | if (!m_savegameTimer->isActive()) | ||
1188 | m_savegameTimer->start(); | 1194 | m_savegameTimer->start(); | ||
1189 | } | 1195 | } | ||
1190 | 1196 | | |||
1191 | void Palapeli::GamePlay::updateSavedGame() | 1197 | void Palapeli::GamePlay::updateSavedGame() | ||
1192 | { | 1198 | { | ||
1193 | static const QString pathTemplate = | 1199 | static const QString pathTemplate = | ||
1194 | QString::fromLatin1("collection/%1.save"); | 1200 | QString::fromLatin1("collection/%1.save"); | ||
1195 | KConfig savedConfig(KStandardDirs::locateLocal("appdata", | 1201 | KConfig savedConfig(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, | ||
1196 | pathTemplate.arg(m_puzzle->identifier()))); | 1202 | pathTemplate.arg(m_puzzle->identifier()))); | ||
1197 | 1203 | | |||
1198 | savePuzzleSettings(&savedConfig); | 1204 | savePuzzleSettings(&savedConfig); | ||
1199 | 1205 | | |||
1200 | // Save the positions of pieces and attributes of piece-holders. | 1206 | // Save the positions of pieces and attributes of piece-holders. | ||
1201 | KConfigGroup headerGroup (&savedConfig, HeaderSaveGroup); | 1207 | KConfigGroup headerGroup (&savedConfig, HeaderSaveGroup); | ||
1202 | KConfigGroup holderGroup (&savedConfig, HolderSaveGroup); | 1208 | KConfigGroup holderGroup (&savedConfig, HolderSaveGroup); | ||
1203 | KConfigGroup locationGroup (&savedConfig, LocationSaveGroup); | 1209 | KConfigGroup locationGroup (&savedConfig, LocationSaveGroup); | ||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |