diff --git a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp index 60100cf..5f0e963 100644 --- a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp @@ -39,6 +39,10 @@ GamePlayingAppMenu::GamePlayingAppMenu(std::shared_ptr menuStack, std float nextPieceCellSizeZoom = ((int) this->nextQueuePosition[0].size.y) / this->settings->getMenu().getPiecesList().getPiece(piece).getLength(); this->nextCellSizeZoom = std::min(this->nextCellSizeZoom, nextPieceCellSizeZoom); } + + this->holdBoxPosition = sf::Rect(sf::Vector2f(this->boardPosition.position.x - ((8.f + 5.f) * this->settings->getWindowSizeMultiplier()), (11.f) * this->settings->getWindowSizeMultiplier()), + sf::Vector2f(8.f * this->settings->getWindowSizeMultiplier(), 8.f * this->settings->getWindowSizeMultiplier())); + this->holdCellSizeZoom = this->nextCellSizeZoom; } void GamePlayingAppMenu::computeFrame() { @@ -152,16 +156,42 @@ void GamePlayingAppMenu::drawFrame() const { for (int i = 0; i < std::min((int) this->game.getNextPieces().size(), 5); i++) { sf::Vector2f nextCellSize(this->nextCellSizeZoom, this->nextCellSizeZoom); sf::Color color = this->getColorOfBlock(this->game.getNextPieces().at(i).getBlockType(), 0); + sf::Color boxColor = sf::Color(150, 150, 150); for (int y = 0; y < this->game.getNextPieces().at(i).getLength(); y++) { for (int x = 0; x < this->game.getNextPieces().at(i).getLength(); x++) { + sf::RectangleShape cell(nextCellSize); if (this->game.getNextPieces().at(i).getPositions().contains(Position{x, y})) { - sf::RectangleShape cell(nextCellSize); cell.setFillColor(color); - cell.setPosition(sf::Vector2f(this->nextQueuePosition[i].position.x + (x * this->nextCellSizeZoom), - this->nextQueuePosition[i].position.y + ((this->game.getNextPieces().at(i).getLength() - y - 1) * this->nextCellSizeZoom))); - this->renderWindow->draw(cell); } + else { + cell.setFillColor(boxColor); + } + cell.setPosition(sf::Vector2f(this->nextQueuePosition[i].position.x + (x * this->nextCellSizeZoom), + this->nextQueuePosition[i].position.y + ((this->game.getNextPieces().at(i).getLength() - y - 1) * this->nextCellSizeZoom))); + this->renderWindow->draw(cell); + } + } + } + + // hold box + if (this->game.getHeldPiece() != nullptr) { + sf::Vector2f holdCellSize(this->holdCellSizeZoom, this->holdCellSizeZoom); + sf::Color color = this->getColorOfBlock(this->game.getHeldPiece()->getBlockType(), 0); + sf::Color boxColor = sf::Color(150, 150, 150); + + for (int y = 0; y < this->game.getHeldPiece()->getLength(); y++) { + for (int x = 0; x < this->game.getHeldPiece()->getLength(); x++) { + sf::RectangleShape cell(holdCellSize); + if (this->game.getHeldPiece()->getPositions().contains(Position{x, y})) { + cell.setFillColor(color); + } + else { + cell.setFillColor(boxColor); + } + cell.setPosition(sf::Vector2f(this->holdBoxPosition.position.x + (x * this->nextCellSizeZoom), + this->holdBoxPosition.position.y + ((this->game.getHeldPiece()->getLength() - y - 1) * this->holdCellSizeZoom))); + this->renderWindow->draw(cell); } } } diff --git a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.h b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.h index 2f53a88..bbcaeca 100644 --- a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.h +++ b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.h @@ -15,6 +15,8 @@ class GamePlayingAppMenu : public AppMenu { bool retryPressed; sf::Rect boardPosition; float cellSizeZoom; + sf::Rect holdBoxPosition; + float holdCellSizeZoom; sf::Rect nextQueuePosition[5]; float nextCellSizeZoom;