From dba3af6ce5aa83f434e8ae8fb3f218d0bf912fcd Mon Sep 17 00:00:00 2001 From: TripleWhy Date: Sat, 10 May 2014 20:11:04 +0200 Subject: [PATCH 1/4] Draw a frame around the last placed tile per player --- Carcasum/gui/boardgraphicsscene.cpp | 22 +++++++++++++++++++++- Carcasum/gui/boardgraphicsscene.h | 1 + Carcasum/static.h | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Carcasum/gui/boardgraphicsscene.cpp b/Carcasum/gui/boardgraphicsscene.cpp index 6f32848..22f62ee 100644 --- a/Carcasum/gui/boardgraphicsscene.cpp +++ b/Carcasum/gui/boardgraphicsscene.cpp @@ -271,6 +271,11 @@ void BoardGraphicsScene::displayNewGame(int callDepth) } return; } + + for (QGraphicsRectItem * frame : frames) + delete frame; + frames.clear(); + qDeleteAll(tileLayer->childItems()); qDeleteAll(openLayer->childItems()); qDeleteAll(meepleLayer->childItems()); @@ -280,12 +285,22 @@ void BoardGraphicsScene::displayNewGame(int callDepth) #endif openTiles.clear(); - removeItem(placementTile); + if (placementTile->parentItem() != 0) + removeItem(placementTile); const Board * board = game->getBoard(); uint arraySize = board->getInternalSize(); setSceneRect(-BOARD_TILE_SIZE / 2.0, -BOARD_TILE_SIZE / 2.0, arraySize * BOARD_TILE_SIZE, arraySize * BOARD_TILE_SIZE); + for (uint i = 0; i < game->getPlayerCount(); ++i) + { + QGraphicsRectItem * rect = new QGraphicsRectItem(-BOARD_TILE_SIZE / 2.0, -BOARD_TILE_SIZE / 2.0, BOARD_TILE_SIZE, BOARD_TILE_SIZE); + rect->setBrush(QBrush()); + rect->setPen(QPen(imgFactory->getPlayerColor(i), BOARD_TILE_FRAME_WIDTH, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin)); + rect->setOpacity(0.5); + frames.push_back(rect); + } + for (uint y = 0; y < arraySize; ++y) { for (uint x = 0; x < arraySize; ++x) @@ -416,6 +431,11 @@ void BoardGraphicsScene::displayPlayerMoved(void * data, int callDepth) item->setRotation(tileMove.orientation * 90); tileLayer->addToGroup(item); + QGraphicsRectItem * frame = frames[d->player]; + frame->setPos(item->pos()); + tileLayer->removeFromGroup(frame); + tileLayer->addToGroup(frame); + if (!meepleMove.isNull()) { QPoint meeplePoint = imgFactory->getPoints(d->tile)[meepleMove.nodeIndex]; diff --git a/Carcasum/gui/boardgraphicsscene.h b/Carcasum/gui/boardgraphicsscene.h index d14157e..cae723c 100644 --- a/Carcasum/gui/boardgraphicsscene.h +++ b/Carcasum/gui/boardgraphicsscene.h @@ -26,6 +26,7 @@ Q_OBJECT QGraphicsItemGroup * textOverlayLayer; #endif + QList frames; QList openTiles; // QList meepleOutlines; QGraphicsPixmapItem * placementTile; diff --git a/Carcasum/static.h b/Carcasum/static.h index 58c9dab..298ba8a 100644 --- a/Carcasum/static.h +++ b/Carcasum/static.h @@ -20,6 +20,7 @@ // GUI #define BOARD_TILE_SIZE 300 #define BOARD_MEEPLE_SIZE 75 +#define BOARD_TILE_FRAME_WIDTH 15 #define BOARDVIEW_INITIAL_TILE_SIZE 50 #define PINFO_ICON_SIZE 40 #define PINFO_MEEPLE_SIZE 10 From 503bd919fc0f2ab3364da5bd8664b7828f3024f7 Mon Sep 17 00:00:00 2001 From: TripleWhy Date: Sat, 10 May 2014 20:37:32 +0200 Subject: [PATCH 2/4] Display drawn tiles --- Carcasum/gui/mainwindow.cpp | 22 +++++++++++++-- Carcasum/gui/mainwindow.h | 5 +++- Carcasum/gui/playerinfoview.cpp | 11 ++++++++ Carcasum/gui/playerinfoview.h | 1 + Carcasum/gui/playerinfoview.ui | 49 +++++++++++++++++---------------- 5 files changed, 61 insertions(+), 27 deletions(-) diff --git a/Carcasum/gui/mainwindow.cpp b/Carcasum/gui/mainwindow.cpp index 8fd9d91..a531a0d 100644 --- a/Carcasum/gui/mainwindow.cpp +++ b/Carcasum/gui/mainwindow.cpp @@ -64,7 +64,7 @@ MainWindow::MainWindow(QWidget *parent) : actionGroup->addAction(ui->actionChoose_Tiles); boardUi = new BoardGraphicsScene(&tileFactory, &imgFactory, ui->boardView); - game = new Game(&rntp, true); + game = new Game(this, true); game->addView(this); gameThread = new GameThread(game, this); @@ -119,6 +119,7 @@ void MainWindow::newGame(int player, const Game * game) l->insertWidget(i, pi); connect(this, SIGNAL(updateNeeded()), pi, SLOT(updateView())); + connect(this, SIGNAL(tileDrawn(int,int)), pi, SLOT(displayTile(int,int))); playerInfos.push_back(pi); } @@ -281,6 +282,21 @@ void MainWindow::nodeUnscored(const Node * /*n*/, const int /*score*/, const Gam { } +int MainWindow::nextTile(const Game * game) +{ + int result; + if (randomTiles) + result = rntp.nextTile(game); + else + result = ui->remainingTiles->nextTile(game); + + int player = game->getNextPlayer(); + TileTypeType tileType = game->getTiles()[result]->tileType; + emit tileDrawn(player, tileType); + + return result; +} + void MainWindow::closeEvent(QCloseEvent * event) { requestEndGame(); @@ -440,13 +456,13 @@ void MainWindow::typeBoxChanged(int index) void MainWindow::on_actionRandom_Tiles_toggled(bool checked) { if (checked) - game->setNextTileProvider(&rntp); + randomTiles = true; } void MainWindow::on_actionChoose_Tiles_toggled(bool checked) { if (checked) - game->setNextTileProvider(ui->remainingTiles); + randomTiles = false; } void MainWindow::on_buttonBox_accepted() diff --git a/Carcasum/gui/mainwindow.h b/Carcasum/gui/mainwindow.h index ba6da5b..4f6beb2 100644 --- a/Carcasum/gui/mainwindow.h +++ b/Carcasum/gui/mainwindow.h @@ -17,7 +17,7 @@ class MainWindow; class PlayerInfoView; -class MainWindow : public QMainWindow, public Player, public ScoreListener +class MainWindow : public QMainWindow, public Player, public ScoreListener, public NextTileProvider { Q_OBJECT @@ -51,6 +51,7 @@ class MainWindow : public QMainWindow, public Player, public ScoreListener jcz::TileFactory tileFactory; TileImageFactory imgFactory = TileImageFactory(&tileFactory); RandomNextTileProvider rntp; + bool randomTiles = true; const std::array colors = {{Qt::red, Qt::blue, Qt::yellow, Qt::darkGreen, Qt::black, Qt::gray}}; //Double brackets not needed in .cpp ... const std::array colorNames= {{ "Red", "Blue", "Yellow", "Green", "Black", "Gray"}}; @@ -72,6 +73,7 @@ class MainWindow : public QMainWindow, public Player, public ScoreListener virtual Player * clone() const; virtual void nodeScored(Node const * n, const int score, Game const * game); virtual void nodeUnscored(Node const * n, const int score, Game const * game); + virtual int nextTile(Game const * game); protected: virtual void closeEvent(QCloseEvent *event); @@ -84,6 +86,7 @@ class MainWindow : public QMainWindow, public Player, public ScoreListener signals: void gameEvent(QString const & msg); void updateNeeded(); + void tileDrawn(int player, int tileType); private slots: void displayGameEvent(QString const & msg); diff --git a/Carcasum/gui/playerinfoview.cpp b/Carcasum/gui/playerinfoview.cpp index e0601dd..bf77843 100644 --- a/Carcasum/gui/playerinfoview.cpp +++ b/Carcasum/gui/playerinfoview.cpp @@ -78,3 +78,14 @@ void PlayerInfoView::updateView() else setPalette(normPalette); } + +void PlayerInfoView::displayTile(int player, int tileType) +{ + if (playerIndex == player) + { + QPixmap const & p = imgFactory->getImage((TileTypeType)tileType); + ui->tileLabel->setPixmap( p.scaled(RTILE_TILE_SIZE, RTILE_TILE_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation) ); + } + else + ui->tileLabel->clear(); +} diff --git a/Carcasum/gui/playerinfoview.h b/Carcasum/gui/playerinfoview.h index 2190c12..fbd0a77 100644 --- a/Carcasum/gui/playerinfoview.h +++ b/Carcasum/gui/playerinfoview.h @@ -31,6 +31,7 @@ Q_OBJECT public slots: void updateView(); + void displayTile(int player, int tileType); private: Ui::PlayerInfoView *ui; diff --git a/Carcasum/gui/playerinfoview.ui b/Carcasum/gui/playerinfoview.ui index 13257a1..d1f5e54 100644 --- a/Carcasum/gui/playerinfoview.ui +++ b/Carcasum/gui/playerinfoview.ui @@ -29,29 +29,6 @@ 0 - - - - 3 - - - 5 - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - @@ -135,6 +112,32 @@ + + + + 3 + + + 5 + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + + From 9dcddc3c2a75163fdf5454b87a598783e2455959 Mon Sep 17 00:00:00 2001 From: TripleWhy Date: Sat, 10 May 2014 23:12:55 +0200 Subject: [PATCH 3/4] Added control help message --- Carcasum/Carcasum.pro | 17 +++++ Carcasum/carcasum_de.ts | 118 +++++++++++++++++++++++---------- Carcasum/carcasum_en.ts | 128 ++++++++++++++++++++++++------------ Carcasum/gui/mainwindow.cpp | 20 ++++++ Carcasum/gui/mainwindow.h | 3 +- Carcasum/gui/mainwindow.ui | 51 +++++--------- 6 files changed, 225 insertions(+), 112 deletions(-) diff --git a/Carcasum/Carcasum.pro b/Carcasum/Carcasum.pro index 99a586b..9d383fe 100644 --- a/Carcasum/Carcasum.pro +++ b/Carcasum/Carcasum.pro @@ -139,3 +139,20 @@ QMAKE_CXXFLAGS_WARN_ON += -Wextra -Werror=switch -Werror=return-type -Werror=del #DEFINES += QT_FORCE_ASSERTS #QMAKE_CXXFLAGS_RELEASE += -g #QMAKE_CFLAGS_RELEASE += -g + + +##This builds qm files. TODO: It also deletes them again on make clean. +#isEmpty(QMAKE_LRELEASE) { +# win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\lrelease.exe +# else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease +## else:QMAKE_LRELEASE = lrelease-qt4 # Yaay, fedora! +#} +#updateqm.input = TRANSLATIONS +##updateqm.output = $$OUT_PWD/${QMAKE_FILE_BASE}.qm +##updateqm.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} -qm $$OUT_PWD/${QMAKE_FILE_BASE}.qm +#updateqm.output = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.qm +#updateqm.commands = $$QMAKE_LRELEASE ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.qm +#updateqm.CONFIG += no_link +# +#QMAKE_EXTRA_COMPILERS += updateqm +#PRE_TARGETDEPS += compiler_updateqm_make_all diff --git a/Carcasum/carcasum_de.ts b/Carcasum/carcasum_de.ts index f3de0ec..13151a9 100644 --- a/Carcasum/carcasum_de.ts +++ b/Carcasum/carcasum_de.ts @@ -12,144 +12,155 @@ MainWindow - - + + New Game Neues Spiel - + Color Farbe - + Type Typ - + Name Name - + # # - + More Options Mehr Optionen - + Load board file: Spielfeld laden: - + Browse... Durchsuchen... - + Log Log - + File Datei - + Game Spiel - + + Help + Hilfe + + + Random Tiles Zufällige Landschaftskarten - + Choose Tiles Landschaftskarten auswählen - + Store board... Spielfeld speichern... - + Exit Beenden - + + + Controls + Steuerung + + + Player Spieler - + Computer Computer - + Player %1 Spieler %1 - + New game started Neues Spiel beginnt - + A non-suitable tile was drawn and discarded. An impossible tile was drawn and discarded. Eine nicht-passende Landschaftskarte wurde gezogen aus dem Spiel genommen. - + Player %1 moved. Spieler %1 hat gezogen. - + Game ended. Spiel beendet. - + Field Wiese - + City Stadt - + Road Straße - + Cloister Kloster - + [Unknown] [Unbekannt] - + %1 scored %n point(s) for players: %2 %1 bringt %n Punkt für Spieler %2 @@ -157,25 +168,60 @@ - + Save Board Spielfeld speichern - + Board File Spielfeld laden + + + Game Controls + +Place tile: left mouse button +Rotate tile: right mouse button + +Place meeple: left mouse button +Place no meeple: right mouse button + +Move board: middle mouse button +Zoom: mouse wheel + Game Controls + +Place tile: left mouse button +Rotate tile: right mouse button + +Place meeple: left mouse button +Place no meeple: right mouse button + +Move board: middle mouse button +Zoom: mouse wheel + + + Spielsteuerung + +Landschaftskarte legen: linke Maustaste +Landschaftskarte drehen: rechte Maustaste + +Meeple setzen: linke Maustaste +Keinen Meeple setzen: rechte Maustaste + +Spielfeld bewegen: mittlere Maustaste +Zoom: Mausrad + PlayerInfoView - + Points: Punkte: - + Meeples: Meeples: @@ -251,12 +297,12 @@ ZipDownload - + Download File? Datei herunterladen? - + %1 was not found in the program directory. This file is needed for better looking tiles. Do you want me to download it for you now? @@ -265,7 +311,7 @@ Diese Datei wird benötigt, damit die Landschaftskarten schöner aussehen. Soll ich die Datei jetzt herunterladen? - + Progress... Fortschritt... diff --git a/Carcasum/carcasum_en.ts b/Carcasum/carcasum_en.ts index 070f523..ca17e7a 100644 --- a/Carcasum/carcasum_en.ts +++ b/Carcasum/carcasum_en.ts @@ -1,6 +1,6 @@ - + Downloader @@ -12,144 +12,155 @@ MainWindow - - + + New Game New Game - + Color Color - + Type Type - + Name Name - + # # - + More Options More Options - + Load board file: Load board file: - + Browse... Browse... - + Log Log - + File File - + Game Game - + + Help + Help + + + Random Tiles Random Tiles - + Choose Tiles Choose Tiles - + Store board... Store board... - + Exit Exit - + + + Controls + Controls + + + Player Player - + Computer Computer - + Player %1 Player %1 - + New game started New game started - + A non-suitable tile was drawn and discarded. An impossible tile was drawn and discarded. A non-suitable tile was drawn and discarded. - + Player %1 moved. Player %1 moved. - + Game ended. Game ended. - + Field Field - + City City - + Road Road - + Cloister Cloister - + [Unknown] [Unknown] - + %1 scored %n point(s) for players: %2 %1 scored %n point for players: %2 @@ -157,25 +168,60 @@ - + Save Board Save Board - + Board File Board File + + + Game Controls + +Place tile: left mouse button +Rotate tile: right mouse button + +Place meeple: left mouse button +Place no meeple: right mouse button + +Move board: middle mouse button +Zoom: mouse wheel + Game Controls + +Place tile: left mouse button +Rotate tile: right mouse button + +Place meeple: left mouse button +Place no meeple: right mouse button + +Move board: middle mouse button +Zoom: mouse wheel + + + Game Controls + +Place tile: left mouse button +Rotate tile: right mouse button + +Place meeple: left mouse button +Place no meeple: right mouse button + +Move board: middle mouse button +Zoom: mouse wheel + PlayerInfoView - + Points: Points: - + Meeples: Meeples: @@ -229,19 +275,19 @@ Random - Random + Random Monte Carlo - Monte Carlo + Monte Carlo Monte Carlo 2 - Monte Carlo 2 + Monte Carlo 2 MCTS - MCTS + MCTS @@ -267,12 +313,12 @@ ZipDownload - + Download File? Download File? - + %1 was not found in the program directory. This file is needed for better looking tiles. Do you want me to download it for you now? @@ -281,7 +327,7 @@ This file is needed for better looking tiles. Do you want me to download it for you now? - + Progress... Progress... diff --git a/Carcasum/gui/mainwindow.cpp b/Carcasum/gui/mainwindow.cpp index a531a0d..05291c1 100644 --- a/Carcasum/gui/mainwindow.cpp +++ b/Carcasum/gui/mainwindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include void MainWindow::GameThread::run() { @@ -502,6 +503,13 @@ void MainWindow::on_buttonBox_accepted() ui->stackedWidget->setCurrentWidget(ui->gameDisplayPage); + QSettings settings; + if (settings.value("firstStart", true).toBool()) + { + on_actionControls_triggered(); + settings.setValue("firstStart", false); + } + gameThread->start(); } @@ -524,3 +532,15 @@ void MainWindow::on_boardFileButton_clicked() QString path = QFileDialog::getOpenFileName(this, tr("Board File")); ui->boardFileEdit->setText(path); } + +void MainWindow::on_actionControls_triggered() +{ + QMessageBox::information(this, tr("Controls"), + tr("Game Controls\n\n" + "Place tile: left mouse button\n" + "Rotate tile: right mouse button\n\n" + "Place meeple: left mouse button\n" + "Place no meeple: right mouse button\n\n" + "Move board: middle mouse button\n" + "Zoom: mouse wheel")); +} diff --git a/Carcasum/gui/mainwindow.h b/Carcasum/gui/mainwindow.h index 4f6beb2..8acfb31 100644 --- a/Carcasum/gui/mainwindow.h +++ b/Carcasum/gui/mainwindow.h @@ -99,10 +99,9 @@ private slots: void on_actionChoose_Tiles_toggled(bool arg1); void on_buttonBox_accepted(); void on_actionNew_Game_triggered(); - void on_actionStore_board_triggered(); - void on_boardFileButton_clicked(); + void on_actionControls_triggered(); private: Ui::MainWindow *ui; diff --git a/Carcasum/gui/mainwindow.ui b/Carcasum/gui/mainwindow.ui index 58bb85f..a8a073a 100644 --- a/Carcasum/gui/mainwindow.ui +++ b/Carcasum/gui/mainwindow.ui @@ -12,16 +12,7 @@ - - 0 - - - 0 - - - 0 - - + 0 @@ -166,16 +157,7 @@ 9 - - 0 - - - 0 - - - 0 - - + 0 @@ -198,8 +180,8 @@ 0 0 - 184 - 68 + 19 + 16 @@ -209,16 +191,7 @@ Log - - 0 - - - 0 - - - 0 - - + 0 @@ -244,7 +217,7 @@ 0 0 408 - 19 + 21 @@ -265,8 +238,15 @@ + + + Help + + + + @@ -311,6 +291,11 @@ Exit + + + Controls + + From 3db8dcb1c48f5ea5dd3df07f29b9c6cd876a9670 Mon Sep 17 00:00:00 2001 From: TripleWhy Date: Sat, 10 May 2014 23:13:17 +0200 Subject: [PATCH 4/4] translation update --- Carcasum/carcasum_de.ts | 30 ++++++++++++++++++++++++++++++ Carcasum/carcasum_en.ts | 30 ++++++++++++++++++++++++++++++ Carcasum/gui/mainwindow.h | 4 ++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/Carcasum/carcasum_de.ts b/Carcasum/carcasum_de.ts index 13151a9..aa76414 100644 --- a/Carcasum/carcasum_de.ts +++ b/Carcasum/carcasum_de.ts @@ -212,6 +212,36 @@ Keinen Meeple setzen: rechte Maustaste Spielfeld bewegen: mittlere Maustaste Zoom: Mausrad + + + Red + Rot + + + + Blue + Blau + + + + Yellow + Gelb + + + + Green + Grün + + + + Black + Schwarz + + + + Gray + Grau + PlayerInfoView diff --git a/Carcasum/carcasum_en.ts b/Carcasum/carcasum_en.ts index ca17e7a..b350e41 100644 --- a/Carcasum/carcasum_en.ts +++ b/Carcasum/carcasum_en.ts @@ -212,6 +212,36 @@ Place no meeple: right mouse button Move board: middle mouse button Zoom: mouse wheel + + + Red + Red + + + + Blue + Blue + + + + Yellow + Yellow + + + + Green + Green + + + + Black + Black + + + + Gray + Gray + PlayerInfoView diff --git a/Carcasum/gui/mainwindow.h b/Carcasum/gui/mainwindow.h index 8acfb31..9abba94 100644 --- a/Carcasum/gui/mainwindow.h +++ b/Carcasum/gui/mainwindow.h @@ -53,8 +53,8 @@ class MainWindow : public QMainWindow, public Player, public ScoreListener, publ RandomNextTileProvider rntp; bool randomTiles = true; - const std::array colors = {{Qt::red, Qt::blue, Qt::yellow, Qt::darkGreen, Qt::black, Qt::gray}}; //Double brackets not needed in .cpp ... - const std::array colorNames= {{ "Red", "Blue", "Yellow", "Green", "Black", "Gray"}}; + const std::array colors = {{Qt::red, Qt::blue, Qt::yellow, Qt::darkGreen, Qt::black, Qt::gray}}; //Double brackets not needed in .cpp ... + const std::array colorNames = {{tr("Red"), tr("Blue"), tr("Yellow"), tr("Green"), tr("Black"), tr("Gray")}}; std::array ngPlayerEdits; PlayerSelector * playerSelector; std::array selectedPlayers = {{}};