void Window::dropEvent(QDropEvent* event) { QStringList files = AddImage::dropEvent(event); if (!files.isEmpty()) { chooseGame(files); } }
void FileManager::start(){ selection = GUI(startOptions).run(); if (selection == -1){ return; } switch (selection){ case(0): //Arcade games. Run MAME std::cout << "MAME" << std::endl; try{ system(mameCommand.c_str()); } catch(...){ std::cout << "System command failed." << std::endl; } break; case(1): //NES Games. Run MESS. std::cout << "MESS" << std::endl; gameSelection = chooseGame(nesDir, nesExtension); if (gameSelection == "NULL"){ start(); return; } rom = gameSelection + nesExtension; try{ system((messCommand + '"' + rom + '"').c_str()); } catch(...){ std::cout << "System command failed." << std::endl; } break; case(2): //GBC Games. Run Gambatte. std::cout << "Gambatte" << std::endl; gameSelection = chooseGame(gbcDir, gbcExtension); if (gameSelection == "NULL"){ start(); return; } rom = gbcDir + gameSelection + gbcExtension; try{ system((gambatteCommand + '"' + rom + '"').c_str()); } catch(...){ std::cout << "System command failed." << std::endl; } break; case(3): //Mega Drive Games. Run PicoDrive. std::cout << "PicoDrive" << std::endl; try{ system((picoCommand).c_str()); } catch(...){ std::cout << "System command failed." << std::endl; } break; case(4): std::cout << "Shut Down" << std::endl; system(shutdownCommand.c_str()); break; } start(); }
void main() { chooseGame(); }
Window::Window() { m_board = new Board(this); connect(m_board, &Board::finished, this, &Window::gameFinished); connect(m_board, &Board::started, this, &Window::gameStarted); connect(m_board, &Board::pauseChanged, this, &Window::gamePauseChanged); QWidget* contents = new QWidget(this); setCentralWidget(contents); View* view = new View(m_board, contents); m_scores = new ScoreBoard(this); m_definitions = new Definitions(m_board->words(), this); connect(m_board, &Board::wordAdded, m_definitions, &Definitions::addWord); connect(m_board, &Board::wordSolved, m_definitions, &Definitions::solveWord); connect(m_board, &Board::wordSelected, m_definitions, &Definitions::selectWord); connect(m_board, &Board::loading, m_definitions, &Definitions::clear); // Create success message m_success = new QLabel(contents); m_success->setAttribute(Qt::WA_TransparentForMouseEvents); QFont f = font(); f.setPointSize(24); QFontMetrics metrics(f); int width = metrics.width(tr("Success")); int height = metrics.height(); int ratio = devicePixelRatio(); QPixmap pixmap(QSize(width + height, height * 2) * ratio); pixmap.setDevicePixelRatio(ratio); pixmap.fill(QColor(0, 0, 0, 0)); { QPainter painter(&pixmap); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 200)); painter.setRenderHint(QPainter::Antialiasing, true); painter.drawRoundedRect(0, 0, width + height, height * 2, 10, 10); painter.setFont(f); painter.setPen(Qt::white); painter.setRenderHint(QPainter::TextAntialiasing, true); painter.drawText(height / 2, height / 2 + metrics.ascent(), tr("Success")); } m_success->setPixmap(pixmap); m_success->hide(); connect(m_board, &Board::loading, m_success, &QLabel::hide); // Create overlay background QLabel* overlay = new QLabel(this); f = font(); f.setPixelSize(20); metrics = QFontMetrics(f); width = std::max(metrics.width(tr("Loading")), metrics.width(tr("Paused"))); for (int i = 0; i < 10; ++i) { QString test(6, QChar(i + 48)); test.insert(4, QLatin1Char(':')); test.insert(2, QLatin1Char(':')); width = std::max(width, metrics.width(test)); } pixmap = QPixmap(QSize(width + 82, 32) * ratio); pixmap.setDevicePixelRatio(ratio); pixmap.fill(Qt::transparent); { QPainter painter(&pixmap); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 200)); painter.setRenderHint(QPainter::Antialiasing, true); painter.drawRoundedRect(0, -32, width + 82, 64, 5, 5); } overlay->setPixmap(pixmap); // Create overlay buttons m_definitions_button = new QLabel(overlay); m_definitions_button->setPixmap(QIcon(":/definitions.png").pixmap(24,24)); m_definitions_button->setCursor(Qt::PointingHandCursor); m_definitions_button->setToolTip(tr("Definitions")); m_definitions_button->installEventFilter(this); m_hint_button = new QLabel(overlay); m_hint_button->setPixmap(QIcon(":/hint.png").pixmap(24,24)); m_hint_button->setCursor(Qt::PointingHandCursor); m_hint_button->setToolTip(tr("Hint")); m_hint_button->setDisabled(true); m_hint_button->installEventFilter(this); connect(m_board, &Board::hintAvailable, m_hint_button, &QLabel::setEnabled); // Create clock m_clock = new Clock(overlay); m_clock->setDisabled(true); connect(m_clock, &Clock::togglePaused, m_board, &Board::togglePaused); connect(m_board, &Board::loading, m_clock, &Clock::setLoading); QHBoxLayout* overlay_layout = new QHBoxLayout(overlay); overlay_layout->setMargin(0); overlay_layout->setSpacing(0); overlay_layout->addSpacing(10); overlay_layout->addWidget(m_definitions_button); overlay_layout->addStretch(); overlay_layout->addWidget(m_clock, 0, Qt::AlignCenter); overlay_layout->addStretch(); overlay_layout->addWidget(m_hint_button); overlay_layout->addSpacing(10); // Lay out board QGridLayout* layout = new QGridLayout(contents); layout->setMargin(0); layout->setSpacing(0); layout->addWidget(view, 0, 0); layout->addWidget(m_success, 0, 0, Qt::AlignCenter); layout->addWidget(overlay, 0, 0, Qt::AlignHCenter | Qt::AlignTop); // Create menus QMenu* menu = menuBar()->addMenu(tr("&Game")); menu->addAction(tr("&New"), this, SLOT(newGame()), QKeySequence::New); menu->addAction(tr("&Choose..."), this, SLOT(chooseGame())); menu->addSeparator(); m_pause_action = menu->addAction(tr("&Pause"), m_board, SLOT(togglePaused()), tr("P")); m_pause_action->setDisabled(true); QAction* action = menu->addAction(tr("&Hint"), m_board, SLOT(showHint()), tr("H")); action->setDisabled(true); connect(m_board, &Board::hintAvailable, action, &QAction::setEnabled); menu->addAction(tr("D&efinitions"), m_definitions, SLOT(selectWord()), tr("D")); menu->addSeparator(); menu->addAction(tr("&Details"), this, SLOT(showDetails())); menu->addAction(tr("&Scores"), m_scores, SLOT(exec())); menu->addSeparator(); action = menu->addAction(tr("&Quit"), qApp, SLOT(quit()), QKeySequence::Quit); action->setMenuRole(QAction::QuitRole); menu = menuBar()->addMenu(tr("&Settings")); menu->addAction(tr("Application &Language..."), this, SLOT(setLocale())); menu = menuBar()->addMenu(tr("&Help")); action = menu->addAction(tr("&About"), this, SLOT(about())); action->setMenuRole(QAction::AboutRole); action = menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); action->setMenuRole(QAction::AboutQtRole); // Restore window geometry QSettings settings; resize(800, 600); restoreGeometry(settings.value("Geometry").toByteArray()); // Continue previous or start new game show(); if (settings.contains("Current/Words") && (settings.value("Current/Version" ).toInt() == 4)) { m_board->openGame(); } else { settings.remove("Current"); newGame(); } }
Window::Window(const QString& file) : m_pause_action(0), m_previous_state(0) { setAcceptDrops(true); // Create states m_states.insert("NewGame", new NewGameState(this)); m_states.insert("OpenGame", new OpenGameState(this)); m_states.insert("Optimizing", new OptimizingState(this)); m_states.insert("Play", new PlayState(this)); m_states.insert("AutoPause", new AutoPauseState(this)); m_states.insert("Pause", new PauseState(this)); m_states.insert("Finish", new FinishState(this)); m_state = m_states.value("NewGame"); // Create widgets m_contents = new QStackedWidget(this); setCentralWidget(m_contents); m_board = new Board(this); m_contents->addWidget(m_board); connect(m_board, &Board::started, this, &Window::gameStarted); connect(m_board, &Board::finished, this, &Window::gameFinished); connect(m_board, &Board::optimizingStarted, this, &Window::optimizingStarted); connect(m_board, &Board::optimizingFinished, this, &Window::optimizingFinished); // Create pause screen m_pause_screen = new QLabel(tr("<p><b><big>Paused</big></b><br>Click to resume playing.</p>"), this); m_pause_screen->setAlignment(Qt::AlignCenter); m_pause_screen->installEventFilter(this); m_contents->addWidget(m_pause_screen); // Create open game screen QLabel* open_game_screen = new QLabel(tr("<p><b><big>Please wait</big></b><br>Loading game...</p>"), this); open_game_screen->setAlignment(Qt::AlignCenter); m_contents->addWidget(open_game_screen); // Create start screen QLabel* start_screen = new QLabel(tr("Click to start a new game."), this); start_screen->setAlignment(Qt::AlignCenter); start_screen->installEventFilter(this); m_contents->addWidget(start_screen); // Create new game screen QLabel* new_game_screen = new QLabel(tr("<p><b><big>Please wait</big></b><br>Generating a new board...</p>"), this); new_game_screen->setAlignment(Qt::AlignCenter); m_contents->addWidget(new_game_screen); // Create optimizing screen QLabel* optimizing_screen = new QLabel(tr("<p><b><big>Please wait</big></b><br>Optimizing word list...</p>"), this); optimizing_screen->setAlignment(Qt::AlignCenter); m_contents->addWidget(optimizing_screen); // Create game menu QMenu* menu = menuBar()->addMenu(tr("&Game")); menu->addAction(tr("New &Game..."), this, SLOT(newGame()), tr("Ctrl+Shift+N")); menu->addAction(tr("&New Roll"), this, SLOT(newRoll()), QKeySequence::New); menu->addAction(tr("&Choose..."), this, SLOT(chooseGame())); menu->addAction(tr("&Share..."), this, SLOT(shareGame())); menu->addSeparator(); QAction* end_action = menu->addAction(tr("&End"), this, SLOT(endGame())); end_action->setEnabled(false); connect(m_board, &Board::pauseAvailable, end_action, &QAction::setEnabled); m_pause_action = menu->addAction(tr("&Pause")); m_pause_action->setCheckable(true); m_pause_action->setShortcut(tr("Ctrl+P")); m_pause_action->setEnabled(false); connect(m_pause_action, &QAction::triggered, this, &Window::setPaused); connect(m_board, &Board::pauseAvailable, m_pause_action, &QAction::setEnabled); menu->addSeparator(); m_details_action = menu->addAction(tr("&Details"), this, SLOT(showDetails())); m_details_action->setEnabled(false); menu->addAction(tr("&High Scores"), this, SLOT(showScores())); menu->addSeparator(); QAction* action = menu->addAction(tr("&Quit"), this, SLOT(close()), tr("Ctrl+Q")); action->setMenuRole(QAction::QuitRole); monitorVisibility(menu); // Create settings menu menu = menuBar()->addMenu(tr("&Settings")); QMenu* submenu = menu->addMenu(tr("Show &Maximum Score")); QAction* score_actions[3]; score_actions[0] = submenu->addAction(tr("&Never")); score_actions[1] = submenu->addAction(tr("&End Of Game")); score_actions[2] = submenu->addAction(tr("&Always")); QActionGroup* group = new QActionGroup(this); for (int i = 0; i < 3; ++i) { score_actions[i]->setData(i); score_actions[i]->setCheckable(true); group->addAction(score_actions[i]); } connect(group, &QActionGroup::triggered, m_board, &Board::setShowMaximumScore); QAction* missed_action = menu->addAction(tr("Show Missed &Words")); missed_action->setCheckable(true); connect(missed_action, &QAction::toggled, m_board, &Board::setShowMissedWords); QAction* counts_action = menu->addAction(tr("Show Word &Counts")); counts_action->setCheckable(true); counts_action->setChecked(true); connect(counts_action, &QAction::toggled, m_board, &Board::setShowWordCounts); menu->addAction(tr("&Board Language..."), this, SLOT(showLanguage())); menu->addSeparator(); menu->addAction(tr("Application &Language..."), this, SLOT(showLocale())); monitorVisibility(menu); // Create help menu menu = menuBar()->addMenu(tr("&Help")); menu->addAction(tr("&Controls"), this, SLOT(showControls())); menu->addSeparator(); action = menu->addAction(tr("&About"), this, SLOT(about())); action->setMenuRole(QAction::AboutRole); action = menu->addAction(tr("About &Hspell"), this, SLOT(aboutHspell())); action->setMenuRole(QAction::ApplicationSpecificRole); action = menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); action->setMenuRole(QAction::AboutQtRole); action = menu->addAction(tr("About &SCOWL"), this, SLOT(aboutScowl())); action->setMenuRole(QAction::ApplicationSpecificRole); monitorVisibility(menu); // Load settings QSettings settings; QAction* score_action = score_actions[qBound(0, settings.value("ShowMaximumScore", 1).toInt(), 2)]; score_action->setChecked(true); m_board->setShowMaximumScore(score_action); missed_action->setChecked(settings.value("ShowMissed", true).toBool()); counts_action->setChecked(settings.value("ShowWordCounts", true).toBool()); restoreGeometry(settings.value("Geometry").toByteArray()); // Start game QString current = file; if (settings.contains("Current/Version")) { if (current.isEmpty() || QMessageBox::question(this, tr("Question"), tr("End the current game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) { current = ":saved:"; } } m_state->finish(); m_contents->setCurrentIndex(3); if (current.isEmpty()) { newGame(); } else { startGame(current); } }
Window::Window(const QStringList& files) : m_board(0) { setAcceptDrops(true); resize(640, 480); // Add statusbar m_slider = new ZoomSlider(this); statusBar()->addPermanentWidget(m_slider); m_completed = new QProgressBar(this); m_completed->setRange(0, 100); m_completed->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); statusBar()->addPermanentWidget(m_completed); statusBar()->setMinimumHeight(statusBar()->sizeHint().height()); m_slider->hide(); m_completed->hide(); // Add contents m_board = new Board(this); connect(m_board, &Board::completionChanged, m_completed, &QProgressBar::setValue); connect(m_board, &Board::finished, this, &Window::gameFinished); connect(m_board, &Board::clearMessage, statusBar(), &QStatusBar::clearMessage); connect(m_board, &Board::showMessage, statusBar(), &QStatusBar::showMessage); connect(m_board, &Board::zoomChanged, m_slider, &ZoomSlider::setValue); connect(m_slider, &ZoomSlider::valueChanged, m_board, &Board::zoom); setCentralWidget(m_board); // Add menus QMenu* menu; menu = menuBar()->addMenu(tr("&Game")); QAction* choose_action = menu->addAction(tr("&Choose..."), this, SLOT(chooseGame())); choose_action->setShortcuts(QList<QKeySequence>() << QKeySequence::New << QKeySequence::Open); menu->addSeparator(); QAction* retrieve_pieces_action = menu->addAction(tr("&Retrieve Pieces"), m_board, SLOT(retrievePieces()), tr("Ctrl+R")); retrieve_pieces_action->setEnabled(false); connect(m_board, &Board::retrievePiecesAvailable, retrieve_pieces_action, &QAction::setEnabled); menu->addSeparator(); QAction* quit_action = menu->addAction(tr("&Quit"), this, SLOT(close()), QKeySequence::Quit); quit_action->setMenuRole(QAction::QuitRole); menu = menuBar()->addMenu(tr("&View")); QAction* zoom_in_action = menu->addAction(tr("Zoom &In"), m_board, SLOT(zoomIn()), tr("+")); zoom_in_action->setEnabled(false); connect(m_board, &Board::zoomInAvailable, zoom_in_action, &QAction::setEnabled); QAction* zoom_out_action = menu->addAction(tr("Zoom &Out"), m_board, SLOT(zoomOut()), tr("-")); zoom_out_action->setEnabled(false); connect(m_board, &Board::zoomOutAvailable, zoom_out_action, &QAction::setEnabled); m_zoom_fit_action = menu->addAction(tr("Best &Fit"), m_board, SLOT(zoomFit())); m_zoom_fit_action->setEnabled(false); menu->addSeparator(); m_toggle_overview_action = menu->addAction(tr("Show O&verview"), m_board, SLOT(toggleOverview()), tr("Tab")); m_toggle_overview_action->setCheckable(true); m_toggle_overview_action->setEnabled(false); connect(m_board, &Board::overviewToggled, m_toggle_overview_action, &QAction::setChecked); menu->addSeparator(); QAction* fullscreen_action = menu->addAction(tr("F&ullscreen")); connect(fullscreen_action, &QAction::toggled, this, &Window::setFullScreen); fullscreen_action->setCheckable(true); #if !defined(Q_OS_MAC) fullscreen_action->setShortcut(tr("F11")); #else fullscreen_action->setShortcut(tr("Ctrl+F")); #endif menu = menuBar()->addMenu(tr("&Settings")); menu->addAction(tr("&Appearance..."), this, SLOT(showAppearance())); menu->addAction(tr("&Language..."), this, SLOT(setLocale())); menu = menuBar()->addMenu(tr("&Help")); menu->addAction(tr("&Controls"), this, SLOT(showControls()), QKeySequence::HelpContents); menu->addSeparator(); QAction* about_action = menu->addAction(tr("&About"), this, SLOT(showAbout())); about_action->setMenuRole(QAction::AboutRole); QAction* about_qt_action = menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); about_qt_action->setMenuRole(QAction::AboutQtRole); // Restore geometry QSettings settings; if (settings.contains("Geometry")) { restoreGeometry(settings.value("Geometry").toByteArray()); } else { resize(settings.value("Size", QSize(1024, 768)).toSize()); settings.remove("Size"); } // Start or load a game show(); chooseGame(files); // Create auto-save timer QTimer* timer = new QTimer(this); connect(timer, &QTimer::timeout, m_board, &Board::saveGame); timer->start(300000); }
void Window::addImages(const QStringList& files) { chooseGame(files); }