omg omg
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
GamePiecesAppMenu::GamePiecesAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
GamePiecesAppMenu::GamePiecesAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||||
AppMenu(menuStack, settings, renderWindow),
|
AppMenu(menuStack, settings, renderWindow),
|
||||||
playerCursor({1, 1}) {
|
playerCursor({1, (unsigned int) this->settings->getSelectedPieces().size() + 1u}) {
|
||||||
|
|
||||||
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
||||||
this->playerCursor.addRow(i + 1, this->settings->getMenu().readPiecesList().getNumberOfPieces(i) + 4);
|
this->playerCursor.addRow(i + 1, this->settings->getMenu().readPiecesList().getNumberOfPieces(i) + 4);
|
||||||
@@ -22,19 +22,42 @@ void GamePiecesAppMenu::computeFrame() {
|
|||||||
this->updateMetaBinds();
|
this->updateMetaBinds();
|
||||||
this->playerCursor.updatePosition();
|
this->playerCursor.updatePosition();
|
||||||
|
|
||||||
|
if (this->playerCursor.movedDown() && this->playerCursor.getPosition().y == 2) {
|
||||||
|
this->playerCursor.goToPosition({0, 2});
|
||||||
|
}
|
||||||
|
|
||||||
if (this->enterReleased) {
|
if (this->enterReleased) {
|
||||||
if (this->playerCursor.getPosition().y == 0) {
|
if (this->playerCursor.getPosition().y == 0) {
|
||||||
this->menuStack->push(std::make_shared<GameDistributionAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
this->menuStack->push(std::make_shared<GameDistributionAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
}
|
}
|
||||||
if (this->playerCursor.getPosition().y > 1) {
|
if (this->playerCursor.getPosition().y > 1) {
|
||||||
//TODO
|
if (this->playerCursor.getPosition().x >= 4) {
|
||||||
|
this->settings->selectPieces(createSinglePieceType(this->playerCursor.getPosition().y - 1), this->playerCursor.getPosition().x - 4);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch (this->playerCursor.getPosition().x) {
|
||||||
|
case 0 : {this->settings->selectPieces(ALL_PIECES, this->playerCursor.getPosition().y - 1); break;}
|
||||||
|
case 1 : {this->settings->selectPieces(CONVEX_PIECES, this->playerCursor.getPosition().y - 1); break;}
|
||||||
|
case 2 : {this->settings->selectPieces(HOLELESS_PIECES, this->playerCursor.getPosition().y - 1); break;}
|
||||||
|
case 3 : {this->settings->selectPieces(OTHER_PIECES, this->playerCursor.getPosition().y - 1); break;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->playerCursor.addPosition(0, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->escReleased) {
|
if (this->escReleased) {
|
||||||
if (this->playerCursor.getPosition().y == 1) {
|
if (this->playerCursor.getPosition().y == 1) {
|
||||||
//TODO
|
if (this->playerCursor.getPosition().x > 0) {
|
||||||
|
this->settings->unselectPieces(this->playerCursor.getPosition().x - 1);
|
||||||
|
this->playerCursor.removePosition(this->playerCursor.getPosition().x - 1, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (this->settings->getSelectedPieces().size() == 0) {
|
||||||
|
this->settings->selectPieces(ALL_PIECES, 4);
|
||||||
|
}
|
||||||
|
this->settings->confirmSelectedPieces();
|
||||||
|
|
||||||
this->menuStack->pop();
|
this->menuStack->pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,24 +74,66 @@ void GamePiecesAppMenu::drawFrame() const {
|
|||||||
|
|
||||||
if (this->playerCursor.getPosition().y == 0) {
|
if (this->playerCursor.getPosition().y == 0) {
|
||||||
this->placeText(text, this->playerCursor, "PIECES DISTRIBUTION", 5.f, 15.f, sf::Vector2u{0, 0});
|
this->placeText(text, this->playerCursor, "PIECES DISTRIBUTION", 5.f, 15.f, sf::Vector2u{0, 0});
|
||||||
// TODO draw pieces line
|
this->drawSelectedPiecesRow(25.f);
|
||||||
this->drawRow(1, 35.f);
|
this->drawRow(1, 35.f, true);
|
||||||
this->drawRow(2, 45.f);
|
this->drawRow(2, 45.f, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO draw pieces line
|
this->drawSelectedPiecesRow(15.f);
|
||||||
|
|
||||||
|
bool drawFromFirstElem = (this->playerCursor.getPosition().y == 1);
|
||||||
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, MAXIMUM_PIECES_SIZE - 2);
|
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, MAXIMUM_PIECES_SIZE - 2);
|
||||||
this->drawRow(firstElem, 25.f);
|
this->drawRow(firstElem, 25.f, drawFromFirstElem);
|
||||||
this->drawRow(firstElem + 1, 35.f);
|
this->drawRow(firstElem + 1, 35.f, drawFromFirstElem);
|
||||||
this->drawRow(firstElem + 2, 45.f);
|
this->drawRow(firstElem + 2, 45.f, drawFromFirstElem);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->renderWindow->display();
|
this->renderWindow->display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamePiecesAppMenu::drawRow(int piecesSize, float yPos) const {
|
void GamePiecesAppMenu::drawSelectedPiecesRow(float yPos) const {
|
||||||
|
sf::RectangleShape rect({(float) this->renderWindow->getSize().x, 8.f * this->settings->getWindowSizeMultiplier()});
|
||||||
|
rect.setPosition({0.f, (yPos - 4.f) * this->settings->getWindowSizeMultiplier()});
|
||||||
|
rect.setFillColor({240, 240, 240});
|
||||||
|
this->renderWindow->draw(rect);
|
||||||
|
|
||||||
|
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier());
|
||||||
|
text.setFillColor({0, 0, 0});
|
||||||
|
|
||||||
|
int elem = (this->playerCursor.getPosition().y == 1) ? std::max(((int) this->playerCursor.getPosition().x) - 4, 0) : 0;
|
||||||
|
float xProgress = 1.f;
|
||||||
|
|
||||||
|
bool first = true;
|
||||||
|
while (true) {
|
||||||
|
if ((this->playerCursor.getPosition().y == 1) && (elem == this->playerCursor.getPosition().x)) {
|
||||||
|
this->placeText(text, {}, "|", xProgress, yPos, {});
|
||||||
|
xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elem >= this->settings->getSelectedPieces().size()) return;
|
||||||
|
|
||||||
|
const auto& [pieceType, value] = this->settings->getSelectedPieces().at(elem);
|
||||||
|
|
||||||
|
int pieceSize = getSizeOfPieces(pieceType);
|
||||||
|
if (pieceSize > 0) {
|
||||||
|
const Piece& piece = this->settings->getMenu().readPiecesList().lookAtPiece({pieceSize, value});
|
||||||
|
int cellSize = (8 * this->settings->getWindowSizeMultiplier()) / (piece.getLength());
|
||||||
|
sf::FloatRect piecePosition(sf::Vector2f(xProgress, yPos - 4.f) * (float) this->settings->getWindowSizeMultiplier(), sf::Vector2f(8 , 8) * (float) this->settings->getWindowSizeMultiplier());
|
||||||
|
this->drawPiece(piece, cellSize, piecePosition, false);
|
||||||
|
xProgress += (1.f + 8.f);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->placeText(text, {}, ((first) ? "" : " ") + getPiecesTypeName(pieceType) + "_" + std::to_string(value), xProgress, yPos, {});
|
||||||
|
xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier()));
|
||||||
|
}
|
||||||
|
|
||||||
|
elem++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GamePiecesAppMenu::drawRow(int piecesSize, float yPos, bool drawFromFirstElem) const {
|
||||||
int numberOfPieces = this->settings->getMenu().readPiecesList().getNumberOfPieces(piecesSize);
|
int numberOfPieces = this->settings->getMenu().readPiecesList().getNumberOfPieces(piecesSize);
|
||||||
int firstElem = std::max(((int) this->playerCursor.getPosition().x) - 7, -4);
|
int firstElem = (drawFromFirstElem) ? -4 : std::max(((int) this->playerCursor.getPosition().x) - 7, -4);
|
||||||
|
|
||||||
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier());
|
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier());
|
||||||
text.setFillColor({0, 0, 0});
|
text.setFillColor({0, 0, 0});
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ class GamePiecesAppMenu : public AppMenu {
|
|||||||
void drawFrame() const override;
|
void drawFrame() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drawRow(int piecesSize, float yPos) const;
|
void drawSelectedPiecesRow(float yPos) const;
|
||||||
|
|
||||||
|
void drawRow(int piecesSize, float yPos, bool drawFromFirstElem) const;
|
||||||
|
|
||||||
void drawPiece(const Piece& piece, int cellSize, const sf::FloatRect& pos, bool selected) const;
|
void drawPiece(const Piece& piece, int cellSize, const sf::FloatRect& pos, bool selected) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
enum PiecesType {
|
enum PiecesType {
|
||||||
CONVEX_PIECES,
|
CONVEX_PIECES,
|
||||||
@@ -19,3 +21,15 @@ inline int getSizeOfPieces(PiecesType type) {
|
|||||||
inline PiecesType createSinglePieceType(int size) {
|
inline PiecesType createSinglePieceType(int size) {
|
||||||
return PiecesType(SINGLE_PIECE + size - 1);
|
return PiecesType(SINGLE_PIECE + size - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::string getPiecesTypeName(PiecesType piecesType) {
|
||||||
|
static const std::string PIECES_TYPE_NAME[] = {
|
||||||
|
"CONVEX",
|
||||||
|
"HOLELESS",
|
||||||
|
"OTHER",
|
||||||
|
"ALL",
|
||||||
|
"SINGLE"
|
||||||
|
};
|
||||||
|
|
||||||
|
return PIECES_TYPE_NAME[piecesType];
|
||||||
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ bool PlayerCursor::addPosition(unsigned int x, unsigned int y) {
|
|||||||
if (x > this->rows.at(y)) return false;
|
if (x > this->rows.at(y)) return false;
|
||||||
|
|
||||||
this->rows.at(y)++;
|
this->rows.at(y)++;
|
||||||
if (x <= this->position.x) {
|
if ((y == this->position.y) && (x <= this->position.x)) {
|
||||||
this->position.x++;
|
this->position.x++;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -82,7 +82,7 @@ bool PlayerCursor::removePosition(unsigned int x, unsigned int y) {
|
|||||||
if (x >= this->rows.at(y)) return false;
|
if (x >= this->rows.at(y)) return false;
|
||||||
|
|
||||||
this->rows.at(y)--;
|
this->rows.at(y)--;
|
||||||
if (x < this->position.x) {
|
if ((y == this->position.y) && (x < this->position.x)) {
|
||||||
this->position.x--;
|
this->position.x--;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ bool Settings::decreaseDistribution(int size) {
|
|||||||
|
|
||||||
void Settings::confirmDistribution() {
|
void Settings::confirmDistribution() {
|
||||||
for (int i = 1; i <= 15; i++) {
|
for (int i = 1; i <= 15; i++) {
|
||||||
this->menu.getPiecesList().changeCustomDistribution(i, (double) this->distributions.at(i) / (DISTRIBUTION_MAX + 0.001));
|
this->menu.getPiecesList().changeCustomDistribution(i, (double) 1 / (this->distributions.at(i) + 0.001));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ bool PiecesFiles::loadPieces(int polyominoSize, std::vector<Piece>& pieces, std:
|
|||||||
char positionByte;
|
char positionByte;
|
||||||
for (int i = 0; i < polyominoSize; i++) {
|
for (int i = 0; i < polyominoSize; i++) {
|
||||||
piecesFile.get(positionByte);
|
piecesFile.get(positionByte);
|
||||||
int x = (positionByte & xMask) >> 4;
|
int x = ((unsigned char) positionByte & xMask) >> 4;
|
||||||
int y = positionByte & yMask;
|
int y = positionByte & yMask;
|
||||||
piecePositions.insert(Position{x, y});
|
piecePositions.insert(Position{x, y});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user