Commit 5814ac6b authored by Ушкова Диана Петровна's avatar Ушкова Диана Петровна
Browse files

this version doesn't work

1 merge request!1created menu
Showing with 31 additions and 16 deletions
+31 -16
......@@ -18,6 +18,7 @@ add_executable(pacman source/main.cpp
source/application/Drawable/Menu/menu.cpp)
target_link_libraries(pacman PRIVATE sfml-window sfml-graphics sfml-system)
target_compile_definitions(pacman PRIVATE ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/")
#target_include_directories(pacman PUBLIC
# ${CMAKE_SOURCE_DIR}/source/application
# ${CMAKE_SOURCE_DIR}/source/application/Event
......
......@@ -7,9 +7,10 @@ namespace config {
// Меню:
const sf::Vector2f BUTTON_SIZE = { 250, 100 };
const size_t BUTTON_FONT_SIZE = static_cast<size_t>(BUTTON_SIZE.y / 1.5f); const float BUTTON_FRAME_THICKNESS = 2.0f;
const char FONT_FILE[] = "Calibri-Light.ttf";
const char FONT_FILE[] = "Calibri.ttf";
const char SELECT_LEVEL_TITLE[] = "Select Level";
const sf::VideoMode SELECT_LEVEL_VIDEO_MODE{ 400, 600 };
const std::vector<std::string> BUTTON_TEXT = {"Easy","Medium", "Hard", "Exit"};
const char BUTTON_TEXT_EASY[] = "Easy";
const char BUTTON_TEXT_MEDIUM[] = "Medium";
const char BUTTON_TEXT_HARD[] = "Hard";
......
#include "button.h"
#include "config.h"
#include "../../../../config/config.h"
#include "../Font/font.h"
void Button::set(sf::Vector2f pos, sf::Vector2f button_size,
......@@ -13,7 +13,7 @@ void Button::set(sf::Vector2f pos, sf::Vector2f button_size,
m_text = sf::Text(text, MyFont::Instance(), font_size);
m_text.setFillColor(config::BUTTON_COLOR_TEXT);
m_text.setPosition(pos);
// m_ptr_command = std::move(ptr_command);
m_ptr_command = std::move(ptr_command);
}
void Button::select() {
......
#include "menu.h"
#include "config.h"
//#include "Select Command/ISelectCommand.h"
#include "../../../../config/config.h"
#include <memory>
Menu::Menu(IStateManager& state_manager) {
for (Button& ptr_button : m_buttons) {
ptr_button.set(sf::Vector2f(100, 120),
size_t button_number = &ptr_button - &m_buttons[0];
ptr_button.set(sf::Vector2f(100, 120 + button_number*120),
config::BUTTON_SIZE,
config::BUTTON_TEXT_EASY,
config::BUTTON_TEXT[button_number],
config::BUTTON_FONT_SIZE,
std::make_unique<ExitCommand>(state_manager));
}
}
void Menu::draw_into(sf::RenderWindow &window) const {
for (const Button& ptr_button : m_buttons)
ptr_button.draw_into(window);
}
void Menu::process_mouse(const sf::Vector2f pos, bool is_pressed) {
for (Button& ptr_button : m_buttons) {
if (ptr_button.is_position_in(pos)) {
ptr_button.select();
if (is_pressed) ptr_button.push();
}
else ptr_button.unselect();
}
}
\ No newline at end of file
#include "IState.h"
#include "config.h"
#include "../../../config/config.h"
#include <iostream>
......@@ -11,25 +11,22 @@ SelectState::SelectState(IStateManager& state_manager,
void SelectState::event_handling() {
sf::Event event;
while (m_window.pollEvent(event)) {
if (sf::Event::Closed) {
m_state_manager.set_next_state(std::make_unique<ExitState>(m_state_manager));
break;
}
if (event.type == sf::Event::Closed) { m_window.close();}
}
}
void SelectState::update() {
const sf::Vector2f pos = m_window.mapPixelToCoords(sf::Mouse::getPosition(m_window));
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
m_menu.process_mouse(true, pos);
m_menu.process_mouse(pos, true);
return;
}
m_menu.process_mouse(false, pos);
m_menu.process_mouse(pos, false);
}
void SelectState::render() {
m_window.clear(config::SELECT_LEVEL_BACKGROUND_COLOR);
m_menu.draw_into(m_window);
m_window.display();
}
......
......@@ -26,6 +26,10 @@ private:
struct GameState: IState, IWindowKeeper {
GameState(IStateManager& state_manager, const sf::VideoMode& video_mode, const std::string& window_title);
void event_handling() override;
void update() override;
void render() override;
bool do_step() override;
};
struct ExitState: IState {
......
#include "app.h"
#include "config.h"
#include "../../../config/config.h"
Application::Application() : m_ptr_state_current(std::make_unique<SelectState>(
*this,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment