diff options
Diffstat (limited to 'src/crepe/system')
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 52 | ||||
-rw-r--r-- | src/crepe/system/InputSystem.h | 8 |
2 files changed, 58 insertions, 2 deletions
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index e69de29..b7a86f4 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -0,0 +1,52 @@ +#include "ComponentManager.h" +#include "../api/Button.h" +#include "../api/EventManager.h" +#include "../api/Transform.h" +#include "../api/Event.h" + +#include "system/InputSystem.h" + +using namespace crepe; + +InputSystem::InputSystem(ComponentManager &component_manager) + : System(component_manager) { + auto &event_manager = EventManager::get_instance(); + + event_manager.subscribe<MouseClickEvent>([this](const MouseClickEvent &event) { + return this->handle_click(event); + }); + + event_manager.subscribe<MouseMoveEvent>([this](const MouseMoveEvent &event) { + return this->handle_move(event); + }); +} + +void InputSystem::update() { +} + +bool InputSystem::handle_click(const MouseClickEvent &event) { + ComponentManager &mgr = this->component_manager; + + std::vector<std::reference_wrapper<Button>> buttons = + mgr.get_components_by_type<Button>(); + + std::vector<std::reference_wrapper<Transform>> transforms = + mgr.get_components_by_type<Transform>(); + for (Button &button : buttons) { + for(Transform& transform : transforms){ + if(button.game_object_id != transform.game_object_id){continue;} + if (!button.interactable) {break;} + if (event.mouse_x >= transform.position.x && event.mouse_x <= transform.position.x + button.width && + event.mouse_y >= transform.position.y && event.mouse_y <= transform.position.y + button.height) { + button.on_click(); + } + } + } + return false; +} + +bool InputSystem::handle_move(const MouseMoveEvent &event) { + + ComponentManager &mgr = this->component_manager; + +} diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h index 642035f..c50d928 100644 --- a/src/crepe/system/InputSystem.h +++ b/src/crepe/system/InputSystem.h @@ -1,14 +1,18 @@ #pragma once #include "System.h" - +#include "../api/Event.h" namespace crepe { class InputSystem : public System { public: using System::System; + InputSystem(ComponentManager & component_manager); void update() override; - void + bool handle_click(const MouseClickEvent &event); + bool handle_move(const MouseMoveEvent &event); + bool handle_key_press(const KeyPressEvent &event); + bool handle_key_release(const KeyReleaseEvent &event); }; } // namespace crepe |