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 "UIComponent_Tooltips.h"
4
5UIComponent_Tooltips::UIComponent_Tooltips(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer)
6{
7 for(int i=0;i<XUSER_MAX_COUNT;i++)
8 {
9 for(int j=0;j<ACTION_MAX_MENU;j++)
10 {
11 m_overrideSFX[i][j]=false;
12 }
13 }
14 // Setup all the Iggy references we need for this scene
15 initialiseMovie();
16
17#ifdef __PSVITA__
18 // initialise vita touch controls with ids
19 for(unsigned int i = 0; i < ETouchInput_Count; ++i)
20 {
21 m_TouchController[i].init(i);
22 }
23#endif
24
25#if defined(__PS3__) || defined(__ORBIS__) || defined(__PSVITA__)
26 if(InputManager.IsCircleCrossSwapped())
27 {
28 IggyDataValue result;
29 IggyDataValue value[1];
30 value[0].type = IGGY_DATATYPE_boolean;
31 value[0].boolval = true;
32 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetABSwap , 1 , value );
33 }
34#endif
35}
36
37wstring UIComponent_Tooltips::getMoviePath()
38{
39 switch( m_parentLayer->getViewport() )
40 {
41 case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
42 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
43 case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT:
44 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT:
45 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT:
46 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
47 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT:
48 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT:
49 m_bSplitscreen = true;
50 return L"ToolTipsSplit";
51 break;
52 case C4JRender::VIEWPORT_TYPE_FULLSCREEN:
53 default:
54 m_bSplitscreen = false;
55 return L"ToolTips";
56 break;
57 }
58}
59
60F64 UIComponent_Tooltips::getSafeZoneHalfWidth()
61{
62 float width = ui.getScreenWidth();
63
64 float safeWidth = 0.0f;
65
66#ifndef __PSVITA__
67 // 85% safezone for tooltips in either SD mode
68 if( !RenderManager.IsHiDef() )
69 {
70 // 85% safezone
71 safeWidth = m_movieWidth * (0.15f / 2);
72 }
73 else
74 {
75 // 90% safezone
76 safeWidth = width * (0.1f / 2);
77 }
78#endif
79 return safeWidth;
80}
81
82void UIComponent_Tooltips::updateSafeZone()
83{
84 // Distance from edge
85 F64 safeTop = 0.0;
86 F64 safeBottom = 0.0;
87 F64 safeLeft = 0.0;
88 F64 safeRight = 0.0;
89
90 switch( m_parentLayer->getViewport() )
91 {
92 case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
93 safeTop = getSafeZoneHalfHeight();
94 safeLeft = getSafeZoneHalfWidth();
95 break;
96 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
97 safeBottom = getSafeZoneHalfHeight();
98 safeLeft = getSafeZoneHalfWidth();
99 break;
100 case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT:
101 safeLeft = getSafeZoneHalfWidth();
102 safeBottom = getSafeZoneHalfHeight();
103 break;
104 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT:
105 safeRight = getSafeZoneHalfWidth();
106 safeBottom = getSafeZoneHalfHeight();
107 break;
108 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT:
109 safeTop = getSafeZoneHalfHeight();
110 safeLeft = getSafeZoneHalfWidth();
111 break;
112 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
113 safeTop = getSafeZoneHalfHeight();
114 safeRight = getSafeZoneHalfWidth();
115 break;
116 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT:
117 safeBottom = getSafeZoneHalfHeight();
118 safeLeft = getSafeZoneHalfWidth();
119 break;
120 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT:
121 safeBottom = getSafeZoneHalfHeight();
122 safeRight = getSafeZoneHalfWidth();
123 break;
124 case C4JRender::VIEWPORT_TYPE_FULLSCREEN:
125 default:
126 safeTop = getSafeZoneHalfHeight();
127 safeBottom = getSafeZoneHalfHeight();
128 safeLeft = getSafeZoneHalfWidth();
129 safeRight = getSafeZoneHalfWidth();
130 break;
131 }
132 setSafeZone(safeTop, safeBottom, safeLeft, safeRight);
133}
134
135void UIComponent_Tooltips::tick()
136{
137 UIScene::tick();
138
139 // set the opacity of the tooltip items
140 unsigned char ucAlpha=app.GetGameSettings(ProfileManager.GetPrimaryPad(),eGameSetting_InterfaceOpacity);
141 float fVal;
142
143 if(ucAlpha<80)
144 {
145 // if we are in a menu, set the minimum opacity for tooltips to 15%
146 if(ui.GetMenuDisplayed(m_iPad) && (ucAlpha<15))
147 {
148 ucAlpha=15;
149 }
150
151 // check if we have the timer running for the opacity
152 unsigned int uiOpacityTimer=app.GetOpacityTimer(m_iPad);
153 if(uiOpacityTimer!=0)
154 {
155 if(uiOpacityTimer<10)
156 {
157 float fStep=(80.0f-(float)ucAlpha)/10.0f;
158 fVal=0.01f*(80.0f-((10.0f-(float)uiOpacityTimer)*fStep));
159 }
160 else
161 {
162 fVal=0.01f*80.0f;
163 }
164 }
165 else
166 {
167 fVal=0.01f*(float)ucAlpha;
168 }
169 }
170 else
171 {
172 // if we are in a menu, set the minimum opacity for tooltips to 15%
173 if(ui.GetMenuDisplayed(m_iPad) && (ucAlpha<15))
174 {
175 ucAlpha=15;
176 }
177 fVal=0.01f*(float)ucAlpha;
178 }
179 setOpacity(fVal);
180
181 bool layoutChanges = false;
182 for (int i = 0; i < eToolTipNumButtons; i++)
183 {
184 if ( !ui.IsReloadingSkin() && m_tooltipValues[i].show && m_tooltipValues[i].label.needsUpdating() )
185 {
186 layoutChanges = true;
187 _SetTooltip(i, m_tooltipValues[i].label, m_tooltipValues[i].show, true);
188 m_tooltipValues[i].label.setUpdated();
189 }
190 }
191 if (layoutChanges) _Relayout();
192}
193
194void UIComponent_Tooltips::render(S32 width, S32 height, C4JRender::eViewportType viewport)
195{
196 if((ProfileManager.GetLockedProfile()!=-1) && !ui.GetMenuDisplayed(m_iPad) && (app.GetGameSettings(m_iPad,eGameSetting_Tooltips)==0 || app.GetGameSettings(m_iPad,eGameSetting_DisplayHUD)==0))
197 {
198 return;
199 }
200
201 if(m_bSplitscreen)
202 {
203 S32 xPos = 0;
204 S32 yPos = 0;
205 switch( viewport )
206 {
207 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
208 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT:
209 yPos = (S32)(ui.getScreenHeight() / 2);
210 break;
211 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT:
212 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
213 xPos = (S32)(ui.getScreenWidth() / 2);
214 break;
215 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT:
216 xPos = (S32)(ui.getScreenWidth() / 2);
217 yPos = (S32)(ui.getScreenHeight() / 2);
218 break;
219 }
220 ui.setupRenderPosition(xPos, yPos);
221
222 S32 tileXStart = 0;
223 S32 tileYStart = 0;
224 S32 tileWidth = width;
225 S32 tileHeight = height;
226
227 switch( viewport )
228 {
229 case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT:
230 case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT:
231 tileHeight = (S32)(ui.getScreenHeight());
232 break;
233 case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
234 tileWidth = (S32)(ui.getScreenWidth());
235 tileYStart = (S32)(m_movieHeight / 2);
236 break;
237 case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
238 tileWidth = (S32)(ui.getScreenWidth());
239 tileYStart = (S32)(m_movieHeight / 2);
240 break;
241 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT:
242 case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
243 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT:
244 case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT:
245 tileYStart = (S32)(m_movieHeight / 2);
246 break;
247 }
248
249 IggyPlayerSetDisplaySize( getMovie(), m_movieWidth, m_movieHeight );
250
251 IggyPlayerDrawTilesStart ( getMovie() );
252
253 m_renderWidth = tileWidth;
254 m_renderHeight = tileHeight;
255 IggyPlayerDrawTile ( getMovie() ,
256 tileXStart ,
257 tileYStart ,
258 tileXStart + tileWidth ,
259 tileYStart + tileHeight ,
260 0 );
261 IggyPlayerDrawTilesEnd ( getMovie() );
262 }
263 else
264 {
265 UIScene::render(width, height, viewport);
266 }
267}
268
269void UIComponent_Tooltips::SetTooltipText( unsigned int tooltip, int iTextID )
270{
271 if( _SetTooltip(tooltip, iTextID) ) _Relayout();
272}
273
274void UIComponent_Tooltips::SetEnableTooltips( bool bVal )
275{
276}
277
278void UIComponent_Tooltips::ShowTooltip( unsigned int tooltip, bool show )
279{
280 if(show != m_tooltipValues[tooltip].show)
281 {
282 _SetTooltip(tooltip, L"", show);
283 _Relayout();
284 }
285}
286
287void UIComponent_Tooltips::SetTooltips( int iA, int iB, int iX, int iY , int iLT, int iRT, int iLB, int iRB, int iLS, int iRS, int iBack, bool forceUpdate)
288{
289 bool needsRelayout = false;
290 needsRelayout = _SetTooltip( eToolTipButtonA, iA ) || needsRelayout;
291 needsRelayout = _SetTooltip( eToolTipButtonB, iB ) || needsRelayout;
292 needsRelayout = _SetTooltip( eToolTipButtonX, iX ) || needsRelayout;
293 needsRelayout = _SetTooltip( eToolTipButtonY, iY ) || needsRelayout;
294 needsRelayout = _SetTooltip( eToolTipButtonLT, iLT ) || needsRelayout;
295 needsRelayout = _SetTooltip( eToolTipButtonRT, iRT ) || needsRelayout;
296 needsRelayout = _SetTooltip( eToolTipButtonLB, iLB ) || needsRelayout;
297 needsRelayout = _SetTooltip( eToolTipButtonRB, iRB ) || needsRelayout;
298 needsRelayout = _SetTooltip( eToolTipButtonLS, iLS ) || needsRelayout;
299 needsRelayout = _SetTooltip( eToolTipButtonRS, iRS ) || needsRelayout;
300 needsRelayout = _SetTooltip( eToolTipButtonRS, iRS ) || needsRelayout;
301 needsRelayout = _SetTooltip( eToolTipButtonBack, iBack ) || needsRelayout;
302 if (needsRelayout) _Relayout();
303}
304
305void UIComponent_Tooltips::EnableTooltip( unsigned int tooltip, bool enable )
306{
307}
308
309bool UIComponent_Tooltips::_SetTooltip(unsigned int iToolTip, int iTextID)
310{
311 bool changed = false;
312 if(iTextID != m_tooltipValues[iToolTip].iString || (iTextID > -1 && !m_tooltipValues[iToolTip].show))
313 {
314 m_tooltipValues[iToolTip].iString = iTextID;
315 changed = true;
316 if(iTextID > -1) _SetTooltip(iToolTip, iTextID, true);
317 else if(iTextID == -2) _SetTooltip(iToolTip, L"", true);
318 else _SetTooltip(iToolTip, L"", false);
319 }
320 return changed;
321}
322
323void UIComponent_Tooltips::_SetTooltip(unsigned int iToolTipId, UIString label, bool show, bool force)
324{
325 if(!force && !show && !m_tooltipValues[iToolTipId].show)
326 {
327 return;
328 }
329 m_tooltipValues[iToolTipId].show = show;
330 m_tooltipValues[iToolTipId].label = label;
331
332 IggyDataValue result;
333 IggyDataValue value[3];
334 value[0].type = IGGY_DATATYPE_number;
335 value[0].number = iToolTipId;
336
337 value[1].type = IGGY_DATATYPE_string_UTF16;
338 IggyStringUTF16 stringVal;
339
340 stringVal.string = (IggyUTF16*)label.c_str();
341 stringVal.length = label.length();
342 value[1].string16 = stringVal;
343
344 value[2].type = IGGY_DATATYPE_boolean;
345 value[2].boolval = show;
346 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetTooltip , 3 , value );
347
348 //app.DebugPrintf("Actual tooltip update!\n");
349}
350
351void UIComponent_Tooltips::_Relayout()
352{
353 IggyDataValue result;
354 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcUpdateLayout, 0 , NULL );
355
356#ifdef __PSVITA__
357 // rebuild touchboxes
358 ui.TouchBoxRebuild(this);
359#endif
360}
361
362#ifdef __PSVITA__
363void UIComponent_Tooltips::handleTouchInput(unsigned int iPad, S32 x, S32 y, int iId, bool bPressed, bool bRepeat, bool bReleased)
364{
365 //app.DebugPrintf("ToolTip Touch ID = %i\n", iId);
366 bool handled = false;
367
368 // 4J - TomK no tooltips no touch!
369 if((!ui.GetMenuDisplayed(ProfileManager.GetPrimaryPad())) && (app.GetGameSettings(ProfileManager.GetPrimaryPad(),eGameSetting_Tooltips) == 0))
370 return;
371
372 // perform action on release
373 if(bReleased)
374 {
375 switch(iId)
376 {
377 case ETouchInput_Touch_A:
378 app.DebugPrintf("ToolTip Map Touch to _PSV_JOY_BUTTON_X\n", iId);
379 if(InputManager.IsCircleCrossSwapped())
380 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_O);
381 else
382 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_X);
383 break;
384 case ETouchInput_Touch_B:
385 app.DebugPrintf("ToolTip Map Touch to _PSV_JOY_BUTTON_O\n", iId);
386 if(InputManager.IsCircleCrossSwapped())
387 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_X);
388 else
389 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_O);
390 break;
391 case ETouchInput_Touch_X:
392 app.DebugPrintf("ToolTip Map Touch to _PSV_JOY_BUTTON_SQUARE\n", iId);
393 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_SQUARE);
394 break;
395 case ETouchInput_Touch_Y:
396 app.DebugPrintf("ToolTip Map Touch to _PSV_JOY_BUTTON_TRIANGLE\n", iId);
397 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_TRIANGLE);
398 break;
399 case ETouchInput_Touch_LT:
400 /* not in use on vita */
401 app.DebugPrintf("ToolTip no action\n", iId);
402 break;
403 case ETouchInput_Touch_RightTrigger:
404 app.DebugPrintf("ToolTip no action\n", iId);
405 /* no action */
406 break;
407 case ETouchInput_Touch_LeftBumper:
408 app.DebugPrintf("ToolTip Map Touch to _PSV_JOY_BUTTON_L1\n", iId);
409 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_L1);
410 break;
411 case ETouchInput_Touch_RightBumper:
412 app.DebugPrintf("ToolTip Map Touch to _PSV_JOY_BUTTON_R1\n", iId);
413 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_R1);
414 break;
415 case ETouchInput_Touch_LeftStick:
416 app.DebugPrintf("ToolTip no action\n", iId);
417 /* no action */
418 break;
419 case ETouchInput_Touch_RightStick:
420 app.DebugPrintf("ToolTip Map Touch to _PSV_JOY_BUTTON_DPAD_DOWN\n", iId);
421 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_DPAD_DOWN);
422 break;
423 case ETouchInput_Touch_Select:
424 app.DebugPrintf("ToolTip Map Touch to _PSV_JOY_BUTTON_SELECT\n", iId);
425 InputManager.MapTouchInput(iPad, _PSV_JOY_BUTTON_SELECT);
426 break;
427 }
428 }
429}
430#endif
431
432void UIComponent_Tooltips::handleReload()
433{
434 app.DebugPrintf("UIComponent_Tooltips::handleReload\n");
435
436#if defined(__PS3__) || defined(__ORBIS__) || defined(__PSVITA__)
437 if(InputManager.IsCircleCrossSwapped())
438 {
439 IggyDataValue result;
440 IggyDataValue value[1];
441 value[0].type = IGGY_DATATYPE_boolean;
442 value[0].boolval = true;
443 IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetABSwap , 1 , value );
444 }
445#endif
446
447 for(unsigned int i = 0; i < eToolTipNumButtons; ++i)
448 {
449 _SetTooltip(i, m_tooltipValues[i].iString, m_tooltipValues[i].show, true);
450 }
451 _Relayout();
452}
453
454void UIComponent_Tooltips::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
455{
456 if( (0 <= iPad) && (iPad <= 3) && m_overrideSFX[iPad][key] )
457 {
458 // don't play a sound for this action
459 switch(key)
460 {
461 case ACTION_MENU_A:
462 case ACTION_MENU_OK:
463 case ACTION_MENU_PAGEUP:
464 case ACTION_MENU_PAGEDOWN:
465 case ACTION_MENU_X:
466 case ACTION_MENU_Y:
467 case ACTION_MENU_B:
468 case ACTION_MENU_CANCEL:
469 case ACTION_MENU_LEFT_SCROLL:
470 case ACTION_MENU_RIGHT_SCROLL:
471 case ACTION_MENU_LEFT:
472 case ACTION_MENU_RIGHT:
473 case ACTION_MENU_UP:
474 case ACTION_MENU_DOWN:
475 sendInputToMovie(key, repeat, pressed, released);
476 break;
477 }
478 }
479 else
480 {
481 switch(key)
482 {
483 case ACTION_MENU_OK:
484 case ACTION_MENU_CANCEL:
485 // 4J-PB - We get both A and OK, and B and Cancel, so only play a sound on one of them.
486 sendInputToMovie(key, repeat, pressed, released);
487 break;
488 case ACTION_MENU_A:
489 case ACTION_MENU_X:
490 case ACTION_MENU_Y:
491 // 4J-PB - play a Press sound
492 //CD - Removed, causes a sound on all presses
493 /*if(pressed)
494 {
495 ui.PlayUISFX(eSFX_Press);
496 }*/
497 sendInputToMovie(key, repeat, pressed, released);
498 break;
499
500 case ACTION_MENU_B:
501 // 4J-PB - play a Press sound
502 //CD - Removed, causes a sound on all presses
503 /*if(pressed)
504 {
505 ui.PlayUISFX(eSFX_Back);
506 }*/
507 sendInputToMovie(key, repeat, pressed, released);
508 break;
509
510 case ACTION_MENU_LEFT_SCROLL:
511 case ACTION_MENU_RIGHT_SCROLL:
512 //CD - Removed, causes a sound on all presses
513 /*if(pressed)
514 {
515 ui.PlayUISFX(eSFX_Scroll);
516 }*/
517 sendInputToMovie(key, repeat, pressed, released);
518 break;
519 case ACTION_MENU_PAGEUP:
520 case ACTION_MENU_PAGEDOWN:
521 case ACTION_MENU_LEFT:
522 case ACTION_MENU_RIGHT:
523 case ACTION_MENU_UP:
524 case ACTION_MENU_DOWN:
525 sendInputToMovie(key, repeat, pressed, released);
526 break;
527 }
528 }
529}
530
531void UIComponent_Tooltips::overrideSFX(int iPad, int key, bool bVal)
532{
533 m_overrideSFX[iPad][key]=bVal;
534}