Changeset View
Changeset View
Standalone View
Standalone View
src/engine/gameplay.cpp
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Line(s) | 111 | while (! m_viewList.isEmpty()) { | |||
---|---|---|---|---|---|
117 | qDebug() << "scene->clearPieces();"; | 117 | qDebug() << "scene->clearPieces();"; | ||
118 | scene->clearPieces(); | 118 | scene->clearPieces(); | ||
119 | qDebug() << "if (scene != m_puzzleTableScene) {"; | 119 | qDebug() << "if (scene != m_puzzleTableScene) {"; | ||
120 | if (scene != m_puzzleTableScene) { | 120 | if (scene != m_puzzleTableScene) { | ||
121 | qDebug() << "DELETING holder" << view->windowTitle(); | 121 | qDebug() << "DELETING holder" << view->windowTitle(); | ||
122 | delete view; | 122 | delete view; | ||
123 | } | 123 | } | ||
124 | } | 124 | } | ||
125 | m_currentHolder = 0; | 125 | m_currentHolder = nullptr; | ||
126 | m_previousHolder = 0; | 126 | m_previousHolder = nullptr; | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | void Palapeli::GamePlay::init() | 129 | void Palapeli::GamePlay::init() | ||
130 | { | 130 | { | ||
131 | // Set up the collection view. | 131 | // Set up the collection view. | ||
132 | m_collectionView->setModel(Palapeli::Collection::instance()); | 132 | m_collectionView->setModel(Palapeli::Collection::instance()); | ||
133 | connect(m_collectionView, SIGNAL(playRequest(Palapeli::Puzzle*)), SLOT(playPuzzle(Palapeli::Puzzle*))); | 133 | connect(m_collectionView, SIGNAL(playRequest(Palapeli::Puzzle*)), SLOT(playPuzzle(Palapeli::Puzzle*))); | ||
134 | 134 | | |||
Show All 27 Lines | 153 | { | |||
162 | deletePuzzleViews(); | 162 | deletePuzzleViews(); | ||
163 | } | 163 | } | ||
164 | 164 | | |||
165 | //BEGIN action handlers | 165 | //BEGIN action handlers | ||
166 | 166 | | |||
167 | void Palapeli::GamePlay::playPuzzle(Palapeli::Puzzle* puzzle) | 167 | void Palapeli::GamePlay::playPuzzle(Palapeli::Puzzle* puzzle) | ||
168 | { | 168 | { | ||
169 | t.start(); // IDW test. START the clock. | 169 | t.start(); // IDW test. START the clock. | ||
170 | // we need to load the preview every time, although when the puzzle | ||||
171 | // is already loaded because the preview is destroyed in actionGoCollection() | ||||
172 | QTimer::singleShot(0, this, SLOT(loadPreview())); | ||||
173 | | ||||
170 | qDebug() << "START playPuzzle(): elapsed 0"; | 174 | qDebug() << "START playPuzzle(): elapsed 0"; | ||
171 | // Get some current action states from the collection. | 175 | // Get some current action states from the collection. | ||
172 | m_canDeletePuzzle = m_mainWindow->actionCollection()-> | 176 | m_canDeletePuzzle = m_mainWindow->actionCollection()-> | ||
173 | action("game_delete")->isEnabled(); | 177 | action("game_delete")->isEnabled(); | ||
174 | m_canExportPuzzle = m_mainWindow->actionCollection()-> | 178 | m_canExportPuzzle = m_mainWindow->actionCollection()-> | ||
175 | action("game_export")->isEnabled(); | 179 | action("game_export")->isEnabled(); | ||
176 | m_centralWidget->setCurrentWidget(m_puzzleTable); | 180 | m_centralWidget->setCurrentWidget(m_puzzleTable); | ||
177 | m_puzzlePreview = new Palapeli::PuzzlePreview(m_mainWindow); | 181 | m_puzzlePreview = new Palapeli::PuzzlePreview(m_mainWindow); | ||
Show All 23 Lines | |||||
201 | } | 205 | } | ||
202 | m_puzzle = puzzle; | 206 | m_puzzle = puzzle; | ||
203 | qDebug() << "RESTART the clock: elapsed" << t.restart(); // IDW test. | 207 | qDebug() << "RESTART the clock: elapsed" << t.restart(); // IDW test. | ||
204 | loadPuzzle(); | 208 | loadPuzzle(); | ||
205 | qDebug() << "Returned from loadPuzzle(): elapsed" << t.elapsed(); | 209 | qDebug() << "Returned from loadPuzzle(): elapsed" << t.elapsed(); | ||
206 | 210 | | |||
207 | // IDW TODO - There is no way to stop loading a puzzle and start loading | 211 | // IDW TODO - There is no way to stop loading a puzzle and start loading | ||
208 | // another. The only option is to Quit or abort Palapeli. | 212 | // another. The only option is to Quit or abort Palapeli. | ||
209 | | ||||
210 | QTimer::singleShot(0, this, SLOT(loadPreview())); | | |||
211 | } | 213 | } | ||
212 | 214 | | |||
213 | void Palapeli::GamePlay::loadPreview() | 215 | void Palapeli::GamePlay::loadPreview() | ||
214 | { | 216 | { | ||
215 | // IDW TODO - This WAS delaying the showing of the LoadingWidget. Now | 217 | // IDW TODO - This WAS delaying the showing of the LoadingWidget. Now | ||
216 | // it is preventing the balls from moving for a few seconds. | 218 | // it is preventing the balls from moving for a few seconds. | ||
217 | 219 | | |||
218 | // Get metadata from archive (tar), to be sure of getting image data. | 220 | // Get metadata from archive (tar), to be sure of getting image data. | ||
219 | // The config/palapeli-collectionrc file lacks image metadata (because | 221 | // The config/palapeli-collectionrc file lacks image metadata (because | ||
220 | // Palapeli must load the collection-list quickly at startup time). | 222 | // Palapeli must load the collection-list quickly at startup time). | ||
221 | const Palapeli::PuzzleComponent* as = | 223 | const Palapeli::PuzzleComponent* as = | ||
222 | m_puzzle->get(Palapeli::PuzzleComponent::ArchiveStorage); | 224 | m_puzzle->get(Palapeli::PuzzleComponent::ArchiveStorage); | ||
223 | const Palapeli::PuzzleComponent* cmd = (as == 0) ? 0 : | 225 | const Palapeli::PuzzleComponent* cmd = (as == nullptr) ? nullptr : | ||
224 | as->cast(Palapeli::PuzzleComponent::Metadata); | 226 | as->cast(Palapeli::PuzzleComponent::Metadata); | ||
225 | if (cmd) { | 227 | if (cmd) { | ||
226 | // Load puzzle preview image from metadata. | 228 | // Load puzzle preview image from metadata. | ||
227 | const Palapeli::PuzzleMetadata md = | 229 | const Palapeli::PuzzleMetadata md = | ||
228 | dynamic_cast<const Palapeli::MetadataComponent*>(cmd)-> | 230 | dynamic_cast<const Palapeli::MetadataComponent*>(cmd)-> | ||
229 | metadata; | 231 | metadata; | ||
230 | m_puzzlePreview->loadImageFrom(md); | 232 | m_puzzlePreview->loadImageFrom(md); | ||
231 | m_mainWindow->setCaption(md.name); // Set main title. | 233 | m_mainWindow->setCaption(md.name); // Set main title. | ||
234 | delete cmd; | ||||
232 | } | 235 | } | ||
233 | 236 | | |||
234 | m_puzzlePreview->setVisible(Settings::puzzlePreviewVisible()); | 237 | m_puzzlePreview->setVisible(Settings::puzzlePreviewVisible()); | ||
235 | connect (m_puzzlePreview, SIGNAL(closing()), | 238 | connect (m_puzzlePreview, SIGNAL(closing()), | ||
236 | SLOT(actionTogglePreview())); // Hide preview: do not delete. | 239 | SLOT(actionTogglePreview())); // Hide preview: do not delete. | ||
240 | // sync with mainWindow | ||||
241 | m_mainWindow->actionCollection()->action("view_preview")-> | ||||
242 | setChecked(Settings::puzzlePreviewVisible()); | ||||
237 | } | 243 | } | ||
238 | 244 | | |||
239 | void Palapeli::GamePlay::playPuzzleFile(const QString& path) | 245 | void Palapeli::GamePlay::playPuzzleFile(const QString& path) | ||
240 | { | 246 | { | ||
241 | const QString id = Palapeli::Puzzle::fsIdentifier(path); | 247 | const QString id = Palapeli::Puzzle::fsIdentifier(path); | ||
242 | playPuzzle(new Palapeli::Puzzle(new Palapeli::ArchiveStorageComponent, | 248 | playPuzzle(new Palapeli::Puzzle(new Palapeli::ArchiveStorageComponent, | ||
243 | path, id)); | 249 | path, id)); | ||
244 | } | 250 | } | ||
245 | 251 | | |||
246 | void Palapeli::GamePlay::actionGoCollection() | 252 | void Palapeli::GamePlay::actionGoCollection() | ||
247 | { | 253 | { | ||
248 | m_centralWidget->setCurrentWidget(m_collectionView); | 254 | m_centralWidget->setCurrentWidget(m_collectionView); | ||
249 | delete m_puzzlePreview; | 255 | delete m_puzzlePreview; | ||
250 | m_puzzlePreview = 0; | 256 | m_puzzlePreview = nullptr; | ||
251 | m_mainWindow->setCaption(QString()); | 257 | m_mainWindow->setCaption(QString()); | ||
252 | // IDW TODO - Disable piece-holder actions. | 258 | // IDW TODO - Disable piece-holder actions. | ||
253 | foreach (Palapeli::View* view, m_viewList) { | 259 | foreach (Palapeli::View* view, m_viewList) { | ||
254 | if (view != m_puzzleTable->view()) { | 260 | if (view != m_puzzleTable->view()) { | ||
255 | view->hide(); | 261 | view->hide(); | ||
256 | } | 262 | } | ||
257 | } | 263 | } | ||
258 | // Disable playing actions and enable collection actions. | 264 | // Disable playing actions and enable collection actions. | ||
259 | setPalapeliMode(false); | 265 | setPalapeliMode(false); | ||
260 | } | 266 | } | ||
261 | 267 | | |||
262 | void Palapeli::GamePlay::actionTogglePreview() | 268 | void Palapeli::GamePlay::actionTogglePreview() | ||
263 | { | 269 | { | ||
264 | // This action is OK during puzzle loading. | 270 | // This action is OK during puzzle loading. | ||
265 | if (m_puzzlePreview) { | 271 | if (m_puzzlePreview) { | ||
266 | m_puzzlePreview->toggleVisible(); | 272 | m_puzzlePreview->toggleVisible(); | ||
267 | m_mainWindow->actionCollection()->action("view_preview")-> | 273 | m_mainWindow->actionCollection()->action("view_preview")-> | ||
268 | setChecked(Settings::puzzlePreviewVisible()); | 274 | setChecked(Settings::puzzlePreviewVisible()); | ||
275 | // remember state | ||||
276 | updateSavedGame(); | ||||
269 | } | 277 | } | ||
270 | } | 278 | } | ||
271 | 279 | | |||
272 | void Palapeli::GamePlay::actionCreate() | 280 | void Palapeli::GamePlay::actionCreate() | ||
273 | { | 281 | { | ||
274 | QPointer<Palapeli::PuzzleCreatorDialog> creatorDialog(new Palapeli::PuzzleCreatorDialog); | 282 | QPointer<Palapeli::PuzzleCreatorDialog> creatorDialog(new Palapeli::PuzzleCreatorDialog); | ||
275 | if (creatorDialog->exec()) | 283 | if (creatorDialog->exec()) | ||
276 | { | 284 | { | ||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | |||||
412 | } | 420 | } | ||
413 | 421 | | |||
414 | void Palapeli::GamePlay::closeHolder(Palapeli::PieceHolder* h) | 422 | void Palapeli::GamePlay::closeHolder(Palapeli::PieceHolder* h) | ||
415 | { | 423 | { | ||
416 | if (h->scene()->pieces().isEmpty()) { | 424 | if (h->scene()->pieces().isEmpty()) { | ||
417 | int count = m_viewList.count(); | 425 | int count = m_viewList.count(); | ||
418 | m_viewList.removeOne(h); | 426 | m_viewList.removeOne(h); | ||
419 | qDebug() << "m_viewList WAS" << count << "NOW" << m_viewList.count(); | 427 | qDebug() << "m_viewList WAS" << count << "NOW" << m_viewList.count(); | ||
420 | m_currentHolder = 0; | 428 | m_currentHolder = nullptr; | ||
421 | m_previousHolder = 0; | 429 | m_previousHolder = nullptr; | ||
422 | h->deleteLater(); | 430 | h->deleteLater(); | ||
423 | positionChanged(0); // Save change - a little later. | 431 | positionChanged(0); // Save change - a little later. | ||
424 | } | 432 | } | ||
425 | else { | 433 | else { | ||
426 | KMessageBox::information(m_mainWindow, | 434 | KMessageBox::information(m_mainWindow, | ||
427 | i18n("The selected piece holder must be empty " | 435 | i18n("The selected piece holder must be empty " | ||
428 | "before you can delete it.")); | 436 | "before you can delete it.")); | ||
429 | } | 437 | } | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 518 | { | |||
520 | 528 | | |||
521 | // Load the puzzle and re-shuffle the pieces. | 529 | // Load the puzzle and re-shuffle the pieces. | ||
522 | loadPuzzle(); | 530 | loadPuzzle(); | ||
523 | } | 531 | } | ||
524 | 532 | | |||
525 | void Palapeli::GamePlay::teleport(Palapeli::Piece* pieceUnderMouse, | 533 | void Palapeli::GamePlay::teleport(Palapeli::Piece* pieceUnderMouse, | ||
526 | const QPointF& scenePos, Palapeli::View* view) | 534 | const QPointF& scenePos, Palapeli::View* view) | ||
527 | { | 535 | { | ||
528 | qDebug() << "GamePlay::teleport: pieceUnder" << (pieceUnderMouse != 0) | 536 | qDebug() << "GamePlay::teleport: pieceUnder" << (pieceUnderMouse != nullptr) | ||
529 | << "scPos" << scenePos | 537 | << "scPos" << scenePos | ||
530 | << "PuzzleTable?" << (view == m_puzzleTable->view()) | 538 | << "PuzzleTable?" << (view == m_puzzleTable->view()) | ||
531 | << "CurrentHolder?" << (view == m_currentHolder); | 539 | << "CurrentHolder?" << (view == m_currentHolder); | ||
532 | if (! m_currentHolder) { | 540 | if (! m_currentHolder) { | ||
533 | KMessageBox::information(m_mainWindow, | 541 | KMessageBox::information(m_mainWindow, | ||
534 | i18n("You need to have a piece holder and click it to " | 542 | i18n("You need to have a piece holder and click it to " | ||
535 | "select it before you can transfer pieces into or " | 543 | "select it before you can transfer pieces into or " | ||
536 | "out of it.")); | 544 | "out of it.")); | ||
▲ Show 20 Lines • Show All 330 Lines • ▼ Show 20 Line(s) | 868 | { | |||
867 | // calling on a MergeGroup object to join the pieces. | 875 | // calling on a MergeGroup object to join the pieces. | ||
868 | 876 | | |||
869 | qDebug() << "RESTORING SAVED PUZZLE."; | 877 | qDebug() << "RESTORING SAVED PUZZLE."; | ||
870 | KConfigGroup holderGroup (&savedConfig, HolderSaveGroup); | 878 | KConfigGroup holderGroup (&savedConfig, HolderSaveGroup); | ||
871 | KConfigGroup locationGroup (&savedConfig, oldFormat ? | 879 | KConfigGroup locationGroup (&savedConfig, oldFormat ? | ||
872 | FormerSaveGroup : LocationSaveGroup); | 880 | FormerSaveGroup : LocationSaveGroup); | ||
873 | 881 | | |||
874 | // Re-create the saved piece-holders, if any. | 882 | // Re-create the saved piece-holders, if any. | ||
875 | m_currentHolder = 0; | 883 | m_currentHolder = nullptr; | ||
876 | for (int groupID = 1; groupID <= nHolders; groupID++) { | 884 | for (int groupID = 1; groupID <= nHolders; groupID++) { | ||
877 | KConfigGroup holder (&savedConfig, | 885 | KConfigGroup holder (&savedConfig, | ||
878 | QString("Holder_%1").arg(groupID)); | 886 | QString("Holder_%1").arg(groupID)); | ||
879 | // Re-create a piece-holder and add it to m_viewList. | 887 | // Re-create a piece-holder and add it to m_viewList. | ||
880 | qDebug() << "RE-CREATE HOLDER" | 888 | qDebug() << "RE-CREATE HOLDER" | ||
881 | << QString("Holder_%1").arg(groupID) << "name" | 889 | << QString("Holder_%1").arg(groupID) << "name" | ||
882 | << holder.readEntry("Name", QString("")); | 890 | << holder.readEntry("Name", QString("")); | ||
883 | createHolder(holder.readEntry("Name", QString("")), | 891 | createHolder(holder.readEntry("Name", QString("")), | ||
▲ Show 20 Lines • Show All 443 Lines • Show Last 20 Lines |