ff
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -5,7 +5,6 @@
|
|||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
|
|
||||||
static const int FRAMES_PER_SECOND = 60; // the number of frames per second, all the values in the app were choosen with this number in mind
|
static const int FRAMES_PER_SECOND = 60; // the number of frames per second, all the values in the app were choosen with this number in mind
|
||||||
static const int MAXIMUM_PIECES_SIZE = 15; // the maximum size of available pieces
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,15 +6,18 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
class AppMenu;
|
||||||
|
using MenuStack = std::stack<std::shared_ptr<AppMenu>>;
|
||||||
|
|
||||||
|
|
||||||
class AppMenu {
|
class AppMenu {
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<std::stack<AppMenu>> 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;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AppMenu(std::shared_ptr<std::stack<AppMenu>> 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) :
|
||||||
menuStack(menuStack),
|
menuStack(menuStack),
|
||||||
settings(settings),
|
settings(settings),
|
||||||
renderWindow(renderWindow)
|
renderWindow(renderWindow)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
InGameAppMenu::InGameAppMenu(std::shared_ptr<std::stack<AppMenu>> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
InGameAppMenu::InGameAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||||
AppMenu(menuStack, settings, renderWindow),
|
AppMenu(menuStack, settings, renderWindow),
|
||||||
game(this->settings->getMenu().startGame(this->settings->getGamemode()))
|
game(this->settings->getMenu().startGame(this->settings->getGamemode()))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class InGameAppMenu : public AppMenu {
|
|||||||
bool paused;
|
bool paused;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InGameAppMenu(std::shared_ptr<std::stack<AppMenu>> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
InGameAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||||
|
|
||||||
void computeFrame();
|
void computeFrame();
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,14 @@
|
|||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
MainAppMenu::MainAppMenu(std::shared_ptr<std::stack<AppMenu>> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
MainAppMenu::MainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||||
AppMenu(menuStack, settings, renderWindow) {
|
AppMenu(menuStack, settings, renderWindow) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainAppMenu::computeFrame() {
|
void MainAppMenu::computeFrame() {
|
||||||
if (sf::Keyboard::isKeyPressed(sfKey::Enter)) {
|
if (sf::Keyboard::isKeyPressed(sfKey::Enter)) {
|
||||||
this->menuStack->push(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)) {
|
else if (sf::Keyboard::isKeyPressed(sfKey::Escape)) {
|
||||||
this->menuStack->pop();
|
this->menuStack->pop();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
class MainAppMenu : public AppMenu {
|
class MainAppMenu : public AppMenu {
|
||||||
public:
|
public:
|
||||||
MainAppMenu(std::shared_ptr<std::stack<AppMenu>> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
MainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||||
|
|
||||||
void computeFrame();
|
void computeFrame();
|
||||||
|
|
||||||
|
|||||||
@@ -13,19 +13,19 @@ static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
|
|||||||
|
|
||||||
GraphApp::GraphApp() {
|
GraphApp::GraphApp() {
|
||||||
this->settings = std::make_shared<Settings>();
|
this->settings = std::make_shared<Settings>();
|
||||||
this->menuStack = std::make_shared<std::stack<AppMenu>>();
|
this->menuStack = std::make_shared<MenuStack>();
|
||||||
this->window = std::make_shared<sf::RenderWindow>();
|
this->renderWindow = std::make_shared<sf::RenderWindow>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphApp::run() {
|
void GraphApp::run() {
|
||||||
changeVideoMode(*this->window, this->settings->getVideoMode());
|
changeVideoMode(*this->renderWindow, this->settings->getVideoMode());
|
||||||
this->menuStack->push(MainAppMenu(this->menuStack, this->settings, this->window));
|
this->menuStack->push(std::make_shared<MainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
|
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
double timeAtNextFrame = 0;
|
double timeAtNextFrame = 0;
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
while (const std::optional event = this->window->pollEvent()) {
|
while (const std::optional event = this->renderWindow->pollEvent()) {
|
||||||
if (event->is<sf::Event::Closed>()) {
|
if (event->is<sf::Event::Closed>()) {
|
||||||
quit = true;
|
quit = true;
|
||||||
}
|
}
|
||||||
@@ -34,16 +34,16 @@ void GraphApp::run() {
|
|||||||
if (!quit) {
|
if (!quit) {
|
||||||
if (clock.getElapsedTime().asMilliseconds() > timeAtNextFrame) {
|
if (clock.getElapsedTime().asMilliseconds() > timeAtNextFrame) {
|
||||||
timeAtNextFrame += TIME_BETWEEN_FRAMES;
|
timeAtNextFrame += TIME_BETWEEN_FRAMES;
|
||||||
this->menuStack->top().computeFrame();
|
this->menuStack->top()->computeFrame();
|
||||||
|
|
||||||
if (this->menuStack->empty()) {
|
if (this->menuStack->empty()) {
|
||||||
quit = true;
|
quit = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->menuStack->top().drawFrame();
|
this->menuStack->top()->drawFrame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window->close();
|
renderWindow->close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
class GraphApp {
|
class GraphApp {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Settings> settings;
|
std::shared_ptr<Settings> settings;
|
||||||
std::shared_ptr<std::stack<AppMenu>> menuStack;
|
std::shared_ptr<MenuStack> menuStack;
|
||||||
std::shared_ptr<sf::RenderWindow> window;
|
std::shared_ptr<sf::RenderWindow> renderWindow;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GraphApp();
|
GraphApp();
|
||||||
|
|||||||
81
src/GraphicalUI/Keybinds.cpp
Normal file
81
src/GraphicalUI/Keybinds.cpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#include "Keybinds.h"
|
||||||
|
|
||||||
|
#include "../Core/Action.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <fstream>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
Keybinds::Keybinds(int layoutNumber) :
|
||||||
|
layoutNumber(layoutNumber) {
|
||||||
|
|
||||||
|
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||||
|
this->keybinds.insert({action, std::set<sfKey>()});
|
||||||
|
}
|
||||||
|
|
||||||
|
this->loadKeybindsFromFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Keybinds::loadKeybindsFromFile() {
|
||||||
|
std::ifstream layoutFile("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin", std::ios::binary);
|
||||||
|
|
||||||
|
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||||
|
this->keybinds.at(action).clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
char byte;
|
||||||
|
while (layoutFile.get(&byte, 1)) {
|
||||||
|
Action action = Action(byte);
|
||||||
|
|
||||||
|
do {
|
||||||
|
layoutFile.get(&byte, 1);
|
||||||
|
if (byte != 0xFF) {
|
||||||
|
this->keybinds.at(action).insert(sfKey(byte));
|
||||||
|
}
|
||||||
|
} while (byte != 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Keybinds::saveKeybindsToFile() const {
|
||||||
|
std::ofstream layoutFile("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin", std::ios::trunc | std::ios::binary);
|
||||||
|
|
||||||
|
char byte;
|
||||||
|
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||||
|
byte = action;
|
||||||
|
layoutFile.write(&byte, 1);
|
||||||
|
|
||||||
|
for (sfKey key : this->keybinds.at(action)) {
|
||||||
|
byte = (int) key;
|
||||||
|
layoutFile.write(&byte, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte = 0xFF;
|
||||||
|
layoutFile.write(&byte, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Keybinds::addKey(Action action, sfKey key) {
|
||||||
|
this->keybinds.at(action).insert(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Keybinds::clearKeys(Action action) {
|
||||||
|
this->keybinds.at(action).clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::set<Action> Keybinds::getActions(sfKey key) const {
|
||||||
|
std::set<Action> actions;
|
||||||
|
|
||||||
|
for (const auto& [action, keys] : this->keybinds) {
|
||||||
|
if (keys.contains(key)) {
|
||||||
|
actions.insert(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::set<sfKey>& Keybinds::getKeybinds(Action action) const {
|
||||||
|
return this->keybinds.at(action);
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "../Core/Action.h"
|
#include "../Core/Action.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <set>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
using sfKey = sf::Keyboard::Key;
|
using sfKey = sf::Keyboard::Key;
|
||||||
@@ -14,7 +14,7 @@ static const int CUSTOMIZABLE_KEYBINDS = NUMBER_OF_KEYBINDS - 1;
|
|||||||
|
|
||||||
class Keybinds {
|
class Keybinds {
|
||||||
private:
|
private:
|
||||||
std::map<Action, std::vector<sfKey>> keybinds;
|
std::map<Action, std::set<sfKey>> keybinds;
|
||||||
int layoutNumber;
|
int layoutNumber;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -28,7 +28,7 @@ class Keybinds {
|
|||||||
|
|
||||||
void clearKeys(Action action);
|
void clearKeys(Action action);
|
||||||
|
|
||||||
const std::vector<Action>& getActions(sfKey key) const;
|
const std::set<Action> getActions(sfKey key) const;
|
||||||
|
|
||||||
const std::vector<sfKey>& getKeybinds(Action action) const;
|
const std::set<sfKey>& getKeybinds(Action action) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
static const int MAXIMUM_BOARD_WIDTH = 40;
|
static const int MAXIMUM_BOARD_WIDTH = 40;
|
||||||
static const int MAXIMUM_BOARD_HEIGHT = 40;
|
static const int MAXIMUM_BOARD_HEIGHT = 40;
|
||||||
|
|
||||||
|
static const int MAXIMUM_PIECES_SIZE = 10;
|
||||||
|
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -137,17 +137,17 @@ void resetKeybindFile(int layout) {
|
|||||||
keybinds.insert({HOLD, sfKey::Z});
|
keybinds.insert({HOLD, sfKey::Z});
|
||||||
}
|
}
|
||||||
|
|
||||||
char contentChar;
|
char byte;
|
||||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||||
contentChar = action;
|
byte = action;
|
||||||
layoutFile.write(&contentChar, 1);
|
layoutFile.write(&byte, 1);
|
||||||
|
|
||||||
if (keybinds.contains(action)) {
|
if (keybinds.contains(action)) {
|
||||||
contentChar = (int) keybinds.at(action);
|
byte = (int) keybinds.at(action);
|
||||||
layoutFile.write(&contentChar, 1);
|
layoutFile.write(&byte, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
contentChar = 0xFF;
|
byte = 0xFF;
|
||||||
layoutFile.write(&contentChar, 1);
|
layoutFile.write(&byte, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user