diff --git a/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp b/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp index 2eb9b44..9bec014 100644 --- a/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp @@ -51,55 +51,67 @@ void GamePiecesAppMenu::drawFrame() const { if (this->playerCursor.getPosition().y == 0) { this->placeText(text, this->playerCursor, "PIECES DISTRIBUTION", 5.f, 15.f, sf::Vector2u{0, 0}); - // draw pieces line + // TODO draw pieces line this->drawRow(1, 35.f); this->drawRow(2, 45.f); } else { - // draw pieces line - int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, MAXIMUM_PIECES_SIZE - 1); + // TODO draw pieces line + int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, MAXIMUM_PIECES_SIZE - 2); this->drawRow(firstElem, 25.f); this->drawRow(firstElem + 1, 35.f); this->drawRow(firstElem + 2, 45.f); - std::cout << this->playerCursor.getPosition().x << " " << this->playerCursor.getPosition().y << " " << firstElem << std::endl; - } - this->renderWindow->display(); } void GamePiecesAppMenu::drawRow(int piecesSize, float yPos) const { int numberOfPieces = this->settings->getMenu().readPiecesList().getNumberOfPieces(piecesSize); - int firstElem = std::clamp(((int) this->playerCursor.getPosition().x) - 3, 0, std::max(numberOfPieces - 6, 0)); + int firstElem = std::max(((int) this->playerCursor.getPosition().x) - 7, -4); + + sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier()); + text.setFillColor({0, 0, 0}); + text.setOutlineColor({255, 255, 255}); + + this->placeText(text, {}, "SIZE " + std::to_string(piecesSize), 1.f, yPos, {}); for (int i = 0; i < 7; i++) { if (i + firstElem >= numberOfPieces) return; - const Piece& piece = this->settings->getMenu().readPiecesList().lookAtPiece({piecesSize, firstElem + i}); - int cellSize = (8 * this->settings->getWindowSizeMultiplier()) / (piece.getLength()); - sf::FloatRect pos(sf::Vector2f(5.f + (i * 10.f), yPos) * (float) this->settings->getWindowSizeMultiplier(), sf::Vector2f(8 , 8) * (float) this->settings->getWindowSizeMultiplier()); - this->drawPiece(piece, cellSize, pos, this->playerCursor.getPosition() == sf::Vector2u{i + firstElem + 4, piecesSize + 2}); - } -} - -void GamePiecesAppMenu::drawPiece(const Piece& piece, int cellSize, const sf::FloatRect& pos, bool selected) const { - sf::RectangleShape cell(sf::Vector2f(cellSize, cellSize)); - sf::Color color = this->getColorOfBlock(piece.getBlockType(), (selected) ? +100 : 0); - sf::Color boxColor = sf::Color(180, 180, 180); - - for (int y = 0; y < piece.getLength(); y++) { - for (int x = 0; x < piece.getLength(); x++) { - if (piece.getPositions().contains(Position{x, y})) { - cell.setFillColor(color); + if ((i + firstElem) < 0) { + switch (i + firstElem) { + case -4 : {this->placeText(text, this->playerCursor, "ALL", 10.f + (i * 10.f), yPos, sf::Vector2u{0, piecesSize + 1u}); break;} + case -3 : {this->placeText(text, this->playerCursor, "CONVEX", 10.f + (i * 10.f), yPos, sf::Vector2u{1, piecesSize + 1u}); break;} + case -2 : {this->placeText(text, this->playerCursor, "HOLELESS", 10.f + (i * 10.f), yPos, sf::Vector2u{2, piecesSize + 1u}); break;} + case -1 : {this->placeText(text, this->playerCursor, "OTHER", 10.f + (i * 10.f), yPos, sf::Vector2u{3, piecesSize + 1u}); break;} } - else { - cell.setFillColor(boxColor); - - } - cell.setPosition(sf::Vector2f(pos.position.x + (x * cellSize), - pos.position.y + ((piece.getLength() - y - 1) * cellSize))); - this->renderWindow->draw(cell); + } + else { + const Piece& piece = this->settings->getMenu().readPiecesList().lookAtPiece({piecesSize, firstElem + i}); + int cellSize = (8 * this->settings->getWindowSizeMultiplier()) / (piece.getLength()); + sf::FloatRect piecePosition(sf::Vector2f(10.f + (i * 10.f), yPos - 4.f) * (float) this->settings->getWindowSizeMultiplier(), sf::Vector2f(8 , 8) * (float) this->settings->getWindowSizeMultiplier()); + this->drawPiece(piece, cellSize, piecePosition, this->playerCursor.getPosition() == sf::Vector2u{i + firstElem + 4u, piecesSize + 1u}); } } } + +void GamePiecesAppMenu::drawPiece(const Piece& piece, int cellSize, const sf::FloatRect& piecePosition, bool selected) const { + sf::RectangleShape rect(piecePosition.size); + rect.setPosition(piecePosition.position); + rect.setFillColor({180, 180, 180}); + if (selected) { + rect.setOutlineColor({0, 0, 0}); + rect.setOutlineThickness(this->settings->getWindowSizeMultiplier() / 2); + } + this->renderWindow->draw(rect); + + sf::RectangleShape cell(sf::Vector2f(cellSize, cellSize)); + cell.setFillColor(this->getColorOfBlock(piece.getBlockType(), 0)); + + for (const Position& cellPosition : piece.getPositions()) { + cell.setPosition(sf::Vector2f(piecePosition.position.x + (cellPosition.x * cellSize), + piecePosition.position.y + ((piece.getLength() - cellPosition.y - 1) * cellSize))); + this->renderWindow->draw(cell); + } +}