From 36657affc6b334919a144d460904c28cb71431b8 Mon Sep 17 00:00:00 2001 From: Bluub Date: Thu, 3 Jun 2021 11:07:01 +0200 Subject: [PATCH 01/36] menu controllable system and buttonComponent --- sources/Component/Button/ButtonComponent.cpp | 25 +++++++++++ sources/Component/Button/ButtonComponent.hpp | 41 +++++++++++++++++ .../MenuControllableSystem.cpp | 44 +++++++++++++++++++ .../MenuControllableSystem.hpp | 30 +++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 sources/Component/Button/ButtonComponent.cpp create mode 100644 sources/Component/Button/ButtonComponent.hpp create mode 100644 sources/System/MenuControllable/MenuControllableSystem.cpp create mode 100644 sources/System/MenuControllable/MenuControllableSystem.hpp diff --git a/sources/Component/Button/ButtonComponent.cpp b/sources/Component/Button/ButtonComponent.cpp new file mode 100644 index 000000000..e08be4e6d --- /dev/null +++ b/sources/Component/Button/ButtonComponent.cpp @@ -0,0 +1,25 @@ +// +// Created by Louis Auzuret on 06/03/21. +// + +#include "ButtonComponent.hpp" + +namespace BBM +{ + ButtonComponent::ButtonComponent(WAL::Entity &entity) + : WAL::Component(entity), onIdle(), onHover(), onClick() + { } + + WAL::Component *ButtonComponent::clone(WAL::Entity &entity) const + { + return new ButtonComponent(entity, onIdle, onHover, onClick); + } + + ButtonComponent::ButtonComponent(WAL::Entity &entity, WAL::Callback<> idleCallback, + WAL::Callback<> hoverCallback, WAL::Callback<> clickCallback) + : WAL::Component(entity), + onIdle(idleCallback), + onHover(hoverCallback), + onClick(clickCallback) + { } +} \ No newline at end of file diff --git a/sources/Component/Button/ButtonComponent.hpp b/sources/Component/Button/ButtonComponent.hpp new file mode 100644 index 000000000..9fdc29c6e --- /dev/null +++ b/sources/Component/Button/ButtonComponent.hpp @@ -0,0 +1,41 @@ +// +// Created by Louis Auzuret on 06/03/21 +// + +#pragma once + +#include "Models/Callback.hpp" +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" + +namespace BBM +{ + class ButtonComponent : public WAL::Component + { + public: + //! @brief onIdle callback + WAL::Callback<> onIdle; + + //! @brief onHover callback + WAL::Callback<> onHover; + + //! @brief onClick callback + WAL::Callback<> onClick; + + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Initialize a new Button component. + explicit ButtonComponent(WAL::Entity &entity); + + //! @brief Constructor with the 3 callback + ButtonComponent(WAL::Entity &entity, WAL::Callback<> idleCallback, WAL::Callback<> hoverCallback, WAL::Callback<> clickCallback); + //! @brief A Controllable component is copy constructable. + ButtonComponent(const ButtonComponent &) = default; + //! @brief default destructor + ~ButtonComponent() override = default; + //! @brief A Button component default assign operator + ButtonComponent &operator=(const ButtonComponent &) = default; + }; +} \ No newline at end of file diff --git a/sources/System/MenuControllable/MenuControllableSystem.cpp b/sources/System/MenuControllable/MenuControllableSystem.cpp new file mode 100644 index 000000000..88ed6231f --- /dev/null +++ b/sources/System/MenuControllable/MenuControllableSystem.cpp @@ -0,0 +1,44 @@ +// +// Created by Louis Auzuret 06/03/21 +// + +#include +#include "Component/Position/PositionComponent.hpp" +#include "System/MenuControllable/MenuControllableSystem.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Entity/Entity.hpp" + +namespace BBM +{ + MenuControllableSystem::MenuControllableSystem() + : WAL::System({ + typeid(ControllableComponent) + }) + {} + + void MenuControllableSystem::onFixedUpdate(WAL::Entity &entity) + { + auto &controllable = entity.getComponent(); + auto buttons = ecs.view<