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
22struct Message;
27class Button : public Component
28{
29public:
30#pragma region static_functions
31 static auto bindLuaTypes(sol::state& lua) -> void;
32 static auto getEnum() -> ComponentTypeEnum
33 {
34 return cButton;
35 }
36
37#pragma endregion
38
39 Button();
40 Button(const Button&);
41 auto operator=(const Button&) -> Button& = default;
42 ~Button() override = default;
43 Button(Button&& other) noexcept;
44 auto operator=(Button&& other) noexcept -> Button& = default;
45
46#pragma region overriden_functions
47
48 auto clone() const -> std::unique_ptr<GameObject> override
49 {
50 return std::make_unique<Button>(*this);
51 }
52
53 auto componentShowMenu() -> void override;
54
55 auto onUpdate(float dt) -> void override;
56
57 auto endWindow() -> void override
58 {
59 } // for debug ImGUI
60 auto onRender() -> void override;
61 auto onEnterEngine() -> void override;
62 auto load(const Stream& stream) -> void override;
63 auto save(Stream& stream) const -> void override;
64
65 friend auto to_json(json& j, const Button& b) -> void;
66 friend auto from_json(const json& j, Button& b) -> void;
67
68 static constexpr auto DESIRED_BUTTON_SPEED = 500.f;
69
70#pragma endregion
71
72#pragma region Button_functions
73
75 auto select() -> void;
76
78 auto highlight() const -> void;
80 auto undoHighlight() const -> void;
82 auto setEvent(std::string newEvent) -> void;
84 auto setSelectLambda(std::string newSelect) -> void;
86 auto setHighlightLambda(std::string newHighlight) -> void;
88 auto setUndoHighlightLambda(std::string newUndoHighlight) -> void;
89
91 static auto checkIfAnyButtonHasBeenPressed() -> bool;
93 static auto setIfAnyButtonHasBeenPressed(bool newState) -> void;
94#pragma endregion
95
96#pragma region messaging_functions
97 auto linkMessages() -> void;
98
99#pragma endregion
100
101private:
102#pragma region member_variables
103
104
106 std::string buttonEvent;
108 std::string messageName;
110 std::unique_ptr<Message> messagePtr;
111
112
114
116 std::function<void(Entity* ent)> selectLambda;
118 std::function<void(Entity* ent)> highlightLambda;
120 std::function<void(Entity* ent)> undoHighlightLambda;
121
124
125#pragma endregion
126
127#pragma region helper_functions
128
129#pragma endregion
130
131#pragma region static_variables
132
133#pragma endregion
134
135};
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 load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Button.cpp:157
auto setUndoHighlightLambda(std::string newUndoHighlight) -> void
Changes the buttons undo highlight lambda.
Definition Button.cpp:248
auto undoHighlight() const -> void
Calls the buttons UndoHighlightLambda. Intended to trigger when a selector moves off of it,...
Definition Button.cpp:223
std::string highlightLambdaName
Definition Button.h:113
static auto setIfAnyButtonHasBeenPressed(bool newState) -> void
Sets the tracker of if any button has been pressed this frame.
Definition Button.cpp:259
std::string messageName
The name of the message we want to create for broadcasting.
Definition Button.h:108
auto highlight() const -> void
Calls the buttons HighlightLambda. Intended to trigger when a selector moves onto it,...
Definition Button.cpp:215
Button()
Definition Button.cpp:53
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Button.cpp:162
auto select() -> void
Selects a button (e.g. like clicking on it). Broadcasts an event that this button was selected.
Definition Button.cpp:197
auto linkMessages() -> void
Definition Button.cpp:264
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Button.cpp:131
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Button.h:48
auto setSelectLambda(std::string newSelect) -> void
Changes the lambda that the button calls when it is selected, but before it broadcasts.
Definition Button.cpp:236
static auto bindLuaTypes(sol::state &lua) -> void
Definition Button.cpp:37
~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:118
static auto checkIfAnyButtonHasBeenPressed() -> bool
Returns if any button has been pressed this frame.
Definition Button.cpp:254
auto componentShowMenu() -> void override
Definition Button.cpp:105
std::string buttonEvent
The event that you want to broadcast when this button is selected.
Definition Button.h:106
auto setEvent(std::string newEvent) -> void
Changes the event that this button broadcasts when selected.
Definition Button.cpp:231
static auto getEnum() -> ComponentTypeEnum
Definition Button.h:32
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Button.h:57
std::unique_ptr< Message > messagePtr
A pointer to the message that this button will broadcast when selected.
Definition Button.h:110
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:116
auto operator=(const Button &) -> Button &=default
std::string selectLambdaName
Definition Button.h:113
static constexpr auto DESIRED_BUTTON_SPEED
Definition Button.h:68
friend auto to_json(json &j, const Button &b) -> void
Definition Button.cpp:169
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:120
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Button.cpp:127
static bool anyButtonHasTriggeredThisFrameAlready
Bool to ensure only one button can activate than once a frame. Currently being updated by Input.
Definition Button.h:123
auto setHighlightLambda(std::string newHighlight) -> void
Changes the buttons highlight lambda.
Definition Button.cpp:242
friend auto from_json(const json &j, Button &b) -> void
Definition Button.cpp:181
std::string undoHighlightLambdaName
Definition Button.h:113
auto onUpdate(float dt) -> void override
called once every frame.
Definition Button.cpp:122
ComponentTypeEnum
This enum lists out every type of component we have.
Definition Component.h:39
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
friend Entity
Definition GameObject.h:90
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
Definition Message.h:35