Brunot
Loading...
Searching...
No Matches
FilteredSelector.h
Go to the documentation of this file.
1
11// ____ __ __ __
12// /\__ _\/\ \ /\ \/\ \
13// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
14// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
15// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
16// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
17// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
18
19
20
21
22#pragma once
23#include "Selector.h"
25
26class Menu;
27
33{
34public:
35#pragma region static_functions
36
37#pragma endregion
38
40 // If you have messages, you will need to un-default the copy and move constructor and call linkMessages in them
42 auto operator=(const FilteredSelector&) -> FilteredSelector& = default;
43 ~FilteredSelector() override = default;
44 FilteredSelector(FilteredSelector&& other) noexcept = default;
45 auto operator=(FilteredSelector&& other) noexcept -> FilteredSelector& = default;
46
47#pragma region overriden_functions
48
49 auto clone() const -> std::unique_ptr<GameObject> override
50 {
51 return std::make_unique<FilteredSelector>(*this);
52 }
53
54 auto componentShowMenu() -> void override;
55 auto onUpdate(float dt) -> void override;
56
57 auto onEnterEngine() -> void override;
58 auto endWindow() -> void override
59 {
60 } // for debug ImGUI
61 auto onRender() -> 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 FilteredSelector& s) -> void;
66 friend auto from_json(const json& j, FilteredSelector& s) -> void;
67
68#pragma endregion
69
70#pragma region FilteredSelector_functions
71
73 auto setFilterID(int id) -> void;
74
76 auto addFilterID(int id) -> void;
77
79 auto removeFilterID(int id) -> void;
80
82 auto isValidID(int id) -> bool override;
83
84#pragma endregion
85
86#pragma region messaging_functions
87
88 auto linkMessages() -> void override;
89
90 auto receiveSelectKeyPressed(const Message* message) -> Message override;
91
92 auto receiveLeftKeyPressed(const Message* message) -> Message override;
93 auto receiveRightKeyPressed(const Message* message) -> Message override;
94 auto receiveUpKeyPressed(const Message* message) -> Message override;
95 auto receiveDownKeyPressed(const Message* message) -> Message override;
96
97#pragma endregion
98
99private:
100#pragma region member_variables
101
102 // This is an (admittedly less than ideal) fix to dodge same frame issues with messaging and updating IDs
103 std::vector<int> IDsToAdd {};
104 bool isDirty = false;
105
107 std::vector<int> filterIDs = {};
108
109#pragma endregion
110
111#pragma region helper_functions
112
113#pragma endregion
114
116 static auto getIDFromMessage(const Message* message) -> int;
117
118#pragma region static_variables
119
120#pragma endregion
121
122};
sys::Json Stream
Definition AudioObject.h:20
nlohmann::json json
Definition Json.cpp:19
An indicator that loops through a parents' nodes children and can "select" them on keypress.
A derived version of selector that only selects from Input if the inputtingDeviceID matches a value i...
Definition FilteredSelector.h:33
FilteredSelector(FilteredSelector &&other) noexcept=default
auto receiveDownKeyPressed(const Message *message) -> Message override
Definition FilteredSelector.cpp:235
std::vector< int > filterIDs
All the IDs that we will receive input from.
Definition FilteredSelector.h:107
bool isDirty
Definition FilteredSelector.h:104
auto componentShowMenu() -> void override
Definition FilteredSelector.cpp:48
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition FilteredSelector.h:49
auto onRender() -> void override
called every frame after update has been called for every object.
Definition FilteredSelector.cpp:104
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition FilteredSelector.h:58
std::vector< int > IDsToAdd
Definition FilteredSelector.h:103
auto receiveUpKeyPressed(const Message *message) -> Message override
Definition FilteredSelector.cpp:226
FilteredSelector()
Definition FilteredSelector.cpp:27
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition FilteredSelector.cpp:114
auto operator=(FilteredSelector &&other) noexcept -> FilteredSelector &=default
auto removeFilterID(int id) -> void
Removes a specific ID from the filter.
Definition FilteredSelector.cpp:152
auto operator=(const FilteredSelector &) -> FilteredSelector &=default
auto linkMessages() -> void override
Definition FilteredSelector.cpp:167
~FilteredSelector() override=default
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition FilteredSelector.cpp:109
auto isValidID(int id) -> bool override
Returns true if the passed in id matches filterID.
Definition FilteredSelector.cpp:157
auto receiveLeftKeyPressed(const Message *message) -> Message override
Definition FilteredSelector.cpp:208
friend auto to_json(json &j, const FilteredSelector &s) -> void
Definition FilteredSelector.cpp:119
auto receiveSelectKeyPressed(const Message *message) -> Message override
Definition FilteredSelector.cpp:198
auto addFilterID(int id) -> void
Adds a new ID to the filter.
Definition FilteredSelector.cpp:146
static auto getIDFromMessage(const Message *message) -> int
Helper function so you don't need to manually convert the message every time to get the inputDeviceID...
Definition FilteredSelector.cpp:249
friend auto from_json(const json &j, FilteredSelector &s) -> void
Definition FilteredSelector.cpp:128
auto setFilterID(int id) -> void
Clears the vector and sets the ID to be just one thing.
Definition FilteredSelector.cpp:139
FilteredSelector(const FilteredSelector &)=default
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition FilteredSelector.cpp:36
auto onUpdate(float dt) -> void override
called once every frame.
Definition FilteredSelector.cpp:87
auto receiveRightKeyPressed(const Message *message) -> Message override
Definition FilteredSelector.cpp:217
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
Selector()
Definition Selector.cpp:40
Definition Message.h:34