From 3a23e41255af0de3c5c7f5d9df981c8b205e291f Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 13 Dec 2024 17:42:34 +0100 Subject: add timer functionality to script --- src/crepe/api/Script.cpp | 2 ++ src/crepe/api/Script.h | 12 ++++++++++++ 2 files changed, 14 insertions(+) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp index 753a9e3..50edea0 100644 --- a/src/crepe/api/Script.cpp +++ b/src/crepe/api/Script.cpp @@ -25,3 +25,5 @@ void Script::set_next_scene(const string & name) { } SaveManager & Script::get_save_manager() const { return this->mediator->save_manager; } + +LoopTimerManager & Script::get_loop_timer() const { return this->mediator->loop_timer; } diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 668e5d1..3569b4a 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -2,6 +2,7 @@ #include +#include "../manager/LoopTimerManager.h" #include "../manager/EventManager.h" #include "../manager/Mediator.h" #include "../system/CollisionSystem.h" @@ -46,9 +47,17 @@ protected: /** * \brief Script update function (empty by default) * + * \param delta_time Time since last fixed update + * * This function is called during the ScriptSystem::update() routine if the \c BehaviorScript * component holding this script instance is active. */ + virtual void update(duration_t delta_time) { return this->update(); } + /** + * \brief Fallback script update function (empty by default) + * + * Allows the game programmer to ignore parameters passed to \c update() + */ virtual void update() {} //! \} @@ -135,6 +144,9 @@ protected: //! Retrieve SaveManager reference SaveManager & get_save_manager() const; + //! Retrieve LoopTimerManager reference + LoopTimerManager & get_loop_timer() const; + //! \} private: -- cgit v1.2.3 From ae80ecde90ea6ab3305deed899bbec1560b93a6f Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 13 Dec 2024 18:05:56 +0100 Subject: `make format` --- src/crepe/api/Script.h | 2 +- src/test/ScriptTest.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 3569b4a..1429108 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -2,8 +2,8 @@ #include -#include "../manager/LoopTimerManager.h" #include "../manager/EventManager.h" +#include "../manager/LoopTimerManager.h" #include "../manager/Mediator.h" #include "../system/CollisionSystem.h" #include "../types.h" diff --git a/src/test/ScriptTest.cpp b/src/test/ScriptTest.cpp index 2aee0fd..499be5a 100644 --- a/src/test/ScriptTest.cpp +++ b/src/test/ScriptTest.cpp @@ -85,4 +85,3 @@ TEST_F(ScriptTest, LoopTimerManager) { EXPECT_EQ(&script.get_loop_timer(), &this->loop_timer); } - -- cgit v1.2.3 From c4c896c2995f2b74fca322736aa944b28b14a1f6 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Tue, 17 Dec 2024 09:29:47 +0100 Subject: start --- src/crepe/api/Button.h | 12 +++++++++++- src/crepe/api/Event.h | 9 --------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h index 08f5dec..e97f884 100644 --- a/src/crepe/api/Button.h +++ b/src/crepe/api/Button.h @@ -3,9 +3,19 @@ #include #include "UIObject.h" - +#include "Event.h" +#include "Metadata.h" namespace crepe { +/** + * \brief Event triggered when a button is pressed + * + */ +class ButtonPressEvent : public Event{ + public: + + +} //! Represents a clickable UI button, derived from the UiObject class. class Button : public UIObject { public: diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h index 73bf461..b0dd931 100644 --- a/src/crepe/api/Event.h +++ b/src/crepe/api/Event.h @@ -94,15 +94,6 @@ public: float scroll_delta = 0; }; -/** - * \brief Event triggered when text is submitted, e.g., from a text input. - */ -class TextSubmitEvent : public Event { -public: - //! The submitted text. - std::string text = ""; -}; - /** * \brief Event triggered to indicate the application is shutting down. */ -- cgit v1.2.3 From eb9c76082d7d0ee0c3e55cb8eadfa5f8978bd8f2 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Tue, 17 Dec 2024 20:12:30 +0100 Subject: button improvements --- src/crepe/api/Button.cpp | 6 ++-- src/crepe/api/Button.h | 50 ++++++++-------------------------- src/crepe/api/Event.h | 3 +- src/crepe/system/InputSystem.cpp | 26 +++++++++--------- src/crepe/system/InputSystem.h | 22 +++++++++++++++ src/test/InputTest.cpp | 59 ++++++++++++++++++++++++++-------------- 6 files changed, 89 insertions(+), 77 deletions(-) (limited to 'src/crepe/api') diff --git a/src/crepe/api/Button.cpp b/src/crepe/api/Button.cpp index 305922c..40153c9 100644 --- a/src/crepe/api/Button.cpp +++ b/src/crepe/api/Button.cpp @@ -2,9 +2,7 @@ namespace crepe { -Button::Button(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, - const std::function & on_click) - : UIObject(id, dimensions, offset), - on_click(on_click) {} +Button::Button(game_object_id_t id, const vec2 & dimensions, const vec2 & offset) + : UIObject(id, dimensions, offset) {} } // namespace crepe diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h index e97f884..5d4156b 100644 --- a/src/crepe/api/Button.h +++ b/src/crepe/api/Button.h @@ -5,18 +5,21 @@ #include "UIObject.h" #include "Event.h" #include "Metadata.h" + namespace crepe { /** - * \brief Event triggered when a button is pressed + * \brief Button component. + * + * This component creates a clickable surface at the transform location with the specified width and height. + * + * The Button can be used in scripts by subscribing a EventHandler to the following events: + * - **ButtonPressEvent**: Triggered when the surface is clicked with the mouse. Contains GameObject metadata. + * - **MouseEnterEvent**: Triggered when the mouse enters the button area. Contains GameObject metadata. + * - **MouseExitEvent**: Triggered when the mouse leaves the button area. Contains GameObject metadata. + * \see EventManager * */ -class ButtonPressEvent : public Event{ - public: - - -} -//! Represents a clickable UI button, derived from the UiObject class. class Button : public UIObject { public: /** @@ -25,43 +28,14 @@ public: * \param id The unique ID of the game object associated with this button. * \param dimensions The width and height of the UIObject * \param offset The offset relative this GameObjects Transform - * \param on_click callback function that will be invoked when the button is clicked. */ - Button(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, - const std::function & on_click); - - // TODO: create separate toggle button class - /** - * \brief The callback function to be executed when the button is clicked. - * - * This function is invoked whenever the button is clicked. It can be set to any - * function that matches the signature `void()`. - */ - std::function on_click = nullptr; - - /** - * \brief Callback function to be executed when the mouse enters the button's boundaries. - * - * This function is triggered when the mouse cursor moves over the button, allowing - * custom actions like visual effects, highlighting, or sound effects. - */ - std::function on_mouse_enter = nullptr; - - /** - * \brief Callback function to be executed when the mouse exits the button's boundaries. - * - * This function is triggered when the mouse cursor moves out of the button's area, - * allowing custom actions like resetting visual effects or playing exit-related effects. - */ - std::function on_mouse_exit = nullptr; + Button(game_object_id_t id, const vec2 & dimensions, const vec2 & offset); private: - //! friend relation for is_pressed and hover variables + //! friend relation hover variable friend class InputSystem; //! Indicates whether the mouse is currently hovering over the button bool hover = false; - -public: }; } // namespace crepe diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h index b0dd931..a03bb54 100644 --- a/src/crepe/api/Event.h +++ b/src/crepe/api/Event.h @@ -3,9 +3,10 @@ #include -#include "api/KeyCodes.h" #include "types.h" +#include "api/KeyCodes.h" + namespace crepe { /** diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index fca540f..5d1537d 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -155,28 +155,27 @@ 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