-
Ушкова Диана Петровна authored0533a46d
#include "Menu.h"
#include "../../../../../workdir/config.h"
#include "../../../BobBuilder/GameBuilders.h"
#include <memory>
Menu::Menu(IStateManager& state_manager) {
float delta = 20;
sf::Vector2f starting_position(80,5);
auto easy_director = std::make_unique<GameBuilderDirector>(
std::make_unique<SimpleBuilder>(
config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
config::ROOM_SIZE),
config::GAME_VIDEO_MODE,
config::EASY_GAME_TITLE,
config::EASY_GAME_ENEMY_RATIO);
auto medium_director = std::make_unique<GameBuilderDirector>(
std::make_unique<SimpleBuilder>(
config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
config::ROOM_SIZE),
config::GAME_VIDEO_MODE,
config::MEDIUM_GAME_TITLE,
config::MEDIUM_GAME_ENEMY_RATIO);
auto hard_director = std::make_unique<GameBuilderDirector>(
std::make_unique<SimpleBuilder>(
config::GAME_VIDEO_MODE.width, config::GAME_VIDEO_MODE.height,
config::ROOM_SIZE),
config::GAME_VIDEO_MODE,
config::HARD_GAME_TITLE,
config::HARD_GAME_ENEMY_RATIO);
auto easy_command = std::make_unique<GameCommand>(state_manager, std::move(easy_director));
auto medium_command = std::make_unique<GameCommand>(state_manager, std::move(medium_director));
auto hard_command = std::make_unique<GameCommand>(state_manager, std::move(hard_director));
auto exit_command = std::make_unique<ExitCommand>(state_manager);
m_buttons.emplace_back(std::make_unique<Button>(sf::Vector2f{starting_position.x, starting_position.y + 1 * config::BUTTON_SIZE.y + 0 * delta}, config::BUTTON_SIZE, config::BUTTON_TEXT_EASY, config::BUTTON_FONT_SIZE , std::move(easy_command)));
m_buttons.emplace_back(std::make_unique<Button>(sf::Vector2f{starting_position.x, starting_position.y + 2 * config::BUTTON_SIZE.y + 1 * delta}, config::BUTTON_SIZE, config::BUTTON_TEXT_MEDIUM, config::BUTTON_FONT_SIZE , std::move(medium_command)));
m_buttons.emplace_back(std::make_unique<Button>(sf::Vector2f{starting_position.x, starting_position.y + 3 * config::BUTTON_SIZE.y + 2 * delta}, config::BUTTON_SIZE, config::BUTTON_TEXT_HARD, config::BUTTON_FONT_SIZE , std::move(hard_command)));
m_buttons.emplace_back(std::make_unique<Button>(sf::Vector2f{starting_position.x, starting_position.y + 4 * config::BUTTON_SIZE.y + 3 * delta}, config::BUTTON_SIZE, config::BUTTON_TEXT_EXIT, config::BUTTON_FONT_SIZE, std::move(exit_command)));
}
void Menu::draw_into(sf::RenderWindow &window) const {
//@todo change to const Button&
for (auto& ptr_button : m_buttons)
ptr_button->draw_into(window);
}
void Menu::process_mouse(const sf::Vector2f pos, bool is_pressed) {
for (auto& ptr_button : m_buttons) {
if (ptr_button->is_position_in(pos)) {
ptr_button->select();
if (is_pressed) ptr_button->push();
}
else ptr_button->unselect();
}
}