l'espoir renaît????
This commit is contained in:
@@ -15,6 +15,10 @@ class AppMenu {
|
|||||||
std::shared_ptr<MenuStack> menuStack;
|
std::shared_ptr<MenuStack> menuStack;
|
||||||
std::shared_ptr<Settings> settings;
|
std::shared_ptr<Settings> settings;
|
||||||
std::shared_ptr<sf::RenderWindow> renderWindow;
|
std::shared_ptr<sf::RenderWindow> renderWindow;
|
||||||
|
bool enterPressed = false;
|
||||||
|
bool enterReleased = false;
|
||||||
|
bool escPressed = false;
|
||||||
|
bool escReleased = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
AppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||||
@@ -25,6 +29,26 @@ class AppMenu {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateMetaBinds() {
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter)) {
|
||||||
|
enterPressed = true;
|
||||||
|
enterReleased = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
enterReleased = enterPressed;
|
||||||
|
enterPressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
|
||||||
|
escPressed = true;
|
||||||
|
escReleased = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
escReleased = escPressed;
|
||||||
|
escPressed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void computeFrame() = 0;
|
virtual void computeFrame() = 0;
|
||||||
|
|
||||||
virtual void drawFrame() const = 0;
|
virtual void drawFrame() const = 0;
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ InGameAppMenu::InGameAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_p
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InGameAppMenu::computeFrame() {
|
void InGameAppMenu::computeFrame() {
|
||||||
|
this->updateMetaBinds();
|
||||||
|
|
||||||
|
if (this->escReleased) {
|
||||||
|
this->menuStack->pop();
|
||||||
|
}
|
||||||
|
else {
|
||||||
std::set<Action> actions;
|
std::set<Action> actions;
|
||||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||||
for (sfKey key : this->settings->getKeybinds().getKeybinds(action)) {
|
for (sfKey key : this->settings->getKeybinds().getKeybinds(action)) {
|
||||||
@@ -37,24 +43,24 @@ void InGameAppMenu::computeFrame() {
|
|||||||
if (!paused) {
|
if (!paused) {
|
||||||
this->game.nextFrame(actions);
|
this->game.nextFrame(actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sf::Keyboard::isKeyPressed(sfKey::Escape)) {
|
|
||||||
this->menuStack->pop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InGameAppMenu::drawFrame() const {
|
void InGameAppMenu::drawFrame() const {
|
||||||
this->renderWindow->clear(sf::Color::Black);
|
this->renderWindow->clear(sf::Color::Black);
|
||||||
|
|
||||||
for (int y = this->game.getBoard().getBaseHeight() + 5; y >= 0; y--) {
|
int sizeMultiplier = this->settings->getWindowSizeMultiplier();
|
||||||
|
sf::Vector2f cellSize((float) sizeMultiplier, (float) sizeMultiplier);
|
||||||
|
|
||||||
|
for (int y = this->game.getBoard().getBaseHeight() + 10; y >= 0; y--) {
|
||||||
for (int x = 0; x < this->game.getBoard().getWidth(); x++) {
|
for (int x = 0; x < this->game.getBoard().getWidth(); x++) {
|
||||||
bool isActivePieceHere = (this->game.getActivePiece() != nullptr) && (this->game.getActivePiece()->getPositions().contains(Position{x, y} - this->game.getActivePiecePosition()));
|
bool isActivePieceHere = (this->game.getActivePiece() != nullptr) && (this->game.getActivePiece()->getPositions().contains(Position{x, y} - this->game.getActivePiecePosition()));
|
||||||
bool isGhostPieceHere = (this->game.getActivePiece() != nullptr) && (this->game.getActivePiece()->getPositions().contains(Position{x, y} - this->game.ghostPiecePosition()));
|
bool isGhostPieceHere = (this->game.getActivePiece() != nullptr) && (this->game.getActivePiece()->getPositions().contains(Position{x, y} - this->game.ghostPiecePosition()));
|
||||||
Block block = (isActivePieceHere || isGhostPieceHere) ? this->game.getActivePiece()->getBlockType() : this->game.getBoard().getBlock(Position{x, y});
|
Block block = (isActivePieceHere || isGhostPieceHere) ? this->game.getActivePiece()->getBlockType() : this->game.getBoard().getBlock(Position{x, y});
|
||||||
|
|
||||||
sf::RectangleShape cell(sf::Vector2f(20.f, 20.f));
|
sf::RectangleShape cell(cellSize);
|
||||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue, (isGhostPieceHere && !isActivePieceHere) ? 150 : 255));
|
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue, (isGhostPieceHere && !isActivePieceHere) ? 150 : 255));
|
||||||
cell.setPosition(sf::Vector2f(x*20, (this->game.getBoard().getBaseHeight() + 10 - y)*20));
|
cell.setPosition(sf::Vector2f(x * sizeMultiplier, (this->game.getBoard().getBaseHeight() + 10 - y) * sizeMultiplier));
|
||||||
this->renderWindow->draw(cell);
|
this->renderWindow->draw(cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ MainAppMenu::MainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<S
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainAppMenu::computeFrame() {
|
void MainAppMenu::computeFrame() {
|
||||||
if (sf::Keyboard::isKeyPressed(sfKey::Enter)) {
|
this->updateMetaBinds();
|
||||||
|
|
||||||
|
if (this->enterReleased) {
|
||||||
this->menuStack->push(std::make_shared<InGameAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
this->menuStack->push(std::make_shared<InGameAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
}
|
}
|
||||||
else if (sf::Keyboard::isKeyPressed(sfKey::Escape)) {
|
if (this->escReleased) {
|
||||||
this->menuStack->pop();
|
this->menuStack->pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ GraphApp::GraphApp() {
|
|||||||
|
|
||||||
void GraphApp::run() {
|
void GraphApp::run() {
|
||||||
changeVideoMode(*this->renderWindow, this->settings->getVideoMode());
|
changeVideoMode(*this->renderWindow, this->settings->getVideoMode());
|
||||||
std::cout << renderWindow->getSize().x << " " << renderWindow->getSize().y << std::endl;
|
|
||||||
this->menuStack->push(std::make_shared<MainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
this->menuStack->push(std::make_shared<MainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
|
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
@@ -34,7 +33,6 @@ void GraphApp::run() {
|
|||||||
|
|
||||||
if (!quit) {
|
if (!quit) {
|
||||||
if (clock.getElapsedTime().asMilliseconds() > timeAtNextFrame) {
|
if (clock.getElapsedTime().asMilliseconds() > timeAtNextFrame) {
|
||||||
timeAtNextFrame += TIME_BETWEEN_FRAMES;
|
|
||||||
this->menuStack->top()->computeFrame();
|
this->menuStack->top()->computeFrame();
|
||||||
|
|
||||||
if (this->menuStack->empty()) {
|
if (this->menuStack->empty()) {
|
||||||
@@ -43,6 +41,10 @@ void GraphApp::run() {
|
|||||||
else {
|
else {
|
||||||
this->menuStack->top()->drawFrame();
|
this->menuStack->top()->drawFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (clock.getElapsedTime().asMilliseconds() > timeAtNextFrame) {
|
||||||
|
timeAtNextFrame += TIME_BETWEEN_FRAMES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,19 +26,20 @@ void Keybinds::loadKeybindsFromFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char byte;
|
char byte;
|
||||||
while (layoutFile.get(byte)) {
|
while (layoutFile.peek() != EOF) {
|
||||||
if (layoutFile.eof()) break;
|
layoutFile.get(byte);
|
||||||
|
|
||||||
Action action = Action(byte);
|
Action action = Action(byte);
|
||||||
|
|
||||||
do {
|
bool separatorMet = false;
|
||||||
|
while (!separatorMet) {
|
||||||
layoutFile.get(byte);
|
layoutFile.get(byte);
|
||||||
if (layoutFile.eof()) break;
|
if (byte == (char) 0xFF) {
|
||||||
|
separatorMet = true;
|
||||||
if (byte != 0xFF) {
|
}
|
||||||
|
else {
|
||||||
this->keybinds.at(action).insert(sfKey(byte));
|
this->keybinds.at(action).insert(sfKey(byte));
|
||||||
}
|
}
|
||||||
} while (byte != 0xFF);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ void Settings::loadSettingsFromFile() {
|
|||||||
|
|
||||||
// window size mode
|
// window size mode
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
std::cout << (int) byte;
|
|
||||||
this->windowSizeMode = byte;
|
this->windowSizeMode = byte;
|
||||||
|
|
||||||
// gamemode
|
// gamemode
|
||||||
@@ -43,7 +42,6 @@ void Settings::loadSettingsFromFile() {
|
|||||||
|
|
||||||
// board width
|
// board width
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
std::cout << (int) byte;
|
|
||||||
this->menu.setBoardWidth(byte);
|
this->menu.setBoardWidth(byte);
|
||||||
|
|
||||||
// board height
|
// board height
|
||||||
@@ -64,6 +62,7 @@ void Settings::loadSettingsFromFile() {
|
|||||||
settingsFile.get(pieceValue);
|
settingsFile.get(pieceValue);
|
||||||
this->selectedPieces.push_back({PiecesType(pieceType), pieceValue});
|
this->selectedPieces.push_back({PiecesType(pieceType), pieceValue});
|
||||||
}
|
}
|
||||||
|
this->confirmSelectedPieces();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::saveSettingsToFile() const {
|
void Settings::saveSettingsToFile() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user