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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
#include "stdafx.h"
#include "UIGroup.h"
#include "UI.h"
UIGroup::UIGroup(EUIGroup group, int iPad)
{
m_group = group;
m_iPad = iPad;
m_bMenuDisplayed = false;
m_bPauseMenuDisplayed = false;
m_bContainerMenuDisplayed = false;
m_bIgnoreAutosaveMenuDisplayed = false;
m_bIgnorePlayerJoinMenuDisplayed = false;
m_updateFocusStateCountdown = 0;
m_viewportType = C4JRender::VIEWPORT_TYPE_FULLSCREEN;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_layers[i] = new UILayer(this);
#ifdef __PSVITA__
m_layers[i]->m_iLayer=(EUILayer)i;
#endif
}
m_tooltips = (UIComponent_Tooltips *)m_layers[static_cast<int>(eUILayer_Tooltips)]->addComponent(0, eUIComponent_Tooltips);
m_tutorialPopup = nullptr;
m_hud = nullptr;
m_pressStartToPlay = nullptr;
if(m_group != eUIGroup_Fullscreen)
{
m_tutorialPopup = (UIComponent_TutorialPopup *)m_layers[static_cast<int>(eUILayer_Popup)]->addComponent(m_iPad, eUIComponent_TutorialPopup);
m_hud = (UIScene_HUD *)m_layers[static_cast<int>(eUILayer_HUD)]->addComponent(m_iPad, eUIScene_HUD);
//m_layers[(int)eUILayer_Chat]->addComponent(m_iPad, eUIComponent_Chat);
}
else
{
m_pressStartToPlay = (UIComponent_PressStartToPlay *)m_layers[static_cast<int>(eUILayer_Tooltips)]->addComponent(0, eUIComponent_PressStartToPlay);
}
// 4J Stu - Pre-allocate this for cached rendering in scenes. It's horribly slow to do dynamically, but we should only need one
// per group as we will only be displaying one of these types of scenes at a time
m_commandBufferList = MemoryTracker::genLists(1);
}
void UIGroup::DestroyAll()
{
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_layers[i]->DestroyAll();
}
}
void UIGroup::ReloadAll()
{
// We only need to reload things when they are likely to be rendered
int highestRenderable = 0;
for(; highestRenderable < eUILayer_COUNT; ++highestRenderable)
{
if(m_layers[highestRenderable]->hidesLowerScenes()) break;
}
if(highestRenderable < eUILayer_Fullscreen) highestRenderable = eUILayer_Fullscreen;
for(; highestRenderable >= 0; --highestRenderable)
{
if(highestRenderable < eUILayer_COUNT) m_layers[highestRenderable]->ReloadAll(highestRenderable != static_cast<int>(eUILayer_Fullscreen));
}
}
void UIGroup::tick()
{
// Ignore this group if the player isn't signed in
if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_layers[i]->tick();
// TODO: May wish to ignore ticking other layers here based on current layer
}
// Handle deferred update focus
if (m_updateFocusStateCountdown > 0)
{
m_updateFocusStateCountdown--;
if (m_updateFocusStateCountdown == 0)_UpdateFocusState();
}
}
void UIGroup::render()
{
// Ignore this group if the player isn't signed in
if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return;
S32 width = 0;
S32 height = 0;
ui.getRenderDimensions(m_viewportType, width, height);
int highestRenderable = 0;
for(; highestRenderable < eUILayer_COUNT; ++highestRenderable)
{
if(m_layers[highestRenderable]->hidesLowerScenes()) break;
}
for(; highestRenderable >= 0; --highestRenderable)
{
if(highestRenderable < eUILayer_COUNT) m_layers[highestRenderable]->render(width, height,m_viewportType);
}
}
bool UIGroup::hidesLowerScenes()
{
// Ignore this group if the player isn't signed in
if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return false;
bool hidesScenes = false;
for(int i = eUILayer_COUNT - 1; i >= 0; --i)
{
hidesScenes = m_layers[i]->hidesLowerScenes();
if(hidesScenes) break;
}
return hidesScenes;
}
void UIGroup::getRenderDimensions(S32 &width, S32 &height)
{
ui.getRenderDimensions(m_viewportType, width, height);
}
// NAVIGATION
bool UIGroup::NavigateToScene(int iPad, EUIScene scene, void *initData, EUILayer layer)
{
bool succeeded = m_layers[static_cast<int>(layer)]->NavigateToScene(iPad, scene, initData);
updateStackStates();
return succeeded;
}
bool UIGroup::NavigateBack(int iPad, EUIScene eScene, EUILayer eLayer)
{
// Keep navigating back on every layer until we hit the target scene
bool foundTarget = false;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
if(eLayer < eUILayer_COUNT && eLayer != i) continue;
foundTarget = m_layers[i]->NavigateBack(iPad, eScene);
if(foundTarget) break;
}
updateStackStates();
return foundTarget;
}
void UIGroup::closeAllScenes()
{
Minecraft *pMinecraft = Minecraft::GetInstance();
if( m_iPad >= 0 )
{
if(pMinecraft != nullptr && pMinecraft->localgameModes[m_iPad] != nullptr )
{
TutorialMode *gameMode = static_cast<TutorialMode *>(pMinecraft->localgameModes[m_iPad]);
// This just allows it to be shown
gameMode->getTutorial()->showTutorialPopup(true);
}
}
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
// Ignore the error layer
if(i != static_cast<int>(eUILayer_Error)) m_layers[i]->closeAllScenes();
}
updateStackStates();
}
UIScene *UIGroup::GetTopScene(EUILayer layer)
{
return m_layers[static_cast<int>(layer)]->GetTopScene();
}
bool UIGroup::GetMenuDisplayed()
{
return m_bMenuDisplayed;
}
bool UIGroup::IsSceneInStack(EUIScene scene)
{
bool found = false;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
found = m_layers[i]->IsSceneInStack(scene);
if(found) break;
}
return found;
}
bool UIGroup::HasFocus(int iPad)
{
bool hasFocus = false;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
if( m_layers[i]->m_hasFocus)
{
if(m_layers[i]->HasFocus(iPad))
{
hasFocus = true;
}
break;
}
}
return hasFocus;
}
#ifdef __PSVITA__
UIScene *UIGroup::getCurrentScene()
{
UIScene *pScene;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
pScene=m_layers[i]->getCurrentScene();
if(pScene!=nullptr) return pScene;
}
return nullptr;
}
#endif
// INPUT
void UIGroup::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
{
// Ignore this group if the player isn't signed in
if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_layers[i]->handleInput(iPad, key, repeat, pressed, released, handled);
if(handled) break;
}
}
// FOCUS
// Check that a layer may recieve focus, specifically that there is no infocus layer above
bool UIGroup::RequestFocus(UILayer* layerPtr)
{
// Find the layer
unsigned int layerIndex = GetLayerIndex(layerPtr);
// Top layer is always allowed focus
if (layerIndex == 0) return true;
// Check layers above to see if any of them have focus
for (int i = layerIndex-1; i >= 0; i--)
{
if (m_layers[i]->m_hasFocus) return false;
}
return true;
}
void UIGroup::showComponent(int iPad, EUIScene scene, EUILayer layer, bool show)
{
m_layers[layer]->showComponent(iPad, scene, show);
}
UIScene *UIGroup::addComponent(int iPad, EUIScene scene, EUILayer layer)
{
return m_layers[layer]->addComponent(iPad, scene);
}
void UIGroup::removeComponent(EUIScene scene, EUILayer layer)
{
m_layers[layer]->removeComponent(scene);
}
void UIGroup::SetViewportType(C4JRender::eViewportType type)
{
if(m_viewportType != type)
{
m_viewportType = type;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_layers[i]->ReloadAll(true);
}
}
}
C4JRender::eViewportType UIGroup::GetViewportType()
{
return m_viewportType;
}
void UIGroup::HandleDLCMountingComplete()
{
// Ignore this group if the player isn't signed in
if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
app.DebugPrintf("UIGroup::HandleDLCMountingComplete - m_layers[%d]\n",i);
m_layers[i]->HandleDLCMountingComplete();
}
}
void UIGroup::HandleDLCInstalled()
{
// Ignore this group if the player isn't signed in
if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_layers[i]->HandleDLCInstalled();
}
}
#ifdef _XBOX_ONE
void UIGroup::HandleDLCLicenseChange()
{
// Ignore this group if the player isn't signed in
if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_layers[i]->HandleDLCLicenseChange();
}
}
#endif
void UIGroup::HandleMessage(EUIMessage message, void *data)
{
// Ignore this group if the player isn't signed in
if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_layers[i]->HandleMessage(message, data);
}
}
bool UIGroup::IsFullscreenGroup()
{
return m_group == eUIGroup_Fullscreen;
}
void UIGroup::handleUnlockFullVersion()
{
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_layers[i]->handleUnlockFullVersion();
}
}
void UIGroup::updateStackStates()
{
m_bMenuDisplayed = false;
m_bPauseMenuDisplayed = false;
m_bContainerMenuDisplayed = false;
m_bIgnoreAutosaveMenuDisplayed = false;
m_bIgnorePlayerJoinMenuDisplayed = false;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
m_bMenuDisplayed = m_bMenuDisplayed || m_layers[i]->m_bMenuDisplayed;
m_bPauseMenuDisplayed = m_bPauseMenuDisplayed || m_layers[i]->m_bPauseMenuDisplayed;
m_bContainerMenuDisplayed = m_bContainerMenuDisplayed || m_layers[i]->m_bContainerMenuDisplayed;
m_bIgnoreAutosaveMenuDisplayed = m_bIgnoreAutosaveMenuDisplayed || m_layers[i]->m_bIgnoreAutosaveMenuDisplayed;
m_bIgnorePlayerJoinMenuDisplayed = m_bIgnorePlayerJoinMenuDisplayed || m_layers[i]->m_bIgnorePlayerJoinMenuDisplayed;
}
}
// Defer update focus till for 10 UI ticks
void UIGroup::UpdateFocusState()
{
m_updateFocusStateCountdown = 10;
}
// Pass focus to uppermost layer that accepts focus
void UIGroup::_UpdateFocusState()
{
bool groupFocusSet = false;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
groupFocusSet = m_layers[i]->updateFocusState(true);
if (groupFocusSet) break;
}
}
// Get the index of the layer
unsigned int UIGroup::GetLayerIndex(UILayer* layerPtr)
{
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
if (m_layers[i] == layerPtr) return i;
}
// can't get here...
return 0;
}
void UIGroup::PrintTotalMemoryUsage(int64_t &totalStatic, int64_t &totalDynamic)
{
int64_t groupStatic = 0;
int64_t groupDynamic = 0;
app.DebugPrintf(app.USER_SR, "-- BEGIN GROUP %d\n",m_group);
for(unsigned int i = 0; i < eUILayer_COUNT; ++i)
{
app.DebugPrintf(app.USER_SR, " \\- BEGIN LAYER %d\n",i);
m_layers[i]->PrintTotalMemoryUsage(groupStatic, groupDynamic);
app.DebugPrintf(app.USER_SR, " \\- END LAYER %d\n",i);
}
app.DebugPrintf(app.USER_SR, "-- Group static: %d, Group dynamic: %d\n", groupStatic, groupDynamic);
totalStatic += groupStatic;
totalDynamic += groupDynamic;
app.DebugPrintf(app.USER_SR, "-- END GROUP %d\n",m_group);
}
int UIGroup::getCommandBufferList()
{
return m_commandBufferList;
}
// Returns the first scene of given type if it exists, nullptr otherwise
UIScene *UIGroup::FindScene(EUIScene sceneType)
{
UIScene *pScene = nullptr;
for (int i = 0; i < eUILayer_COUNT; i++)
{
pScene = m_layers[i]->FindScene(sceneType);
#ifdef __PS3__
if (pScene != nullptr) return pScene;
#else
if (pScene != nullptr) return pScene;
#endif
}
return pScene;
}
|