[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/games/kolf-ng
From: Stefan Majewsky <majewsky () gmx ! net>
Date: 2009-03-28 22:31:43
Message-ID: 1238279503.530070.6077.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 946233 by majewsky:
Add a basic "New game" dialog, that allows to configure the participating players. \
(Also fix some problems with the new code paths that are used now.)
M +3 -0 CMakeLists.txt
M +1 -4 elements/scene.cpp
M +2 -3 engine/game-normal.cpp
M +3 -2 engine/game-normal.h
M +3 -0 engine/game.h
M +5 -0 engine/player.cpp
M +1 -0 engine/player.h
A interface/dialogs (directory)
A interface/dialogs/newgame-playerlist.cpp [License: GPL (v2+)]
A interface/dialogs/newgame-playerlist.h [License: GPL (v2+)]
A interface/dialogs/newgame-playerwidget.cpp [License: GPL (v2+)]
A interface/dialogs/newgame-playerwidget.h [License: GPL (v2+)]
A interface/dialogs/newgame.cpp [License: GPL (v2+)]
A interface/dialogs/newgame.h [License: GPL (v2+)]
M +25 -22 interface/mainwindow.cpp
M +0 -4 interface/mainwindow.h
M +2 -0 interface/mainwindow_p.h
M +19 -16 interface/transposeproxymodel.cpp
M +1 -10 main.cpp
--- trunk/playground/games/kolf-ng/CMakeLists.txt #946232:946233
@@ -51,6 +51,9 @@
interface/view.cpp
interface/view2d.cpp
interface/view3d.cpp
+ interface/dialogs/newgame.cpp
+ interface/dialogs/newgame-playerlist.cpp
+ interface/dialogs/newgame-playerwidget.cpp
main.cpp
)
--- trunk/playground/games/kolf-ng/elements/scene.cpp #946232:946233
@@ -82,9 +82,7 @@
{
removeItem(object);
m_objects.removeAll(object);
- Kolf::Ball* ball = qobject_cast<Kolf::Ball*>(object);
- if (ball)
- m_balls.removeAll(ball);
+ m_balls.removeAll(reinterpret_cast<Kolf::Ball*>(object)); //a dynamic_cast or \
qobject_cast does not work because this method is called from the Kolf::Object \
destructor (when the Kolf::Ball part does no longer exist) disconnect(object);
}
}
@@ -97,7 +95,6 @@
emit nextFrameSimulated();
//temporary friction implementation
bool ballsMovingNew = false;
- //TODO: (perhaps) optimize by storing balls in a second list instead of casting all \
the time foreach (Kolf::Ball* ball, m_balls)
{
Kolf::VectorF newVelocity = ball->velocity();
--- trunk/playground/games/kolf-ng/engine/game-normal.cpp #946232:946233
@@ -38,10 +38,9 @@
{
}
-Kolf::Player* Kolf::NormalGame::addPlayer()
+Kolf::LocalPlayer* Kolf::NormalGame::addPlayer()
{
- const QString name = i18n("Player %1", playerCount() + 1);
- Kolf::Player* newPlayer = new Kolf::LocalPlayer(name, course()->holeCount());
+ Kolf::LocalPlayer* newPlayer = new Kolf::LocalPlayer(QString(), \
course()->holeCount()); Kolf::Game::addPlayer(newPlayer);
return newPlayer;
}
--- trunk/playground/games/kolf-ng/engine/game-normal.h #946232:946233
@@ -23,6 +23,7 @@
namespace Kolf
{
+ class LocalPlayer;
/**
* \class NormalGame
@@ -38,8 +39,8 @@
NormalGame(Kolf::Course* course, Kolf::View* view);
virtual ~NormalGame();
- Kolf::Player* addPlayer(); ///< \warning Do not use after the game has started.
- bool startGame(); ///< Fails if no players have been added to the game or if the \
course does not contain any holes. + Kolf::LocalPlayer* addPlayer(); ///< \warning \
Do not use after the game has started. + virtual bool startGame();
Q_SIGNALS:
void playerMoveStarted(int player);
void playerMoveEnded(int player);
--- trunk/playground/games/kolf-ng/engine/game.h #946232:946233
@@ -54,6 +54,9 @@
///Returns the player with the given \a playerIndex. (You cannot access the par \
player through this method.) Kolf::Player* player(int playerIndex) const;
+ ///Starts the game (or fails if no players have been added to the game or if the \
course does not contain any holes). + virtual bool startGame() = 0;
+ ///Returns the index of the hole that is currently being played on.
int currentHole() const;
protected:
///Changes the current hole (as known to the model).
--- trunk/playground/games/kolf-ng/engine/player.cpp #946232:946233
@@ -87,6 +87,11 @@
}
}
+void Kolf::Player::setName(const QString& name)
+{
+ m_name = name;
+}
+
int Kolf::Player::currentScore() const
{
return m_scores.value(m_currentHole);
--- trunk/playground/games/kolf-ng/engine/player.h #946232:946233
@@ -46,6 +46,7 @@
QColor color() const;
QString name() const;
void setColor(QColor color);
+ void setName(const QString& name);
Kolf::View* view() const; ///< \sa populate(), depopulate()
int score(int hole) const;
--- trunk/playground/games/kolf-ng/interface/mainwindow.cpp #946232:946233
@@ -18,10 +18,11 @@
#include "mainwindow.h"
#include "mainwindow_p.h"
+#include "dialogs/newgame.h"
#include "../engine/course.h"
-#include "../engine/game-normal.h"
#include "../engine/player.h"
+#include <QPointer>
#include <KAction>
#include <KActionCollection>
#include <KApplication>
@@ -36,6 +37,7 @@
: m_parent(parent)
, m_scoreCard(new Kolf::ScoreCard(parent))
, m_view(new Kolf::View)
+ , m_game(0)
, m_view2DAct(new KAction(KIcon(), i18n("&2D view"), m_parent->actionCollection()))
, m_view3DAct(new KAction(KIcon(), i18n("&3D view"), m_parent->actionCollection()))
{
@@ -46,13 +48,14 @@
Kolf::MainWindowPrivate::~MainWindowPrivate()
{
delete m_scoreCard;
+ delete m_game;
//m_view is deleted by ~KXmlGuiWindow
}
void Kolf::MainWindowPrivate::setupActions()
{
KStandardGameAction::gameNew(this, SLOT(newGame()), m_parent->actionCollection());
- KStandardAction::preferences(this, SLOT(configureSettings()), \
m_parent->actionCollection()); +// KStandardAction::preferences(this, \
SLOT(configureSettings()), m_parent->actionCollection()); //view actions
m_parent->actionCollection()->addAction("view_activateview2d", m_view2DAct);
m_view2DAct->setCheckable(true);
@@ -66,7 +69,25 @@
void Kolf::MainWindowPrivate::newGame()
{
- //TODO: Kolf::MainWindowPrivate::newGame
+ QPointer<Kolf::NewGameDialog> dialog = new Kolf::NewGameDialog();
+ dialog->setTargetView(m_view);
+ dialog->exec();
+ //dialog might have been deleted meanwhile (I do not know how at the moment, but \
this prevents future crashes) + if (!dialog)
+ return;
+ //start game if dialog was not aborted
+ Kolf::Game* game = dialog->game();
+ if (game)
+ {
+ //delete old game
+ m_scoreCard->setModel(0);
+ delete m_game;
+ //start new game
+ m_game = game;
+ m_scoreCard->setModel(game);
+ game->startGame();
+ }
+ delete dialog;
}
void Kolf::MainWindowPrivate::configureSettings()
@@ -95,13 +116,12 @@
Kolf::MainWindow::MainWindow()
: p(new Kolf::MainWindowPrivate(this))
{
- //prevents application from crashing on exit
- setAttribute(Qt::WA_DeleteOnClose, false);
//the usual setup
p->setupActions();
setAutoSaveSettings();
setupGUI();
setCentralWidget(p->m_view);
+ show();
}
Kolf::MainWindow::~MainWindow()
@@ -109,23 +129,6 @@
delete p;
}
-void Kolf::MainWindow::startGameDEBUG(const QString& courseName)
-{
- //DEBUG - I'm aware of the awful memory leaks I'm introducing here.
- Kolf::NormalGame* game = new Kolf::NormalGame(new Kolf::Course(courseName), \
p->m_view);
- Kolf::Player* player1 = game->addPlayer();
- player1->setColor(Qt::blue);
- Kolf::Player* player2 = game->addPlayer();
- player2->setColor(Qt::red);
- game->startGame();
- p->m_scoreCard->setModel(game);
-}
-
-void Kolf::MainWindow::closeEvent(QCloseEvent* /*event*/)
-{
- kapp->quit();
-}
-
//END Kolf::MainWindow
#include "mainwindow_p.moc"
--- trunk/playground/games/kolf-ng/interface/mainwindow.h #946232:946233
@@ -30,10 +30,6 @@
public:
MainWindow();
~MainWindow();
-
- void startGameDEBUG(const QString& courseName);
- protected:
- virtual void closeEvent(QCloseEvent* event);
private:
Kolf::MainWindowPrivate* const p;
};
--- trunk/playground/games/kolf-ng/interface/mainwindow_p.h #946232:946233
@@ -19,6 +19,7 @@
#ifndef KOLF_MAINWINDOW_PRIVATE_H
#define KOLF_MAINWINDOW_PRIVATE_H
+#include "../engine/game.h"
#include "mainwindow.h"
#include "scorecard.h"
#include "view.h"
@@ -38,6 +39,7 @@
Kolf::MainWindow* m_parent;
Kolf::ScoreCard* m_scoreCard;
Kolf::View* m_view;
+ Kolf::Game* m_game;
KAction* m_view2DAct;
KAction* m_view3DAct;
public Q_SLOTS:
--- trunk/playground/games/kolf-ng/interface/transposeproxymodel.cpp #946232:946233
@@ -27,25 +27,28 @@
{
if (sourceModel == m_sourceModel)
return;
- disconnect(m_sourceModel, 0, this, 0);
+ if (m_sourceModel)
+ disconnect(m_sourceModel, 0, this, 0);
m_sourceModel = sourceModel;
reset();
//connect things properly
- connect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex&, int, \
int)), this, SLOT(slotColumnsAboutToBeInserted(const QModelIndex&, \
int, int)));
- connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex&, int, int)), \
this, SLOT(slotColumnsAboutToBeRemoved(const QModelIndex&, int, \
int)));
- connect(sourceModel, SIGNAL(columnsInserted(const QModelIndex&, int, int)), this, \
SLOT(slotColumnsInserted(const QModelIndex&, int, int)));
- connect(sourceModel, SIGNAL(columnsRemoved(const QModelIndex&, int, int)), this, \
SLOT(slotColumnsRemoved(const QModelIndex&, int, int)));
- connect(sourceModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), \
this, SLOT(slotDataChanged(const QModelIndex&, const QModelIndex&)));
- connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation, int, int)), this, \
SLOT(slotHeaderDataChanged(Qt::Orientation, int, int)));
- connect(sourceModel, SIGNAL(layoutAboutToBeChanged()), this, \
SIGNAL(layoutAboutToBeChanged()));
- connect(sourceModel, SIGNAL(layoutChanged()), this, SIGNAL(layoutChanged()));
- connect(sourceModel, SIGNAL(modelAboutToBeReset()), this, \
SIGNAL(modelAboutToBeReset()));
- connect(sourceModel, SIGNAL(modelReset()), this, SIGNAL(modelReset()));
- connect(sourceModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex&, int, int)), \
this, SLOT(slotRowsAboutToBeInserted(const QModelIndex&, int, int)));
- connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int, int)), \
this, SLOT(slotRowsAboutToBeRemoved(const QModelIndex&, int, int)));
- connect(sourceModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, \
SLOT(slotRowsInserted(const QModelIndex&, int, int)));
- connect(sourceModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, \
SLOT(slotRowsRemoved(const QModelIndex&, int, int)));
-
+ if (sourceModel)
+ {
+ connect(sourceModel, SIGNAL(columnsAboutToBeInserted(const QModelIndex&, int, \
int)), this, SLOT(slotColumnsAboutToBeInserted(const QModelIndex&, int, int))); \
+ connect(sourceModel, SIGNAL(columnsAboutToBeRemoved(const QModelIndex&, int, \
int)), this, SLOT(slotColumnsAboutToBeRemoved(const QModelIndex&, int, int))); \
+ connect(sourceModel, SIGNAL(columnsInserted(const QModelIndex&, int, int)), this, \
SLOT(slotColumnsInserted(const QModelIndex&, int, int))); + connect(sourceModel, \
SIGNAL(columnsRemoved(const QModelIndex&, int, int)), this, \
SLOT(slotColumnsRemoved(const QModelIndex&, int, int))); + connect(sourceModel, \
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, \
SLOT(slotDataChanged(const QModelIndex&, const QModelIndex&))); \
+ connect(sourceModel, SIGNAL(headerDataChanged(Qt::Orientation, int, int)), this, \
SLOT(slotHeaderDataChanged(Qt::Orientation, int, int))); + connect(sourceModel, \
SIGNAL(layoutAboutToBeChanged()), this, SIGNAL(layoutAboutToBeChanged())); \
+ connect(sourceModel, SIGNAL(layoutChanged()), this, SIGNAL(layoutChanged())); \
+ connect(sourceModel, SIGNAL(modelAboutToBeReset()), this, \
SIGNAL(modelAboutToBeReset())); + connect(sourceModel, SIGNAL(modelReset()), this, \
SIGNAL(modelReset())); + connect(sourceModel, SIGNAL(rowsAboutToBeInserted(const \
QModelIndex&, int, int)), this, SLOT(slotRowsAboutToBeInserted(const QModelIndex&, \
int, int))); + connect(sourceModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, \
int, int)), this, SLOT(slotRowsAboutToBeRemoved(const QModelIndex&, int, int))); \
+ connect(sourceModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, \
SLOT(slotRowsInserted(const QModelIndex&, int, int))); + connect(sourceModel, \
SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(slotRowsRemoved(const \
QModelIndex&, int, int))); + }
}
QAbstractTableModel* Kolf::TransposeProxyModel::sourceModel() const
--- trunk/playground/games/kolf-ng/main.cpp #946232:946233
@@ -33,18 +33,9 @@
//TODO: credit all authors and contributors of Kolf 1.x
KCmdLineArgs::init(argc, argv, &about);
- KCmdLineOptions options;
- options.add("c").add("course <name>", ki18n("Start the course with the given \
name"), "test1");
- KCmdLineArgs::addCmdLineOptions(options);
-
KApplication app;
KGlobal::locale()->insertCatalog("libkdegames");
- Kolf::MainWindow window;
- window.show();
- KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
- window.startGameDEBUG(args->getOption("course"));
- args->clear();
-
+ new Kolf::MainWindow;
return app.exec();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic