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 endWindow() -> void override
56 {
57 } // for debug ImGUI
58 auto onRender() -> void override;
59 auto load(Stream& stream) -> void override;
60 auto save(Stream& stream) const -> void override;
61
62 friend auto to_json(json& j, const Selector& s) -> void;
63 friend auto from_json(const json& j, Selector& s) -> void;
64
65
66#pragma endregion
67
68#pragma region Selector_functions
69
70 auto setEnabled(bool state) -> void
71 {
72 enabled = state;
73 }
74
75#pragma endregion
76
77#pragma region messaging_functions
78
79 auto linkMessages() -> void;
80
81 auto receiveLeftKeyPressed(const Message* message) -> Message;
82 auto receiveRightKeyPressed(const Message* message) -> Message;
83 auto receiveUpKeyPressed(const Message* message) -> Message;
84 auto receiveDownKeyPressed(const Message* message) -> Message;
85
86 auto receiveSelectKeyPressed(const Message* message) -> Message;
87
89 auto moveUp(Menu* menu) -> void;
91 auto moveDown(Menu* menu) -> void;
93 auto moveLeft(Menu* menu) -> void;
95 auto moveRight(Menu* menu) -> void;
96
97#pragma endregion
98
99private:
100#pragma region member_variables
101
104
105
106#pragma endregion
107
108#pragma region helper_functions
109
110
112 virtual auto select() -> void;
113
114 auto moveToNewParent(Entity* newParent) -> void;
115
116#pragma endregion
117
118
119#pragma region static_variables
120
121#pragma endregion
122
123};
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
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:40
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:118
auto moveRight(Menu *menu) -> void
Helper function that actually moves the selector right in a menu.
Definition Selector.cpp:170
auto receiveRightKeyPressed(const Message *message) -> Message
Definition Selector.cpp:230
bool enabled
If the selector is disabled, it does not move around or select.
Definition Selector.h:103
auto moveToNewParent(Entity *newParent) -> void
Definition Selector.cpp:130
auto moveDown(Menu *menu) -> void
Helper function that actually moves the selector down in a menu.
Definition Selector.cpp:154
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Selector.cpp:100
auto linkMessages() -> void
Definition Selector.cpp:189
~Selector() override=default
virtual auto select() -> void
Selects the button that the selector is hovering over.
Definition Selector.cpp:179
auto operator=(Selector &&other) noexcept -> Selector &=default
auto receiveLeftKeyPressed(const Message *message) -> Message
Definition Selector.cpp:220
Selector()
Definition Selector.cpp:39
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:105
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Selector.cpp:76
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Selector.h:55
auto componentShowMenu() -> void override
Definition Selector.cpp:63
auto receiveDownKeyPressed(const Message *message) -> Message
Definition Selector.cpp:250
auto receiveUpKeyPressed(const Message *message) -> Message
Definition Selector.cpp:240
friend auto to_json(json &j, const Selector &s) -> void
Definition Selector.cpp:110
auto moveLeft(Menu *menu) -> void
Helper function that actually moves the selector left in a menu.
Definition Selector.cpp:162
auto moveUp(Menu *menu) -> void
Helper function that actually moves the selector up in a menu.
Definition Selector.cpp:146
auto receiveSelectKeyPressed(const Message *message) -> Message
Definition Selector.cpp:260
auto onUpdate(float dt) -> void override
called once every frame.
Definition Selector.cpp:70
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:70
Definition Message.h:34