diff --git a/CMakeLists.txt b/CMakeLists.txt index 2709236975184ba86e411bccdfb061012e982a80..9a293afd0bd55aa31c8bd58e159a717a8233ccb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,11 @@ FetchContent_MakeAvailable(sfml) add_executable(pac-man "source/main.cpp" "source/Application.cpp" - "source/State/SelectState.cpp") + "source/State/SelectState.cpp" + "source/Drawable/Menu.cpp" + "source/Drawable/Button.cpp" + +) target_include_directories(pac-man PUBLIC include/) target_link_libraries(pac-man PUBLIC sfml-window sfml-graphics sfml-system) \ No newline at end of file diff --git a/include/Application.h b/include/Application.h index 9abda4a0837bc1b7f9a323c69072b71db0cb46d6..28bbb9395a773eaaab4b6c2731c6dd383a38db73 100644 --- a/include/Application.h +++ b/include/Application.h @@ -10,6 +10,6 @@ private: std::unique_ptr<IState> m_ptr_state_next; std::unique_ptr<IState> m_ptr_state_current; public: - Application(); + Application(); ///@todo int run(); }; \ No newline at end of file diff --git a/include/Drawable/Button.h b/include/Drawable/Button.h index c9cdfc836f34c7d2c2e6b75731d0ed2d7b723f09..03a3a2c9ad47d6f240f10b0f7ab582a849177588 100644 --- a/include/Drawable/Button.h +++ b/include/Drawable/Button.h @@ -1,18 +1,20 @@ #pragma once #include "IDrawable.h" +#include "ISelectCommand.h" class Button: public IDrawable { public: - void set(); - void select(); - void unselect(); - bool is_selected(); - void is_position_in(sf::Vector2f pos); - void push(); - void draw_into(sf::RenderWindow& window) const override; + void set(); ///@todo + void select(); ///@todo + void unselect(); ///@todo + bool is_selected(); ///@todo + void is_position_in(sf::Vector2f pos); ///@todo + void push() const; + void draw_into(sf::RenderWindow& window) const override; ///@todo private: sf::Text m_text; bool m_is_selected = false; sf::RectangleShape m_rectangle; + std::unique_ptr<ISelectCommand> m_ptr_command; }; \ No newline at end of file diff --git a/include/Drawable/Menu.h b/include/Drawable/Menu.h index 87912b6f2a19d794887abb696776311f8bd74525..f49e17df380b394508c137e1022cfe55b4895245 100644 --- a/include/Drawable/Menu.h +++ b/include/Drawable/Menu.h @@ -1,11 +1,14 @@ #pragma once -#include "IDrawable.h" +#include "Button.h" #include "States/IState.h" class Menu: public IDrawable { public: - void process_mouse(sf::Vector2f pos, bool is_pressed); + void draw_into(sf::RenderWindow& window) const override; + void process_mouse(sf::Vector2f pos, bool is_pressed); ///@todo public: - Menu(IStateManager& state_manager); + Menu(IStateManager& state_manager); ///@todo +private: + std::array<Button, 4> m_buttons; }; \ No newline at end of file diff --git a/include/ISelectCommand.h b/include/ISelectCommand.h index 3f59c932d39b02caf58f2abac65bdd9246f0a7da..ae9204f1d084f9cabb23c9c5136086974656e96f 100644 --- a/include/ISelectCommand.h +++ b/include/ISelectCommand.h @@ -1,2 +1,7 @@ #pragma once +class ISelectCommand { +public: + virtual void execute() = 0; + virtual ~ISelectCommand() = default; +}; \ No newline at end of file diff --git a/include/IWindowKeeper.h b/include/IWindowKeeper.h index 1a2eb6b7799b3125a777f6ee95fe79d3b220d3bb..e79acd3bc587e231f70a27c1fbab354c65e4a87a 100644 --- a/include/IWindowKeeper.h +++ b/include/IWindowKeeper.h @@ -4,11 +4,11 @@ class IWindowKeeper { protected: - virtual void event_handling() = 0; - virtual void update() = 0; - virtual void render() = 0; + virtual void event_handling() = 0; ///@todo + virtual void update() = 0; ///@todo + virtual void render() = 0; ///@todo public: - IWindowKeeper(const sf::VideoMode& video_mode, const std::string& window_title); + IWindowKeeper(const sf::VideoMode& video_mode, const std::string& window_title); ///@todo protected: sf::RenderWindow m_window; }; \ No newline at end of file diff --git a/include/States/SelectState.h b/include/States/SelectState.h index 38d3cf5f2bea3cd4580db58493aaae94fb43b895..40bea801dcafecf1a4efc08d39813fd8e6879d31 100644 --- a/include/States/SelectState.h +++ b/include/States/SelectState.h @@ -1,9 +1,13 @@ #pragma once -#include "States/IState.h" #include "IWindowKeeper.h" +#include "Drawable/Menu.h" class SelectState: public IState, public IWindowKeeper { public: + bool do_step() override; ///@todo SelectState(IStateManager& state_manager, const sf::VideoMode& video_mode, const std::string& window_title); +private: + Menu m_menu; + }; \ No newline at end of file diff --git a/source/Drawable/Button.cpp b/source/Drawable/Button.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fcf6a1bf778eef2eb02a02796df239481a775743 --- /dev/null +++ b/source/Drawable/Button.cpp @@ -0,0 +1,5 @@ +#include "Drawable/Button.h" + +void Button::push() const { + m_ptr_command->execute(); +} \ No newline at end of file diff --git a/source/Drawable/Menu.cpp b/source/Drawable/Menu.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f474d3977f1ecd505ba1f982eb787f465002305 --- /dev/null +++ b/source/Drawable/Menu.cpp @@ -0,0 +1,6 @@ +#include "Drawable/Menu.h" + +void Menu::draw_into(sf::RenderWindow& window) const { + for (const Button& ptr_button : m_buttons) + ptr_button.draw_into(window); +} diff --git a/source/State/SelectState.cpp b/source/State/SelectState.cpp index 2b15afc8ef1ce524718494400f0e65e790964e33..d0e20cbd82aae0a25478530505473cd57fb8ce34 100644 --- a/source/State/SelectState.cpp +++ b/source/State/SelectState.cpp @@ -1 +1,4 @@ -#include "States/SelectState.h" \ No newline at end of file +#include "States/SelectState.h" + +SelectState::SelectState(IStateManager& state_manager, const sf::VideoMode& video_mode, const std::string& window_title): + IWindowKeeper(video_mode, window_title), IState(state_manager), m_menu(state_manager) {} \ No newline at end of file