[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/games/granatier/src
From: Mathias Kraus <k.hias () gmx ! de>
Date: 2009-09-23 22:48:31
Message-ID: 1253746111.050417.16437.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1027372 by mkraus:
refactoring of mainwindow.cpp/.h
M +105 -120 mainwindow.cpp
M +53 -66 mainwindow.h
--- trunk/playground/games/granatier/src/mainwindow.cpp #1027371:1027372
@@ -54,124 +54,104 @@
Ui::GeneralSettings ui;
};
-MainWindow::MainWindow() {
- // Initialize the game
- m_game = NULL;
- m_view = NULL;
+MainWindow::MainWindow()
+{
+ // Initialize the game
+ m_game = NULL;
+ m_view = NULL;
m_playerSettings = new PlayerSettings();
- // Set the window menus
- KStandardGameAction::gameNew(this, SLOT(newGame(bool)), actionCollection());
- KStandardGameAction::highscores(this, SLOT(showHighscores()), actionCollection());
- KStandardAction::preferences(this, SLOT(showSettings()), actionCollection());
- KStandardGameAction::quit(this, SLOT(close()), actionCollection());
- KAction* soundAction = new KToggleAction(i18n("&Play sounds"), this);
- soundAction->setChecked(Settings::sounds());
- actionCollection()->addAction("sounds", soundAction);
- connect(soundAction, SIGNAL(triggered(bool)), this, SLOT(setSoundsEnabled(bool)));
- KAction* levelAction = new KAction(i18n("&Change level"), this);
- actionCollection()->addAction("level", levelAction);
- connect(levelAction, SIGNAL(triggered(bool)), this, SLOT(changeLevel()));
+ // Set the window menus
+ KStandardGameAction::gameNew(this, SLOT(newGame(bool)), actionCollection());
+ //KStandardGameAction::highscores(this, SLOT(showHighscores()), \
actionCollection()); + KStandardAction::preferences(this, SLOT(showSettings()), \
actionCollection()); + KStandardGameAction::quit(this, SLOT(close()), \
actionCollection()); + KAction* soundAction = new KToggleAction(i18n("&Play \
sounds"), this); + soundAction->setChecked(Settings::sounds());
+ actionCollection()->addAction("sounds", soundAction);
+ connect(soundAction, SIGNAL(triggered(bool)), this, \
SLOT(setSoundsEnabled(bool))); // init game
initGame();
- // KScoreDialog
- m_kScoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score | \
KScoreDialog::Level, this);
- // Setup the window
- setupGUI();
+ // Setup the window
+ setupGUI();
}
-MainWindow::~MainWindow() {
- delete m_game;
- delete m_view;
+MainWindow::~MainWindow()
+{
+ delete m_game;
+ delete m_view;
delete m_playerSettings;
- delete m_kScoreDialog;
}
-void MainWindow::initGame() {
+void MainWindow::initGame()
+{
//the focus has to be set at the beginning and also at the end to cover all \
possible cases //TODO: check why setting the focus only at the end doesn't work
this->setFocusProxy(m_view);
this->setFocus();
- // If a Game instance already exists
- if (m_game) {
- // Delete the Game instance
- delete m_game;
- }
- // Create a new Game instance
- m_game = new Game(m_playerSettings);
- connect(m_game, SIGNAL(gameOver(bool)), this, SLOT(newGame(bool))); // TODO Remove \
the useless bool parameter from gameOver()
- // If a GameView instance already exists
- if (m_view) {
- // Delete the GameView instance
- delete m_view;
- }
- // Create a new GameView instance
- m_view = new GameView(m_game);
- m_view->setBackgroundBrush(Qt::black);
- setCentralWidget(m_view);
+ // If a Game instance already exists
+ if (m_game)
+ {
+ // Delete the Game instance
+ delete m_game;
+ }
+ // Create a new Game instance
+ m_game = new Game(m_playerSettings);
+ connect(m_game, SIGNAL(gameOver(bool)), this, SLOT(newGame(bool))); // TODO \
Remove the useless bool parameter from gameOver() + // If a GameView instance \
already exists + if (m_view)
+ {
+ // Delete the GameView instance
+ delete m_view;
+ }
+ // Create a new GameView instance
+ m_view = new GameView(m_game);
+ m_view->setBackgroundBrush(Qt::black);
+ setCentralWidget(m_view);
m_game->setGameScene(dynamic_cast <GameScene*> (m_view->scene()));
- //m_view->setFocus();
+
this->setFocusProxy(m_view);
this->setFocus();
}
-void MainWindow::newGame(const bool gameOver) {
- bool gameRunning; // True if the game is running (game timer is active), false \
otherwise
-
- gameRunning = m_game->getTimer()->isActive();
- // If the game is running
- if (gameRunning) {
- // Pause the game
- m_game->pause();
- }
- // If the game was not over
- if (!gameOver){
- // Confirm before starting a new game
- if (KMessageBox::warningYesNo(this, i18n("Are you sure you want to quit the \
current game?"), i18n("New game")) == KMessageBox::Yes) {
- // Start a new game
- initGame();
- }
- else {
- // If the game was running
- if (gameRunning) {
- // Resume the game
- m_game->start();
- }
- }
- }
- else {
- // Display the score information
- KMessageBox::information(this, i18n("The winner is %1.").arg(m_game->getWinner()), \
i18n("Game Over"));
- // Add the score to the highscores table
-// m_kScoreDialog->setConfigGroup(KGameDifficulty::localizedLevelString());
-// KScoreDialog::FieldInfo scoreInfo;
-// scoreInfo[KScoreDialog::Level].setNum(m_game->getLevel());
-// scoreInfo[KScoreDialog::Score].setNum(m_game->getScore());
-// // If the new score is a highscore then display the highscore dialog
-// if (m_kScoreDialog->addScore(scoreInfo)) {
-// // If the payer did not cheat, manage Highscores
-// if (!m_game->isCheater()) {
-// m_kScoreDialog->exec();
-// } else { // else, warn the player not to cheat again :)
-// KMessageBox::information(this, i18n("You cheated, no Highscore for you ;)"), \
i18n("Cheater!"));
-// }
-// }
-
- // Start a new game
- initGame();
- }
+void MainWindow::newGame(const bool gameOver)
+{
+ bool gameRunning; // True if the game is running (game timer is active), \
false otherwise +
+ gameRunning = m_game->getTimer()->isActive();
+ // If the game is running
+ if (gameRunning)
+ {
+ // Pause the game
+ m_game->pause();
+ }
+ // If the game was not over
+ if (!gameOver)
+ {
+ // Confirm before starting a new game
+ if (KMessageBox::warningYesNo(this, i18n("Are you sure you want to quit the \
current game?"), i18n("New game")) == KMessageBox::Yes) + {
+ // Start a new game
+ initGame();
+ }
+ else
+ {
+ // If the game was running
+ if (gameRunning)
+ {
+ // Resume the game
+ m_game->start();
+ }
+ }
+ }
+ else
+ {
+ // Display the score information
+ KMessageBox::information(this, i18n("The winner is \
%1.").arg(m_game->getWinner()), i18n("Game Over")); + // Start a new game
+ initGame();
+ }
}
-void MainWindow::changeLevel() {
- int newLevel = KInputDialog::getInteger(i18n("Change level"), i18nc("The number of \
the game level", "Level"), m_game->getLevel(), 1, 1000000, 1, 10, 0, \
this);
- if (newLevel > 0) {
- m_game->setLevel(newLevel);
- }
-}
-
-void MainWindow::showHighscores() {
- m_kScoreDialog->exec();
-}
-
void MainWindow::setSoundsEnabled(bool p_enabled) {
m_game->setSoundsEnabled(p_enabled);
}
@@ -197,7 +177,7 @@
settingsDialog->show();
}
-void MainWindow::loadSettings()
+void MainWindow::applyNewSettings()
{
Settings::self()->setDummy(0);
m_playerSettings->savePlayerSettings();
@@ -209,25 +189,30 @@
m_playerSettings->discardUnsavedSettings();
}
-void MainWindow::close() {
- bool gameRunning; // True if the game is running (game timer is active), false \
otherwise
-
- gameRunning = m_game->getTimer()->isActive();
- // If the game is running
- if (gameRunning) {
- // Pause the game
- m_game->pause();
- }
- // Confirm before closing
- if(KMessageBox::warningYesNo(this, i18n("Are you sure you want to quit \
Granatier?"), i18nc("To quit Granatier", "Quit")) == \
KMessageBox::Yes) {
- KXmlGuiWindow::close();
- }
- else {
- // If the game was running
- if (gameRunning) {
- // Resume the game
- m_game->start();
- }
- }
+void MainWindow::close()
+{
+ bool gameRunning; // True if the game is running (game timer is active), \
false otherwise +
+ gameRunning = m_game->getTimer()->isActive();
+ // If the game is running
+ if (gameRunning)
+ {
+ // Pause the game
+ m_game->pause();
+ }
+ // Confirm before closing
+ if(KMessageBox::warningYesNo(this, i18n("Are you sure you want to quit \
Granatier?"), i18nc("To quit Granatier", "Quit")) == KMessageBox::Yes) + {
+ KXmlGuiWindow::close();
+ }
+ else
+ {
+ // If the game was running
+ if (gameRunning)
+ {
+ // Resume the game
+ m_game->start();
+ }
+ }
}
--- trunk/playground/games/granatier/src/mainwindow.h #1027371:1027372
@@ -33,83 +33,70 @@
*/
class MainWindow : public KXmlGuiWindow {
- Q_OBJECT
+Q_OBJECT
- private :
-
- /** The GameView instance that manages the game drawing and the collisions */
- GameView* m_view;
+private :
+
+ /** The GameView instance that manages the game drawing and the collisions */
+ GameView* m_view;
- /** The Game instance that manages the main loop and events */
- Game* m_game;
-
- /** The PlayerSettings instance for player name, shortcuts ... */
- PlayerSettings* m_playerSettings;
+ /** The Game instance that manages the main loop and events */
+ Game* m_game;
+
+ /** The PlayerSettings instance for player name, shortcuts ... */
+ PlayerSettings* m_playerSettings;
+
+public:
- /** The highscores dialog */
- KScoreDialog* m_kScoreDialog;
-
- public:
+ /**
+ * Creates a new MainWindow instance.
+ */
+ MainWindow();
- /**
- * Creates a new MainWindow instance.
- */
- MainWindow();
+ /**
+ * Deletes the MainWindow instance.
+ */
+ ~MainWindow();
- /**
- * Deletes the MainWindow instance.
- */
- ~MainWindow();
+private slots:
- private slots:
+ /**
+ * Initializes the MainWindow for a new game.
+ * Creates a new Game instance and a new GameView instance that displays the \
game. + */
+ void initGame();
- /**
- * Initializes the MainWindow for a new game.
- * Creates a new Game instance and a new GameView instance that displays the game.
- */
- void initGame();
+ /**
+ * Starts a new game.
+ * @param p_gameOver true if the game was over, false if a game is running
+ */
+ void newGame(const bool p_gameOver = false);
- /**
- * Starts a new game.
- * @param p_gameOver true if the game was over, false if a game is running
- */
- void newGame(const bool p_gameOver = false);
+ /**
+ * Sets the sounds enabled / disabled.
+ * @param p_enabled if true the sounds will be enabled, otherwise they will be \
disabled + */
+ void setSoundsEnabled(bool p_enabled);
- /**
- * Shows the highscores dialog.
- */
- void showHighscores();
+ /**
+ * Shows the settings dialog.
+ */
+ void showSettings();
- /**
- * Shows a dialog enabling to change the current level.
- */
- void changeLevel();
+ /**
+ * Loads the settings.
+ */
+ void applyNewSettings();
+
+ /**
+ * Cancel at settings dialog clicked.
+ */
+ void settingsDialogCanceled();
- /**
- * Sets the sounds enabled / disabled.
- * @param p_enabled if true the sounds will be enabled, otherwise they will be \
disabled
- */
- void setSoundsEnabled(bool p_enabled);
-
- /**
- * Shows the settings dialog.
- */
- void showSettings();
-
- /**
- * Loads the settings.
- */
- void loadSettings();
-
- /**
- * Cancel at settings dialog clicked.
- */
- void settingsDialogCanceled();
-
- /**
- * Closes the MainWindow.
- */
- void close();
+ /**
+ * Closes the MainWindow.
+ */
+ void close();
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic