diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-19 09:17:46 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-19 09:17:46 +0100 |
commit | 226e01dcd77821d1fccdf42074606ce80528637e (patch) | |
tree | 7277669f47bc27d2017a808f3145e1ad24c5d365 /src/crepe/system/InputSystem.cpp | |
parent | 01e77b907cb02ea8a161f620664feb3b16ccb697 (diff) | |
parent | 8eb67c614b70da6e6767ccf543d64000ea468f79 (diff) |
Merge branch 'loek/replay' into loek/scriptsloek/scripts
Diffstat (limited to 'src/crepe/system/InputSystem.cpp')
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 58720dd..d209282 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -10,10 +10,8 @@ using namespace crepe; void InputSystem::fixed_update() { ComponentManager & mgr = this->mediator.component_manager; - SDLContext & context = this->mediator.sdl_context; std::vector<EventData> event_list = context.get_events(); - RefVector<Button> buttons = mgr.get_components_by_type<Button>(); RefVector<Camera> cameras = mgr.get_components_by_type<Camera>(); OptionalRef<Camera> curr_cam_ref; @@ -155,28 +153,25 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_pos) { ComponentManager & mgr = this->mediator.component_manager; - + EventManager & event_mgr = this->mediator.event_manager; RefVector<Button> buttons = mgr.get_components_by_type<Button>(); for (Button & button : buttons) { if (!button.active) continue; - RefVector<Transform> transform_vec - = mgr.get_components_by_id<Transform>(button.game_object_id); - Transform & transform(transform_vec.front().get()); - + Metadata & metadata + = mgr.get_components_by_id<Metadata>(button.game_object_id).front(); + Transform & transform + = mgr.get_components_by_id<Transform>(button.game_object_id).front(); bool was_hovering = button.hover; if (this->is_mouse_inside_button(mouse_pos, button, transform)) { button.hover = true; - if (!button.on_mouse_enter) continue; if (!was_hovering) { - button.on_mouse_enter(); + event_mgr.trigger_event<ButtonEnterEvent>(metadata); } } else { button.hover = false; - // Trigger the on_exit callback if the hover state just changed to false - if (!button.on_mouse_exit) continue; if (was_hovering) { - button.on_mouse_exit(); + event_mgr.trigger_event<ButtonExitEvent>(metadata); } } } @@ -184,19 +179,18 @@ void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_p void InputSystem::handle_click(const MouseButton & mouse_button, const vec2 & mouse_pos) { ComponentManager & mgr = this->mediator.component_manager; - + EventManager & event_mgr = this->mediator.event_manager; RefVector<Button> buttons = mgr.get_components_by_type<Button>(); for (Button & button : buttons) { if (!button.active) continue; - if (!button.on_click) continue; - RefVector<Transform> transform_vec - = mgr.get_components_by_id<Transform>(button.game_object_id); - Transform & transform = transform_vec.front().get(); + Metadata & metadata + = mgr.get_components_by_id<Metadata>(button.game_object_id).front(); + Transform & transform + = mgr.get_components_by_id<Transform>(button.game_object_id).front(); if (this->is_mouse_inside_button(mouse_pos, button, transform)) { - - button.on_click(); + event_mgr.trigger_event<ButtonPressEvent>(metadata); } } } |