From 4643588f793ae1a3264bfbfecd74e991111ca275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=87=D0=B5=D0=BD=D0=B8=D0=BD=20=D0=94=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=D0=B0=20=D0=9C=D0=B8=D1=85=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= <dmpechenin@edu.hse.ru> Date: Mon, 24 Mar 2025 15:45:14 +0300 Subject: [PATCH] Bug with dark/light mode was fixed --- source/States/SelectState/Menu.cpp | 10 ++-- source/States/SelectState/Menu.h | 4 +- source/States/SelectState/SelectState.h | 3 +- source/Themes/ChangeThemeCommand.cpp | 67 ++----------------------- source/Themes/ChangeThemeCommand.h | 6 +-- 5 files changed, 15 insertions(+), 75 deletions(-) diff --git a/source/States/SelectState/Menu.cpp b/source/States/SelectState/Menu.cpp index 7a66288..f4680e9 100644 --- a/source/States/SelectState/Menu.cpp +++ b/source/States/SelectState/Menu.cpp @@ -4,7 +4,7 @@ #include <Themes/ChangeThemeCommand.h> #include <Themes/Themes.h> -Menu::Menu(IStateManager& state_manager) : m_state_manager(state_manager) { +Menu::Menu(IStateManager& state_manager, SelectState& select_state) { const float pos_left = (static_cast<float>(config::SELECT_LEVEL_VIDEO_MODE.width) - config::BUTTON_SIZE.x) / 2; const float pos_diff = (static_cast<float>(config::SELECT_LEVEL_VIDEO_MODE.height) - config::BUTTON_SIZE.y * 5 - config::BUTTON_CHANGE_THEME_SIZE.y) / 10; const float pos_top = (static_cast<float>(config::SELECT_LEVEL_VIDEO_MODE.height) - config::BUTTON_SIZE.y*5 - pos_diff*5 - config::BUTTON_CHANGE_THEME_SIZE.y) / 2; @@ -22,7 +22,7 @@ Menu::Menu(IStateManager& state_manager) : m_state_manager(state_manager) { config::EASY_GAME_ENEMY_RATIO)); auto medium_level_command = std::make_unique<GameCommand>( - m_state_manager, + state_manager, std::make_unique<GameBuilderDirector>( std::make_unique<SimpleBuilder>(width, height, config::ROOM_SIZE, room_color, config::ENEMY_SPEED_MEDIEUM), config::GAME_VIDEO_MODE, @@ -30,7 +30,7 @@ Menu::Menu(IStateManager& state_manager) : m_state_manager(state_manager) { config::MEDIUM_GAME_ENEMY_RATIO)); auto hard_level_command = std::make_unique<GameCommand>( - m_state_manager, + state_manager, std::make_unique<GameBuilderDirector>( std::make_unique<ComplexBuilder>(width, height, config::ROOM_SIZE, room_color, config::ENEMY_SPEED_HARD), config::GAME_VIDEO_MODE, @@ -38,14 +38,14 @@ Menu::Menu(IStateManager& state_manager) : m_state_manager(state_manager) { config::HARD_GAME_ENEMY_RATIO)); auto extreme_level_command = std::make_unique<GameCommand>( - m_state_manager, + state_manager, std::make_unique<GameBuilderDirector>( std::make_unique<ComplexRandomBuilder>(width, height, config::ROOM_SIZE, room_color, config::ENEMY_SPEED_EXTREME), config::GAME_VIDEO_MODE, config::EXTREME_GAME_TITLE, config::HARD_GAME_ENEMY_RATIO)); - auto change_theme_command = std::make_unique<ChangeThemeCommand>(*this); + auto change_theme_command = std::make_unique<ChangeThemeCommand>(select_state); m_buttons[0].set(sf::Vector2f{pos_left, pos_top}, config::BUTTON_SIZE, config::BUTTON_TEXT_EASY, config::BUTTON_FONT_SIZE, std::move(easy_level_command)); diff --git a/source/States/SelectState/Menu.h b/source/States/SelectState/Menu.h index f88825f..ce8e7a7 100644 --- a/source/States/SelectState/Menu.h +++ b/source/States/SelectState/Menu.h @@ -8,11 +8,9 @@ class SelectState; class Menu final : public IDrawable { public: - explicit Menu(IStateManager& state_manager); + explicit Menu(IStateManager& state_manager, SelectState& select_state); void process_mouse(sf::Vector2f pos, bool is_pressed); void draw_into(sf::RenderWindow& window) const override; - friend class ChangeThemeCommand; private: std::array<Button, 6> m_buttons; - IStateManager& m_state_manager; }; \ No newline at end of file diff --git a/source/States/SelectState/SelectState.h b/source/States/SelectState/SelectState.h index c2561ac..d566067 100644 --- a/source/States/SelectState/SelectState.h +++ b/source/States/SelectState/SelectState.h @@ -6,10 +6,11 @@ class SelectState final : public IState, public IWindowKeeper { public: explicit SelectState(IStateManager& state_manager, const sf::VideoMode& video_mode, const sf::String& window_title) : - IState(state_manager), IWindowKeeper(video_mode, window_title), m_menu(state_manager) { + IState(state_manager), IWindowKeeper(video_mode, window_title), m_menu(state_manager, *this) { m_window.setFramerateLimit(config::FRAME_RATE_LIMIT); } bool do_step() override; + friend class ChangeThemeCommand; private: void event_handling() override; void update() override; diff --git a/source/Themes/ChangeThemeCommand.cpp b/source/Themes/ChangeThemeCommand.cpp index 44670ba..1bbf748 100644 --- a/source/Themes/ChangeThemeCommand.cpp +++ b/source/Themes/ChangeThemeCommand.cpp @@ -1,70 +1,11 @@ #include "ChangeThemeCommand.h" #include "Themes.h" #include <States/ChangeStateCommand.h> +#include <thread> void ChangeThemeCommand::execute() { Themes::Instance().change_theme(); - - const auto width = config::GAME_VIDEO_MODE.width; - const auto height = config::GAME_VIDEO_MODE.height; - const auto room_color = Themes::Instance().get_game_color_room(); - - auto easy_level_command = std::make_unique<GameCommand>( - m_menu.m_state_manager, - std::make_unique<GameBuilderDirector>( - std::make_unique<SimpleBuilder>(width, height, config::ROOM_SIZE, room_color, 0), - config::GAME_VIDEO_MODE, - config::EASY_GAME_TITLE, - config::EASY_GAME_ENEMY_RATIO)); - - auto medium_level_command = std::make_unique<GameCommand>( - m_menu.m_state_manager, - std::make_unique<GameBuilderDirector>( - std::make_unique<SimpleBuilder>(width, height, config::ROOM_SIZE, room_color, config::ENEMY_SPEED_MEDIEUM), - config::GAME_VIDEO_MODE, - config::MEDIUM_GAME_TITLE, - config::MEDIUM_GAME_ENEMY_RATIO)); - - auto hard_level_command = std::make_unique<GameCommand>( - m_menu.m_state_manager, - std::make_unique<GameBuilderDirector>( - std::make_unique<ComplexBuilder>(width, height, config::ROOM_SIZE, room_color, config::ENEMY_SPEED_HARD), - config::GAME_VIDEO_MODE, - config::HARD_GAME_TITLE, - config::HARD_GAME_ENEMY_RATIO)); - - auto extreme_level_command = std::make_unique<GameCommand>( - m_menu.m_state_manager, - std::make_unique<GameBuilderDirector>( - std::make_unique<ComplexRandomBuilder>(width, height, config::ROOM_SIZE, room_color, config::ENEMY_SPEED_EXTREME), - config::GAME_VIDEO_MODE, - config::EXTREME_GAME_TITLE, - config::HARD_GAME_ENEMY_RATIO)); - - auto change_theme_command = std::make_unique<ChangeThemeCommand>(m_menu); - - m_menu.m_buttons[0].change_text_color(); - m_menu.m_buttons[0].change_button_color(); - m_menu.m_buttons[0].change_command(std::move(easy_level_command)); - - m_menu.m_buttons[1].change_text_color(); - m_menu.m_buttons[1].change_button_color(); - m_menu.m_buttons[1].change_command(std::move(medium_level_command)); - - m_menu.m_buttons[2].change_text_color(); - m_menu.m_buttons[2].change_button_color(); - m_menu.m_buttons[2].change_command(std::move(hard_level_command)); - - m_menu.m_buttons[3].change_text_color(); - m_menu.m_buttons[3].change_button_color(); - m_menu.m_buttons[3].change_command(std::move(extreme_level_command)); - - m_menu.m_buttons[4].change_text_color(); - m_menu.m_buttons[4].change_button_color(); - m_menu.m_buttons[4].change_command(std::make_unique<ExitCommand>(m_menu.m_state_manager)); - - m_menu.m_buttons[5].change_text_color(); - m_menu.m_buttons[5].change_button_color(); - m_menu.m_buttons[5].change_button_text(Themes::Instance().get_button_change_theme_text()); - m_menu.m_buttons[5].change_command(std::move(change_theme_command)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + m_select_state.m_menu = std::move(Menu{m_select_state.m_state_manager, m_select_state}); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } \ No newline at end of file diff --git a/source/Themes/ChangeThemeCommand.h b/source/Themes/ChangeThemeCommand.h index 80c96a2..91c504f 100644 --- a/source/Themes/ChangeThemeCommand.h +++ b/source/Themes/ChangeThemeCommand.h @@ -4,8 +4,8 @@ class ChangeThemeCommand final : public ISelectCommand { public: - explicit ChangeThemeCommand(Menu& menu) : m_menu(menu) {} + explicit ChangeThemeCommand(SelectState& select_state) : m_select_state(select_state) {} void execute() override; private: - Menu& m_menu; -}; + SelectState& m_select_state; +}; \ No newline at end of file -- GitLab