1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141 | #include "fsCNotificationsGui.h"
#include <fsCore/src/debug/fsAssert.h>
#include <fsCore/src/fsCResourceName.h>
#include <fsRenderer/src/fsCBrushManager.h>
#include <fsRenderer/src/fsCBrush.h>
#include <fsRenderer/src/components/fsCSpriteComponent.h>
#include <fsRenderer/src/components/fsCTextSpriteComponent.h>
#include "../../../fsIDisplay.h"
#include "../../../src/fsCAppCoreMain.h"
#include "../../../src/fsCEntity.h"
#include "fsCore/fsIFile.h"
const fsCUniqueId fsCNotificationsGui::mTypeId("fsCNotificationsGui");
fsCNotificationsGui* fsCNotificationsGui::mInstance = nullptr;
void fsCNotificationsGui::notificationAddToQueue(const fsStr& pMessage)
{
if (messageIsUniqueGet(pMessage))
{
mPendingNotifications.push_back(pMessage);
}
}
fsBool fsCNotificationsGui::messageIsUniqueGet(const fsStr& pMessage) const
{
if (mActive)
{
fsCEntity* const textEnt = parentGet()->childFind("NotificationsGuiText");
fsAssert(textEnt != nullptr, "Expected fsCNotificationsGui to have an entity called 'NotificationsGuiText'.\n");
fsITextSpriteComponent* const txtBox = textEnt->textComponentGet();
fsAssert(txtBox != nullptr, "Expected fsCNotificationsGui to have a text box called 'NotificationsGuiText'.\n");
if (pMessage == txtBox->textGet())
{
return false;
}
}
for (const fsStr& notification : mPendingNotifications)<--- Consider using std::all_of or std::none_of algorithm instead of a raw loop.
{
if (pMessage == notification)
{
return false;
}
}
return true;
}
void fsCNotificationsGui::updateDo(fsS32 pDeltaMs)
{
if (mActive)
{
mElapsedTimeMs += pDeltaMs;
parentGet()->posSet(fsPoint(0, static_cast<fsS32>(mPosYGraph.valueGet(mElapsedTimeMs))));
if (mElapsedTimeMs >= mPosYGraph.periodGet())
{
mActive = false;
mElapsedTimeMs = 0;
}
}
else if (!mPendingNotifications.empty())
{
fsCEntity* const textEnt = parentGet()->childFind("NotificationsGuiText");
fsAssert(textEnt != nullptr, "Expected fsCNotificationsGui to have an entity called 'NotificationsGuiText'.\n");
fsITextSpriteComponent* const txtBox = textEnt->textComponentGet();
fsAssert(txtBox != nullptr, "Expected fsCNotificationsGui to have a text box called 'NotificationsGuiText'.\n");
txtBox->textSet(mPendingNotifications.front());
mActive = true;
mElapsedTimeMs = 0;
mPendingNotifications.erase(mPendingNotifications.begin());
}
}
void fsCNotificationsGui::initialiseFromVariableTableDo(const fsCVariableTable& pVars)
{
fsIGuiComponent::initialiseFromVariableTableDo(pVars);
positionInit();
}
void fsCNotificationsGui::positionInit()
{
fsCEntity* const bgEnt = parentGet()->childFind("NotificationsGuiBackground");
fsAssert(bgEnt != nullptr, "Expected fsCNotificationsGui to have an entity called 'NotificationsGuiBackground'.\n");
fsISpriteComponent* bgSprComp = bgEnt->spriteComponentGet();
fsAssert(bgSprComp != nullptr, "Expected fsCNotificationsGui background to have a sprite component.\n");
const fsS32 sprHeight = bgSprComp->brushGet()->dimensionsGet().y;
const fsS32 offPosY = -(fsIDisplay::instanceGet()->designCanvasWidthGet() / 2) - (sprHeight / 2);
const fsS32 onPosY = -(fsIDisplay::instanceGet()->designCanvasHeightGet() / 2) + (sprHeight / 2);
mPosYGraph.dataAdd(0, static_cast<fsF32>(offPosY));
mPosYGraph.dataAdd(200, static_cast<fsF32>(onPosY));
mPosYGraph.dataAdd(3000, static_cast<fsF32>(onPosY));
mPosYGraph.dataAdd(200, static_cast<fsF32>(offPosY));
parentGet()->posSet(fsPoint(0, offPosY));
}
void fsCNotificationsGui::create()
{
auto notificationsFile = fsCResourceName("gui/notificationsGui/notificationsGui.gui", fsCResourceName::eRES_LOCATION_ASSETS);
if (!fsIFile::fileExistsGet(notificationsFile)) {
notificationsFile = fsCResourceName("gui/notificationsGui/notificationsGui.txt", fsCResourceName::eRES_LOCATION_ASSETS);
}
if (fsIFile::fileExistsGet(notificationsFile)) {
fsCEntity* myEnt = guiCreateFromFile(notificationsFile);
mInstance = myEnt->componentGet<fsCNotificationsGui>();
fsAssert(mInstance != nullptr, "Expect to find a fsCNotificationsGui after loading notificationsGui.txt\n");
fsCAppCoreMain::instanceGet()->childAddToAppOverlay(myEnt);
}
}
fsCNotificationsGui* fsCNotificationsGui::instanceGet()
{
fsAssert(mInstance != nullptr, "Not created.\n");
return mInstance;
}
fsIComponent* fsCNotificationsGui::create(fsCEntity* pParent)
{
return new fsCNotificationsGui(pParent);
}
fsCNotificationsGui::fsCNotificationsGui(fsCEntity* const pParent) :
fsIGuiComponent(pParent),
mElapsedTimeMs(0),
mActive(false)
{
}
fsCNotificationsGui::~fsCNotificationsGui()
{
}
|