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#include "System/ActionList.h"
22
27class Button : public Component
28{
29public:
30#pragma region static_Lambdas
31
32#pragma endregion
33
34 Button();
35 Button(const Button&);
36 auto operator=(const Button&) -> Button& = default;
37 ~Button() override = default;
38 Button(Button&& other) noexcept;
39 auto operator=(Button&& other) noexcept -> Button& = default;
40
41#pragma region overriden_Lambdas
42
43 auto clone() const -> std::unique_ptr<GameObject> override
44 {
45 return std::make_unique<Button>(*this);
46 }
47
48 auto componentShowMenu() -> void override;
49
50 auto onUpdate(float dt) -> void override;
51
52 auto endWindow() -> void override
53 {
54 } // for debug ImGUI
55 auto onRender() -> void override;
56 auto onEnterEngine() -> void override;
57 auto load(Stream& stream) -> void override;
58 auto save(Stream& stream) const -> void override;
59
60 friend auto to_json(json& j, const Button& b) -> void;
61 friend auto from_json(const json& j, Button& b) -> void;
62
63 static constexpr auto DESIRED_BUTTON_SPEED = 500.f;
64
65#pragma endregion
66
67#pragma region Button_Lambdas
68
70 auto select() -> void;
71
73 auto highlight() const -> void;
75 auto undoHighlight() const -> void;
77 auto setEvent(std::string newEvent) -> void;
79 auto setSelectLambda(std::string newSelect) -> void;
81 auto setHighlightLambda(std::string newHighlight) -> void;
83 auto setUndoHighlightLambda(std::string newUndoHighlight) -> void;
84
86 static auto checkIfAnyButtonHasBeenPressed() -> bool;
88 static auto setIfAnyButtonHasBeenPressed(bool newState) -> void;
89#pragma endregion
90
91#pragma region messaging_functions
92 auto linkMessages() -> void;
93
94#pragma endregion
95
96private:
97#pragma region member_variables
98
99
101 std::string buttonEvent;
103 std::string messageName;
105 std::unique_ptr<Message> messagePtr;
106
107
109
111 std::function<void(Entity* ent)> selectLambda;
113 std::function<void(Entity* ent)> highlightLambda;
115 std::function<void(Entity* ent)> undoHighlightLambda;
116
119
120#pragma endregion
121
122#pragma region helper_Lambdas
123
124#pragma endregion
125
126#pragma region static_variables
127
128#pragma endregion
129
130};
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:28
auto setUndoHighlightLambda(std::string newUndoHighlight) -> void
Changes the buttons undo highlight lambda.
Definition Button.cpp:217
auto undoHighlight() const -> void
Calls the buttons UndoHighlightLambda. Intended to trigger when a selector moves off of it,...
Definition Button.cpp:195
std::string highlightLambdaName
Definition Button.h:108
static auto setIfAnyButtonHasBeenPressed(bool newState) -> void
Sets the tracker of if any button has been pressed this frame.
Definition Button.cpp:228
std::string messageName
The name of the message we want to create for broadcasting.
Definition Button.h:103
auto highlight() const -> void
Calls the buttons HighlightLambda. Intended to trigger when a selector moves onto it,...
Definition Button.cpp:190
Button()
Definition Button.cpp:34
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Button.cpp:137
auto select() -> void
Selects a button (e.g. like clicking on it). Broadcasts an event that this button was selected.
Definition Button.cpp:172
auto linkMessages() -> void
Definition Button.cpp:233
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Button.h:43
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Button.cpp:132
auto setSelectLambda(std::string newSelect) -> void
Changes the lambda that the button calls when it is selected, but before it broadcasts.
Definition Button.cpp:205
~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:113
static auto checkIfAnyButtonHasBeenPressed() -> bool
Returns if any button has been pressed this frame.
Definition Button.cpp:223
auto componentShowMenu() -> void override
Definition Button.cpp:86
std::string buttonEvent
The event that you want to broadcast when this button is selected.
Definition Button.h:101
auto setEvent(std::string newEvent) -> void
Changes the event that this button broadcasts when selected.
Definition Button.cpp:200
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Button.h:52
std::unique_ptr< Message > messagePtr
A pointer to the message that this button will broadcast when selected.
Definition Button.h:105
auto operator=(Button &&other) noexcept -> Button &=default
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Button.cpp:112
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:111
auto operator=(const Button &) -> Button &=default
std::string selectLambdaName
Definition Button.h:108
static constexpr auto DESIRED_BUTTON_SPEED
Definition Button.h:63
friend auto to_json(json &j, const Button &b) -> void
Definition Button.cpp:144
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:115
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Button.cpp:108
static bool anyButtonHasTriggeredThisFrameAlready
Bool to ensure only one button can activate than once a frame. Currently being updated by Input.
Definition Button.h:118
auto setHighlightLambda(std::string newHighlight) -> void
Changes the buttons highlight lambda.
Definition Button.cpp:211
friend auto from_json(const json &j, Button &b) -> void
Definition Button.cpp:156
std::string undoHighlightLambdaName
Definition Button.h:108
auto onUpdate(float dt) -> void override
called once every frame.
Definition Button.cpp:103
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