From 5d73e751d7f954cf7c3a38862c8f387d7227a6c2 Mon Sep 17 00:00:00 2001 From: zulianc Date: Sun, 30 Mar 2025 13:07:17 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20de=20qqch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/files_format.md | 2 +- src/GraphicalUI/AppMenus/AppMenu.h | 7 ++++ .../AppMenus/GamePiecesAppMenu.cpp | 40 +++++++++++++++++-- src/GraphicalUI/AppMenus/GamePiecesAppMenu.h | 3 ++ .../AppMenus/GamePlayingAppMenu.cpp | 7 ---- src/GraphicalUI/AppMenus/GamePlayingAppMenu.h | 2 - 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/doc/files_format.md b/doc/files_format.md index bfbcb5a..fa2891e 100644 --- a/doc/files_format.md +++ b/doc/files_format.md @@ -47,5 +47,5 @@ The settings file has the following format: - The last selected width of the board, stored with 1 byte - The last selected height of the board, stored with 1 byte - The uniformity mode (0 for default distribution, 1 for uniformous distribution, 2 for custom distribution), stored with 1 byte - - If custom distribution is set, store the proportion of each size (15x1 byte total) + - For each size, store the custom proportion (from 0 to 10) (15x1 byte total) - Every selected pieces, using 1 byte for the type of selection (once again converted from an Enum) and 1 byte for the actual value diff --git a/src/GraphicalUI/AppMenus/AppMenu.h b/src/GraphicalUI/AppMenus/AppMenu.h index f10c27c..762fd5e 100644 --- a/src/GraphicalUI/AppMenus/AppMenu.h +++ b/src/GraphicalUI/AppMenus/AppMenu.h @@ -80,4 +80,11 @@ class AppMenu { text.setPosition(sf::Vector2f({sizeMultiplier * 40.f, sizeMultiplier * yPos})); this->renderWindow->draw(text); } + + sf::Color getColorOfBlock(Block block, int luminosityShift) const { + Color rgbColor = BLOCKS_COLOR[block]; + return sf::Color(std::clamp(rgbColor.red + luminosityShift, 0, 255), + std::clamp(rgbColor.green + luminosityShift, 0, 255), + std::clamp(rgbColor.blue + luminosityShift, 0, 255)); + } }; diff --git a/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp b/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp index 03daa4a..2eb9b44 100644 --- a/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp @@ -59,13 +59,47 @@ void GamePiecesAppMenu::drawFrame() const { // draw pieces line int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, MAXIMUM_PIECES_SIZE - 1); this->drawRow(firstElem, 25.f); - this->drawRow(firstElem, 35.f); - this->drawRow(firstElem, 45.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 { - //TODO + int numberOfPieces = this->settings->getMenu().readPiecesList().getNumberOfPieces(piecesSize); + int firstElem = std::clamp(((int) this->playerCursor.getPosition().x) - 3, 0, std::max(numberOfPieces - 6, 0)); + + 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); + } + 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); + } + } } diff --git a/src/GraphicalUI/AppMenus/GamePiecesAppMenu.h b/src/GraphicalUI/AppMenus/GamePiecesAppMenu.h index a3619a8..68afc3e 100644 --- a/src/GraphicalUI/AppMenus/GamePiecesAppMenu.h +++ b/src/GraphicalUI/AppMenus/GamePiecesAppMenu.h @@ -5,6 +5,7 @@ #include #include +#include #include @@ -21,4 +22,6 @@ class GamePiecesAppMenu : public AppMenu { private: void drawRow(int piecesSize, float yPos) const; + + void drawPiece(const Piece& piece, int cellSize, const sf::FloatRect& pos, bool selected) const; }; diff --git a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp index 823b4f3..8f0a280 100644 --- a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp @@ -271,13 +271,6 @@ void GamePlayingAppMenu::drawFrame() const { this->renderWindow->display(); } -sf::Color GamePlayingAppMenu::getColorOfBlock(Block block, int luminosityShift) const { - Color rgbColor = BLOCKS_COLOR[block]; - return sf::Color(std::clamp(rgbColor.red + luminosityShift, 0, 255), - std::clamp(rgbColor.green + luminosityShift, 0, 255), - std::clamp(rgbColor.blue + luminosityShift, 0, 255)); -} - sf::Vector2f GamePlayingAppMenu::getBoardBlockPosition(int x, int y) const { return sf::Vector2f(this->boardPosition.position.x + (x * this->cellSizeZoom), this->boardPosition.position.y + ((this->game.getBoard().getBaseHeight() + 9 - y) * this->cellSizeZoom)); diff --git a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.h b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.h index c233115..1fa0b92 100644 --- a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.h +++ b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.h @@ -28,7 +28,5 @@ class GamePlayingAppMenu : public AppMenu { void drawFrame() const override; - sf::Color getColorOfBlock(Block block, int luminosityShift) const; - sf::Vector2f getBoardBlockPosition(int x, int y) const; };