Brunot
Loading...
Searching...
No Matches
Button.h
Go to the documentation of this file.
1
10// ____ __ __ __
11// /\__ _\/\ \ /\ \/\ \
12// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
13// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
14// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
15// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
16// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
17
18
19#pragma once
20#include "Framework/Component.h"
21
26class Button : public Component
27{
28public:
29#pragma region static_functions
30
31#pragma endregion
32
33 Button();
34 Button(const Button&);
35 auto operator=(const Button&) -> Button& = default;
36 ~Button() override = default;
37 Button(Button&& other) noexcept;
38 auto operator=(Button&& other) noexcept -> Button& = default;
39
40#pragma region overriden_functions
41
42 auto clone() const -> std::unique_ptr<GameObject> override
43 {
44 return std::make_unique<Button>(*this);
45 }
46
47 auto componentShowMenu() -> void override;
48
49 auto onUpdate(float dt) -> void override;
50
51 auto endWindow() -> void override
52 {
53 } // for debug ImGUI
54 auto onRender() -> void override;
55 auto onEnterEngine() -> void override;
56 auto load(const Stream& stream) -> void override;
57 auto save(Stream& stream) const -> void override;
58
59 friend auto to_json(json& j, const Button& b) -> void;
60 friend auto from_json(const json& j, Button& b) -> void;
61
62 static constexpr auto DESIRED_BUTTON_SPEED = 500.f;
63
64#pragma endregion
65
66#pragma region Button_functions
67
69 auto select() -> void;
70
72 auto highlight() const -> void;
74 auto undoHighlight() const -> void;
76 auto setEvent(std::string newEvent) -> void;
78 auto setSelectLambda(std::string newSelect) -> void;
80 auto setHighlightLambda(std::string newHighlight) -> void;
82 auto setUndoHighlightLambda(std::string newUndoHighlight) -> void;
83
85 static auto checkIfAnyButtonHasBeenPressed() -> bool;
87 static auto setIfAnyButtonHasBeenPressed(bool newState) -> void;
88#pragma endregion
89
90#pragma region messaging_functions
91 auto linkMessages() -> void;
92
93#pragma endregion
94
95private:
96#pragma region member_variables
97
98
100 std::string buttonEvent;
102 std::string messageName;
104 std::unique_ptr<Message> messagePtr;
105
106
108
110 std::function<void(Entity* ent)> selectLambda;
112 std::function<void(Entity* ent)> highlightLambda;
114 std::function<void(Entity* ent)> undoHighlightLambda;
115
118
119#pragma endregion
120
121#pragma region helper_functions
122
123#pragma endregion
124
125#pragma region static_variables
126
127#pragma endregion
128
129};
sys::Json Stream
Definition AudioObject.h:20
The base class for components, holding all of their shared All components should inherit from this.
nlohmann::json json
Definition Json.cpp:19
A class that can be "activated" to broadcast a message.
Definition Button.h:27
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Button.cpp:134
auto setUndoHighlightLambda(std::string newUndoHighlight) -> void
Changes the buttons undo highlight lambda.
Definition Button.cpp:219
auto undoHighlight() const -> void
Calls the buttons UndoHighlightLambda. Intended to trigger when a selector moves off of it,...
Definition Button.cpp:197
std::string highlightLambdaName
Definition Button.h:107
static auto setIfAnyButtonHasBeenPressed(bool newState) -> void
Sets the tracker of if any button has been pressed this frame.
Definition Button.cpp:230
std::string messageName
The name of the message we want to create for broadcasting.
Definition Button.h:102
auto highlight() const -> void
Calls the buttons HighlightLambda. Intended to trigger when a selector moves onto it,...
Definition Button.cpp:192
Button()
Definition Button.cpp:36
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Button.cpp:139
auto select() -> void
Selects a button (e.g. like clicking on it). Broadcasts an event that this button was selected.
Definition Button.cpp:174
auto linkMessages() -> void
Definition Button.cpp:235
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Button.cpp:114
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Button.h:42
auto setSelectLambda(std::string newSelect) -> void
Changes the lambda that the button calls when it is selected, but before it broadcasts.
Definition Button.cpp:207
~Button() override=default
std::function< void(Entity *ent)> highlightLambda
The Lambda called when the button is hovered over by a Selector. Intended for visual effects.
Definition Button.h:112
static auto checkIfAnyButtonHasBeenPressed() -> bool
Returns if any button has been pressed this frame.
Definition Button.cpp:225
auto componentShowMenu() -> void override
Definition Button.cpp:88
std::string buttonEvent
The event that you want to broadcast when this button is selected.
Definition Button.h:100
auto setEvent(std::string newEvent) -> void
Changes the event that this button broadcasts when selected.
Definition Button.cpp:202
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Button.h:51
std::unique_ptr< Message > messagePtr
A pointer to the message that this button will broadcast when selected.
Definition Button.h:104
auto operator=(Button &&other) noexcept -> Button &=default
std::function< void(Entity *ent)> selectLambda
Lambda called when the button is selected but BEFORE the message is broadcast. Intended for visual ef...
Definition Button.h:110
auto operator=(const Button &) -> Button &=default
std::string selectLambdaName
Definition Button.h:107
static constexpr auto DESIRED_BUTTON_SPEED
Definition Button.h:62
friend auto to_json(json &j, const Button &b) -> void
Definition Button.cpp:146
std::function< void(Entity *ent)> undoHighlightLambda
The Lambda called when the button is no longer hovered over. Returns the button to its default state.
Definition Button.h:114
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Button.cpp:110
static bool anyButtonHasTriggeredThisFrameAlready
Bool to ensure only one button can activate than once a frame. Currently being updated by Input.
Definition Button.h:117
auto setHighlightLambda(std::string newHighlight) -> void
Changes the buttons highlight lambda.
Definition Button.cpp:213
friend auto from_json(const json &j, Button &b) -> void
Definition Button.cpp:158
std::string undoHighlightLambdaName
Definition Button.h:107
auto onUpdate(float dt) -> void override
called once every frame.
Definition Button.cpp:105
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
friend Entity
Definition GameObject.h:84
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23