aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-19 15:16:16 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-19 15:16:16 +0100
commit6c2fc3716c9c6c68e982b243af5f7ed04fb35e86 (patch)
treec5a20a8a5352edc19cca1d6ddcbf7869db6e1055 /src/crepe/system
parent60cbc3d649775053ac1d333716c9f5fda651a643 (diff)
button handling
Diffstat (limited to 'src/crepe/system')
-rw-r--r--src/crepe/system/InputSystem.cpp52
-rw-r--r--src/crepe/system/InputSystem.h8
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