added startup menu
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
GameBoard::GameBoard(int boardWidth, int boardHeight, const std::shared_ptr<PiecesList>& piecesList, int nextQueueLength) :
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
GameParameters::GameParameters(Gamemode gamemode, const Player& controls) :
|
||||
gamemode(gamemode),
|
||||
controls(controls) {
|
||||
|
||||
|
||||
this->reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -120,8 +120,6 @@ void GamePlayingAppMenu::drawFrame() const {
|
||||
}
|
||||
}
|
||||
|
||||
// end coutdown
|
||||
|
||||
if (drawActivePiece) {
|
||||
// ghost piece
|
||||
sf::Color ghostColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), 100);
|
||||
|
||||
74
src/GraphicalUI/AppMenus/StartUpAppMenu.cpp
Normal file
74
src/GraphicalUI/AppMenus/StartUpAppMenu.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "StartUpAppMenu.h"
|
||||
|
||||
#include "AppMenu.h"
|
||||
#include "MainAppMenu.h"
|
||||
#include "../PlayerCursor.h"
|
||||
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
||||
StartUpAppMenu::StartUpAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||
AppMenu(menuStack, settings, renderWindow),
|
||||
playerCursor({LOADED_PIECES_SIZE + 1}) {
|
||||
|
||||
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
|
||||
}
|
||||
|
||||
void StartUpAppMenu::computeFrame() {
|
||||
this->updateMetaBinds();
|
||||
this->playerCursor.updatePosition();
|
||||
|
||||
if (this->playerCursor.getPosition().x < MINIMUM_PIECES_SIZE) {
|
||||
if (this->playerCursor.movedLeft()) {
|
||||
this->playerCursor.goToPosition({LOADED_PIECES_SIZE, 0});
|
||||
}
|
||||
else {
|
||||
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
|
||||
}
|
||||
}
|
||||
|
||||
if (this->enterReleased) {
|
||||
*this->settings = Settings(this->playerCursor.getPosition().x);
|
||||
this->menuStack->pop();
|
||||
|
||||
if (this->settings->hasLoadedPieces()) {
|
||||
this->menuStack->push(std::make_shared<MainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||
}
|
||||
else {
|
||||
std::cout << "ERROR: COULD NOT LOAD PIECES" << std::endl;
|
||||
std::cout << "ARGUMENT WAS: " << this->playerCursor.getPosition().x << std::endl;
|
||||
}
|
||||
}
|
||||
else if (this->escReleased) {
|
||||
this->menuStack->pop();
|
||||
}
|
||||
}
|
||||
|
||||
void StartUpAppMenu::drawFrame() const {
|
||||
this->renderWindow->clear(sf::Color(200, 200, 200));
|
||||
|
||||
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2);
|
||||
text.setFillColor(sf::Color(0, 0, 0));
|
||||
text.setOutlineColor(sf::Color(255, 255, 255));
|
||||
|
||||
this->placeTitle(text, {}, "SELECT MAXIMUM PIECES SIZE", 10.f, {});
|
||||
this->placeTitle(text, this->playerCursor, "< " + std::to_string(this->playerCursor.getPosition().x) + " >", 25.f, this->playerCursor.getPosition());
|
||||
|
||||
text.setOutlineColor({0, 0, 0});
|
||||
if (this->playerCursor.getPosition().x <= 10) {
|
||||
text.setFillColor({0, 255, 0});
|
||||
this->placeTitle(text, {}, "LOW LOAD TIME", 40.f, {});
|
||||
}
|
||||
else if (this->playerCursor.getPosition().x <= 13) {
|
||||
text.setFillColor({255, 255, 0});
|
||||
this->placeTitle(text, {}, "MEDIUM LOAD TIME", 40.f, {});
|
||||
}
|
||||
else {
|
||||
text.setFillColor({255, 0, 0});
|
||||
this->placeTitle(text, {}, "LONG LOAD TIME", 40.f, {});
|
||||
}
|
||||
|
||||
this->renderWindow->display();
|
||||
}
|
||||
21
src/GraphicalUI/AppMenus/StartUpAppMenu.h
Normal file
21
src/GraphicalUI/AppMenus/StartUpAppMenu.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "AppMenu.h"
|
||||
#include "../PlayerCursor.h"
|
||||
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
||||
class StartUpAppMenu : public AppMenu {
|
||||
private:
|
||||
PlayerCursor playerCursor;
|
||||
|
||||
public:
|
||||
StartUpAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||
|
||||
void computeFrame() override;
|
||||
|
||||
void drawFrame() const override;
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "GraphApp.h"
|
||||
|
||||
#include "AppMenus/AppMenu.h"
|
||||
#include "AppMenus/MainAppMenu.h"
|
||||
#include "AppMenus/StartUpAppMenu.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <stack>
|
||||
@@ -11,15 +11,15 @@
|
||||
static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
|
||||
|
||||
|
||||
GraphApp::GraphApp(int maximumPiecesSize) {
|
||||
this->settings = std::make_shared<Settings>(maximumPiecesSize);
|
||||
GraphApp::GraphApp() {
|
||||
this->settings = std::make_shared<Settings>(0);
|
||||
this->menuStack = std::make_shared<MenuStack>();
|
||||
this->renderWindow = std::make_shared<sf::RenderWindow>();
|
||||
}
|
||||
|
||||
void GraphApp::run() {
|
||||
this->settings->changeVideoMode(*this->renderWindow);
|
||||
this->menuStack->push(std::make_shared<MainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||
this->menuStack->push(std::make_shared<StartUpAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||
|
||||
bool quit = false;
|
||||
double timeAtNextFrame = 0;
|
||||
|
||||
@@ -15,7 +15,7 @@ class GraphApp {
|
||||
std::shared_ptr<sf::RenderWindow> renderWindow;
|
||||
|
||||
public:
|
||||
GraphApp(int maximumPiecesSize);
|
||||
GraphApp();
|
||||
|
||||
void run();
|
||||
};
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include "../Core/Menu.h"
|
||||
#include "Keybinds.h"
|
||||
#include "PiecesType.h"
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <SFML/Graphics.hpp>
|
||||
@@ -15,9 +17,26 @@ static const int DISTRIBUTION_MAX = 10;
|
||||
|
||||
|
||||
Settings::Settings(int maximumPiecesSize) {
|
||||
this->maximumPiecesSize = maximumPiecesSize;
|
||||
for (int i = 1; i <= this->maximumPiecesSize; i++) {
|
||||
this->menu.getPiecesList().loadPieces(i);
|
||||
if (maximumPiecesSize < MINIMUM_PIECES_SIZE || maximumPiecesSize > LOADED_PIECES_SIZE) {
|
||||
this->maximumPiecesSize = 0;
|
||||
this->loadedPieces = false;
|
||||
}
|
||||
else {
|
||||
bool loaded = true;
|
||||
int i = 1;
|
||||
while (loaded && (i <= maximumPiecesSize)) {
|
||||
loaded = this->menu.getPiecesList().loadPieces(i);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (loaded) {
|
||||
this->maximumPiecesSize = maximumPiecesSize;
|
||||
this->loadedPieces = true;
|
||||
}
|
||||
else {
|
||||
this->maximumPiecesSize = 0;
|
||||
this->loadedPieces = false;
|
||||
}
|
||||
}
|
||||
|
||||
this->keybinds.reserve(NUMBER_OF_KEYBINDS);
|
||||
@@ -68,50 +87,58 @@ void Settings::loadSettingsFromFile() {
|
||||
settingsFile.get(byte);
|
||||
this->menu.setBoardHeight(byte);
|
||||
|
||||
// piece distribution
|
||||
settingsFile.get(byte);
|
||||
this->menu.getPiecesList().setDistributionMode(DistributionMode(byte));
|
||||
|
||||
this->distributions.clear();
|
||||
this->distributions.push_back(0);
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
if (this->loadedPieces) {
|
||||
// piece distribution
|
||||
settingsFile.get(byte);
|
||||
this->distributions.push_back(byte);
|
||||
}
|
||||
this->confirmDistribution();
|
||||
this->menu.getPiecesList().setDistributionMode(DistributionMode(byte));
|
||||
|
||||
// selected pieces
|
||||
char pieceType;
|
||||
char pieceSize;
|
||||
char lowByte;
|
||||
char midByte;
|
||||
char highByte;
|
||||
this->distributions.clear();
|
||||
this->distributions.push_back(0);
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
settingsFile.get(byte);
|
||||
this->distributions.push_back(byte);
|
||||
}
|
||||
this->confirmDistribution();
|
||||
|
||||
this->selectedPieces.clear();
|
||||
while (settingsFile.get(pieceType)) {
|
||||
if (settingsFile.eof()) break;
|
||||
|
||||
if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
|
||||
settingsFile.get(pieceSize);
|
||||
// selected pieces
|
||||
char pieceType;
|
||||
char pieceSize;
|
||||
char lowByte;
|
||||
char midByte;
|
||||
char highByte;
|
||||
|
||||
if (!(pieceSize > this->maximumPiecesSize)) {
|
||||
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceSize);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!(getSizeOfPieces(PiecesType(pieceType)) > this->maximumPiecesSize)) {
|
||||
settingsFile.get(lowByte);
|
||||
settingsFile.get(midByte);
|
||||
settingsFile.get(highByte);
|
||||
int pieceNumber = ((unsigned char) lowByte) + ((unsigned char) midByte << 8) + ((unsigned char) highByte << 16);
|
||||
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber);
|
||||
this->selectedPieces.clear();
|
||||
while (settingsFile.get(pieceType)) {
|
||||
if (settingsFile.eof()) break;
|
||||
|
||||
if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
|
||||
settingsFile.get(pieceSize);
|
||||
|
||||
if (!(pieceSize > this->maximumPiecesSize)) {
|
||||
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceSize);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!(getSizeOfPieces(PiecesType(pieceType)) > this->maximumPiecesSize)) {
|
||||
settingsFile.get(lowByte);
|
||||
settingsFile.get(midByte);
|
||||
settingsFile.get(highByte);
|
||||
int pieceNumber = ((unsigned char) lowByte) + ((unsigned char) midByte << 8) + ((unsigned char) highByte << 16);
|
||||
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
this->confirmSelectedPieces();
|
||||
}
|
||||
else {
|
||||
this->distributions.clear();
|
||||
this->selectedPieces.clear();
|
||||
}
|
||||
this->confirmSelectedPieces();
|
||||
}
|
||||
|
||||
void Settings::saveSettingsToFile() const {
|
||||
if (!this->loadedPieces) return;
|
||||
|
||||
this->keybinds.at(CUSTOMIZABLE_KEYBINDS).saveKeybindsToFile();
|
||||
|
||||
std::ofstream settingsFile("data/config/settings.bin", std::ios::trunc | std::ios::binary);
|
||||
@@ -247,16 +274,21 @@ void Settings::setGamemode(Gamemode gamemode) {
|
||||
}
|
||||
|
||||
void Settings::selectPieces(PiecesType type, int value) {
|
||||
if (!this->loadedPieces) return;
|
||||
|
||||
this->selectedPieces.emplace_back(type, value);
|
||||
}
|
||||
|
||||
void Settings::unselectPieces(int index) {
|
||||
if (!this->loadedPieces) return;
|
||||
if (index >= this->selectedPieces.size()) return;
|
||||
|
||||
this->selectedPieces.erase(this->selectedPieces.begin() + index);
|
||||
}
|
||||
|
||||
void Settings::confirmSelectedPieces() {
|
||||
if (!this->loadedPieces) return;
|
||||
|
||||
this->menu.getPiecesList().unselectAll();
|
||||
|
||||
if (this->getSelectedPieces().size() == 0) {
|
||||
@@ -281,6 +313,7 @@ void Settings::confirmSelectedPieces() {
|
||||
}
|
||||
|
||||
bool Settings::increaseDistribution(int size) {
|
||||
if (!this->loadedPieces) return false;
|
||||
if (size < 1 || size > this->maximumPiecesSize) return false;
|
||||
|
||||
if (this->distributions.at(size) < DISTRIBUTION_MAX) {
|
||||
@@ -291,6 +324,7 @@ bool Settings::increaseDistribution(int size) {
|
||||
}
|
||||
|
||||
bool Settings::decreaseDistribution(int size) {
|
||||
if (!this->loadedPieces) return false;
|
||||
if (size < 1 || size > this->maximumPiecesSize) return false;
|
||||
|
||||
if (this->distributions.at(size) > 0) {
|
||||
@@ -301,6 +335,8 @@ bool Settings::decreaseDistribution(int size) {
|
||||
}
|
||||
|
||||
void Settings::confirmDistribution() {
|
||||
if (!this->loadedPieces) return;
|
||||
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
this->menu.getPiecesList().changeCustomDistribution(i, (double) 1 / (this->distributions.at(i) + 0.001));
|
||||
}
|
||||
@@ -318,6 +354,10 @@ int Settings::getMaximumPiecesSize() const {
|
||||
return this->maximumPiecesSize;
|
||||
}
|
||||
|
||||
bool Settings::hasLoadedPieces() const {
|
||||
return this->loadedPieces;
|
||||
}
|
||||
|
||||
int Settings::getKeybindsLayout() const {
|
||||
return this->chosenKeybinds;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Core/Menu.h"
|
||||
#include "StartUpMenu.h"
|
||||
#include "Keybinds.h"
|
||||
#include "PiecesType.h"
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <vector>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
static const int MAXIMUM_BOARD_WIDTH = 40;
|
||||
static const int MAXIMUM_BOARD_HEIGHT = 40;
|
||||
|
||||
static const int MINIMUM_PIECES_SIZE = 4;
|
||||
static const int MAXIMUM_PIECES_SIZE = 15;
|
||||
|
||||
//#define __JMINOS_RELEASE__
|
||||
#ifdef __JMINOS_RELEASE__
|
||||
static const int LOADED_PIECES_SIZE = 15;
|
||||
#else
|
||||
static const int LOADED_PIECES_SIZE = 10;
|
||||
#endif
|
||||
|
||||
static const std::pair<PiecesType, int> DEFAULT_SELECTION = {ALL_PIECES, MINIMUM_PIECES_SIZE};
|
||||
|
||||
|
||||
class Settings {
|
||||
private:
|
||||
Menu menu;
|
||||
int maximumPiecesSize;
|
||||
bool loadedPieces;
|
||||
std::vector<Keybinds> keybinds;
|
||||
int chosenKeybinds;
|
||||
int windowSizeMode;
|
||||
@@ -67,6 +79,8 @@ class Settings {
|
||||
|
||||
int getMaximumPiecesSize() const;
|
||||
|
||||
bool hasLoadedPieces() const;
|
||||
|
||||
int getKeybindsLayout() const;
|
||||
|
||||
Gamemode getGamemode() const;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#include "StartUpMenu.h"
|
||||
|
||||
#include "PlayerCursor.h"
|
||||
|
||||
|
||||
StartUpMenu::StartUpMenu() :
|
||||
playerCursor({LOADED_PIECES_SIZE}) {
|
||||
|
||||
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
|
||||
}
|
||||
|
||||
int StartUpMenu::getMaximumPiecesSize() {
|
||||
return LOADED_PIECES_SIZE;
|
||||
//TODO
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "PiecesType.h"
|
||||
#include "PlayerCursor.h"
|
||||
|
||||
|
||||
static const int MINIMUM_PIECES_SIZE = 4;
|
||||
static const int MAXIMUM_PIECES_SIZE = 15;
|
||||
|
||||
//#define __JMINOS_RELEASE__
|
||||
#ifdef __JMINOS_RELEASE__
|
||||
static const int LOADED_PIECES_SIZE = 15;
|
||||
#else
|
||||
static const int LOADED_PIECES_SIZE = 10;
|
||||
#endif
|
||||
|
||||
static const std::pair<PiecesType, int> DEFAULT_SELECTION = {ALL_PIECES, MINIMUM_PIECES_SIZE};
|
||||
|
||||
|
||||
class StartUpMenu {
|
||||
private:
|
||||
PlayerCursor playerCursor;
|
||||
|
||||
public:
|
||||
StartUpMenu();
|
||||
|
||||
int getMaximumPiecesSize();
|
||||
};
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "StartUpMenu.h"
|
||||
#include "GraphApp.h"
|
||||
#include "../Pieces/PiecesFiles.h"
|
||||
|
||||
@@ -31,10 +30,7 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
StartUpMenu startUp;
|
||||
int maximumPiecesSize = startUp.getMaximumPiecesSize();
|
||||
|
||||
GraphApp UI(maximumPiecesSize);
|
||||
GraphApp UI;
|
||||
UI.run();
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user