Commit f12b894d authored by Michal Humpula's avatar Michal Humpula Committed by Frederik Schwarzer

Port to frameworks branch: mark last move stone

REVIEW: 125506
GUI: visually marking last move with slightly different stone
parent a907bc81
......@@ -77,4 +77,9 @@ QDebug operator<<(QDebug debug, const Stone &stone)
return debug;
}
bool operator==(const Stone &stone, const Stone &other)
{
return (stone.x() == other.x()) && (stone.y() == other.y());
}
} // End of namespace Kigo
......@@ -70,6 +70,8 @@ private:
QDebug operator<<(QDebug debug, const Stone &stone);
bool operator==(const Stone &stone, const Stone &other);
} // End of namespace Kigo
#endif
......@@ -134,13 +134,16 @@ void GameScene::updateStoneItems()
QGraphicsPixmapItem *item;
const int halfStoneSize = m_stonePixmapSize.width() / 2;
const Stone lastStone = (m_game->moves().size() > 0) ? m_game->lastMove().stone() : Stone::Invalid;
foreach (item, m_stoneItems) { // Clear all stone items
removeItem(item);
}
m_stoneItems.clear();
foreach (const Stone &stone, m_game->stones(m_game->blackPlayer())) {
item = addPixmap(ThemeRenderer::self()->renderElement(ThemeRenderer::Element::BlackStone, m_stonePixmapSize));
ThemeRenderer::Element element = (stone == lastStone) ? ThemeRenderer::Element::BlackStoneLast : ThemeRenderer::Element::BlackStone;
item = addPixmap(ThemeRenderer::self()->renderElement(element, m_stonePixmapSize));
item->setZValue(2);
const int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
item->setPos(QPointF(m_gridRect.x() + xOff * m_cellSize - halfStoneSize + 1,
......@@ -148,7 +151,8 @@ void GameScene::updateStoneItems()
m_stoneItems.append(item);
}
foreach (const Stone &stone, m_game->stones(m_game->whitePlayer())) {
item = addPixmap(ThemeRenderer::self()->renderElement(ThemeRenderer::Element::WhiteStone, m_stonePixmapSize));
ThemeRenderer::Element element = (stone == lastStone) ? ThemeRenderer::Element::WhiteStoneLast : ThemeRenderer::Element::WhiteStone;
item = addPixmap(ThemeRenderer::self()->renderElement(element, m_stonePixmapSize));
item->setZValue(2);
const int xOff = stone.x() >= 'I' ? stone.x() - 'A' - 1 : stone.x() - 'A';
item->setPos(QPointF(m_gridRect.x() + xOff * m_cellSize - halfStoneSize + 1,
......
......@@ -112,6 +112,9 @@ QPixmap ThemeRenderer::renderElement(Element element, const QSize &size) const
case Element::WhiteStone:
cacheName = QStringLiteral("white_stone_%1x%2").arg(size.width()).arg(size.height());
break;
case Element::WhiteStoneLast:
cacheName = QStringLiteral("white_stone_last_%1x%2").arg(size.width()).arg(size.height());
break;
case Element::WhiteStoneTransparent:
cacheName = QStringLiteral("white_stone_%1x%2_trans").arg(size.width()).arg(size.height());
break;
......@@ -121,6 +124,9 @@ QPixmap ThemeRenderer::renderElement(Element element, const QSize &size) const
case Element::BlackStone:
cacheName = QStringLiteral("black_stone_%1x%2").arg(size.width()).arg(size.height());
break;
case Element::BlackStoneLast:
cacheName = QStringLiteral("black_stone_last_%1x%2").arg(size.width()).arg(size.height());
break;
case Element::BlackStoneTransparent:
cacheName = QStringLiteral("black_stone_%1x%2_trans").arg(size.width()).arg(size.height());
break;
......@@ -151,6 +157,9 @@ QPixmap ThemeRenderer::renderElement(Element element, const QSize &size) const
case Element::WhiteStone:
m_renderer->render(&p, QStringLiteral("white_stone"));
break;
case Element::WhiteStoneLast:
m_renderer->render(&p, QStringLiteral("white_stone_last"));
break;
case Element::WhiteStoneTransparent:
p.setOpacity(0.5);
m_renderer->render(&p, QStringLiteral("white_stone"));
......@@ -161,6 +170,9 @@ QPixmap ThemeRenderer::renderElement(Element element, const QSize &size) const
case Element::BlackStone:
m_renderer->render(&p, QStringLiteral("black_stone"));
break;
case Element::BlackStoneLast:
m_renderer->render(&p, QStringLiteral("black_stone_last"));
break;
case Element::BlackStoneTransparent:
p.setOpacity(0.5);
m_renderer->render(&p, QStringLiteral("black_stone"));
......@@ -193,6 +205,9 @@ QSize ThemeRenderer::elementSize(Element element) const
case Element::WhiteStone:
sizeRect = m_renderer->boundsOnElement(QStringLiteral("white_stone"));
break;
case Element::WhiteStoneLast:
sizeRect = m_renderer->boundsOnElement(QStringLiteral("white_stone"));
break;
case Element::WhiteStoneTransparent:
sizeRect = m_renderer->boundsOnElement(QStringLiteral("white_stone"));
break;
......@@ -202,6 +217,9 @@ QSize ThemeRenderer::elementSize(Element element) const
case Element::BlackStone:
sizeRect = m_renderer->boundsOnElement(QStringLiteral("black_stone"));
break;
case Element::BlackStoneLast:
sizeRect = m_renderer->boundsOnElement(QStringLiteral("black_stone"));
break;
case Element::BlackStoneTransparent:
sizeRect = m_renderer->boundsOnElement(QStringLiteral("black_stone"));
break;
......
......@@ -60,9 +60,11 @@ public:
Board,
HandicapMark,
WhiteStone,
WhiteStoneLast,
WhiteStoneTransparent,
WhiteTerritory,
BlackStone,
BlackStoneLast,
BlackStoneTransparent,
BlackTerritory,
PlacementMarker
......
Markdown is supported
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