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#include "Component/Transform.h"
29
30enum class menuType
31{
34};
35
40class Menu : public Component
41{
42public:
43#pragma region static_functions
44
45#pragma endregion
46
47 Menu(float gapSize, int widthSize, int heightSize, menuType typeMenu);
48
50 : Component(cMenu, "Menu")
51 {
52 }
53
54 // If you have messages, you will need to un-default the copy and move constructor and call linkMessages in them
55 Menu(const Menu&) = default;
56 auto operator=(const Menu&) -> Menu& = default;
57 ~Menu() override = default;
58 Menu(Menu&& other) noexcept = default;
59 auto operator=(Menu&& other) noexcept -> Menu& = default;
60
61#pragma region overriden_functions
62
63 auto clone() const -> std::unique_ptr<GameObject> override { return std::make_unique<Menu>(*this); }
64
65 auto componentShowMenu() -> void override;
66 // for debug ImGUI
67 auto onUpdate(float dt) -> void override;
68
69 auto endWindow() -> void override {} // for debug ImGUI
70 auto onRender() -> void override;
71 auto onEnterEngine() -> void override;
72 auto load(const Stream& stream) -> void override;
73 auto save(Stream& stream) const -> void override;
74
75 friend auto to_json(json& j, const Menu& m) -> void;
76
77 friend auto from_json(const json& j, Menu& m) -> void;
78
79
80#pragma endregion
81
82#pragma region Menu_functions
83
84#pragma endregion
85
89 auto width() const -> int;
90
94 auto sizeWidth() const -> int;
95
99 auto height() const -> int;
100
104 auto createEmptyButton() -> std::unique_ptr<Entity>;
105
109 auto getTranslationOfIndex(int x, int y) -> Point2D;
110
111
115 auto pushEntityHorizontal(Entity* entity) -> void;
116
120 auto pushEntity(Entity* entity) -> void;
121
122
126 auto removeEntity(int x, int y) -> void;
127
131 auto removeEntity(Entity* entity) -> void;
132
136 auto getAboveEntity(Entity* entity) -> Entity*;
140 auto getBelowEntity(Entity* entity) -> Entity*;
144 auto getLeftEntity(Entity* entity) -> Entity*;
148 auto getRightEntity(Entity* entity) -> Entity*;
149
153 auto getMenuElementPosition(Entity* entity) const -> std::pair<int, int>;
154
158 auto updateMenuChildren() -> void;
159
163 auto compactMenu() -> void;
164
168 auto horizontalCompactMenu() -> void;
169
178 auto getButtonEntity(int x, int y) -> Entity*;
179
183 auto deleteAllEntities() const -> void;
184
185
186 auto fillMenu() -> void;
187
191 auto getChildScale() const -> Vector4D;
192
193 auto drawDebugLines(AffineMatrix transform) -> void;
194
195#pragma region messaging_functions
196 auto linkMessages() -> void;
197
198#pragma endregion
199
200private:
201#pragma region helper_struct
202
203 // Struct that contains a bunch of information for calculating where children should be positioned
205 {
206 // Scale of children inside the menu
209
210 // Position for where children start out
212 // How far the children should be moved right to travel one space
214 // How far the children should be moved up to travel one space
216 };
217
218#pragma endregion
219
220#pragma region member_variables
221
223 float gapBetweenObjects = 0.01f;
228
229 Vector4D originPoint{0.f, 0.f, 0, 1};
230 Vector4D menuScale{1.f, 1.f, 0.f, 0.f};
231
236
237
239 std::vector<std::vector<Entity*>> buttons;
240
241#pragma endregion
242
243#pragma region helper_functions
244
248 auto returnWrappedMenuPosition(int x, int y) -> Point2D;
252 auto returnDefaultMenuPosition(int x, int y) -> Point2D;
253
257 auto returnButtonIndexWrapped(int x, int y) -> Entity*;
261 auto returnButtonIndexDefault(int x, int y) -> Entity*;
262
267 auto getButtonPosition(Entity* ent) -> std::pair<int, int>;
268
274
280
284 auto repositionItems(const std::vector<Entity*>& ent, int column) -> void;
285
290 auto repositionHorizontalItems(const std::vector<Entity*>& ent, int column) -> void;
291
292#pragma endregion
293
294#pragma region static_variables
295
296#pragma endregion
297
298};
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:31
@ mWrapped
Definition Menu.h:33
@ mDefault
Definition Menu.h:32
Vector4D Point2D
Definition Transform.h:21
@ cMenu
Definition Component.h:63
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
Definition Entity.h:39
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:41
auto linkMessages() -> void
Definition Menu.cpp:442
auto getRightEntity(Entity *entity) -> Entity *
When given an entity, it will return the one right in the menu.
Definition Menu.cpp:395
menuType type
How to tell if the menu wraps.
Definition Menu.h:233
auto getMenuElementPosition(Entity *entity) const -> std::pair< int, int >
Returns the index of the entity in the menu.
Definition Menu.cpp:400
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:500
auto updateMenuChildren() -> void
Resizes menu in memory, allocates new items, and then calls compact menu.
Definition Menu.cpp:410
auto createEmptyButton() -> std::unique_ptr< Entity >
Creates an empty button, intended for filling the board.
Definition Menu.cpp:729
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Menu.h:63
std::vector< std::vector< Entity * > > buttons
The managed items/entities for the menu.
Definition Menu.h:239
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Menu.cpp:193
int maxItemsWide
How wide menu grid is (how many objects it can hold horizontally).
Definition Menu.h:225
auto repositionHorizontalItems(const 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:696
auto deleteAllEntities() const -> void
Deletes all entities inside of the grid.
Definition Menu.cpp:563
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:525
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:446
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:614
auto compactMenu() -> void
Visually shrinks the menu, intended for when an element gets removed.
Definition Menu.cpp:206
auto getAboveEntity(Entity *entity) -> Entity *
When given an entity, it will return the one above in the menu.
Definition Menu.cpp:377
Vector4D menuScale
Definition Menu.h:230
auto componentShowMenu() -> void override
Definition Menu.cpp:58
Vector4D originPoint
Definition Menu.h:229
PositioningInformation posInfo
Used to keep track of where items in the menu should be put in the game.
Definition Menu.h:235
friend auto from_json(const json &j, Menu &m) -> void
Definition Menu.cpp:760
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Menu.cpp:198
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:553
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:472
int maxItemsHeight
How tall the menu grid is (how many objects it can hold vertically).
Definition Menu.h:227
auto sizeWidth() const -> int
Returns the current width of the menu.
Definition Menu.cpp:719
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Menu.cpp:160
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Menu.h:69
auto getLeftEntity(Entity *entity) -> Entity *
When given an entity, it will return the one left in the menu.
Definition Menu.cpp:389
~Menu() override=default
friend auto to_json(json &j, const Menu &m) -> void
Definition Menu.cpp:747
auto pushEntity(Entity *entity) -> void
A universal push function that automatically fills in empty spaces.
Definition Menu.cpp:315
auto getBelowEntity(Entity *entity) -> Entity *
When given an entity, it will return the one below in the menu.
Definition Menu.cpp:383
auto repositionItems(const 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:679
auto getChildScale() const -> Vector4D
Returns what the scale of a child inside the menu should be.
Definition Menu.cpp:609
auto removeEntity(int x, int y) -> void
Removes a specific entity at given index.
Definition Menu.cpp:344
auto getTranslationOfIndex(int x, int y) -> Point2D
Returns the translation of an item at given index.
Definition Menu.cpp:288
auto drawDebugLines(AffineMatrix transform) -> void
Definition Menu.cpp:165
auto onUpdate(float dt) -> void override
called once every frame.
Definition Menu.cpp:145
auto height() const -> int
Returns the height of the menu.
Definition Menu.cpp:724
auto pushEntityHorizontal(Entity *entity) -> void
Pushes an item to the first row of a menu, intended for the cards.
Definition Menu.cpp:299
auto fillMenu() -> void
Definition Menu.cpp:578
Menu(const Menu &)=default
void recalculatePositioning()
Recalculates where children inside the menu should be positioned + scaled in the game.
Definition Menu.cpp:633
float gapBetweenObjects
How much visual space is put between objects in the menu.
Definition Menu.h:223
auto operator=(const Menu &) -> Menu &=default
Menu()
Definition Menu.h:49
Menu(float gapSize, int widthSize, int heightSize, menuType typeMenu)
Definition Menu.cpp:48
void recalculateHorizontalPositioning()
Recalculates where children inside the menu should be positioned + scaled in the game.
Definition Menu.cpp:658
auto width() const -> int
Returns the maximum width of the menu.
Definition Menu.cpp:714
auto horizontalCompactMenu() -> void
Visually shrinks the menu, intended for when an element gets removed from a player hand.
Definition Menu.cpp:247
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Menu.cpp:185
Definition AffineMatrix.h:30
Definition Menu.h:205
Vector4D right
Definition Menu.h:213
float objectWidth
Definition Menu.h:207
Vector4D up
Definition Menu.h:215
float objectHeight
Definition Menu.h:208
Point2D start
Definition Menu.h:211
Definition Vector4D.h:23