GigaPasjans
Loading...
Searching...
No Matches
Screen.h
1// Plik utworzony przez Piotra ChudziƄskiego w dniu 17.04.2025
2#pragma once
3
4#include <andromenda/Components/SelectionTextComponent.h>
5#include <andromenda/Surface.h>
6
7namespace Game
8{
13 struct MenuEntry
14 {
20
26
32
37 std::function<void()> Action;
38
39 MenuEntry(const WideString &display, const String &id, const std::function<void()> &action) :
40 Display(display), Id(id), Component(new Andromenda::SelectionTextComponent(Display)), Action(action)
41 {
42 }
43
49 inline void Register(Andromenda::Surface &surface) { surface.RegisterComponent(Id, Component); }
50 };
51
56 class IScreen
57 {
58 public:
59 virtual ~IScreen() = default;
60
65 virtual void Repose() {};
66
72 virtual void Build(Andromenda::Surface &surface) = 0;
73
78 virtual void Draw() = 0;
79
85 virtual void OnSurfaceCallback(const String &id) = 0;
86 };
87
92 class MenuScreen : public IScreen
93 {
94 private:
99 std::vector<MenuEntry> m_Actions;
100
101 protected:
106 void DrawMenu(Andromenda::Surface &surface, int32 positionY) const;
107
109 void OnSurfaceCallback(const String &id) override;
110
117 template<typename... Args>
118 void AddEntry(Args... args)
119 {
120 m_Actions.emplace_back(std::forward<Args>(args)...);
121 }
122 };
123} // namespace Game
Text component that can be selectable.
Definition SelectionTextComponent.h:14
The renderer of component registry.
Definition Surface.h:28
void RegisterComponent(const String &name, Component *component) override
Registers given component to given unique name.
Definition Surface.cpp:334
Represents object that registers components .
Definition Screen.h:57
virtual void OnSurfaceCallback(const String &id)=0
Event called when any component sends callback.
virtual void Repose()
Event called when this screen is being closed.
Definition Screen.h:65
virtual void Build(Andromenda::Surface &surface)=0
Event called when this screen is being opened.
virtual void Draw()=0
Event called when screen is getting rerendered and this screen is currently rendered screen.
Represents a screen where user have to make a choice from declared entries.
Definition Screen.h:93
void AddEntry(Args... args)
Adds an entry to list of entries.
Definition Screen.h:118
void DrawMenu(Andromenda::Surface &surface, int32 positionY) const
Draws menu at given position.
Definition MenuScreen.cpp:6
void OnSurfaceCallback(const String &id) override
Event called when any component sends callback.
Definition MenuScreen.cpp:18
Represents a mutable sequence of characters, providing various member functions for string manipulati...
Definition String.h:16
Represents a mutable sequence of utf-16 characters, providing various member functions for string man...
Definition WideString.h:14
Andromenda::SelectionTextComponent * Component
Component associated with this entry.
Definition Screen.h:31
String Id
Identifier used to register component.
Definition Screen.h:25
void Register(Andromenda::Surface &surface)
Registers associated component.
Definition Screen.h:49
std::function< void()> Action
Callback that will be called when user select this entry.
Definition Screen.h:37
WideString Display
Display text of an entry.
Definition Screen.h:19