début de qqch
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user