From ad539de7d11c92202714dde12a33e15d49e60a84 Mon Sep 17 00:00:00 2001 From: Marja Hassinen Date: Sat, 2 Jan 2010 20:00:38 +0200 Subject: [PATCH] Level collections (draft). --- data/intro.dat | 2 + data/intro01.dat | 13 ++++ data/intro01.leg | 1 + data/intro02.dat | 15 +++++ data/intro02.leg | 1 + data/intro03.leg | 1 + data/level01.dat | 13 ---- data/level01.leg | 1 - data/level02.dat | 15 ----- data/level02.leg | 1 - data/level03.leg | 1 - src/collections.ui | 174 ++++++++++++++++++++++++++++++++++++++++++++++++ src/game.cpp | 76 +++++++++++++++------ src/game.h | 22 +++++-- src/main.cpp | 42 +++++++----- src/main.ui | 187 ++++++++++------------------------------------------ src/src.pro | 4 +- src/startlevel.ui | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++ 18 files changed, 519 insertions(+), 230 deletions(-) create mode 100644 data/basic.dat create mode 100644 data/intro.dat create mode 100644 data/intro01.dat create mode 100644 data/intro01.leg create mode 100644 data/intro02.dat create mode 100644 data/intro02.leg create mode 100644 data/intro03.leg delete mode 100644 data/level01.dat delete mode 100644 data/level01.leg delete mode 100644 data/level02.dat delete mode 100644 data/level02.leg delete mode 100644 data/level03.leg create mode 100644 src/collections.ui create mode 100644 src/startlevel.ui diff --git a/data/basic.dat b/data/basic.dat new file mode 100644 index 0000000..e69de29 diff --git a/data/intro.dat b/data/intro.dat new file mode 100644 index 0000000..b4edef8 --- /dev/null +++ b/data/intro.dat @@ -0,0 +1,2 @@ +intro01 +intro02 diff --git a/data/intro01.dat b/data/intro01.dat new file mode 100644 index 0000000..60553a7 --- /dev/null +++ b/data/intro01.dat @@ -0,0 +1,13 @@ +5 +7 +2 +12 0 0 +14 4 6 +6 +1 9 +2 9 +3 9 +4 9 +5 9 +6 9 +60 diff --git a/data/intro01.leg b/data/intro01.leg new file mode 100644 index 0000000..4d45ced --- /dev/null +++ b/data/intro01.leg @@ -0,0 +1 @@ +Build a pipe from the start
to the end . \ No newline at end of file diff --git a/data/intro02.dat b/data/intro02.dat new file mode 100644 index 0000000..d291a33 --- /dev/null +++ b/data/intro02.dat @@ -0,0 +1,15 @@ +5 +7 +4 +12 4 2 +14 4 5 +3 1 1 +7 2 3 +6 +1 9 +2 9 +3 9 +4 9 +5 9 +6 9 +80 diff --git a/data/intro02.leg b/data/intro02.leg new file mode 100644 index 0000000..15729de --- /dev/null +++ b/data/intro02.leg @@ -0,0 +1 @@ +You must use all pre-placed pipes.
For pieces with two pipes, and ,
both pipes must be used. diff --git a/data/intro03.leg b/data/intro03.leg new file mode 100644 index 0000000..32f385a --- /dev/null +++ b/data/intro03.leg @@ -0,0 +1 @@ +To maximize your profit,
build as long and complicated pipe as you can! \ No newline at end of file diff --git a/data/level01.dat b/data/level01.dat deleted file mode 100644 index 60553a7..0000000 --- a/data/level01.dat +++ /dev/null @@ -1,13 +0,0 @@ -5 -7 -2 -12 0 0 -14 4 6 -6 -1 9 -2 9 -3 9 -4 9 -5 9 -6 9 -60 diff --git a/data/level01.leg b/data/level01.leg deleted file mode 100644 index 4d45ced..0000000 --- a/data/level01.leg +++ /dev/null @@ -1 +0,0 @@ -Build a pipe from the start
to the end . \ No newline at end of file diff --git a/data/level02.dat b/data/level02.dat deleted file mode 100644 index d291a33..0000000 --- a/data/level02.dat +++ /dev/null @@ -1,15 +0,0 @@ -5 -7 -4 -12 4 2 -14 4 5 -3 1 1 -7 2 3 -6 -1 9 -2 9 -3 9 -4 9 -5 9 -6 9 -80 diff --git a/data/level02.leg b/data/level02.leg deleted file mode 100644 index 15729de..0000000 --- a/data/level02.leg +++ /dev/null @@ -1 +0,0 @@ -You must use all pre-placed pipes.
For pieces with two pipes, and ,
both pipes must be used. diff --git a/data/level03.leg b/data/level03.leg deleted file mode 100644 index 32f385a..0000000 --- a/data/level03.leg +++ /dev/null @@ -1 +0,0 @@ -To maximize your profit,
build as long and complicated pipe as you can! \ No newline at end of file diff --git a/src/collections.ui b/src/collections.ui new file mode 100644 index 0000000..00dca22 --- /dev/null +++ b/src/collections.ui @@ -0,0 +1,174 @@ + + + LevelCollections + + + + 0 + 0 + 800 + 430 + + + + + Sans Serif + 20 + + + + false + + + QWidget +{ + background-color: #15445d; + color: #9fb2bc; +} + + + + + + + Sans Serif + 20 + + + + + + + Qt::RichText + + + 10 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Sans Serif + 20 + + + + QAbstractItemView::NoEditTriggers + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Sans Serif + 20 + + + + Start + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Sans Serif + 20 + + + + Quit + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/game.cpp b/src/game.cpp index df29387..0aad055 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -18,12 +18,12 @@ #include "game.h" #include -#include +#include #include #include #include -#include #include +#include QString pieceToIconId(const Piece* piece, bool flow1 = false, bool flow2 = false) @@ -79,7 +79,6 @@ GameField::GameField(QTableWidget* ui) void GameField::initGame(int rows_, int cols_, int count, PrePlacedPiece* prePlaced) { fieldUi->clear(); - // FIXME: Does the table widget call the destructors of its items... rows = rows_; cols = cols_; @@ -202,8 +201,6 @@ void GameField::indicateFlow(int row, int col, Direction dir) QLabel* label = (QLabel*)fieldUi->indexWidget(mIndex); label->setPixmap(QPixmap(iconId)); - // The pixmap won't show nicely if we're just sleeping... - QApplication::processEvents(); } QHash, const Piece*> AvailablePieces::pieceCache; @@ -532,33 +529,73 @@ void GameController::computeFlow() flowPreplaced += 1; } -LevelSwitcher::LevelSwitcher(GameController* gameController, QLabel* levelLabel, - QFrame* startFrame, QLabel* startTitle, QLabel* startLabel, QPushButton* startButton, - QLabel* scoreLabel, - - QStringList levels) - : gameController(gameController), levelLabel(levelLabel), - startFrame(startFrame), startTitle(startTitle), startLabel(startLabel), startButton(startButton), - scoreLabel(scoreLabel), - levels(levels), level(0), totalScore(0) +LevelSwitcher::LevelSwitcher(GameController* gameController, + QWidget* levelWidget, QListWidget* levelList, + QPushButton* levelStartButton, + QWidget* startWidget, QLabel* startTitle, + QLabel* startLabel, QPushButton* startButton, + QLabel* levelLabel, QLabel* scoreLabel, + QStringList levelCollections) + : gameController(gameController), + levelWidget(levelWidget), levelList(levelList), levelStartButton(levelStartButton), + startWidget(startWidget), startTitle(startTitle), startLabel(startLabel), startButton(startButton), + levelLabel(levelLabel), scoreLabel(scoreLabel), + levelCollections(levelCollections), level(0), totalScore(0) { + connect(levelStartButton, SIGNAL(clicked()), this, SLOT(onLevelCollectionChosen())); + connect(startButton, SIGNAL(clicked()), this, SLOT(onStartClicked())); connect(gameController, SIGNAL(levelPassed(int)), this, SLOT(onLevelPassed(int))); connect(gameController, SIGNAL(levelFailed()), this, SLOT(onLevelFailed())); startTitle->setText("Starting a new game."); scoreLabel->setText("0"); + chooseLevelCollection(); +} + +void LevelSwitcher::chooseLevelCollection() +{ + levelList->clear(); + foreach (const QString& collection, levelCollections) { + QListWidgetItem *newItem = new QListWidgetItem(); + newItem->setText(collection); + levelList->addItem(newItem); // transfers ownership + } + levelWidget->show(); +} + +void LevelSwitcher::onLevelCollectionChosen() +{ + levelWidget->hide(); + QString collection = levelList->currentItem()->text(); + QFile file(QString(LEVDIR) + "/" + collection + ".dat"); + if (!file.exists()) + qFatal("Error reading game file: doesn't exist"); + file.open(QIODevice::ReadOnly); + QTextStream levelData(&file); + levels.clear(); + + while (!levelData.atEnd()) + levels << levelData.readLine(); + + level = 0; + totalScore = 0; initiateLevel(); } void LevelSwitcher::onStartClicked() { - startFrame->hide(); + startWidget->hide(); levelLabel->setText(QString::number(level+1)); gameController->startLevel(QString(LEVDIR) + "/" + levels[level] + ".dat"); } void LevelSwitcher::initiateLevel() { + if (level >= levels.size()) { + qWarning() << "Level index too large"; + return; + } + QFile file(QString(LEVDIR) + "/" + levels[level] + ".leg"); if (!file.exists()) qFatal("Error reading game file: doesn't exist"); @@ -568,7 +605,7 @@ void LevelSwitcher::initiateLevel() QString introText = gameData.readLine(); introText.replace("IMGDIR", IMGDIR); startLabel->setText(introText); - startFrame->show(); + startWidget->show(); } void LevelSwitcher::onLevelPassed(int score) @@ -586,7 +623,7 @@ void LevelSwitcher::onLevelPassed(int score) startLabel->setText("Start a new game?"); // TODO: go to the level set selection screen level = 0; - startFrame->show(); + startWidget->show(); } } @@ -597,14 +634,13 @@ void LevelSwitcher::onLevelFailed() } // Todo next: -// desktop stuff -// icon for app manager -// install all graphics // better graphics // save & load // level collections: introduction + basic // more levels // make fixed pipes look different than non-fixed ones +// color theme +// transparency // -------------- // re-placing pieces // graphical hints on what to do next diff --git a/src/game.h b/src/game.h index cf83eb2..88540a1 100644 --- a/src/game.h +++ b/src/game.h @@ -28,7 +28,7 @@ class QTableWidgetItem; class QLabel; class QWidget; class QPushButton; -class QFrame; +class QListWidget; enum PieceType { @@ -229,26 +229,34 @@ class LevelSwitcher : public QObject { Q_OBJECT public: - LevelSwitcher(GameController* gameController, QLabel* levelLabel, - QFrame* startFrame, QLabel* startTitle, QLabel* startLabel, QPushButton* startButton, - QLabel* scoreLabel, + LevelSwitcher(GameController* gameController, + QWidget* levelWidget, QListWidget* levelList, QPushButton* levelStartButton, + QWidget* startWidget, QLabel* startTitle, QLabel* startLabel, QPushButton* startButton, + QLabel* levelLabel, QLabel* scoreLabel, QStringList levels); - void initiateLevel(); private slots: + void onLevelCollectionChosen(); void onStartClicked(); void onLevelPassed(int score); void onLevelFailed(); private: + void initiateLevel(); + void chooseLevelCollection(); + GameController* gameController; // Not owned - QLabel* levelLabel; // Not owned - QFrame* startFrame; // Not owned + QWidget* levelWidget; // Not owned + QListWidget* levelList; // Not owned + QPushButton* levelStartButton; // Not owned + QWidget* startWidget; // Not owned QLabel* startTitle; // Not owned QLabel* startLabel; // Not owned QPushButton* startButton; // Not owned + QLabel* levelLabel; // Not owned QLabel* scoreLabel; // Not owned + QStringList levelCollections; QStringList levels; int level; int totalScore; diff --git a/src/main.cpp b/src/main.cpp index e02d796..043a304 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,6 @@ #include "ui_main.h" +#include "ui_startlevel.h" +#include "ui_collections.h" #include "game.h" #include @@ -9,28 +11,36 @@ int main(int argc, char** argv) { - QApplication app(argc, argv); + QApplication app(argc, argv); - qDebug() << "Reading levels from" << LEVDIR; - qDebug() << "Reading images from" << IMGDIR; + qDebug() << "Reading levels from" << LEVDIR; + qDebug() << "Reading images from" << IMGDIR; - QWidget mainWindow; - - Ui::Main ui; - ui.setupUi(&mainWindow); - QObject::connect(ui.quitButton, SIGNAL(clicked()), &app, SLOT(quit())); + QWidget mainWindow; + Ui::Main ui; + ui.setupUi(&mainWindow); - GameField field(ui.gameTable); - AvailablePieces pieces(ui.pieceTable); - QStringList levels; - levels << "level01" << "level02"; - GameController controller(&pieces, &field, ui.timeLabel, ui.doneButton); - LevelSwitcher switcher(&controller, ui.levelLabel, ui.startFrame, ui.startTitle, ui.startLabel, ui.startButton, ui.scoreLabel, levels); + Ui::StartLevel startUi; + startUi.setupUi(ui.startWidget); + QObject::connect(startUi.quitButton, SIGNAL(clicked()), &app, SLOT(quit())); - mainWindow.show(); + Ui::LevelCollections levelUi; + levelUi.setupUi(ui.collectionWidget); + QObject::connect(levelUi.quitButton, SIGNAL(clicked()), &app, SLOT(quit())); + GameField field(ui.gameTable); + AvailablePieces pieces(ui.pieceTable); + QStringList levelCollections; + levelCollections << "intro" << "basic"; // TODO: read from fs + GameController controller(&pieces, &field, ui.timeLabel, ui.doneButton); + LevelSwitcher switcher(&controller, + ui.collectionWidget, levelUi.levelList, levelUi.startButton, + ui.startWidget, startUi.startTitle, + startUi.startLabel, startUi.startButton, + ui.levelLabel, ui.scoreLabel, levelCollections); + mainWindow.show(); - return app.exec(); + return app.exec(); } diff --git a/src/main.ui b/src/main.ui index 09f3ca4..af1e222 100644 --- a/src/main.ui +++ b/src/main.ui @@ -22,6 +22,13 @@ Evil Plumber + + QWidget +{ + background-color: #15445d; + color: #9fb2bc; +} + @@ -266,160 +273,6 @@ - - - - 100 - 90 - 581 - 251 - - - - - Sans Serif - - - - true - - - QFrame::Box - - - QFrame::Raised - - - 3 - - - 0 - - - - - 0 - 0 - 581 - 251 - - - - - - - - Sans Serif - - - - - - - Qt::RichText - - - 10 - - - - - - - - Sans Serif - - - - - - - Qt::RichText - - - 10 - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - Sans Serif - 20 - - - - Start - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Quit - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - @@ -439,6 +292,32 @@ + + + + 0 + 0 + 800 + 430 + + + + + + + + + + 10 + 10 + 800 + 430 + + + + + + diff --git a/src/src.pro b/src/src.pro index b986b40..7ad7ce6 100644 --- a/src/src.pro +++ b/src/src.pro @@ -5,7 +5,7 @@ INCLUDEPATH += . # Input HEADERS += game.h -FORMS += main.ui +FORMS += main.ui collections.ui startlevel.ui SOURCES += game.cpp main.cpp include("../common.pri") @@ -17,7 +17,7 @@ INSTALLS += target levels images desktop iconxpm icon26 icon40 icon64 target.path =$$BINDIR levels.path = $$DATADIR/$${TARGET} -levels.files = ../data/level01.dat ../data/level01.leg ../data/level02.dat ../data/level02.leg +levels.files = ../data/*.dat ../data/*.leg images.path = $$DATADIR/$${TARGET} images.files = ../img/*.png diff --git a/src/startlevel.ui b/src/startlevel.ui new file mode 100644 index 0000000..756eab0 --- /dev/null +++ b/src/startlevel.ui @@ -0,0 +1,180 @@ + + + StartLevel + + + + 0 + 0 + 800 + 430 + + + + + Sans Serif + 20 + + + + false + + + QWidget +{ + background-color: #15445d; + color: #9fb2bc; +} + + + + + + + Sans Serif + 20 + + + + + + + Qt::RichText + + + 10 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Sans Serif + 20 + + + + + + + Qt::RichText + + + 10 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Sans Serif + 20 + + + + Start + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Sans Serif + 20 + + + + Quit + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + -- 1.7.9.5