Brunot
Loading...
Searching...
No Matches
Selector.h
Go to the documentation of this file.
1
12// ____ __ __ __
13// /\__ _\/\ \ /\ \/\ \
14// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
15// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
16// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
17// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
18// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
19
20
21#pragma once
22#include "Framework/Component.h"
23
24class Menu;
25
30class Selector : public Component
31{
32public:
33#pragma region static_functions
34
35#pragma endregion
36
37 Selector();
38 // If you have messages, you will need to un-default the copy and move constructor and call linkMessages in them
39 Selector(const Selector&);
40 auto operator=(const Selector&) -> Selector& = default;
41 ~Selector() override = default;
42 Selector(Selector&& other) noexcept;
43 auto operator=(Selector&& other) noexcept -> Selector& = default;
44
45#pragma region overriden_functions
46
47 auto clone() const -> std::unique_ptr<GameObject> override
48 {
49 return std::make_unique<Selector>(*this);
50 }
51
52 auto componentShowMenu() -> void override;
53 auto onUpdate(float dt) -> void override;
54
55 auto onEnterEngine() -> void override;
56 auto endWindow() -> void override
57 {
58 } // for debug ImGUI
59 auto onRender() -> void override;
60 auto load(const Stream& stream) -> void override;
61 auto save(Stream& stream) const -> void override;
62
63 friend auto to_json(json& j, const Selector& s) -> void;
64 friend auto from_json(const json& j, Selector& s) -> void;
65
67 virtual auto isValidID(int id) -> bool;
68
69
70#pragma endregion
71
72#pragma region Selector_functions
73
75 auto select() -> void;
76
77 auto setEnabled(bool state) -> void
78 {
79 enabled = state;
80 }
81
82#pragma endregion
83
84#pragma region messaging_functions
85
86 virtual auto linkMessages() -> void;
87
88 virtual auto receiveLeftKeyPressed(const Message* message) -> Message;
89 virtual auto receiveRightKeyPressed(const Message* message) -> Message;
90 virtual auto receiveUpKeyPressed(const Message* message) -> Message;
91 virtual auto receiveDownKeyPressed(const Message* message) -> Message;
92
93 virtual auto receiveSelectKeyPressed(const Message* message) -> Message;
94
96 auto moveUp(Menu* menu) -> void;
98 auto moveDown(Menu* menu) -> void;
100 auto moveLeft(Menu* menu) -> void;
102 auto moveRight(Menu* menu) -> void;
103
104#pragma endregion
105
106protected:
108 Selector(const char* typeName);
109
110#pragma region member_variables
113private:
114
115#pragma endregion
116
117#pragma region helper_functions
118
119 auto moveToNewParent(Entity* newParent) -> void;
120
121#pragma endregion
122
123
124#pragma region static_variables
125
126#pragma endregion
127
128};
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
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
friend Entity
Definition GameObject.h:84
std::string typeName
the typeName of a GameObject.
Definition GameObject.h:545
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
A menu that organizes its parents' children (in the node) either horizontally or vertically.
Definition Menu.h:41
An indicator that loops through a parents' nodes children and can "select" them on keypress.
Definition Selector.h:31
friend auto from_json(const json &j, Selector &s) -> void
Definition Selector.cpp:121
auto moveRight(Menu *menu) -> void
Helper function that actually moves the selector right in a menu.
Definition Selector.cpp:178
virtual auto receiveRightKeyPressed(const Message *message) -> Message
Definition Selector.cpp:243
bool enabled
If the selector is disabled, it does not move around or select.
Definition Selector.h:112
auto moveToNewParent(Entity *newParent) -> void
Definition Selector.cpp:287
auto moveDown(Menu *menu) -> void
Helper function that actually moves the selector down in a menu.
Definition Selector.cpp:162
virtual auto linkMessages() -> void
Definition Selector.cpp:202
~Selector() override=default
auto select() -> void
Selects the button that the selector is hovering over.
Definition Selector.cpp:133
auto operator=(Selector &&other) noexcept -> Selector &=default
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Selector.cpp:74
virtual auto receiveLeftKeyPressed(const Message *message) -> Message
Definition Selector.cpp:233
Selector()
Definition Selector.cpp:40
auto operator=(const Selector &) -> Selector &=default
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Selector.cpp:108
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Selector.cpp:79
virtual auto isValidID(int id) -> bool
Virtual function used by FilteredSelector. Always returns true in Selector.
Definition Selector.cpp:197
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Selector.h:56
auto componentShowMenu() -> void override
Definition Selector.cpp:61
virtual auto receiveDownKeyPressed(const Message *message) -> Message
Definition Selector.cpp:263
virtual auto receiveUpKeyPressed(const Message *message) -> Message
Definition Selector.cpp:253
friend auto to_json(json &j, const Selector &s) -> void
Definition Selector.cpp:113
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Selector.cpp:103
auto moveLeft(Menu *menu) -> void
Helper function that actually moves the selector left in a menu.
Definition Selector.cpp:170
auto moveUp(Menu *menu) -> void
Helper function that actually moves the selector up in a menu.
Definition Selector.cpp:154
virtual auto receiveSelectKeyPressed(const Message *message) -> Message
Definition Selector.cpp:273
auto onUpdate(float dt) -> void override
called once every frame.
Definition Selector.cpp:68
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Selector.h:47
auto setEnabled(bool state) -> void
Definition Selector.h:77
Definition Message.h:34