Commit 78e5068e authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

converted phases toolbar to graphics item

parent 20194617
......@@ -5,6 +5,24 @@
#include <math.h>
#include <QDebug>
QMap<QString, QPixmap> PhasePixmapGenerator::pmCache;
QPixmap PhasePixmapGenerator::generatePixmap(int height, QString name)
{
QString key = name + QString::number(height);
if (pmCache.contains(key))
return pmCache.value(key);
QSvgRenderer svg(QString(":/resources/phases/icon_phase_" + name + ".svg"));
QPixmap pixmap(height, height);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
svg.render(&painter, QRectF(0, 0, height, height));
pmCache.insert(key, pixmap);
return pixmap;
}
QMap<QString, QPixmap> CounterPixmapGenerator::pmCache;
QPixmap CounterPixmapGenerator::generatePixmap(int height, QString name, bool highlight)
......
......@@ -4,6 +4,14 @@
#include <QPixmap>
#include <QMap>
class PhasePixmapGenerator {
private:
static QMap<QString, QPixmap> pmCache;
public:
static QPixmap generatePixmap(int size, QString name);
static void clear() { pmCache.clear(); }
};
class CounterPixmapGenerator {
private:
static QMap<QString, QPixmap> pmCache;
......
......@@ -162,7 +162,11 @@ void DeckViewContainer::setDeck(DeckList *deck)
TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
: Tab(), clients(_clients), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), started(false), resuming(_resuming), currentPhase(-1), infoPopup(0)
{
scene = new GameScene(this);
phasesToolbar = new PhasesToolbar;
phasesToolbar->hide();
connect(phasesToolbar, SIGNAL(sendGameCommand(GameCommand *, int)), this, SLOT(sendGameCommand(GameCommand *, int)));
scene = new GameScene(phasesToolbar, this);
gameView = new GameView(scene);
gameView->hide();
......@@ -185,10 +189,6 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
deckViewContainerLayout = new QVBoxLayout;
phasesToolbar = new PhasesToolbar;
phasesToolbar->hide();
connect(phasesToolbar, SIGNAL(sendGameCommand(GameCommand *, int)), this, SLOT(sendGameCommand(GameCommand *, int)));
QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->addWidget(cardInfo);
verticalLayout->addWidget(playerListWidget, 1);
......@@ -197,7 +197,6 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
verticalLayout->addLayout(hLayout);
mainLayout = new QHBoxLayout;
mainLayout->addWidget(phasesToolbar);
mainLayout->addWidget(gameView, 10);
mainLayout->addLayout(deckViewContainerLayout, 10);
mainLayout->addLayout(verticalLayout);
......@@ -221,9 +220,28 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
aLeaveGame = new QAction(this);
connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame()));
phasesMenu = new QMenu(this);
for (int i = 0; i < phasesToolbar->phaseCount(); ++i) {
QAction *temp = new QAction(QString(), this);
connect(temp, SIGNAL(triggered()), this, SLOT(actPhaseAction()));
switch (i) {
case 0: temp->setShortcut(tr("F5")); break;
case 2: temp->setShortcut(tr("F6")); break;
case 3: temp->setShortcut(tr("F7")); break;
case 4: temp->setShortcut(tr("F8")); break;
case 9: temp->setShortcut(tr("F9")); break;
case 10: temp->setShortcut(tr("F10")); break;
default: ;
}
phasesMenu->addAction(temp);
phaseActions.append(temp);
}
phasesMenu->addSeparator();
phasesMenu->addAction(aNextPhase);
tabMenu = new QMenu(this);
playersSeparator = tabMenu->addSeparator();
tabMenu->addAction(aNextPhase);
tabMenu->addMenu(phasesMenu);
tabMenu->addAction(aNextTurn);
tabMenu->addSeparator();
tabMenu->addAction(aRemoveLocalArrows);
......@@ -251,6 +269,10 @@ TabGame::~TabGame()
void TabGame::retranslateUi()
{
for (int i = 0; i < phaseActions.size(); ++i)
phaseActions[i]->setText(phasesToolbar->getLongPhaseName(i));
phasesMenu->setTitle(tr("&Phases"));
tabMenu->setTitle(tr("&Game"));
aNextPhase->setText(tr("Next &phase"));
aNextPhase->setShortcut(tr("Ctrl+Space"));
......@@ -300,6 +322,12 @@ void TabGame::actSay()
}
}
void TabGame::actPhaseAction()
{
int phase = phaseActions.indexOf(static_cast<QAction *>(sender()));
emit sendGameCommand(new Command_SetActivePhase(-1, phase), -1);
}
void TabGame::actNextPhase()
{
int phase = currentPhase;
......
......@@ -93,6 +93,7 @@ private:
QMap<int, QString> spectators;
bool started;
bool resuming;
QStringList phasesList;
int currentPhase;
int activePlayer;
......@@ -111,8 +112,9 @@ private:
QHBoxLayout *mainLayout;
ZoneViewLayout *zoneLayout;
QAction *playersSeparator;
QMenu *playersMenu;
QMenu *phasesMenu;
QAction *aConcede, *aLeaveGame, *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
QList<QAction *> phaseActions;
Player *addPlayer(int playerId, ServerInfo_User *info);
......@@ -145,6 +147,7 @@ private slots:
void actLeaveGame();
void actRemoveLocalArrows();
void actSay();
void actPhaseAction();
void actNextPhase();
void actNextTurn();
public:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment