the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#include <assert.h>
4#include "..\XUI\XUI_HelpControls.h"
5#include "XUI_Ctrl_4JList.h"
6
7#include "..\..\..\Minecraft.World\net.minecraft.world.level.h"
8#include "..\..\..\Minecraft.World\LevelData.h"
9#include "..\..\MultiplayerLocalPlayer.h"
10
11#define ALIGN_START 0
12#define ALIGN_END 1
13typedef struct
14{
15 WCHAR wchName[20];
16 int iAlign;
17 D3DXVECTOR3 vPos;
18}
19CONTROLDETAILS;
20
21LPCWSTR CScene_Controls::m_LayoutNameA[3]=
22{
23 L"1",
24 L"2",
25 L"3",
26};
27CONTROLDETAILS controlDetailsA[MAX_CONTROLS]=
28{
29 {
30 L"FigA",ALIGN_END // _360_JOY_BUTTON_A
31 },
32 {
33 L"FigB",ALIGN_END // _360_JOY_BUTTON_B
34 },
35 {
36 L"FigX",ALIGN_END // _360_JOY_BUTTON_X
37 },
38 {
39 L"FigY",ALIGN_END // _360_JOY_BUTTON_Y
40 },
41 {
42 L"FigStart",ALIGN_END // _360_JOY_BUTTON_START
43 },
44 {
45 L"FigBack",ALIGN_START // _360_JOY_BUTTON_BACK
46 },
47 {
48 L"FigRB",ALIGN_END // _360_JOY_BUTTON_RB
49 },
50 {
51 L"FigLB",ALIGN_START // _360_JOY_BUTTON_LB
52 },
53 {
54 L"FigRStickButton",ALIGN_END // _360_JOY_BUTTON_RTHUMB
55 },
56 {
57 L"FigLStickButton",ALIGN_START // _360_JOY_BUTTON_LTHUMB
58 },
59 // Move
60 {
61 L"FigRStick",ALIGN_END // _360_JOY_BUTTON_RSTICK_RIGHT
62 },
63 // Look
64 {
65 L"FigLStick",ALIGN_START // _360_JOY_BUTTON_LSTICK_RIGHT
66 },
67 {
68 L"FigRT",ALIGN_END // RT
69 },
70 {
71 L"FigLT",ALIGN_START // LT
72 },
73 {
74 L"FigDpadR",ALIGN_START // DpadR
75 },
76 {
77 L"FigDpadL",ALIGN_START // DpadL
78 },
79 {
80 L"FigDpad",ALIGN_START // DpadL
81 },
82
83};
84
85//----------------------------------------------------------------------------------
86// Performs initialization tasks - retrieves controls.
87//----------------------------------------------------------------------------------
88HRESULT CScene_Controls::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
89{
90 MapChildControls();
91 XuiControlSetText(m_SouthPaw,app.GetString(IDS_SOUTHPAW));
92 XuiControlSetText(m_InvertLook,app.GetString(IDS_INVERT_LOOK));
93
94 m_iPad=*(int *)pInitData->pvInitData;
95 // if we're not in the game, we need to use basescene 0
96 bool bNotInGame=(Minecraft::GetInstance()->level==NULL);
97 bool bSplitscreen=(app.GetLocalPlayerCount()>1);
98 m_iCurrentTextIndex=0;
99 m_bCreativeMode = !bNotInGame && Minecraft::GetInstance()->localplayers[m_iPad] && Minecraft::GetInstance()->localplayers[m_iPad]->abilities.mayfly;
100
101 if(!bNotInGame)
102 {
103 // disable the build ver display
104 m_BuildVer.SetShow(FALSE);
105 }
106
107 if(bSplitscreen)
108 {
109 app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad,32.0f);
110 CXuiSceneBase::ShowLogo( m_iPad, FALSE );
111 }
112 else
113 {
114 if(bNotInGame)
115 {
116 CXuiSceneBase::ShowLogo( DEFAULT_XUI_MENU_USER, TRUE );
117 }
118 else
119 {
120 CXuiSceneBase::ShowLogo( m_iPad, TRUE );
121 }
122 }
123
124 // if we're not in the game, we need to use basescene 0
125 if(bNotInGame)
126 {
127 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
128 }
129 else
130 {
131 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
132 }
133
134 m_iSchemeTextA[0]=IDS_CONTROLS_SCHEME0;
135 m_iSchemeTextA[1]=IDS_CONTROLS_SCHEME1;
136 m_iSchemeTextA[2]=IDS_CONTROLS_SCHEME2;
137
138 // get the figures
139 HXUIOBJ hObj;
140 HRESULT hr;
141
142 // turn off all the figures to start with
143 for(int i=0;i<MAX_CONTROLS;i++)
144 {
145 m_FigA[i].GetChildById(controlDetailsA[i].wchName,&hObj);
146 hr=XuiElementGetPosition(hObj,&controlDetailsA[i].vPos);
147 if(controlDetailsA[i].iAlign==ALIGN_END)
148 {
149 float fW,fH;
150 hr=XuiElementGetBounds(hObj,&fW,&fH);
151 controlDetailsA[i].vPos.x+=fW;
152 controlDetailsA[i].vPos.y+=fH;
153 }
154
155 // if we're in splitscreen, half all the numbers
156 if(bSplitscreen)
157 {
158 controlDetailsA[i].vPos.x/=2.0f;
159 controlDetailsA[i].vPos.y/=2.0f;
160 }
161 m_FigA[i].SetShow(FALSE);
162 m_TextPresenterA[i] = NULL;
163 }
164
165 // fill out the layouts list
166 VOID *pObj;
167 XuiObjectFromHandle( m_SchemeList, &pObj );
168 m_pLayoutList = (CXuiCtrl4JList *)pObj;
169 CXuiCtrl4JList::LIST_ITEM_INFO ListInfo[3];
170 ZeroMemory(ListInfo,sizeof(CXuiCtrl4JList::LIST_ITEM_INFO)*3);
171
172 for(int i=0;i<3;i++)
173 {
174 ListInfo[i].pwszText=m_LayoutNameA[i];
175 ListInfo[i].hXuiBrush=NULL;
176 ListInfo[i].fEnabled=TRUE;
177 m_pLayoutList->AddData(ListInfo[i]);
178 }
179
180 m_bIgnoreNotifies=true;
181 m_bIgnoreNotifies=false;
182 int iSelected=app.GetGameSettings(m_iPad,eGameSetting_ControlScheme);
183 XuiControlSetText(m_SchemeList,app.GetString(IDS_CONTROLS_LAYOUT));
184 hr=m_pLayoutList->SetCurSelVisible(iSelected);
185 m_iCurrentNavigatedControlsLayout=iSelected;
186
187 LPWSTR layoutString = new wchar_t[ 128 ];
188 swprintf( layoutString, 128, L"%ls : %ls", app.GetString( IDS_CURRENT_LAYOUT ),app.GetString(m_iSchemeTextA[iSelected]));
189 XuiControlSetText(m_CurrentLayout,layoutString);
190
191 //PositionAllText(m_iPad);
192
193 swprintf( layoutString, 128, L"%ls%ls", VER_PRODUCTVERSION_STR_W,app.DLCInstallProcessCompleted()?L"_DLC":L" ");
194
195 m_BuildVer.SetText(layoutString);
196 delete [] layoutString;
197
198 // Set check box initial states.
199 BOOL bInvertLook = app.GetGameSettings(m_iPad,eGameSetting_ControlInvertLook);
200 m_InvertLook.SetCheck( bInvertLook );
201
202 BOOL bSouthPaw = app.GetGameSettings(m_iPad,eGameSetting_ControlSouthPaw);
203 m_SouthPaw.SetCheck( bSouthPaw );
204
205 return S_OK;
206}
207
208
209
210HRESULT CScene_Controls::OnTransitionStart( XUIMessageTransition *pTransition, BOOL& bHandled )
211{
212
213 if(pTransition->dwTransAction==XUI_TRANSITION_ACTION_DESTROY ) return S_OK;
214
215 if(pTransition->dwTransType == XUI_TRANSITION_TO || pTransition->dwTransType == XUI_TRANSITION_BACKTO)
216 {
217 int iSelected=app.GetGameSettings(m_iPad,eGameSetting_ControlScheme);
218 // and update the highlight on the current selection
219 m_pLayoutList->SetBorder(iSelected,TRUE);
220
221 PositionAllText(m_iPad);
222 }
223
224 return S_OK;
225}
226
227void CScene_Controls::PositionAllText(int iPad)
228{
229 // turn off all the figures to start with
230 for(int i=0;i<MAX_CONTROLS;i++)
231 {
232 m_FigA[i].SetShow(FALSE);
233 }
234
235 m_iCurrentTextIndex=0;
236 if(m_bCreativeMode)
237 {
238 PositionText(iPad,IDS_CONTROLS_JUMPFLY,MINECRAFT_ACTION_JUMP);
239 }
240 else
241 {
242 PositionText(iPad,IDS_CONTROLS_JUMP,MINECRAFT_ACTION_JUMP);
243 }
244 PositionText(iPad,IDS_CONTROLS_INVENTORY,MINECRAFT_ACTION_INVENTORY);
245 PositionText(iPad,IDS_CONTROLS_PAUSE,MINECRAFT_ACTION_PAUSEMENU);
246 if(m_bCreativeMode)
247 {
248 PositionText(iPad,IDS_CONTROLS_SNEAKFLY,MINECRAFT_ACTION_SNEAK_TOGGLE);
249 }
250 else
251 {
252 PositionText(iPad,IDS_CONTROLS_SNEAK,MINECRAFT_ACTION_SNEAK_TOGGLE);
253 }
254 PositionText(iPad,IDS_CONTROLS_USE,MINECRAFT_ACTION_USE);
255 PositionText(iPad,IDS_CONTROLS_ACTION,MINECRAFT_ACTION_ACTION);
256 PositionText(iPad,IDS_CONTROLS_HELDITEM,MINECRAFT_ACTION_RIGHT_SCROLL);
257 PositionText(iPad,IDS_CONTROLS_HELDITEM,MINECRAFT_ACTION_LEFT_SCROLL);
258 PositionText(iPad,IDS_CONTROLS_DROP,MINECRAFT_ACTION_DROP);
259 PositionText(iPad,IDS_CONTROLS_CRAFTING,MINECRAFT_ACTION_CRAFTING);
260
261 PositionText(iPad,IDS_CONTROLS_THIRDPERSON,MINECRAFT_ACTION_RENDER_THIRD_PERSON);
262 PositionText(iPad,IDS_CONTROLS_PLAYERS,MINECRAFT_ACTION_GAME_INFO);
263
264 // Swap for southpaw.
265 if ( app.GetGameSettings(m_iPad,eGameSetting_ControlSouthPaw) )
266 {
267 // Move
268 PositionText(iPad,IDS_CONTROLS_LOOK,MINECRAFT_ACTION_RIGHT);
269 // Look
270 PositionText(iPad,IDS_CONTROLS_MOVE,MINECRAFT_ACTION_LOOK_RIGHT);
271 }
272 else // Normal right handed.
273 {
274 // Move
275 PositionText(iPad,IDS_CONTROLS_MOVE,MINECRAFT_ACTION_RIGHT);
276 // Look
277 PositionText(iPad,IDS_CONTROLS_LOOK,MINECRAFT_ACTION_LOOK_RIGHT);
278 }
279
280 // If we're in controls mode 1, and creative mode show the dpad for Creative Mode
281 if(m_bCreativeMode && (m_iCurrentNavigatedControlsLayout==0))
282 {
283 PositionTextDirect(iPad,IDS_CONTROLS_DPAD,16,true);
284 }
285 else
286 {
287 PositionTextDirect(iPad,IDS_CONTROLS_DPAD,16,false);
288 }
289}
290
291HRESULT CScene_Controls::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled)
292{
293 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode);
294
295 HRESULT hr=S_OK;
296
297 // Explicitly handle B button presses
298 switch(pInputData->dwKeyCode)
299 {
300
301 case VK_PAD_B:
302 case VK_ESCAPE:
303
304 app.CheckGameSettingsChanged(true,pInputData->UserIndex);
305 app.NavigateBack(pInputData->UserIndex);
306 rfHandled = TRUE;
307 break;
308 }
309
310 return hr;
311}
312
313void CScene_Controls::PositionText(int iPad,int iTextID, unsigned char ucAction)
314{
315 // position the text depending on the control id
316 //int iTextWidth;
317 XUIRect xuiRect;
318 LPCWSTR pwchText;
319 D3DXVECTOR3 vpos,vScale;
320 HXUIOBJ hFigGroup;
321 unsigned int uiVal=InputManager.GetGameJoypadMaps(m_iCurrentNavigatedControlsLayout,ucAction);
322
323 // get the visual of the fig group and use any scaling in it to adjust the text positions
324 XuiElementGetChildById(m_hObj,L"FigGroup",&hFigGroup);
325 XuiElementGetScale(hFigGroup,&vScale);
326
327 // check the width of the control with the text set in it
328 if(m_TextPresenterA[m_iCurrentTextIndex]==NULL)
329 {
330 HXUIOBJ hObj=NULL;
331 HRESULT hr=XuiControlGetVisual(m_TextA[m_iCurrentTextIndex].m_hObj,&hObj);
332 hr=XuiElementGetChildById(hObj,L"Text",&m_TextPresenterA[m_iCurrentTextIndex]);
333 }
334
335 pwchText=app.GetString(iTextID);
336 HRESULT hr=XuiTextPresenterMeasureText(m_TextPresenterA[m_iCurrentTextIndex], pwchText, &xuiRect);
337 m_TextA[m_iCurrentTextIndex].SetBounds(xuiRect.right,xuiRect.bottom);
338
339 int iControlDetailsIndex=0;
340 switch(uiVal)
341 {
342 case _360_JOY_BUTTON_A:
343 iControlDetailsIndex=0;
344 break;
345 case _360_JOY_BUTTON_B:
346 iControlDetailsIndex=1;
347 break;
348 case _360_JOY_BUTTON_X:
349 iControlDetailsIndex=2;
350 break;
351 case _360_JOY_BUTTON_Y:
352 iControlDetailsIndex=3;
353 break;
354 case _360_JOY_BUTTON_START:
355 iControlDetailsIndex=4;
356 break;
357 case _360_JOY_BUTTON_BACK:
358 iControlDetailsIndex=5;
359 break;
360 case _360_JOY_BUTTON_RB:
361 iControlDetailsIndex=6;
362 break;
363 case _360_JOY_BUTTON_LB:
364 iControlDetailsIndex=7;
365 break;
366 case _360_JOY_BUTTON_RTHUMB:
367 iControlDetailsIndex=8;
368 break;
369 case _360_JOY_BUTTON_LTHUMB:
370 iControlDetailsIndex=9;
371 break;
372 // Look
373 case _360_JOY_BUTTON_RSTICK_RIGHT:
374 iControlDetailsIndex=10;
375 break;
376 // Move
377 case _360_JOY_BUTTON_LSTICK_RIGHT:
378 iControlDetailsIndex=11;
379 break;
380 case _360_JOY_BUTTON_RT:
381 iControlDetailsIndex=12;
382 break;
383 // Move
384 case _360_JOY_BUTTON_LT:
385 iControlDetailsIndex=13;
386 break;
387 case _360_JOY_BUTTON_DPAD_RIGHT:
388 iControlDetailsIndex=14;
389 break;
390 case _360_JOY_BUTTON_DPAD_LEFT:
391 iControlDetailsIndex=15;
392 break;
393 }
394
395 hr=m_FigA[iControlDetailsIndex].SetShow(TRUE);
396 // position the control depending on the text width
397
398 if(!RenderManager.IsHiDef() && !RenderManager.IsWidescreen())
399 {
400 // 480 mode - we need to scale the text positions
401 if(controlDetailsA[iControlDetailsIndex].iAlign==ALIGN_END)
402 {
403 vpos.x=(controlDetailsA[iControlDetailsIndex].vPos.x + 5.0f)* vScale.x;
404 }
405 else
406 {
407 vpos.x=(controlDetailsA[iControlDetailsIndex].vPos.x - 5.0f)* vScale.x - xuiRect.right;
408 }
409
410 vpos.y=(controlDetailsA[iControlDetailsIndex].vPos.y * vScale.y) - (xuiRect.bottom/2.0f);
411 }
412 else
413 {
414 if(controlDetailsA[iControlDetailsIndex].iAlign==ALIGN_END)
415 {
416 vpos.x=(controlDetailsA[iControlDetailsIndex].vPos.x + 5.0f);
417 }
418 else
419 {
420 vpos.x=(controlDetailsA[iControlDetailsIndex].vPos.x - 5.0f) - xuiRect.right;
421 }
422
423 vpos.y=(controlDetailsA[iControlDetailsIndex].vPos.y ) - (xuiRect.bottom/2.0f);
424 }
425
426 vpos.x=floor(vpos.x);
427 vpos.y=floor(vpos.y);
428 vpos.z=0.0f;
429
430 m_TextA[m_iCurrentTextIndex].SetPosition(&vpos);
431 m_TextA[m_iCurrentTextIndex].SetText(pwchText);
432 m_TextA[m_iCurrentTextIndex].SetShow(TRUE);
433 m_iCurrentTextIndex++;
434}
435
436void CScene_Controls::PositionTextDirect(int iPad,int iTextID, int iControlDetailsIndex, bool bShow)
437{
438 // position the text depending on the control id
439 //int iTextWidth;
440 XUIRect xuiRect;
441 LPCWSTR pwchText;
442 D3DXVECTOR3 vpos,vScale;
443 HXUIOBJ hFigGroup;
444
445 if(bShow==false)
446 {
447 m_TextA[m_iCurrentTextIndex++].SetShow(FALSE);
448 return;
449 }
450 // get the visual of the fig group and use any scaling in it to adjust the text positions
451 XuiElementGetChildById(m_hObj,L"FigGroup",&hFigGroup);
452 XuiElementGetScale(hFigGroup,&vScale);
453
454 // check the width of the control with the text set in it
455 if(m_TextPresenterA[m_iCurrentTextIndex]==NULL)
456 {
457 HXUIOBJ hObj=NULL;
458 HRESULT hr=XuiControlGetVisual(m_TextA[m_iCurrentTextIndex].m_hObj,&hObj);
459 hr=XuiElementGetChildById(hObj,L"Text",&m_TextPresenterA[m_iCurrentTextIndex]);
460 }
461
462 pwchText=app.GetString(iTextID);
463 HRESULT hr=XuiTextPresenterMeasureText(m_TextPresenterA[m_iCurrentTextIndex], pwchText, &xuiRect);
464 m_TextA[m_iCurrentTextIndex].SetBounds(xuiRect.right,xuiRect.bottom);
465
466
467
468 hr=m_FigA[iControlDetailsIndex].SetShow(TRUE);
469 // position the control depending on the text width
470
471 if(!RenderManager.IsHiDef() && !RenderManager.IsWidescreen())
472 {
473 // 480 mode - we need to scale the text positions
474 if(controlDetailsA[iControlDetailsIndex].iAlign==ALIGN_END)
475 {
476 vpos.x=(controlDetailsA[iControlDetailsIndex].vPos.x + 5.0f)* vScale.x;
477 }
478 else
479 {
480 vpos.x=(controlDetailsA[iControlDetailsIndex].vPos.x - 5.0f)* vScale.x - xuiRect.right;
481 }
482
483 vpos.y=(controlDetailsA[iControlDetailsIndex].vPos.y * vScale.y) - (xuiRect.bottom/2.0f);
484 }
485 else
486 {
487 if(controlDetailsA[iControlDetailsIndex].iAlign==ALIGN_END)
488 {
489 vpos.x=(controlDetailsA[iControlDetailsIndex].vPos.x + 5.0f);
490 }
491 else
492 {
493 vpos.x=(controlDetailsA[iControlDetailsIndex].vPos.x - 5.0f) - xuiRect.right;
494 }
495
496 vpos.y=(controlDetailsA[iControlDetailsIndex].vPos.y ) - (xuiRect.bottom/2.0f);
497 }
498
499 vpos.x=floor(vpos.x);
500 vpos.y=floor(vpos.y);
501 vpos.z=0.0f;
502
503 m_TextA[m_iCurrentTextIndex].SetPosition(&vpos);
504 m_TextA[m_iCurrentTextIndex].SetText(pwchText);
505 m_TextA[m_iCurrentTextIndex].SetShow(TRUE);
506 m_iCurrentTextIndex++;
507}
508
509HRESULT CScene_Controls::OnNotifySelChanged( HXUIOBJ hObjSource, XUINotifySelChanged* pNotifySelChangedData, BOOL& bHandled )
510{
511 if( ( !m_bIgnoreNotifies )&&( hObjSource==m_pLayoutList->m_hObj ) )
512 {
513 m_iCurrentNavigatedControlsLayout=pNotifySelChangedData->iItem;
514 PositionAllText(m_iPad);
515 }
516 if(pNotifySelChangedData->iOldItem!=-1 && hObjSource==m_SchemeList )
517 {
518 CXuiSceneBase::PlayUISFX(eSFX_Focus);
519 }
520 return S_OK;
521}
522
523
524
525
526HRESULT CScene_Controls::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPress* pNotifyPressData,BOOL& rfHandled)
527{
528 // This assumes all buttons can only be pressed with the A button
529 ui.AnimateKeyPress(pNotifyPressData->UserIndex, VK_PAD_A);
530
531 // Handle check box changes.
532 if ( hObjPressed == m_InvertLook.m_hObj )
533 {
534 BOOL bIsChecked = m_InvertLook.IsChecked();
535 app.SetGameSettings(m_iPad,eGameSetting_ControlInvertLook,(unsigned char)( bIsChecked ) );
536 }
537 else if ( hObjPressed == m_SouthPaw.m_hObj )
538 {
539 BOOL bIsChecked = m_SouthPaw.IsChecked();
540 app.SetGameSettings(m_iPad,eGameSetting_ControlSouthPaw,(unsigned char)( bIsChecked ) );
541 PositionAllText(m_iPad);
542 }
543 else if( hObjPressed == m_SchemeList)
544 {
545 // check what's been selected
546 app.SetGameSettings(m_iPad,eGameSetting_ControlScheme,(unsigned char)m_SchemeList.GetCurSel());
547 LPWSTR layoutString = new wchar_t[ 128 ];
548 swprintf( layoutString, 128, L"%ls : %ls", app.GetString( IDS_CURRENT_LAYOUT ),app.GetString(m_iSchemeTextA[m_SchemeList.GetCurSel()]) );
549
550 XuiControlSetText(m_CurrentLayout,layoutString);
551 delete [] layoutString;
552 // and update the highlight on the current selection
553 for(int i=0;i<m_pLayoutList->GetItemCount();i++)
554 {
555 m_pLayoutList->SetBorder(i,FALSE);
556 }
557 m_pLayoutList->SetBorder(m_SchemeList.GetCurSel(),TRUE);
558 }
559 return S_OK;
560}
561
562HRESULT CScene_Controls::OnCustomMessage_Splitscreenplayer(bool bJoining, BOOL& bHandled)
563{
564 bHandled=true;
565 return app.AdjustSplitscreenScene_PlayerChanged(m_hObj,&m_OriginalPosition,m_iPad,bJoining,32.0f);
566}