keybinds menu
This commit is contained in:
87
src/GraphicalUI/AppMenus/SettingsKeybindsAppMenu.cpp
Normal file
87
src/GraphicalUI/AppMenus/SettingsKeybindsAppMenu.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "SettingsKeybindsAppMenu.h"
|
||||
|
||||
#include "AppMenu.h"
|
||||
#include "../PlayerCursor.h"
|
||||
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <regex>
|
||||
#include <filesystem>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
||||
SettingsKeybindsAppMenu::SettingsKeybindsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||
AppMenu(menuStack, settings, renderWindow),
|
||||
playerCursor(std::vector<unsigned int>(12, 1)) {
|
||||
|
||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||
std::string textureName = ACTION_NAMES[action];
|
||||
textureName = std::regex_replace(textureName, std::regex(" "), "");
|
||||
|
||||
std::filesystem::path texturePath("data/images/keybinds/" + textureName + ".png");
|
||||
this->iconTextures[action] = sf::Texture(texturePath, false, {{0, 0}, {16, 16}});
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsKeybindsAppMenu::computeFrame() {
|
||||
this->updateMetaBinds();
|
||||
this->playerCursor.updatePosition();
|
||||
|
||||
if (this->playerCursor.movedLeft()) {
|
||||
this->settings->selectPreviousKeybinds();
|
||||
}
|
||||
if (this->playerCursor.movedRight()) {
|
||||
this->settings->selectNextKeybinds();
|
||||
}
|
||||
|
||||
if (this->enterReleased) {
|
||||
//TODO
|
||||
}
|
||||
if (this->escReleased) {
|
||||
this->menuStack->pop();
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsKeybindsAppMenu::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, std::optional<PlayerCursor>(), "KEYBINDS SETTINGS", 5.f, std::optional<sf::Vector2u>());
|
||||
|
||||
if (this->settings->getKeybindsLayout() == CUSTOMIZABLE_KEYBINDS) {
|
||||
this->placeText(text, this->playerCursor, "< CUSTOM >", 5.f, 15.f, {0, 0});
|
||||
}
|
||||
else {
|
||||
this->placeText(text, this->playerCursor, "< DEFAULT " + std::to_string(this->settings->getKeybindsLayout() + 1) + " >", 5.f, 15.f, {0, 0});
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int firstElem = (this->playerCursor.getPosition().y == 0) ? (unsigned int) 0 : (this->playerCursor.getPosition().y - 1);
|
||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||
if (i >= firstElem && i < (firstElem + 3)) {
|
||||
sf::String string;
|
||||
for (sfKey key : this->settings->getKeybinds().getKeybinds(action)) {
|
||||
auto keyString = getKeyStringRepresentation(key);
|
||||
if (keyString.has_value()) {
|
||||
string += keyString.value() + " ";
|
||||
}
|
||||
}
|
||||
this->placeText(text, this->playerCursor, setStringToUpperCase(ACTION_NAMES[action]), 20.f, ((i - firstElem) * 10) + 25.f, {0, (unsigned int) i + 1});
|
||||
this->placeText(text, this->playerCursor, string, 50.f, ((i - firstElem) * 10) + 25.f, {0, (unsigned int) i + 1});
|
||||
|
||||
sf::Sprite sprite(this->iconTextures[action]);
|
||||
sprite.setOrigin(sprite.getLocalBounds().getCenter());
|
||||
sprite.setPosition(sf::Vector2f(10.f, ((i - firstElem) * 10) + 25.f) * (float) this->settings->getWindowSizeMultiplier());
|
||||
sprite.setScale(sprite.getScale() * ((float) this->settings->getWindowSizeMultiplier() / 2));
|
||||
this->renderWindow->draw(sprite);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
this->renderWindow->display();
|
||||
}
|
||||
Reference in New Issue
Block a user