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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293 |
#include "gfCParkHudGui.h"
#include <fsCore/src/fsCUniqueId.h>
#include <fsCore/src/fsCAppSettings.h>
#include <fsCore/src/fsCResourceName.h>
#include <fsCore/fsSColour.h>
#include <fsAppCore/src/fsCAppCoreMain.h>
#include <fsAppCore/src/fsCEntity.h>
#include <fsAppCore/src/fsCEntityFactory.h>
#include <fsAppCore/fsIScene.h>
#include <fsAppCore/src/components/gui/elements/fsCButtonComponent.h>
#include <fsRenderer/src/components/fsISpriteComponent.h>
#include <fsRenderer/src/components/fsITextSpriteComponent.h>
#include "gfCParkCatalogueGui.h"
#include "gfCParkLevelComponent.h"
#include "gfCParkPlacementComponent.h"
#include "gfCParkClearComponent.h"
#include "sim/gfCParkDaySim.h"
#include "sim/gfCDayEconomySim.h"
const fsCUniqueId gfCParkHudGui::mTypeId("gfCParkHudGui");
namespace
{
const fsStr gShopGuiEntityName("ParkCatalogueGui");
const fsStr gPlacerEntityName("placementCursor");
const fsStr gClearPlacerEntityName("clearPlacer");
}
const gfCParkLevelComponent* gfCParkHudGui::parkLevelGet() const
{
if (fsCEntity* const levelEnt =
fsCAppCoreMain::instanceGet()->sceneGet()->firstEntityWithComponentsOfFamilyType<gfCParkLevelComponent>())
{
return levelEnt->firstComponentOfFamilyType<gfCParkLevelComponent>();
}
return nullptr;
}
gfCParkCatalogueGui* gfCParkHudGui::catalogueGuiGetOrCreate()
{
if (fsCEntity* const shopEnt = parentGet()->childFind(gShopGuiEntityName))
{
return shopEnt->firstComponentOfFamilyType<gfCParkCatalogueGui>();
}
fsCEntity* const shopEnt = fsIGuiComponent::guiCreateFromFile(fsCResourceName(
fsCAppCoreMain::instanceGet()->settingsGet()->strGet("shopGui"),
fsCResourceName::eRES_LOCATION_ASSETS));
parentGet()->childAdd(shopEnt);
return shopEnt->firstComponentOfFamilyType<gfCParkCatalogueGui>();
}
void gfCParkHudGui::buildModeSet(fsBool pEnabled)
{
mBuildMode = pEnabled;
// Build and clear are one-at-a-time tools; arming build cancels any clear.
if (pEnabled)
{
clearModeSet(false);
}
if (fsCEntity* const menuEnt = parentGet()->childFind("shopButton"))
{
if (fsISpriteComponent* const sprite = menuEnt->spriteComponentGet())
{
sprite->colourSet(pEnabled
? fsSColour4B(255, 220, 140, 255)
: fsSColour4B::fsWHITE());
}
}
if (pEnabled)
{
// The catalogue root is the category row. Descending into it refreshes
// these same buttons, ensuring only one hierarchy level is ever visible.
catalogueGuiGetOrCreate();
return;
}
// Closing build mode cancels the armed placement tool without charging for
// an unplaced item, then removes the floating catalogue buttons.
fsIScene* const scene = fsCAppCoreMain::instanceGet()->sceneGet();
if (fsCEntity* const levelEnt =
scene->firstEntityWithComponentsOfFamilyType<gfCParkLevelComponent>())
{
if (fsCEntity* const placerEnt = levelEnt->childFind(gPlacerEntityName))
{
if (gfCParkPlacementComponent* const placement =
placerEnt->firstComponentOfFamilyType<gfCParkPlacementComponent>())
{
placement->placementEnd();
}
}
}
if (fsCEntity* const shopEnt = parentGet()->childFind(gShopGuiEntityName))
{
shopEnt->destroy();
}
}
void gfCParkHudGui::clearModeSet(fsBool pEnabled)
{
mClearMode = pEnabled;
if (fsCEntity* const clearButtonEnt = parentGet()->childFind("clearButton"))
{
if (fsISpriteComponent* const sprite = clearButtonEnt->spriteComponentGet())
{
sprite->colourSet(pEnabled
? fsSColour4B(150, 235, 150, 255)
: fsSColour4B::fsWHITE());
}
}
// The per-cell cost is only meaningful while the tool is armed - otherwise
// the player has no way to know what clearing forest costs before trying it.
fsCEntity* const costEnt = parentGet()->childFind("clearCostText");
if (costEnt)
{
costEnt->visibleSet(pEnabled);
}
fsIScene* const scene = fsCAppCoreMain::instanceGet()->sceneGet();
fsCEntity* const levelEnt =
scene->firstEntityWithComponentsOfFamilyType<gfCParkLevelComponent>();
if (!levelEnt)
{
return;
}
if (pEnabled)
{
// Arming clear closes build mode (and its catalogue) so only one tool runs.
buildModeSet(false);
if (costEnt)
{
if (gfCParkLevelComponent* const parkLevel =<--- Variable 'parkLevel' can be declared as pointer to const
levelEnt->firstComponentOfFamilyType<gfCParkLevelComponent>())
{
costEnt->textComponentGet()->textSet(
fsStr(parkLevel->forestClearCostGet()) + " coins/tile");
}
}
fsCEntity* clearPlacerEnt = levelEnt->childFind(gClearPlacerEntityName);
if (!clearPlacerEnt)
{
clearPlacerEnt = levelEnt->entityFactoryGet()->emptyEntityCreate(gClearPlacerEntityName);
levelEnt->childAdd(clearPlacerEnt);
}
gfCParkClearComponent* clearTool =
clearPlacerEnt->firstComponentOfFamilyType<gfCParkClearComponent>();
if (!clearTool)
{
clearTool = clearPlacerEnt->componentAdd<gfCParkClearComponent>();
}
clearTool->clearBegin();
return;
}
// Disarming: tear down the clear tool (its host entity goes with it).
if (fsCEntity* const clearPlacerEnt = levelEnt->childFind(gClearPlacerEntityName))
{
if (gfCParkClearComponent* const clearTool =
clearPlacerEnt->firstComponentOfFamilyType<gfCParkClearComponent>())
{
clearTool->clearEnd();
}
}
}
void gfCParkHudGui::initialiseFromVariableTableDo(const fsCVariableTable& pVars)
{
fsIGuiComponent::initialiseFromVariableTableDo(pVars);
buildModeSet(false);
// Cost readout only makes sense once the clear tool is armed - see clearModeSet.
if (fsCEntity* const costEnt = parentGet()->childFind("clearCostText"))
{
costEnt->visibleSet(false);
}
}
void gfCParkHudGui::updateDo(fsS32 pDeltaMs)
{
const gfCParkLevelComponent* const parkLevel = parkLevelGet();
if (!parkLevel)
{
return;
}
if (fsCEntity* const dayTimerEnt = parentGet()->childFind("dayTimerText"))
{
const fsS32 secondsRemaining = parkLevel->dayRemainingMsGet() / 1000;
dayTimerEnt->textComponentGet()->textSet(fsStr(secondsRemaining));
}
if (fsCEntity* const dayEnt = parentGet()->childFind("dayText"))
{
dayEnt->textComponentGet()->textSet(fsStr(parkLevel->dayIndexGet()));
}
if (const gfCParkDaySim* const sim = parkLevel->simGet())
{
if (fsCEntity* const coinsEnt = parentGet()->childFind("coinsText"))
{
coinsEnt->textComponentGet()->textSet(fsStr(sim->economyGet().coinsGet()));
}
if (fsCEntity* const staffEnt = parentGet()->childFind("staffText"))
{
staffEnt->textComponentGet()->textSet(
fsStr("Kiosk ") + fsStr(sim->staffAvailableGet()) + "/" + fsStr(sim->staffTotalGet())
+ " Food " + fsStr(sim->staffAvailableGet(gfCParkDaySim::mStaffTypeFood))
+ "/" + fsStr(sim->staffTotalGet(gfCParkDaySim::mStaffTypeFood)));
}
if (fsCEntity* const visitorsEnt = parentGet()->childFind("visitorsText"))
{
visitorsEnt->textComponentGet()->textSet(
fsStr("Visitors ") + fsStr(sim->guestsSpawnedGet())
+ "/" + fsStr(sim->visitorArrivalTargetGet()));
}
if (fsCEntity* const demandEnt = parentGet()->childFind("parkDemandText"))
{
demandEnt->textComponentGet()->textSet(
fsStr("Demand ") + fsStr(sim->visitorDemandGet())
+ " Cap " + fsStr(sim->visitorQuotaGet()));
}
if (fsCEntity* const reputationEnt = parentGet()->childFind("parkReputationText"))
{
reputationEnt->textComponentGet()->textSet(
fsStr("Reputation ") + fsStr(parkLevel->parkReputationGet()) + "%");
}
if (fsCEntity* const comfortEnt = parentGet()->childFind("parkComfortText"))
{
comfortEnt->textComponentGet()->textSet(
fsStr("Walking comfort ")
+ fsStr(sim->walkingSatisfactionPercentGet()) + "%");
}
if (fsCEntity* const satisfactionEnt = parentGet()->childFind("parkSatisfactionText"))
{
satisfactionEnt->textComponentGet()->textSet(
fsStr("Today ")
+ fsStr(sim->economyGet().satisfactionAveragePercentGet()) + "%");
}
}
}
fsBool gfCParkHudGui::onButtonClicked(fsCButtonComponent* pButtonComp)
{
const fsStr& buttonName = pButtonComp->parentGet()->nameGet();
if ("shopButton" == buttonName)
{
buildModeSet(!mBuildMode);
return true;
}
if ("clearButton" == buttonName)
{
clearModeSet(!mClearMode);
return true;
}
return fsIGuiComponent::onButtonClicked(pButtonComp);
}
fsIComponent* const gfCParkHudGui::create(fsCEntity* const pParent)
{
return new gfCParkHudGui(pParent);
}
gfCParkHudGui::gfCParkHudGui(fsCEntity* const pParent):
fsIGuiComponent(pParent),
mBuildMode(false),
mClearMode(false)
{
}
gfCParkHudGui::~gfCParkHudGui()
{
}
|