Brunot
Loading...
Searching...
No Matches
Menu.h
Go to the documentation of this file.
1
16// ____ __ __ __
17// /\__ _\/\ \ /\ \/\ \
18// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
19// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
20// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
21// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
22// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
23
24
25#pragma once
26#include "Button.h"
27#include "Framework/Component.h"
28
29enum class menuType
30{
33};
34
39class Menu : public Component
40{
41public:
42#pragma region static_functions
43
44#pragma endregion
45
46 Menu(float gapSize, int widthSize, int heightSize, menuType typeMenu);
47
49 : Component(cMenu, "Menu")
50 {
51 }
52
53 // If you have messages, you will need to un-default the copy and move constructor and call linkMessages in them
54 Menu(const Menu&) = default;
55 auto operator=(const Menu&) -> Menu& = default;
56 ~Menu() override = default;
57 Menu(Menu&& other) noexcept = default;
58 auto operator=(Menu&& other) noexcept -> Menu& = default;
59
60#pragma region overriden_functions
61
62 auto clone() const -> std::unique_ptr<GameObject> override
63 {
64 return std::make_unique<Menu>(*this);
65 }
66
67 auto componentShowMenu() -> void override;
68 // for debug ImGUI
69 auto onUpdate(float dt) -> void override;
70
71 auto endWindow() -> void override
72 {
73 } // for debug ImGUI
74 auto onRender() -> void override;
75 auto onEnterEngine() -> void override;
76 auto load(Stream& stream) -> void override;
77 auto save(Stream& stream) const -> void override;
78
79 friend auto to_json(json& j, const Menu& m) -> void;
80
81 friend auto from_json(const json& j, Menu& m) -> void;
82
83
84#pragma endregion
85
86#pragma region Menu_functions
87
88#pragma endregion
89
93 auto width() const -> int;
94
98 auto height() const -> int;
99
103 auto createEmptyButton() -> std::unique_ptr<Entity>;
104
108 auto getTranslationOfIndex(int x, int y) -> Point2D;
109
113 auto pushEntityHorizontal(Entity* entity) -> void;
114
118 auto pushEntity(Entity* entity) -> void;
119
120
124 auto removeEntity(int x, int y) -> void;
125
129 auto getAboveEntity(Entity* entity) -> Entity*;
133 auto getBelowEntity(Entity* entity) -> Entity*;
137 auto getLeftEntity(Entity* entity) -> Entity*;
141 auto getRightEntity(Entity* entity) -> Entity*;
142
147 auto getGamespacePositionForEntity(Entity* entity) const -> Vector4D;
148
152 auto getMenuElementPosition(Entity* entity) const -> std::pair<int, int>;
153
157 auto updateMenuChildren() -> void;
158
162 auto compactMenu() -> void;
163
171 auto getButtonEntity(int x, int y) -> Entity*;
172
176 auto deleteAllEntities() const -> void;
177
178
179 auto fillMenu() -> void;
180
181#pragma region messaging_functions
182 auto linkMessages() -> void;
183
184#pragma endregion
185
186private:
187#pragma region member_variables
188
190 float gapBetweenObjects = 0.01f;
197
199 std::vector<std::vector<Entity*>> buttons;
200
201#pragma endregion
202
203#pragma region helper_functions
204
209 auto arrangeEntityAccordingToPositionInMenu(Entity* entity) const -> void;
210
214 auto returnWrappedMenuPosition(int x, int y) -> Point2D;
218 auto returnDefaultMenuPosition(int x, int y) -> Point2D;
219
223 auto returnButtonIndexWrapped(int x, int y) -> Entity*;
227 auto returnButtonIndexDefault(int x, int y) -> Entity*;
228
233 auto getButtonPosition(Entity* ent) -> std::pair<int, int>;
234
238 auto repositionItems(std::vector<Entity*> ent, int column) -> void;
239
240
241#pragma endregion
242
243#pragma region static_variables
244
245#pragma endregion
246
247};
sys::Json Stream
Definition AudioObject.h:20
A class that can be "activated" to broadcast a message.
The base class for components, holding all of their shared All components should inherit from this.
nlohmann::json json
Definition Json.cpp:19
menuType
Definition Menu.h:30
@ mWrapped
Definition Menu.h:32
@ mDefault
Definition Menu.h:31
Vector4D Point2D
Definition Transform.h:21
@ cMenu
Definition Component.h:61
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
Definition Entity.h:33
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
auto repositionItems(std::vector< Entity * > ent, int column) -> void
Visually arranges the entities in a given column, intended as a helper function for compactMenu.
Definition Menu.cpp:546
auto linkMessages() -> void
Definition Menu.cpp:362
auto getRightEntity(Entity *entity) -> Entity *
When given an entity, it will return the one right in the menu.
Definition Menu.cpp:277
menuType type
How to tell if the menu wraps.
Definition Menu.h:196
auto getMenuElementPosition(Entity *entity) const -> std::pair< int, int >
Returns the index of the entity in the menu.
Definition Menu.cpp:322
auto returnButtonIndexWrapped(int x, int y) -> Entity *
Returns the menu position while accounting for wrapped logic, intended as a helper function for getBu...
Definition Menu.cpp:420
auto updateMenuChildren() -> void
Resizes menu in memory, allocates new items, and then calls compact menu.
Definition Menu.cpp:332
auto createEmptyButton() -> std::unique_ptr< Entity >
Creates an empty button, intended for filling the board.
Definition Menu.cpp:595
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Menu.h:62
std::vector< std::vector< Entity * > > buttons
The managed items/entities for the menu.
Definition Menu.h:199
auto deleteAllEntities() const -> void
Deletes all entities inside of the grid.
Definition Menu.cpp:483
auto returnButtonIndexDefault(int x, int y) -> Entity *
Returns the menu position while accounting for default logic, intended as a helper function for getBu...
Definition Menu.cpp:445
auto returnWrappedMenuPosition(int x, int y) -> Point2D
Returns the menu position while accounting for wrapped logic, intended as a helper function for retur...
Definition Menu.cpp:366
auto operator=(Menu &&other) noexcept -> Menu &=default
Menu(Menu &&other) noexcept=default
auto getButtonPosition(Entity *ent) -> std::pair< int, int >
takes in the entity and returns the index (x and y) of where it is in the menu
Definition Menu.cpp:529
auto compactMenu() -> void
Visually shrinks the menu, intended for when an element gets removed.
Definition Menu.cpp:153
auto getAboveEntity(Entity *entity) -> Entity *
When given an entity, it will return the one above in the menu.
Definition Menu.cpp:259
auto componentShowMenu() -> void override
Definition Menu.cpp:48
friend auto from_json(const json &j, Menu &m) -> void
Definition Menu.cpp:624
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Menu.cpp:145
auto getButtonEntity(int x, int y) -> Entity *
takes in a position, and gets the entitiy in the position, blocking overflow by locking to edges,...
Definition Menu.cpp:473
auto returnDefaultMenuPosition(int x, int y) -> Point2D
Returns the menu position while accounting for default logic, intended as a helper function for retur...
Definition Menu.cpp:392
int maxMenuHeight
How tall the menu grid is (how many objects it can hold vertically).
Definition Menu.h:194
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Menu.cpp:128
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Menu.h:71
auto getLeftEntity(Entity *entity) -> Entity *
When given an entity, it will return the one left in the menu.
Definition Menu.cpp:271
auto getGamespacePositionForEntity(Entity *entity) const -> Vector4D
Gets where an entity is in its gamespace position, based on where it is in the menu.
Definition Menu.cpp:307
~Menu() override=default
int maxMenuWidth
How wide menu grid is (how many objects it can hold horizontally).
Definition Menu.h:192
friend auto to_json(json &j, const Menu &m) -> void
Definition Menu.cpp:613
auto pushEntity(Entity *entity) -> void
A universal push function that automatically fills in empty spaces.
Definition Menu.cpp:219
auto getBelowEntity(Entity *entity) -> Entity *
When given an entity, it will return the one below in the menu.
Definition Menu.cpp:265
auto removeEntity(int x, int y) -> void
Removes a specific entity at given index.
Definition Menu.cpp:248
auto getTranslationOfIndex(int x, int y) -> Point2D
Returns the translation of an item at given index.
Definition Menu.cpp:192
auto onUpdate(float dt) -> void override
called once every frame.
Definition Menu.cpp:123
auto height() const -> int
Returns the height of the menu.
Definition Menu.cpp:590
auto pushEntityHorizontal(Entity *entity) -> void
Pushes an item to the first row of a menu, intended for the cards.
Definition Menu.cpp:203
auto fillMenu() -> void
Definition Menu.cpp:498
Menu(const Menu &)=default
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Menu.cpp:140
float gapBetweenObjects
How much visual space is put between objects in the menu.
Definition Menu.h:190
auto operator=(const Menu &) -> Menu &=default
Menu()
Definition Menu.h:48
Menu(float gapSize, int widthSize, int heightSize, menuType typeMenu)
Definition Menu.cpp:40
auto width() const -> int
Returns the width of the menu.
Definition Menu.cpp:585
auto arrangeEntityAccordingToPositionInMenu(Entity *entity) const -> void
Moves an entity to its gamespace position, based on where it is in the menu.
Definition Menu.cpp:283
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Menu.cpp:132
Definition Vector4D.h:23