the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "UI.h"
3#include "UIScene.h"
4
5#include "..\..\Lighting.h"
6#include "..\..\LocalPlayer.h"
7#include "..\..\ItemRenderer.h"
8#include "..\..\..\Minecraft.World\net.minecraft.world.item.h"
9
10UIScene::UIScene(int iPad, UILayer *parentLayer)
11{
12 m_parentLayer = parentLayer;
13 m_iPad = iPad;
14 swf = NULL;
15 m_pItemRenderer = NULL;
16
17 bHasFocus = false;
18 m_hasTickedOnce = false;
19 m_bFocussedOnce = false;
20 m_bVisible = true;
21 m_bCanHandleInput = false;
22 m_bIsReloading = false;
23
24 m_iFocusControl = -1;
25 m_iFocusChild = 0;
26 m_lastOpacity = 1.0f;
27 m_bUpdateOpacity = false;
28
29 m_backScene = NULL;
30
31 m_cacheSlotRenders = false;
32 m_needsCacheRendered = true;
33 m_expectedCachedSlotCount = 0;
34 m_callbackUniqueId = 0;
35}
36
37UIScene::~UIScene()
38{
39 /* Destroy the Iggy player. */
40 IggyPlayerDestroy( swf );
41
42 for(AUTO_VAR(it,m_registeredTextures.begin()); it != m_registeredTextures.end(); ++it)
43 {
44 ui.unregisterSubstitutionTexture( it->first, it->second );
45 }
46
47 if(m_callbackUniqueId != 0)
48 {
49 ui.UnregisterCallbackId(m_callbackUniqueId);
50 }
51
52 if(m_pItemRenderer != NULL) delete m_pItemRenderer;
53}
54
55void UIScene::destroyMovie()
56{
57 /* Destroy the Iggy player. */
58 IggyPlayerDestroy( swf );
59 swf = NULL;
60
61 // Clear out the controls collection (doesn't delete the controls, and they get re-setup later)
62 m_controls.clear();
63
64 // Clear out all the fast names for the current movie
65 m_fastNames.clear();
66}
67
68void UIScene::reloadMovie(bool force)
69{
70 if(!force && (stealsFocus() && (getSceneType() != eUIScene_FullscreenProgress && !bHasFocus))) return;
71
72 m_bIsReloading = true;
73 if(swf)
74 {
75 /* Destroy the Iggy player. */
76 IggyPlayerDestroy( swf );
77
78 // Clear out the controls collection (doesn't delete the controls, and they get re-setup later)
79 m_controls.clear();
80
81 // Clear out all the fast names for the current movie
82 m_fastNames.clear();
83 }
84
85 // Reload everything
86 initialiseMovie();
87
88 handlePreReload();
89
90 // Reload controls
91 for(AUTO_VAR(it, m_controls.begin()); it != m_controls.end(); ++it)
92 {
93 (*it)->ReInit();
94 }
95
96 updateComponents();
97 handleReload();
98
99 IggyDataValue result;
100 IggyDataValue value[1];
101
102 value[0].type = IGGY_DATATYPE_number;
103 value[0].number = m_iFocusControl;
104
105 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetFocus , 1 , value );
106
107 m_needsCacheRendered = true;
108 m_bIsReloading = false;
109}
110
111bool UIScene::needsReloaded()
112{
113 return !swf && (!stealsFocus() || bHasFocus);
114}
115
116bool UIScene::hasMovie()
117{
118 return swf != NULL;
119}
120
121F64 UIScene::getSafeZoneHalfHeight()
122{
123 float height = ui.getScreenHeight();
124
125 float safeHeight = 0.0f;
126
127#ifndef __PSVITA__
128 if( !RenderManager.IsHiDef() && RenderManager.IsWidescreen() )
129 {
130 // 90% safezone
131 safeHeight = height * (0.15f / 2);
132 }
133 else
134 {
135 // 90% safezone
136 safeHeight = height * (0.1f / 2);
137 }
138#endif
139 return safeHeight;
140}
141
142F64 UIScene::getSafeZoneHalfWidth()
143{
144 float width = ui.getScreenWidth();
145
146 float safeWidth = 0.0f;
147#ifndef __PSVITA__
148 if( !RenderManager.IsHiDef() && RenderManager.IsWidescreen() )
149 {
150 // 85% safezone
151 safeWidth = width * (0.15f / 2);
152 }
153 else
154 {
155 // 90% safezone
156 safeWidth = width * (0.1f / 2);
157 }
158#endif
159 return safeWidth;
160}
161
162void UIScene::updateSafeZone()
163{
164 // Distance from edge
165 F64 safeTop = 0.0;
166 F64 safeBottom = 0.0;
167 F64 safeLeft = 0.0;
168 F64 safeRight = 0.0;
169
170 switch( m_parentLayer->getViewport() )
171 {
172 case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
173 safeTop = getSafeZoneHalfHeight();
174 break;
175 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
176 safeBottom = getSafeZoneHalfHeight();
177 break;
178 case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT:
179 safeLeft = getSafeZoneHalfWidth();
180 break;
181 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT:
182 safeRight = getSafeZoneHalfWidth();
183 break;
184 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT:
185 safeTop = getSafeZoneHalfHeight();
186 safeLeft = getSafeZoneHalfWidth();
187 break;
188 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
189 safeTop = getSafeZoneHalfHeight();
190 safeRight = getSafeZoneHalfWidth();
191 break;
192 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT:
193 safeBottom = getSafeZoneHalfHeight();
194 safeLeft = getSafeZoneHalfWidth();
195 break;
196 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT:
197 safeBottom = getSafeZoneHalfHeight();
198 safeRight = getSafeZoneHalfWidth();
199 break;
200 case C4JRender::VIEWPORT_TYPE_FULLSCREEN:
201 default:
202 safeTop = getSafeZoneHalfHeight();
203 safeBottom = getSafeZoneHalfHeight();
204 safeLeft = getSafeZoneHalfWidth();
205 safeRight = getSafeZoneHalfWidth();
206 break;
207 }
208 setSafeZone(safeTop, safeBottom, safeLeft, safeRight);
209}
210
211void UIScene::setSafeZone(S32 safeTop, S32 safeBottom, S32 safeLeft, S32 safeRight)
212{
213 IggyDataValue result;
214 IggyDataValue value[4];
215
216 value[0].type = IGGY_DATATYPE_number;
217 value[0].number = safeTop;
218 value[1].type = IGGY_DATATYPE_number;
219 value[1].number = safeBottom;
220 value[2].type = IGGY_DATATYPE_number;
221 value[2].number = safeLeft;
222 value[3].type = IGGY_DATATYPE_number;
223 value[3].number = safeRight;
224 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetSafeZone , 4 , value );
225}
226
227void UIScene::initialiseMovie()
228{
229 loadMovie();
230 mapElementsAndNames();
231
232 updateSafeZone();
233
234 m_bUpdateOpacity = true;
235}
236
237#ifdef __PSVITA__
238void UIScene::SetFocusToElement(int iID)
239{
240 IggyDataValue result;
241 IggyDataValue value[1];
242
243 value[0].type = IGGY_DATATYPE_number;
244 value[0].number = iID;
245
246 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetFocus , 1 , value );
247
248 // also trigger handle focus change (just in case if anything else in relation needs updating!)
249 _handleFocusChange(iID, 0);
250}
251#endif
252
253bool UIScene::mapElementsAndNames()
254{
255 m_rootPath = IggyPlayerRootPath( swf );
256
257 m_funcRemoveObject = registerFastName( L"RemoveObject" );
258 m_funcSlideLeft = registerFastName( L"SlideLeft" );
259 m_funcSlideRight = registerFastName( L"SlideRight" );
260 m_funcSetSafeZone = registerFastName( L"SetSafeZone" );
261 m_funcSetAlpha = registerFastName( L"SetAlpha" );
262 m_funcSetFocus = registerFastName( L"SetFocus" );
263 m_funcHorizontalResizeCheck = registerFastName( L"DoHorizontalResizeCheck");
264 return true;
265}
266
267extern CRITICAL_SECTION s_loadSkinCS;
268void UIScene::loadMovie()
269{
270 EnterCriticalSection(&UIController::ms_reloadSkinCS); // MGH - added to prevent crash loading Iggy movies while the skins were being reloaded
271 wstring moviePath = getMoviePath();
272
273#ifdef __PS3__
274 if(RenderManager.IsWidescreen())
275 {
276 moviePath.append(L"720.swf");
277 m_loadedResolution = eSceneResolution_720;
278 }
279 else
280 {
281 moviePath.append(L"480.swf");
282 m_loadedResolution = eSceneResolution_480;
283 }
284#elif defined __PSVITA__
285 moviePath.append(L"Vita.swf");
286 m_loadedResolution = eSceneResolution_Vita;
287#elif defined _WINDOWS64
288 if(ui.getScreenHeight() == 720)
289 {
290 moviePath.append(L"720.swf");
291 m_loadedResolution = eSceneResolution_720;
292 }
293 else if(ui.getScreenHeight() == 480)
294 {
295 moviePath.append(L"480.swf");
296 m_loadedResolution = eSceneResolution_480;
297 }
298 else if(ui.getScreenHeight() < 720)
299 {
300 moviePath.append(L"Vita.swf");
301 m_loadedResolution = eSceneResolution_Vita;
302 }
303 else
304 {
305 moviePath.append(L"1080.swf");
306 m_loadedResolution = eSceneResolution_1080;
307 }
308#else
309 moviePath.append(L"1080.swf");
310 m_loadedResolution = eSceneResolution_1080;
311#endif
312
313 if(!app.hasArchiveFile(moviePath))
314 {
315 app.DebugPrintf("WARNING: Could not find iggy movie %ls, falling back on 720\n", moviePath.c_str());
316
317 moviePath = getMoviePath();
318 moviePath.append(L"720.swf");
319 m_loadedResolution = eSceneResolution_720;
320
321 if(!app.hasArchiveFile(moviePath))
322 {
323 app.DebugPrintf("ERROR: Could not find any iggy movie for %ls!\n", moviePath.c_str());
324#ifndef _CONTENT_PACKAGE
325 __debugbreak();
326#endif
327 app.FatalLoadError();
328 }
329 }
330
331 byteArray baFile = ui.getMovieData(moviePath.c_str());
332 __int64 beforeLoad = ui.iggyAllocCount;
333 swf = IggyPlayerCreateFromMemory ( baFile.data , baFile.length, NULL);
334 __int64 afterLoad = ui.iggyAllocCount;
335 IggyPlayerInitializeAndTickRS ( swf );
336 __int64 afterTick = ui.iggyAllocCount;
337
338 if(!swf)
339 {
340 app.DebugPrintf("ERROR: Failed to load iggy scene!\n");
341#ifndef _CONTENT_PACKAGE
342 __debugbreak();
343#endif
344 app.FatalLoadError();
345 }
346 app.DebugPrintf( app.USER_SR, "Loaded iggy movie %ls\n", moviePath.c_str() );
347 IggyProperties *properties = IggyPlayerProperties ( swf );
348 m_movieHeight = properties->movie_height_in_pixels;
349 m_movieWidth = properties->movie_width_in_pixels;
350
351 m_renderWidth = m_movieWidth;
352 m_renderHeight = m_movieHeight;
353
354 S32 width, height;
355 m_parentLayer->getRenderDimensions(width, height);
356 IggyPlayerSetDisplaySize( swf, width, height );
357
358 IggyPlayerSetUserdata(swf,this);
359
360//#ifdef _DEBUG
361#if 0
362 IggyMemoryUseInfo memoryInfo;
363 rrbool res;
364 int iteration = 0;
365 __int64 totalStatic = 0;
366 __int64 totalDynamic = 0;
367 while(res = IggyDebugGetMemoryUseInfo ( swf ,
368 NULL ,
369 0 ,
370 0 ,
371 iteration ,
372 &memoryInfo ))
373 {
374 totalStatic += memoryInfo.static_allocation_bytes;
375 totalDynamic += memoryInfo.dynamic_allocation_bytes;
376 app.DebugPrintf(app.USER_SR, "%ls - %.*s static: %d ( %d ) dynamic: %d ( %d )\n", moviePath.c_str(), memoryInfo.subcategory_stringlen, memoryInfo.subcategory,
377 memoryInfo.static_allocation_bytes, memoryInfo.static_allocation_count, memoryInfo.dynamic_allocation_bytes, memoryInfo.dynamic_allocation_count);
378 ++iteration;
379 //if(memoryInfo.static_allocation_bytes > 0) getDebugMemoryUseRecursive(moviePath, memoryInfo);
380
381 }
382
383 app.DebugPrintf(app.USER_SR, "%ls - Total: %d, Expected: %d, Diff: %d\n", moviePath.c_str(), totalStatic + totalDynamic, afterTick - beforeLoad, (afterTick - beforeLoad) - (totalStatic + totalDynamic));
384
385#endif
386 LeaveCriticalSection(&UIController::ms_reloadSkinCS);
387
388}
389
390void UIScene::getDebugMemoryUseRecursive(const wstring &moviePath, IggyMemoryUseInfo &memoryInfo)
391{
392 rrbool res;
393 IggyMemoryUseInfo internalMemoryInfo;
394 int internalIteration = 0;
395 while(res = IggyDebugGetMemoryUseInfo ( swf ,
396 NULL ,
397 memoryInfo.subcategory ,
398 memoryInfo.subcategory_stringlen ,
399 internalIteration ,
400 &internalMemoryInfo ))
401 {
402 app.DebugPrintf(app.USER_SR, "%ls - %.*s static: %d ( %d ) dynamic: %d ( %d )\n", moviePath.c_str(), internalMemoryInfo.subcategory_stringlen, internalMemoryInfo.subcategory,
403 internalMemoryInfo.static_allocation_bytes, internalMemoryInfo.static_allocation_count, internalMemoryInfo.dynamic_allocation_bytes, internalMemoryInfo.dynamic_allocation_count);
404 ++internalIteration;
405 if(internalMemoryInfo.subcategory_stringlen > memoryInfo.subcategory_stringlen) getDebugMemoryUseRecursive(moviePath, internalMemoryInfo);
406 }
407}
408
409void UIScene::PrintTotalMemoryUsage(__int64 &totalStatic, __int64 &totalDynamic)
410{
411 if(!swf) return;
412
413 IggyMemoryUseInfo memoryInfo;
414 rrbool res;
415 int iteration = 0;
416 __int64 sceneStatic = 0;
417 __int64 sceneDynamic = 0;
418 while(res = IggyDebugGetMemoryUseInfo ( swf ,
419 NULL ,
420 "" ,
421 0 ,
422 iteration ,
423 &memoryInfo ))
424 {
425 sceneStatic += memoryInfo.static_allocation_bytes;
426 sceneDynamic += memoryInfo.dynamic_allocation_bytes;
427 totalStatic += memoryInfo.static_allocation_bytes;
428 totalDynamic += memoryInfo.dynamic_allocation_bytes;
429 ++iteration;
430
431 }
432
433 app.DebugPrintf(app.USER_SR, " \\- Scene static: %d , Scene dynamic: %d , Total: %d - %ls\n", sceneStatic, sceneDynamic, sceneStatic + sceneDynamic, getMoviePath().c_str());
434}
435
436void UIScene::tick()
437{
438 if(m_bIsReloading) return;
439 if(m_hasTickedOnce) m_bCanHandleInput = true;
440 while(IggyPlayerReadyToTick( swf ))
441 {
442 tickTimers();
443 for(AUTO_VAR(it, m_controls.begin()); it != m_controls.end(); ++it)
444 {
445 (*it)->tick();
446 }
447 IggyPlayerTickRS( swf );
448 m_hasTickedOnce = true;
449 }
450}
451
452UIControl* UIScene::GetMainPanel()
453{
454 return NULL;
455}
456
457
458void UIScene::addTimer(int id, int ms)
459{
460 int currentTime = System::currentTimeMillis();
461
462 TimerInfo info;
463 info.running = true;
464 info.duration = ms;
465 info.targetTime = currentTime + ms;
466 m_timers[id] = info;
467}
468
469void UIScene::killTimer(int id)
470{
471 AUTO_VAR(it, m_timers.find(id));
472 if(it != m_timers.end())
473 {
474 it->second.running = false;
475 }
476}
477
478void UIScene::tickTimers()
479{
480 int currentTime = System::currentTimeMillis();
481 for(AUTO_VAR(it, m_timers.begin()); it != m_timers.end();)
482 {
483 if(!it->second.running)
484 {
485 it = m_timers.erase(it);
486 }
487 else
488 {
489 if(currentTime > it->second.targetTime)
490 {
491 handleTimerComplete(it->first);
492
493 // Auto-restart
494 it->second.targetTime = it->second.duration + currentTime;
495 }
496 ++it;
497 }
498 }
499}
500
501IggyName UIScene::registerFastName(const wstring &name)
502{
503 IggyName var;
504 AUTO_VAR(it,m_fastNames.find(name));
505 if(it != m_fastNames.end())
506 {
507 var = it->second;
508 }
509 else
510 {
511 var = IggyPlayerCreateFastName ( getMovie() , (IggyUTF16 *)name.c_str() , -1 );
512 m_fastNames[name] = var;
513 }
514 return var;
515}
516
517void UIScene::removeControl( UIControl_Base *control, bool centreScene)
518{
519 IggyDataValue result;
520 IggyDataValue value[2];
521
522 string name = control->getControlName();
523 IggyStringUTF8 stringVal;
524 stringVal.string = (char*)name.c_str();
525 stringVal.length = name.length();
526 value[0].type = IGGY_DATATYPE_string_UTF8;
527 value[0].string8 = stringVal;
528
529 value[1].type = IGGY_DATATYPE_boolean;
530 value[1].boolval = centreScene;
531 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcRemoveObject , 2 , value );
532
533#ifdef __PSVITA__
534 // update the button positions since they may have changed
535 UpdateSceneControls();
536
537 // mark the button as removed
538 control->setHidden(true);
539 // remove it from the touchboxes
540 ui.TouchBoxRebuild(control->getParentScene());
541#endif
542
543}
544
545void UIScene::slideLeft()
546{
547 IggyDataValue result;
548 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSlideLeft , 0 , NULL );
549}
550
551void UIScene::slideRight()
552{
553 IggyDataValue result;
554 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSlideRight , 0 , NULL );
555}
556
557void UIScene::doHorizontalResizeCheck()
558{
559 IggyDataValue result;
560 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcHorizontalResizeCheck , 0 , NULL );
561}
562
563void UIScene::render(S32 width, S32 height, C4JRender::eViewportType viewport)
564{
565 if(m_bIsReloading) return;
566 if(!m_hasTickedOnce || !swf) return;
567 ui.setupRenderPosition(viewport);
568 IggyPlayerSetDisplaySize( swf, width, height );
569 IggyPlayerDraw( swf );
570}
571
572void UIScene::setOpacity(float percent)
573{
574 if(percent != m_lastOpacity || (m_bUpdateOpacity && getMovie()))
575 {
576 m_lastOpacity = percent;
577
578 // 4J-TomK once a scene has been freshly loaded or re-loaded we force update opacity via initialiseMovie
579 if(m_bUpdateOpacity)
580 m_bUpdateOpacity = false;
581
582 IggyDataValue result;
583 IggyDataValue value[1];
584 value[0].type = IGGY_DATATYPE_number;
585 value[0].number = percent;
586
587 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetAlpha , 1 , value );
588 }
589}
590
591void UIScene::setVisible(bool visible)
592{
593 m_bVisible = visible;
594}
595
596void UIScene::customDraw(IggyCustomDrawCallbackRegion *region)
597{
598 app.DebugPrintf("Handling custom draw for scene with no override!\n");
599}
600
601void UIScene::customDrawSlotControl(IggyCustomDrawCallbackRegion *region, int iPad, shared_ptr<ItemInstance> item, float fAlpha, bool isFoil, bool bDecorations)
602{
603 if (item!= NULL)
604 {
605 if(m_cacheSlotRenders)
606 {
607 if( (m_cachedSlotDraw.size() + 1) == m_expectedCachedSlotCount)
608 {
609 //Make sure that pMinecraft->player is the correct player so that player specific rendering
610 // eg clock and compass, are rendered correctly
611 Minecraft *pMinecraft=Minecraft::GetInstance();
612 shared_ptr<MultiplayerLocalPlayer> oldPlayer = pMinecraft->player;
613 if( iPad >= 0 && iPad < XUSER_MAX_COUNT ) pMinecraft->player = pMinecraft->localplayers[iPad];
614
615 // Setup GDraw, normal game render states and matrices
616 //CustomDrawData *customDrawRegion = ui.setupCustomDraw(this,region);
617 PIXBeginNamedEvent(0,"Starting Iggy custom draw\n");
618 CustomDrawData *customDrawRegion = ui.calculateCustomDraw(region);
619 ui.beginIggyCustomDraw4J(region, customDrawRegion);
620 ui.setupCustomDrawGameState();
621
622 int list = m_parentLayer->m_parentGroup->getCommandBufferList();
623
624 bool useCommandBuffers = false;
625#ifdef _XBOX_ONE
626 useCommandBuffers = true;
627
628 // 4J Stu - Temporary until we fix the glint animation which needs updated if we are just replaying a command buffer
629 m_needsCacheRendered = true;
630#endif
631
632 if(!useCommandBuffers || m_needsCacheRendered)
633 {
634#if (!defined __PS3__) && (!defined __PSVITA__)
635 if(useCommandBuffers) RenderManager.CBuffStart(list, true);
636#endif
637 PIXBeginNamedEvent(0,"Draw uncached");
638 ui.setupCustomDrawMatrices(this, customDrawRegion);
639 _customDrawSlotControl(customDrawRegion, iPad, item, fAlpha, isFoil, bDecorations, useCommandBuffers);
640 delete customDrawRegion;
641 PIXEndNamedEvent();
642
643 PIXBeginNamedEvent(0,"Draw all cache");
644 // Draw all the cached slots
645 for(AUTO_VAR(it, m_cachedSlotDraw.begin()); it != m_cachedSlotDraw.end(); ++it)
646 {
647 CachedSlotDrawData *drawData = *it;
648 ui.setupCustomDrawMatrices(this, drawData->customDrawRegion);
649 _customDrawSlotControl(drawData->customDrawRegion, iPad, drawData->item, drawData->fAlpha, drawData->isFoil, drawData->bDecorations, useCommandBuffers);
650 delete drawData->customDrawRegion;
651 delete drawData;
652 }
653 PIXEndNamedEvent();
654#ifndef __PS3__
655 if(useCommandBuffers) RenderManager.CBuffEnd();
656#endif
657 }
658 m_cachedSlotDraw.clear();
659
660#ifndef __PS3__
661 if(useCommandBuffers) RenderManager.CBuffCall(list);
662#endif
663
664 // Finish GDraw and anything else that needs to be finalised
665 ui.endCustomDraw(region);
666
667 pMinecraft->player = oldPlayer;
668 }
669 else
670 {
671 PIXBeginNamedEvent(0,"Caching region");
672 CachedSlotDrawData *drawData = new CachedSlotDrawData();
673 drawData->item = item;
674 drawData->fAlpha = fAlpha;
675 drawData->isFoil = isFoil;
676 drawData->bDecorations = bDecorations;
677 drawData->customDrawRegion = ui.calculateCustomDraw(region);
678
679 m_cachedSlotDraw.push_back(drawData);
680 PIXEndNamedEvent();
681 }
682 }
683 else
684 {
685 // Setup GDraw, normal game render states and matrices
686 CustomDrawData *customDrawRegion = ui.setupCustomDraw(this,region);
687
688 Minecraft *pMinecraft=Minecraft::GetInstance();
689
690 //Make sure that pMinecraft->player is the correct player so that player specific rendering
691 // eg clock and compass, are rendered correctly
692 shared_ptr<MultiplayerLocalPlayer> oldPlayer = pMinecraft->player;
693 if( iPad >= 0 && iPad < XUSER_MAX_COUNT ) pMinecraft->player = pMinecraft->localplayers[iPad];
694
695 _customDrawSlotControl(customDrawRegion, iPad, item, fAlpha, isFoil, bDecorations, false);
696 delete customDrawRegion;
697 pMinecraft->player = oldPlayer;
698
699 // Finish GDraw and anything else that needs to be finalised
700 ui.endCustomDraw(region);
701 }
702 }
703}
704
705void UIScene::_customDrawSlotControl(CustomDrawData *region, int iPad, shared_ptr<ItemInstance> item, float fAlpha, bool isFoil, bool bDecorations, bool usingCommandBuffer)
706{
707 Minecraft *pMinecraft=Minecraft::GetInstance();
708
709 float bwidth,bheight;
710 bwidth = region->x1 - region->x0;
711 bheight = region->y1 - region->y0;
712
713 float x = region->x0;
714 float y = region->y0;
715
716 // Base scale on height of this control, compared to height of what the item renderer normally renders (16 pixels high). Potentially
717 // we might want separate x & y scales here
718
719 float scaleX = bwidth / 16.0f;
720 float scaleY = bheight / 16.0f;
721
722 glEnable(GL_RESCALE_NORMAL);
723 glPushMatrix();
724 glRotatef(120, 1, 0, 0);
725 Lighting::turnOn();
726 glPopMatrix();
727
728 float pop = item->popTime;
729 if (pop > 0)
730 {
731 glPushMatrix();
732 float squeeze = 1 + pop / (float) Inventory::POP_TIME_DURATION;
733 float sx = x;
734 float sy = y;
735 float sxoffs = 8 * scaleX;
736 float syoffs = 12 * scaleY;
737 glTranslatef((float)(sx + sxoffs), (float)(sy + syoffs), 0);
738 glScalef(1 / squeeze, (squeeze + 1) / 2, 1);
739 glTranslatef((float)-(sx + sxoffs), (float)-(sy + syoffs), 0);
740 }
741
742 PIXBeginNamedEvent(0,"Render and decorate");
743 if(m_pItemRenderer == NULL) m_pItemRenderer = new ItemRenderer();
744 RenderManager.StateSetBlendEnable(true);
745 RenderManager.StateSetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
746 RenderManager.StateSetBlendFactor(0xffffffff);
747 m_pItemRenderer->renderAndDecorateItem(pMinecraft->font, pMinecraft->textures, item, x, y,scaleX,scaleY,fAlpha,isFoil,false, !usingCommandBuffer);
748 PIXEndNamedEvent();
749
750 if (pop > 0)
751 {
752 glPopMatrix();
753 }
754
755 if(bDecorations)
756 {
757 if((scaleX!=1.0f) ||(scaleY!=1.0f))
758 {
759 glPushMatrix();
760 glScalef(scaleX, scaleY, 1.0f);
761 int iX= (int)(0.5f+((float)x)/scaleX);
762 int iY= (int)(0.5f+((float)y)/scaleY);
763
764 m_pItemRenderer->renderGuiItemDecorations(pMinecraft->font, pMinecraft->textures, item, iX, iY, fAlpha);
765 glPopMatrix();
766 }
767 else
768 {
769 m_pItemRenderer->renderGuiItemDecorations(pMinecraft->font, pMinecraft->textures, item, (int)x, (int)y, fAlpha);
770 }
771 }
772
773 Lighting::turnOff();
774 glDisable(GL_RESCALE_NORMAL);
775}
776
777// 4J Stu - Not threadsafe
778//void UIScene::navigateForward(int iPad, EUIScene scene, void *initData)
779//{
780// if(m_parentLayer == NULL)
781// {
782// app.DebugPrintf("A scene is trying to navigate forwards, but it's parent layer is NULL!\n");
783//#ifndef _CONTENT_PACKAGE
784// __debugbreak();
785//#endif
786// }
787// else
788// {
789// m_parentLayer->NavigateToScene(iPad,scene,initData);
790// }
791//}
792
793void UIScene::navigateBack()
794{
795 //CD - Added for audio
796 ui.PlayUISFX(eSFX_Back);
797
798 ui.NavigateBack(m_iPad);
799
800 if(m_parentLayer == NULL)
801 {
802// app.DebugPrintf("A scene is trying to navigate back, but it's parent layer is NULL!\n");
803#ifndef _CONTENT_PACKAGE
804// __debugbreak();
805#endif
806 }
807 else
808 {
809// m_parentLayer->removeScene(this);
810
811#ifdef _DURANGO
812 if (ui.GetTopScene(0))
813 InputManager.SetEnabledGtcButtons( ui.GetTopScene(0)->getDefaultGtcButtons() );
814#endif
815 }
816
817}
818
819void UIScene::gainFocus()
820{
821 if( !bHasFocus && stealsFocus() )
822 {
823 // 4J Stu - Don't do this
824 /*
825 IggyEvent event;
826 IggyMakeEventFocusGained( &event , 0);
827
828 IggyEventResult result;
829 IggyPlayerDispatchEventRS( getMovie() , &event , &result );
830
831 app.DebugPrintf("Sent gain focus event to scene\n");
832 */
833 bHasFocus = true;
834 if(needsReloaded())
835 {
836 reloadMovie();
837 }
838
839 updateTooltips();
840 updateComponents();
841
842 if(!m_bFocussedOnce)
843 {
844 IggyDataValue result;
845 IggyDataValue value[1];
846
847 value[0].type = IGGY_DATATYPE_number;
848 value[0].number = -1;
849
850 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetFocus , 1 , value );
851 }
852
853 handleGainFocus(m_bFocussedOnce);
854 if(bHasFocus) m_bFocussedOnce = true;
855 }
856 else if(bHasFocus && stealsFocus())
857 {
858 updateTooltips();
859 }
860}
861
862void UIScene::loseFocus()
863{
864 if(bHasFocus)
865 {
866 // 4J Stu - Don't do this
867 /*
868 IggyEvent event;
869 IggyMakeEventFocusLost( &event );
870 IggyEventResult result;
871 IggyPlayerDispatchEventRS ( getMovie() , &event , &result );
872 */
873
874 app.DebugPrintf("Sent lose focus event to scene\n");
875 bHasFocus = false;
876 handleLoseFocus();
877 }
878}
879
880void UIScene::handleGainFocus(bool navBack)
881{
882#ifdef _DURANGO
883 InputManager.SetEnabledGtcButtons( this->getDefaultGtcButtons() );
884#endif
885}
886
887void UIScene::updateTooltips()
888{
889 if(!ui.IsReloadingSkin())
890 ui.SetTooltips(m_iPad, -1);
891}
892
893void UIScene::sendInputToMovie(int key, bool repeat, bool pressed, bool released)
894{
895 if(!swf) return;
896
897 int iggyKeyCode = convertGameActionToIggyKeycode(key);
898
899 if(iggyKeyCode < 0)
900 {
901 app.DebugPrintf("UI WARNING: Ignoring input as game action does not translate to an Iggy keycode\n");
902 return;
903 }
904 IggyEvent keyEvent;
905 // 4J Stu - Keyloc is always standard as we don't care about shift/alt
906 IggyMakeEventKey( &keyEvent, pressed?IGGY_KEYEVENT_Down:IGGY_KEYEVENT_Up, (IggyKeycode)iggyKeyCode, IGGY_KEYLOC_Standard );
907
908 IggyEventResult result;
909 IggyPlayerDispatchEventRS ( swf , &keyEvent , &result );
910}
911
912int UIScene::convertGameActionToIggyKeycode(int action)
913{
914 // TODO: This action to key mapping should probably use the control mapping
915 int keycode = -1;
916 switch(action)
917 {
918#ifdef __ORBIS__
919 case ACTION_MENU_TOUCHPAD_PRESS:
920#endif
921 case ACTION_MENU_A:
922 keycode = IGGY_KEYCODE_ENTER;
923 break;
924 case ACTION_MENU_B:
925 keycode = IGGY_KEYCODE_ESCAPE;
926 break;
927 case ACTION_MENU_X:
928 keycode = IGGY_KEYCODE_F1;
929 break;
930 case ACTION_MENU_Y:
931 keycode = IGGY_KEYCODE_F2;
932 break;
933 case ACTION_MENU_OK:
934 keycode = IGGY_KEYCODE_ENTER;
935 break;
936 case ACTION_MENU_CANCEL:
937 keycode = IGGY_KEYCODE_ESCAPE;
938 break;
939 case ACTION_MENU_UP:
940 keycode = IGGY_KEYCODE_UP;
941 break;
942 case ACTION_MENU_DOWN:
943 keycode = IGGY_KEYCODE_DOWN;
944 break;
945 case ACTION_MENU_RIGHT:
946 keycode = IGGY_KEYCODE_RIGHT;
947 break;
948 case ACTION_MENU_LEFT:
949 keycode = IGGY_KEYCODE_LEFT;
950 break;
951 case ACTION_MENU_PAGEUP:
952 keycode = IGGY_KEYCODE_PAGE_UP;
953 break;
954 case ACTION_MENU_PAGEDOWN:
955#ifdef __PSVITA__
956 if (!InputManager.IsVitaTV())
957 {
958 keycode = IGGY_KEYCODE_F6;
959 }
960 else
961#endif
962 {
963 keycode = IGGY_KEYCODE_PAGE_DOWN;
964 }
965 break;
966 case ACTION_MENU_RIGHT_SCROLL:
967 keycode = IGGY_KEYCODE_F3;
968 break;
969 case ACTION_MENU_LEFT_SCROLL:
970 keycode = IGGY_KEYCODE_F4;
971 break;
972 case ACTION_MENU_STICK_PRESS:
973 break;
974 case ACTION_MENU_OTHER_STICK_PRESS:
975 keycode = IGGY_KEYCODE_F5;
976 break;
977 case ACTION_MENU_OTHER_STICK_UP:
978 keycode = IGGY_KEYCODE_F11;
979 break;
980 case ACTION_MENU_OTHER_STICK_DOWN:
981 keycode = IGGY_KEYCODE_F12;
982 break;
983 case ACTION_MENU_OTHER_STICK_LEFT:
984 break;
985 case ACTION_MENU_OTHER_STICK_RIGHT:
986 break;
987 };
988
989 return keycode;
990}
991
992bool UIScene::allowRepeat(int key)
993{
994 // 4J-PB - ignore repeats of action ABXY buttons
995 // fix for PS3 213 - [MAIN MENU] Holding down buttons will continue to activate every prompt.
996 switch(key)
997 {
998 case ACTION_MENU_OK:
999 case ACTION_MENU_CANCEL:
1000 case ACTION_MENU_A:
1001 case ACTION_MENU_B:
1002 case ACTION_MENU_X:
1003 case ACTION_MENU_Y:
1004 return false;
1005 }
1006 return true;
1007}
1008
1009void UIScene::externalCallback(IggyExternalFunctionCallUTF16 * call)
1010{
1011 if(wcscmp((wchar_t *)call->function_name.string,L"handlePress")==0)
1012 {
1013 if(call->num_arguments != 2)
1014 {
1015 app.DebugPrintf("Callback for handlePress did not have the correct number of arguments\n");
1016#ifndef _CONTENT_PACKAGE
1017 __debugbreak();
1018#endif
1019 return;
1020 }
1021 if(call->arguments[0].type != IGGY_DATATYPE_number || call->arguments[1].type != IGGY_DATATYPE_number)
1022 {
1023 app.DebugPrintf("Arguments for handlePress were not of the correct type\n");
1024#ifndef _CONTENT_PACKAGE
1025 __debugbreak();
1026#endif
1027 return;
1028 }
1029 handlePress(call->arguments[0].number, call->arguments[1].number);
1030 }
1031 else if(wcscmp((wchar_t *)call->function_name.string,L"handleFocusChange")==0)
1032 {
1033 if(call->num_arguments != 2)
1034 {
1035 app.DebugPrintf("Callback for handleFocusChange did not have the correct number of arguments\n");
1036#ifndef _CONTENT_PACKAGE
1037 __debugbreak();
1038#endif
1039 return;
1040 }
1041 if(call->arguments[0].type != IGGY_DATATYPE_number || call->arguments[1].type != IGGY_DATATYPE_number)
1042 {
1043 app.DebugPrintf("Arguments for handleFocusChange were not of the correct type\n");
1044#ifndef _CONTENT_PACKAGE
1045 __debugbreak();
1046#endif
1047 return;
1048 }
1049 _handleFocusChange(call->arguments[0].number, call->arguments[1].number);
1050 }
1051 else if(wcscmp((wchar_t *)call->function_name.string,L"handleInitFocus")==0)
1052 {
1053 if(call->num_arguments != 2)
1054 {
1055 app.DebugPrintf("Callback for handleInitFocus did not have the correct number of arguments\n");
1056#ifndef _CONTENT_PACKAGE
1057 __debugbreak();
1058#endif
1059 return;
1060 }
1061 if(call->arguments[0].type != IGGY_DATATYPE_number || call->arguments[1].type != IGGY_DATATYPE_number)
1062 {
1063 app.DebugPrintf("Arguments for handleInitFocus were not of the correct type\n");
1064#ifndef _CONTENT_PACKAGE
1065 __debugbreak();
1066#endif
1067 return;
1068 }
1069 _handleInitFocus(call->arguments[0].number, call->arguments[1].number);
1070 }
1071 else if(wcscmp((wchar_t *)call->function_name.string,L"handleCheckboxToggled")==0)
1072 {
1073 if(call->num_arguments != 2)
1074 {
1075 app.DebugPrintf("Callback for handleCheckboxToggled did not have the correct number of arguments\n");
1076#ifndef _CONTENT_PACKAGE
1077 __debugbreak();
1078#endif
1079 return;
1080 }
1081 if(call->arguments[0].type != IGGY_DATATYPE_number || call->arguments[1].type != IGGY_DATATYPE_boolean)
1082 {
1083 app.DebugPrintf("Arguments for handleCheckboxToggled were not of the correct type\n");
1084#ifndef _CONTENT_PACKAGE
1085 __debugbreak();
1086#endif
1087 return;
1088 }
1089 handleCheckboxToggled(call->arguments[0].number, call->arguments[1].boolval);
1090 }
1091 else if(wcscmp((wchar_t *)call->function_name.string,L"handleSliderMove")==0)
1092 {
1093 if(call->num_arguments != 2)
1094 {
1095 app.DebugPrintf("Callback for handleSliderMove did not have the correct number of arguments\n");
1096#ifndef _CONTENT_PACKAGE
1097 __debugbreak();
1098#endif
1099 return;
1100 }
1101 if(call->arguments[0].type != IGGY_DATATYPE_number || call->arguments[1].type != IGGY_DATATYPE_number)
1102 {
1103 app.DebugPrintf("Arguments for handleSliderMove were not of the correct type\n");
1104#ifndef _CONTENT_PACKAGE
1105 __debugbreak();
1106#endif
1107 return;
1108 }
1109 handleSliderMove(call->arguments[0].number, call->arguments[1].number);
1110 }
1111 else if(wcscmp((wchar_t *)call->function_name.string,L"handleAnimationEnd")==0)
1112 {
1113 if(call->num_arguments != 0)
1114 {
1115 app.DebugPrintf("Callback for handleAnimationEnd did not have the correct number of arguments\n");
1116#ifndef _CONTENT_PACKAGE
1117 __debugbreak();
1118#endif
1119 return;
1120 }
1121 handleAnimationEnd();
1122 }
1123 else if(wcscmp((wchar_t *)call->function_name.string,L"handleSelectionChanged")==0)
1124 {
1125 if(call->num_arguments != 1)
1126 {
1127 app.DebugPrintf("Callback for handleSelectionChanged did not have the correct number of arguments\n");
1128#ifndef _CONTENT_PACKAGE
1129 __debugbreak();
1130#endif
1131 return;
1132 }
1133 if(call->arguments[0].type != IGGY_DATATYPE_number)
1134 {
1135 app.DebugPrintf("Arguments for handleSelectionChanged were not of the correct type\n");
1136#ifndef _CONTENT_PACKAGE
1137 __debugbreak();
1138#endif
1139 return;
1140 }
1141 handleSelectionChanged(call->arguments[0].number);
1142 }
1143 else if(wcscmp((wchar_t *)call->function_name.string,L"handleRequestMoreData")==0)
1144 {
1145 if(call->num_arguments == 0)
1146 {
1147 handleRequestMoreData(0,false);
1148 }
1149 else
1150 {
1151 if(call->num_arguments != 2)
1152 {
1153 app.DebugPrintf("Callback for handleRequestMoreData did not have the correct number of arguments\n");
1154#ifndef _CONTENT_PACKAGE
1155 __debugbreak();
1156#endif
1157 return;
1158 }
1159 if(call->arguments[0].type != IGGY_DATATYPE_number || call->arguments[1].type != IGGY_DATATYPE_boolean)
1160 {
1161 app.DebugPrintf("Arguments for handleRequestMoreData were not of the correct type\n");
1162#ifndef _CONTENT_PACKAGE
1163 __debugbreak();
1164#endif
1165 return;
1166 }
1167 handleRequestMoreData(call->arguments[0].number, call->arguments[1].boolval);
1168 }
1169 }
1170 else if(wcscmp((wchar_t *)call->function_name.string,L"handleTouchBoxRebuild")==0)
1171 {
1172 handleTouchBoxRebuild();
1173 }
1174 else
1175 {
1176 app.DebugPrintf("Unhandled callback: %s\n", call->function_name.string);
1177 }
1178}
1179
1180void UIScene::registerSubstitutionTexture(const wstring &textureName, PBYTE pbData, DWORD dwLength, bool deleteData)
1181{
1182 m_registeredTextures[textureName] = deleteData;;
1183 ui.registerSubstitutionTexture(textureName, pbData, dwLength);
1184}
1185
1186bool UIScene::hasRegisteredSubstitutionTexture(const wstring &textureName)
1187{
1188 AUTO_VAR(it, m_registeredTextures.find( textureName ) );
1189
1190 return it != m_registeredTextures.end();
1191}
1192
1193void UIScene::_handleFocusChange(F64 controlId, F64 childId)
1194{
1195 m_iFocusControl = (int)controlId;
1196 m_iFocusChild = (int)childId;
1197
1198 handleFocusChange(controlId, childId);
1199 ui.PlayUISFX(eSFX_Focus);
1200}
1201
1202void UIScene::_handleInitFocus(F64 controlId, F64 childId)
1203{
1204 m_iFocusControl = (int)controlId;
1205 m_iFocusChild = (int)childId;
1206
1207 //handleInitFocus(controlId, childId);
1208 handleFocusChange(controlId, childId);
1209}
1210
1211bool UIScene::controlHasFocus(int iControlId)
1212{
1213 return m_iFocusControl == iControlId;
1214}
1215
1216bool UIScene::controlHasFocus(UIControl_Base *control)
1217{
1218 return controlHasFocus( control->getId() );
1219}
1220
1221int UIScene::getControlChildFocus()
1222{
1223 return m_iFocusChild;
1224}
1225
1226int UIScene::getControlFocus()
1227{
1228 return m_iFocusControl;
1229}
1230
1231void UIScene::setBackScene(UIScene *scene)
1232{
1233 m_backScene = scene;
1234}
1235
1236UIScene *UIScene::getBackScene()
1237{
1238 return m_backScene;
1239}
1240#ifdef __PSVITA__
1241void UIScene::UpdateSceneControls()
1242{
1243 AUTO_VAR(itEnd, GetControls()->end());
1244 for (AUTO_VAR(it, GetControls()->begin()); it != itEnd; it++)
1245 {
1246 UIControl *control=(UIControl *)*it;
1247 control->UpdateControl();
1248 }
1249}
1250#endif
1251
1252void UIScene::HandleMessage(EUIMessage message, void *data)
1253{
1254}
1255
1256size_t UIScene::GetCallbackUniqueId()
1257{
1258 if( m_callbackUniqueId == 0)
1259 {
1260 m_callbackUniqueId = ui.RegisterForCallbackId(this);
1261 }
1262 return m_callbackUniqueId;
1263}
1264
1265bool UIScene::isReadyToDelete()
1266{
1267 return true;
1268}