ScoresForm & MainForm: Selection of scores source (local/remote) implemented.
[mines3d.git] / ui / qt / MainForm.cpp
blob245cd1adf5d82a23a29698035db49b9dfa3e0386
1 /*
2 * File: MainForm.cpp
3 * Created: 7.1.2010
4 * Author: Petr Kubizňák
5 * Purpose:
6 */
8 /* -------------------------------------------------------------------------- */
10 #include "MainForm.h"
11 #include "../../asserts.h"
12 #include "../../exceptions/GeneralException.h"
13 #include <QtGui/QPushButton>
14 #include <QtGui/QLabel>
15 #include <QtGui/QMouseEvent>
16 #include <QtGui/QInputDialog>
17 #include <QtGui/QMessageBox>
18 #include <cstdio>
19 #include <iostream>
20 #include <fstream>
21 using namespace std;
23 /***************************** CLASS FieldButton ******************************/
25 FieldButton::FieldButton(MainForm *mainForm, int posX, int posY, int posZ) : QPushButton(mainForm) {
26 this->mainForm = mainForm;
28 //obecne nastaveni
29 this->posX = posX;
30 this->posY = posY;
31 this->posZ = posZ;
32 this->setText(" ");
33 this->setCheckable(true);
34 this->setFocusPolicy(Qt::NoFocus);
35 this->setMinimumWidth(23);
36 this->setMinimumHeight(23);
38 //rozmery komponent
39 QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
40 sizePolicy.setHorizontalStretch(0);
41 sizePolicy.setVerticalStretch(0);
42 sizePolicy.setHeightForWidth(true);
43 this->setSizePolicy(sizePolicy);
45 //fonty: normalni a zvyrazneny (pro oznacena tlacitka)
46 fontNormal = new QFont(this->font());
47 fontHighlight = new QFont(this->font());
48 fontHighlight->setUnderline(true);
49 fontHighlight->setBold(true);
52 /* -------------------------------------------------------------------------- */
54 FieldButton::~FieldButton(void) {
55 delete fontNormal;
56 delete fontHighlight;
59 /* -------------------------------------------------------------------------- */
61 /* stisk tlacitka */
62 void FieldButton::onClick(bool b) {
63 this->setChecked(true);
64 if(b) mainForm->uncover(posZ, posY, posX);
67 /* -------------------------------------------------------------------------- */
69 /* udalost najeti mysi nad tlacitko */
70 void FieldButton::enterEvent(QEvent *e) {
71 assert(mainForm);
72 mainForm->buttonHovered(posZ, posY, posX);
74 QPushButton::enterEvent(e);
77 /* -------------------------------------------------------------------------- */
79 /* udalost odjeti mysi z tlacitka */
80 void FieldButton::leaveEvent(QEvent *e) {
81 assert(mainForm);
82 mainForm->buttonLeft(posZ, posY, posX);
84 QPushButton::leaveEvent(e);
87 /* -------------------------------------------------------------------------- */
89 /* udalost stisku tlacitka */
90 void FieldButton::mousePressEvent(QMouseEvent *e) {
91 if(e->button() == Qt::RightButton) {
92 if(!this->isChecked()) mainForm->mark(posZ, posY, posX);
95 if(e->button() == Qt::MiddleButton )
97 mainForm->locked = !mainForm->locked;
100 QPushButton::mousePressEvent(e);
103 /* -------------------------------------------------------------------------- */
105 /* zvyrazni tlacitko zmenou fontu */
106 void FieldButton::highlight(void) {
107 this->setFont(*fontHighlight);
110 /* -------------------------------------------------------------------------- */
112 /* "odvyrazni" tlacitko zpet */
113 void FieldButton::unhighlight(void) {
114 this->setFont(*fontNormal);
118 /*********************************/// CLASS ///********************************/
120 /**************************** Class MarksIndicator ****************************/
122 /* -------------------------------------------------------------------------- */
124 MarksIndicator::MarksIndicator(QWidget *parent, int total) : QLabel(parent) {
125 this->total = total;
126 this->marked = 0;
127 fontNormal = new QFont(this->font());
128 fontBold = new QFont(this->font());
129 fontBold->setBold(true);
132 /* -------------------------------------------------------------------------- */
134 MarksIndicator::~MarksIndicator(void) {
135 delete fontNormal;
136 delete fontBold;
139 /* -------------------------------------------------------------------------- */
141 /* prekresli komponentu */
142 void MarksIndicator::repaint(void) {
143 char str[20];
144 sprintf(str, "Marks: %d / %d ", marked, total);
145 this->setText(str);
146 this->setFont(marked <= total ? *fontNormal : *fontBold);
149 /* -------------------------------------------------------------------------- */
151 /* nastavi celkovy pocet vlajecek, totez vraci */
152 int MarksIndicator::setTotal(int value) {
153 total = value;
154 repaint();
155 return value;
158 /* -------------------------------------------------------------------------- */
160 /* nastavi oznaceny pocet vlajecek, totez vraci */
161 int MarksIndicator::setMarked(int value) {
162 marked = value;
163 repaint();
164 return value;
167 /*********************************/// CLASS ///********************************/
169 /******************************* Class MainForm *******************************/
171 //makro pro otestovani existence tlacitka se zadanym umistenim
172 #define TEST_COORDS(l,r,c) { assert(l>=0 && l<this->layers); \
173 assert(r>=0 && r<this->rows); assert(c>=0 && c<this->cols); }
175 //nazev souboru s nastavenim
176 #define FILE_SETTINGS ".mines3d_settings"
177 #define FILE_SCORES_ROOKIE ".mines3d_scores_rookie"
178 #define FILE_SCORES_ADVANCED ".mines3d_scores_advanced"
179 #define FILE_SCORES_SUICIDE ".mines3d_scores_suicide"
180 #define FILE_SCORES_CUSTOM ".mines3d_scores_custom"
182 /* -------------------------------------------------------------------------- */
184 MainForm::MainForm(QWidget *parent) : QMainWindow(parent) {
185 ui.setupUi(this);
187 //zrusime zbytecne okraje
188 ui.scrollArea->setContentsMargins(0,0,0,0);
189 ui.scrollAreaWidgetContents->setContentsMargins(0,0,0,0);
190 ui.horizontalLayout->setContentsMargins(0,0,0,0);
191 ui.boardWidget->setContentsMargins(0,0,0,0);
192 ui.verticalLayout_3->setContentsMargins(0,0,0,0);
194 //status bar
195 marksIndicator = new MarksIndicator(this);
196 statusBar()->addPermanentWidget(marksIndicator);
198 //napojeni signalu na sloty
199 QObject::connect(ui.actionNew, SIGNAL(triggered()), this, SLOT(actionNew_Trigger()));
200 QObject::connect(ui.actionSettings, SIGNAL(triggered()), this, SLOT(actionSettings_Trigger()));
201 QObject::connect(ui.actionScores, SIGNAL(triggered()), this, SLOT(actionScores_Trigger()));
202 QObject::connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(actionAbout_Trigger()));
204 board = NULL;
205 settingsFrm = NULL;
206 scoresFrm = NULL;
207 aboutFrm = NULL;
209 tc = new Thread_controller();
210 sql_c = new Sql_connector();
211 locked = false;
213 //nacteme nastaveni ze souboru, pri neuspechu pouzijeme vychozi hodnoty
214 if(!loadSettings()) {
215 layers = PRESETS[0][0];
216 rows = PRESETS[0][1];
217 cols = PRESETS[0][2];
218 mines = PRESETS[0][3];
219 soundMusic = MUSIC_SLOW;
220 audioController.bSoundEnabled = true;
222 if(soundMusic < 0 || soundMusic >= NUM_MUSICS) soundMusic = MUSIC_NOTHING;
223 //nacteme vysledky predchozich her
224 loadScores();
225 loadRemoteScores();
226 name = "<unknown>"; //vychozi jmeno uzivatele (pri zapisu do vysledku)
228 //vyrobime novou hru
229 newGame();
232 /* -------------------------------------------------------------------------- */
234 MainForm::~MainForm() {
235 cout << "MAINFORM DESTRUCTOR" << endl;
236 freeGui();
237 saveSettings();
238 saveScores();
239 delete settingsFrm;
240 delete scoresFrm;
241 delete aboutFrm;
242 delete marksIndicator;
245 /* -------------------------------------------------------------------------- */
247 /* nacte nastaveni ze standardniho souboru, vraci uspech operace */
248 bool MainForm::loadSettings(void) {
249 ifstream ifs(FILE_SETTINGS, ifstream::in);
250 if(!ifs.good()) return false;
251 ifs >> layers >> rows >> cols >> mines >> soundMusic >> audioController.bSoundEnabled;
252 if(!ifs.good() || layers<=0 || rows<=0 || cols<=0 || mines<=0) {
253 ifs.close();
254 return false;
256 ifs.close();
257 return true;
260 /* -------------------------------------------------------------------------- */
262 /* ulozi nastaveni do standardniho souboru, vraci uspech operace */
263 bool MainForm::saveSettings(void) {
264 ofstream ofs(FILE_SETTINGS, ofstream::out);
265 if(!ofs.good()) return false;
266 ofs << layers << " " << rows << " " << cols << " " << mines << " " <<
267 soundMusic << " " << audioController.bSoundEnabled << endl << endl;
268 if(!ofs.good()) return false;
269 ofs.close();
270 return true;
273 /* -------------------------------------------------------------------------- */
275 /* nacte vsechna skore, vraci uspech operace */
276 bool MainForm::loadScores(void) {
277 return loadScoresFile(scoreRookie, FILE_SCORES_ROOKIE) &
278 loadScoresFile(scoreAdvanced, FILE_SCORES_ADVANCED) &
279 loadScoresFile(scoreSuicide, FILE_SCORES_SUICIDE) &
280 loadScoresFile(scoreCustom, FILE_SCORES_CUSTOM);
283 /* -------------------------------------------------------------------------- */
285 /* ulozi vsechna skore, vraci uspech operace */
286 bool MainForm::saveScores(void) {
287 return saveScoresFile(scoreRookie, FILE_SCORES_ROOKIE) &
288 saveScoresFile(scoreAdvanced, FILE_SCORES_ADVANCED) &
289 saveScoresFile(scoreSuicide, FILE_SCORES_SUICIDE) &
290 saveScoresFile(scoreCustom, FILE_SCORES_CUSTOM);
293 /* -------------------------------------------------------------------------- */
295 /* nacte skore ze zadaneho souboru do daneho listu, vraci uspech operace */
296 bool MainForm::loadScoresFile(list<ScoreRecord> &scoresList, const char *filename) {
297 ifstream ifs(filename, ifstream::in);
298 if(!ifs.good()) return false;
299 //dokud je co cist, cteme soubor do struktury
300 while(true) {
301 ScoreRecord scoreItem;
302 ifs >> scoreItem.time;
303 ifs.ignore(1); //ignorujeme mezeru
304 ifs.getline(scoreItem.name, sizeof(scoreItem.name));
305 if(!ifs.good()) {
306 ifs.close();
307 return true;
309 scoresList.push_back(scoreItem);
313 /* -------------------------------------------------------------------------- */
315 /* ulozi skore do zadaneho souboru z daneho listu, vraci uspech operace */
316 bool MainForm::saveScoresFile(list<ScoreRecord> &scoresList, const char *filename) {
317 ofstream ofs(filename, ofstream::out);
318 if(!ofs.good()) return false;
319 //zapiseme strukturu do souboru
320 for(list<ScoreRecord>::iterator it = scoresList.begin(); it != scoresList.end(); it++)
321 ofs << (*it).time << " " << (*it).name << endl;
322 ofs << endl;
323 if(!ofs.good()) return false;
324 ofs.close();
325 return true;
328 /* -------------------------------------------------------------------------- */
330 bool MainForm::loadRemoteScores(void) {
331 bool b = true;
332 sql_c->connect();
333 b &= sql_c->getTop10(Board::ModeRookie , scoreRookieSql);
334 b &= sql_c->getTop10(Board::ModeAdvanced , scoreAdvancedSql);
335 b &= sql_c->getTop10(Board::ModeSuicide , scoreSuicideSql);
336 b &= sql_c->getTop10(Board::ModeCustom , scoreCustomSql);
337 sql_c->disconnect();
338 return b;
341 /* -------------------------------------------------------------------------- */
343 /* vraci true, pokud "a" predchazi pred "b" (podle casu), jinak false */
344 bool MainForm::cmpScoreByTime(const ScoreRecord &a, const ScoreRecord &b) {
345 return a.time < b.time;
348 /* -------------------------------------------------------------------------- */
350 /* vyrobi tlacitka a dalsi komponenty potrebne pro hru
351 * jako meze cyklu pouziva hodnoty layers, rows, cols a mines! */
352 void MainForm::buildGui(void) {
353 layerWidget = new QWidget * [layers];
354 layerGrid = new QGridLayout * [layers];
355 fieldBtn = new FieldButton *** [layers];
356 for(int i=0; i<layers; i++) {
357 layerWidget[i] = new QWidget(ui.scrollAreaWidgetContents);
358 ui.verticalLayout_3->addWidget(layerWidget[i]);
359 layerGrid[i] = new QGridLayout(layerWidget[i]);
360 layerGrid[i]->setHorizontalSpacing(0);
361 layerGrid[i]->setVerticalSpacing(0);
363 fieldBtn[i] = new FieldButton ** [rows];
364 for(int j=0; j<rows; j++) {
365 fieldBtn[i][j] = new FieldButton * [cols];
366 for(int k=0; k<cols; k++) {
367 fieldBtn[i][j][k] = new FieldButton(this, k, j, i);
368 layerGrid[i]->addWidget(fieldBtn[i][j][k], j, k);
369 QObject::connect(fieldBtn[i][j][k], SIGNAL(clicked(bool)), fieldBtn[i][j][k], SLOT(onClick(bool)));
374 tc->update_data(rows,cols,layers,board);
375 tc->run_thread();
378 /* -------------------------------------------------------------------------- */
380 /* uvolni prostredky alokovane metodou buildGui()
381 * jako meze cyklu pouziva rozmery v board! */
382 void MainForm::freeGui(void) {
383 for(int i=0; i<board->getLayersCount(); i++) {
384 for(int j=0; j<board->getRowsCount(); j++) {
385 for(int k=0; k<board->getColsCount(); k++) delete fieldBtn[i][j][k];
386 delete [] fieldBtn[i][j];
388 delete [] fieldBtn[i];
390 delete [] fieldBtn;
392 for(int i=0; i<board->getLayersCount(); i++) {
393 delete layerGrid[i];
394 delete layerWidget[i];
396 delete [] layerGrid;
397 delete [] layerWidget;
400 /* -------------------------------------------------------------------------- */
402 /* volano tridou FieldButton pri udalosti enterEvent, zvyrazni souvisejici tlacitka */
403 void MainForm::buttonHovered(int l, int r, int c) {
404 TEST_COORDS(l,r,c)
406 if(gameOver) return;
408 tc->mutex_lock();
409 if (!locked)
411 tc->selected[0] = l;
412 tc->selected[1] = r;
413 tc->selected[2] = c;
414 if ( tc->ptf != 0 )tc->ptf();
416 tc->selected[3] = l;
417 tc->selected[4] = r;
418 tc->selected[5] = c;
419 tc->mutex_unlock();
421 for(int nl=l-1; nl<=l+1; nl++) {
422 if(nl<0 || nl>=this->layers) continue;
423 for(int nr=r-1; nr<=r+1; nr++) {
424 if(nr<0 || nr>=this->rows) continue;
425 for(int nc=c-1; nc<=c+1; nc++) {
426 if(nc<0 || nc>=this->cols) continue;
427 fieldBtn[nl][nr][nc]->highlight();
431 audioController.PlaySound(SOUND_BUTTON_HOVER);
434 /* -------------------------------------------------------------------------- */
436 /* volano tridou FieldButton pri udalosti leaveEvent, odzvyrazni souvisejici tlacitka */
437 void MainForm::buttonLeft(int l, int r, int c) {
438 TEST_COORDS(l,r,c)
440 if(gameOver) return;
442 for(int nl=l-1; nl<=l+1; nl++) {
443 if(nl<0 || nl>=this->layers) continue;
444 for(int nr=r-1; nr<=r+1; nr++) {
445 if(nr<0 || nr>=this->rows) continue;
446 for(int nc=c-1; nc<=c+1; nc++) {
447 if(nc<0 || nc>=this->cols) continue;
448 fieldBtn[nl][nr][nc]->unhighlight();
454 /* -------------------------------------------------------------------------- */
456 /* volano tridou FieldButton pri stisku tlacitka, odkryje souvisejici tlacitka */
457 int MainForm::uncover(int l, int r, int c) {
458 TEST_COORDS(l,r,c)
459 char numStr[10];
461 startTime(); //pokud jeste nemerime cas, zacneme nyni
463 //pole je oznacene jako zaminovane, nejde odkryt
464 if(board->getField(l,r,c).hasMark()) {
465 fieldBtn[l][r][c]->setChecked(false);
466 audioController.PlaySound(SOUND_NOTHING);
467 return SOUND_NOTHING;
470 //odkryjeme pole
471 if(board->uncover(l, r, c)) { //VYBUCH!
472 fieldBtn[l][r][c]->setText("!!");
473 audioController.PlaySound(SOUND_GAME_OVER);
474 setGameOver(false);
475 return SOUND_GAME_OVER;
476 } else {
477 int num = board->getField(l,r,c).getNeighboursCnt();
478 if(num) {
479 sprintf(numStr, "%d", num);
480 fieldBtn[l][r][c]->setText(numStr); //vypiseme pocet min v okoli
481 } else { //0 min -> musime zaktualizovat celou desku
482 for(int i=0; i<this->layers; i++)
483 for(int j=0; j<this->rows; j++)
484 for(int k=0; k<this->cols; k++) {
485 fieldBtn[i][j][k]->setChecked(!board->getField(i,j,k).isCovered());
486 if(fieldBtn[i][j][k]->isChecked()) {
487 num = board->getField(i,j,k).getNeighboursCnt();
488 sprintf(numStr, "%d", num);
489 if(num) fieldBtn[i][j][k]->setText(numStr);
493 if(board->isCleared()) {
494 audioController.PlaySound(SOUND_GAME_VICTORY);
495 setGameOver(true);
496 return SOUND_GAME_VICTORY;
499 audioController.PlaySound(SOUND_BUTTON_SUCCESS);
500 return SOUND_BUTTON_SUCCESS;
503 /* -------------------------------------------------------------------------- */
505 /* volano tridou FieldButton pri stisku praveho tlacitka, (od)znaci dane policko */
506 void MainForm::mark(int l, int r, int c) {
507 TEST_COORDS(l,r,c)
509 startTime(); //pokud jeste nemerime cas, zacneme nyni
511 const Field &field = board->getField(l, r, c);
512 if(!field.isCovered()) return;
513 board->setFieldMark(l,r,c, !field.hasMark());
514 fieldBtn[l][r][c]->setText(field.hasMark() ? "M" : " "); //znacka
516 marksIndicator->setMarked(board->getMarkedCount());
519 /* -------------------------------------------------------------------------- */
521 /* nastavi pocatecni cas hry */
522 void MainForm::startTime(void) {
523 if(tStart==-1) tStart = time(NULL); //pocatek mereni casu
526 /* -------------------------------------------------------------------------- */
528 /* vytvori novou hru s aktualnim nastavenim */
529 void MainForm::newGame(void) {
530 if(board)
532 tc->mutex_lock();
533 freeGui(); //uvolni stare gui (jeste podle stareho nastaveni)
534 delete board; board = NULL;
535 tc->b = 0;
536 locked = false;
537 tc->mutex_unlock();
539 try {
540 board = new Board(rows, cols, layers, mines);
541 } catch(GeneralException e) {
542 char text[200];
543 snprintf(text, 199, "An error occured:\n%s\nUnable to start game.", e.errText.data());
544 QMessageBox::warning(this, "Mines3D", text, QMessageBox::Ok);
545 return;
547 ui.scrollAreaWidgetContents->setEnabled(true);
548 gameOver = false;
549 marksIndicator->setTotal(mines);
550 marksIndicator->setMarked(0);
551 buildGui();
552 tStart = -1; //indikuje, ze jeste nezacalo mereni (zacne prvnim kliknutim)
553 audioController.PlayMusic(soundMusic);
556 /* -------------------------------------------------------------------------- */
558 /* ukonci hru -> znemozni stisk tlacitek atp.;
559 * atr success je true, pokud uzivatel vyhral, jinak false */
560 void MainForm::setGameOver(bool success) {
561 audioController.PlayMusic(MUSIC_NOTHING);
563 gameOver = true;
564 tStop = time(NULL);
565 ui.scrollAreaWidgetContents->setEnabled(false);
567 //odvyraznime vsechna tlacitka a vykreslime polohy min
568 for(int i=0; i<this->layers; i++) {
569 for(int j=0; j<this->rows; j++)
570 for(int k=0; k<this->cols; k++) {
571 fieldBtn[i][j][k]->unhighlight();
572 if(board->getField(i,j,k).hasMine())
573 fieldBtn[i][j][k]->setText(success ? "M" : "!!");
576 //vyhodnoceni vysledku
577 if(!success) {
578 statusBar()->showMessage("Oooops, you stepped on a mine which exploxed!", 10000);
579 } else {
580 char str[100];
581 const int tTotal = tStop-tStart;
582 sprintf(str, "Very well, mister! You cleared the board in %d:%02d.", tTotal/60, tTotal%60);
583 statusBar()->showMessage(str, 10000);
584 processTopTen(tTotal); //zapis do tabulky (pokud je cas v top10)
588 /* -------------------------------------------------------------------------- */
590 /* pokud je zadany cas v top10, umozni zapis do tabulky a vraci true, jinak false */
591 bool MainForm::processTopTen(int time) {
592 bool ok;
594 list<ScoreRecord> *l, *ld;
595 switch(board->getMode()) {
596 case Board::ModeRookie: l=&scoreRookie; ld=&scoreRookieSql; break;
597 case Board::ModeAdvanced: l=&scoreAdvanced; ld=&scoreAdvancedSql; break;
598 case Board::ModeSuicide: l=&scoreSuicide; ld=&scoreSuicideSql; break;
599 case Board::ModeCustom: l=&scoreCustom; ld=&scoreCustomSql; break;
600 default: return false;
603 l->sort(cmpScoreByTime); //seradime vzestupne podle casu
604 //je-li v seznamu jeste misto nebo nejhorsi cas je horsi, nez soucasny, jedna se o top10 -> pridame zaznam
605 if(l->size() < 10 || l->back().time > time) {
607 //vyzveme uzivatele k zadani jmena
608 QString text = QInputDialog::getText(this, "Top 10!", "You have made the top 10!\nPlease type in your name:",
609 QLineEdit::Normal, name, &ok);
610 //pokud bylo stisknuto OK
611 if(ok) name = text; //zapamatujem si vlozene jmeno
612 else return false; //uzivatel si nepreje vlozit zaznam
614 sql_c->connect(); // nahrani dat do databaze
615 sql_c->insertScore(name.toUtf8().data(), time, board->getMode());
616 sql_c->getTop10(board->getMode(),*ld);
617 sql_c->disconnect();
619 ScoreRecord scoreItem;
620 snprintf(scoreItem.name, 40, "%s", name.toUtf8().data());
621 scoreItem.time = time;
622 if(l->size() >= 10) l->pop_back(); //neni jiz misto -> vymazeme nejhorsi cas
623 l->push_back(scoreItem); //vlozime zaznam
624 if(scoresFrm) scoresFrm->replaceModel(board->getMode(), l); //zaktualizujeme model dat ve formulari vysledku
625 if(scoresFrm) scoresFrm->replaceModel(board->getMode(), ld, false);
626 actionScores_Trigger(); //zobrazime vysledky
627 return true;
629 return false; //v seznamu neni misto (cas nebyl dostatecne rychly)
632 /* -------------------------------------------------------------------------- */
634 /* stisk tlacitka "New" v menu */
635 void MainForm::actionNew_Trigger(void) {
636 newGame();
639 /* -------------------------------------------------------------------------- */
641 /* stisk tlacitka "Settings..." v menu */
642 void MainForm::actionSettings_Trigger(void) {
643 if(!settingsFrm) settingsFrm = new SettingsForm();
645 //zobrazime aktualni nastaveni
646 int mode = board ? board->getMode() : Board::ModeRookie;
647 switch(mode) {
648 case Board::ModeRookie:
649 settingsFrm->ui.rookieRadio->setChecked(true);
650 settingsFrm->rookieRadio_Clicked();
651 break;
652 case Board::ModeAdvanced:
653 settingsFrm->ui.advancedRadio->setChecked(true);
654 settingsFrm->advancedRadio_Clicked();
655 break;
656 case Board::ModeSuicide:
657 settingsFrm->ui.suicideRadio->setChecked(true);
658 settingsFrm->suicideRadio_Clicked();
659 break;
660 case Board::ModeCustom:
661 settingsFrm->ui.customRadio->setChecked(true);
662 settingsFrm->ui.layersSpinBox->setValue(this->layers);
663 settingsFrm->ui.rowsSpinBox->setValue(this->rows);
664 settingsFrm->ui.columnsSpinBox->setValue(this->cols);
665 settingsFrm->ui.minesSpinBox->setValue(this->mines);
666 settingsFrm->customRadio_Clicked();
667 break;
670 settingsFrm->setSoundEffectsOn(audioController.bSoundEnabled);
671 EMusicType mType;
672 switch(soundMusic) {
673 case MUSIC_SLOW: mType = MUSIC_1; break;
674 case MUSIC_FAST: mType = MUSIC_2; break;
675 default: mType = MUSIC_NO; break;
677 settingsFrm->setSoundMusicType(mType);
679 //zobrazime dialog a vyhodnotime odpoved
680 if(settingsFrm->exec() == QDialog::Accepted) {
681 layers = settingsFrm->ui.layersSpinBox->value();
682 rows = settingsFrm->ui.rowsSpinBox->value();
683 cols = settingsFrm->ui.columnsSpinBox->value();
684 mines = settingsFrm->ui.minesSpinBox->value();
686 audioController.bSoundEnabled = settingsFrm->getSoundEffectsOn();
687 switch(settingsFrm->getSoundMusicType()) {
688 case MUSIC_1: soundMusic = MUSIC_SLOW; break;
689 case MUSIC_2: soundMusic = MUSIC_FAST; break;
690 default: soundMusic = MUSIC_NOTHING; break;
692 audioController.PlayMusic(soundMusic);
694 if((board->getLayersCount()!=layers) || (board->getRowsCount()!=rows) ||
695 (board->getColsCount()!=cols) || (board->getMinesCount()!=mines)) newGame();
699 /* -------------------------------------------------------------------------- */
701 /* stisk tlacitka "Hall of Fame" v menu */
702 void MainForm::actionScores_Trigger(void) {
703 if(!scoresFrm) scoresFrm = new ScoresForm(
704 &scoreRookie, &scoreAdvanced, &scoreSuicide, &scoreCustom,
705 &scoreRookieSql, &scoreAdvancedSql, &scoreSuicideSql, &scoreCustomSql);
706 scoresFrm->exec(board->getMode());
709 /* -------------------------------------------------------------------------- */
711 void MainForm::actionAbout_Trigger(void) {
712 if(!aboutFrm) aboutFrm = new AboutForm();
713 aboutFrm->exec();
716 /* -------------------------------------------------------------------------- */