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 <xuiresource.h>
3#include <xuiapp.h>
4#include <assert.h>
5#include "..\..\..\Minecraft.World\LevelSettings.h"
6#include "..\..\..\Minecraft.World\StringHelpers.h"
7#include "XUI_MultiGameInfo.h"
8#include "XUI_MultiGameJoinLoad.h"
9#include "..\..\..\Minecraft.World\LevelSettings.h"
10#include "..\..\..\Minecraft.World\Difficulty.h"
11
12#define UPDATE_PLAYERS_TIMER_ID 0
13#define UPDATE_PLAYERS_TIMER_TIME 30000
14
15//----------------------------------------------------------------------------------
16// Performs initialization tasks - retrieves controls.
17//----------------------------------------------------------------------------------
18HRESULT CScene_MultiGameInfo::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
19{
20 MapChildControls();
21
22 XuiControlSetText(playersList,app.GetString(IDS_PLAYERS));
23 XuiControlSetText(m_JoinGame,app.GetString(IDS_JOIN_GAME));
24 XuiControlSetText(m_labelDifficulty,app.GetString(IDS_LABEL_DIFFICULTY));
25 XuiControlSetText(m_labelGameType,app.GetString(IDS_LABEL_GAME_TYPE));
26 XuiControlSetText(m_labelGamertagsOn,app.GetString(IDS_LABEL_GAMERTAGS));
27 XuiControlSetText(m_labelStructuresOn,app.GetString(IDS_LABEL_STRUCTURES));
28 XuiControlSetText(m_labelLevelType,app.GetString(IDS_LABEL_LEVEL_TYPE));
29 XuiControlSetText(m_labelPvP,app.GetString(IDS_LABEL_PvP));
30 XuiControlSetText(m_labelTrust,app.GetString(IDS_LABEL_TRUST));
31 XuiControlSetText(m_labelTNTOn,app.GetString(IDS_LABEL_TNT));
32 XuiControlSetText(m_labelFireOn,app.GetString(IDS_LABEL_FIRE_SPREADS));
33
34 JoinMenuInitData *initData = (JoinMenuInitData *)pInitData->pvInitData;
35 m_selectedSession = initData->selectedSession;
36 m_iPad = initData->iPad;
37 // 4J-PB - don't delete this - it's part of the joinload structure
38 //delete initData;
39
40 for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i)
41 {
42 if( m_selectedSession->data.players[i] != NULL )
43 {
44 playersList.InsertItems(i,1);
45#ifndef _CONTENT_PACKAGE
46 if(app.DebugSettingsOn() && (app.GetGameSettingsDebugMask()&(1L<<eDebugSetting_DebugLeaderboards)))
47 {
48 playersList.SetText(i, L"WWWWWWWWWWWWWWWW" );
49 }
50 else
51#endif
52 {
53 playersList.SetText(i, convStringToWstring( m_selectedSession->data.szPlayers[i] ).c_str() );
54 }
55 }
56 else
57 {
58 // Leave the loop when we hit the first NULL player
59 break;
60 }
61 }
62
63 unsigned int uiGameHostSettings = m_selectedSession->data.m_uiGameHostSettings;
64 switch(app.GetGameHostOption(uiGameHostSettings,eGameHostOption_Difficulty))
65 {
66 case Difficulty::EASY:
67 m_difficulty.SetText( app.GetString(IDS_DIFFICULTY_TITLE_EASY) );
68 break;
69 case Difficulty::NORMAL:
70 m_difficulty.SetText( app.GetString(IDS_DIFFICULTY_TITLE_NORMAL) );
71 break;
72 case Difficulty::HARD:
73 m_difficulty.SetText( app.GetString(IDS_DIFFICULTY_TITLE_HARD) );
74 break;
75 case Difficulty::PEACEFUL:
76 default:
77 m_difficulty.SetText( app.GetString(IDS_DIFFICULTY_TITLE_PEACEFUL) );
78 break;
79 }
80
81 unsigned int hostOption = app.GetGameHostOption(uiGameHostSettings,eGameHostOption_GameType);
82
83 if (hostOption == GameType::CREATIVE->getId())
84 {
85 m_GameType.SetText( app.GetString(IDS_CREATIVE) );
86 }
87 else if (hostOption == GameType::SURVIVAL->getId())
88 {
89 m_GameType.SetText( app.GetString(IDS_SURVIVAL) );
90 }
91 else
92 {
93 m_GameType.SetText( app.GetString(IDS_SURVIVAL) );
94 }
95
96 if(app.GetGameHostOption(uiGameHostSettings,eGameHostOption_Gamertags)) m_gamertagsOn.SetText( app.GetString(IDS_ON) );
97 else m_gamertagsOn.SetText( app.GetString(IDS_OFF) );
98
99 if(app.GetGameHostOption(uiGameHostSettings,eGameHostOption_Structures)) m_structuresOn.SetText( app.GetString(IDS_ON) );
100 else m_structuresOn.SetText( app.GetString(IDS_OFF) );
101
102 if(app.GetGameHostOption(uiGameHostSettings,eGameHostOption_LevelType)) m_levelType.SetText( app.GetString(IDS_LEVELTYPE_SUPERFLAT) );
103 else m_levelType.SetText( app.GetString(IDS_LEVELTYPE_NORMAL) );
104
105 if(app.GetGameHostOption(uiGameHostSettings,eGameHostOption_PvP)) m_pvpOn.SetText( app.GetString(IDS_ON) );
106 else m_pvpOn.SetText( app.GetString(IDS_OFF) );
107
108 if(app.GetGameHostOption(uiGameHostSettings,eGameHostOption_TrustPlayers)) m_trustPlayers.SetText( app.GetString(IDS_ON) );
109 else m_trustPlayers.SetText( app.GetString(IDS_OFF) );
110
111 if(app.GetGameHostOption(uiGameHostSettings,eGameHostOption_TNT)) m_tntOn.SetText( app.GetString(IDS_ON) );
112 else m_tntOn.SetText( app.GetString(IDS_OFF) );
113
114 if(app.GetGameHostOption(uiGameHostSettings,eGameHostOption_FireSpreads)) m_fireOn.SetText( app.GetString(IDS_ON) );
115 else m_fireOn.SetText( app.GetString(IDS_OFF) );
116
117 m_bIgnoreInput = false;
118
119 // Alert the app the we want to be informed of ethernet connections
120 app.SetLiveLinkRequired( true );
121
122 TelemetryManager->RecordMenuShown(m_iPad, eUIScene_JoinMenu, 0);
123
124 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT, IDS_TOOLTIPS_BACK );
125
126 XuiSetTimer(m_hObj,UPDATE_PLAYERS_TIMER_ID,UPDATE_PLAYERS_TIMER_TIME);
127
128 return S_OK;
129}
130
131
132
133//----------------------------------------------------------------------------------
134// Handler for the button press message.
135//----------------------------------------------------------------------------------
136HRESULT CScene_MultiGameInfo::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPress* pNotifyPressData, BOOL& rfHandled)
137{
138 if(m_bIgnoreInput) return S_OK;
139
140 // This assumes all buttons can only be pressed with the A button
141 ui.AnimateKeyPress(pNotifyPressData->UserIndex, VK_PAD_A);
142
143 if ( hObjPressed == m_JoinGame )
144 {
145 // check we have the texture pack required for the game
146
147
148 SetShow( FALSE );
149 m_bIgnoreInput=true;
150
151 // 4J Stu - If we only have one controller connected, then don't show the sign-in UI again
152 DWORD connectedControllers = 0;
153 for(unsigned int i = 0; i < XUSER_MAX_COUNT; ++i)
154 {
155 if( InputManager.IsPadConnected(i) || ProfileManager.IsSignedIn(i) ) ++connectedControllers;
156 }
157
158 if(connectedControllers == 1 || !RenderManager.IsHiDef())
159 {
160 JoinGame( this );
161 }
162 else
163 {
164 ProfileManager.RequestSignInUI(false, false, false, true, false,&CScene_MultiGameInfo::StartGame_SignInReturned, this,ProfileManager.GetPrimaryPad());
165 }
166 }
167
168 return S_OK;
169}
170
171HRESULT CScene_MultiGameInfo::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled)
172{
173 if(m_bIgnoreInput) return S_OK;
174
175 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode);
176
177 HRESULT hr = S_OK;
178
179 // Explicitly handle B button presses
180 switch(pInputData->dwKeyCode)
181 {
182 case VK_PAD_B:
183 case VK_ESCAPE:
184 app.NavigateBack(pInputData->UserIndex);
185 rfHandled = TRUE;
186 break;
187 case VK_PAD_Y:
188 if(m_selectedSession != NULL && playersList.TreeHasFocus() && playersList.GetItemCount() > 0)
189 {
190 PlayerUID xuid = m_selectedSession->data.players[playersList.GetCurSel()];
191 if( xuid != INVALID_XUID )
192 hr = XShowGamerCardUI(ProfileManager.GetLockedProfile(), xuid);
193 }
194 break;
195 }
196
197 return hr;
198}
199
200HRESULT CScene_MultiGameInfo::OnNavReturn(HXUIOBJ hObj,BOOL& rfHandled)
201{
202 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT, IDS_TOOLTIPS_BACK);
203
204 return S_OK;
205}
206
207HRESULT CScene_MultiGameInfo::OnNotifySelChanged(HXUIOBJ hObjSource, XUINotifySelChanged *pNotifySelChangedData, BOOL& bHandled)
208{
209 if(pNotifySelChangedData->iOldItem!=-1)
210 {
211 CXuiSceneBase::PlayUISFX(eSFX_Focus);
212 }
213 bHandled = TRUE;
214
215 return S_OK;
216}
217
218HRESULT CScene_MultiGameInfo::OnNotifySetFocus(HXUIOBJ hObjSource, XUINotifyFocus *pNotifyFocusData, BOOL& bHandled)
219{
220 if( playersList.TreeHasFocus() && playersList.GetItemCount() > 0 )
221 {
222 ui.SetTooltips( DEFAULT_XUI_MENU_USER, -1, IDS_TOOLTIPS_BACK, -1, IDS_TOOLTIPS_VIEW_GAMERCARD );
223 bHandled = TRUE;
224 }
225 return S_OK;
226}
227
228HRESULT CScene_MultiGameInfo::OnNotifyKillFocus(HXUIOBJ hObjSource, XUINotifyFocus *pNotifyFocusData, BOOL& bHandled)
229{
230 if( pNotifyFocusData->hObjOther == m_JoinGame )
231 {
232 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT, IDS_TOOLTIPS_BACK );
233 bHandled = TRUE;
234 }
235 return S_OK;
236}
237
238int CScene_MultiGameInfo::StartGame_SignInReturned(void *pParam,bool bContinue, int iPad)
239{
240 CScene_MultiGameInfo* pClass = (CScene_MultiGameInfo*)pParam;
241
242 if(bContinue==true)
243 {
244 // It's possible that the player has not signed in - they can back out
245 if(ProfileManager.IsSignedIn(iPad))
246 {
247 JoinGame(pClass);
248 }
249 }
250 else
251 {
252 pClass->SetShow( TRUE );
253 pClass->m_bIgnoreInput=false;
254 }
255 return 0;
256}
257
258// Shared function to join the game that is the same whether we used the sign-in UI or not
259void CScene_MultiGameInfo::JoinGame(CScene_MultiGameInfo* pClass)
260{
261 DWORD dwLocalUsersMask = 0;
262 bool noPrivileges = false;
263 DWORD dwSignedInUsers = 0;
264
265 // if we're in SD mode, then only the primary player gets to play
266 if(RenderManager.IsHiDef())
267 {
268 for(unsigned int index = 0; index < XUSER_MAX_COUNT; ++index)
269 {
270 if(ProfileManager.IsSignedIn(index) )
271 {
272 ++dwSignedInUsers;
273 if( !ProfileManager.AllowedToPlayMultiplayer(index) ) noPrivileges = true;
274 dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(index);
275 }
276 }
277 }
278 else
279 {
280 if(ProfileManager.IsSignedIn(ProfileManager.GetPrimaryPad()) )
281 {
282 ++dwSignedInUsers;
283 if( !ProfileManager.AllowedToPlayMultiplayer(ProfileManager.GetPrimaryPad()) ) noPrivileges = true;
284 dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(ProfileManager.GetPrimaryPad());
285 }
286 }
287
288 // Check if user-created content is allowed, as we cannot play multiplayer if it's not
289 bool noUGC = false;
290 BOOL pccAllowed = TRUE;
291 BOOL pccFriendsAllowed = TRUE;
292 ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed);
293 if(!pccAllowed && !pccFriendsAllowed) noUGC = true;
294
295 if(noUGC)
296 {
297 pClass->SetShow( TRUE );
298 pClass->m_bIgnoreInput=false;
299 UINT uiIDA[1];
300 uiIDA[0]=IDS_CONFIRM_OK;
301
302 int messageText = IDS_NO_USER_CREATED_CONTENT_PRIVILEGE_SINGLE_LOCAL;
303 if(dwSignedInUsers > 1) messageText = IDS_NO_USER_CREATED_CONTENT_PRIVILEGE_ALL_LOCAL;
304
305 StorageManager.RequestMessageBox( IDS_CONNECTION_FAILED, messageText, uiIDA,1,ProfileManager.GetPrimaryPad(),NULL,NULL, app.GetStringTable());
306
307 }
308 else if(noPrivileges)
309 {
310 pClass->SetShow( TRUE );
311 pClass->m_bIgnoreInput=false;
312 UINT uiIDA[1];
313 uiIDA[0]=IDS_CONFIRM_OK;
314 StorageManager.RequestMessageBox( IDS_NO_MULTIPLAYER_PRIVILEGE_TITLE, IDS_NO_MULTIPLAYER_PRIVILEGE_JOIN_TEXT, uiIDA,1,ProfileManager.GetPrimaryPad(),NULL,NULL, app.GetStringTable());
315 }
316 else
317 {
318 CGameNetworkManager::eJoinGameResult result = g_NetworkManager.JoinGame( pClass->m_selectedSession, dwLocalUsersMask );
319
320 // Alert the app the we no longer want to be informed of ethernet connections
321 app.SetLiveLinkRequired( false );
322
323 if( result != CGameNetworkManager::JOINGAME_SUCCESS )
324 {
325 int exitReasonStringId = -1;
326 switch(result)
327 {
328 case CGameNetworkManager::JOINGAME_FAIL_SERVER_FULL:
329 exitReasonStringId = IDS_DISCONNECTED_SERVER_FULL;
330 break;
331 }
332
333 if( exitReasonStringId == -1 )
334 {
335 app.NavigateBack(ProfileManager.GetPrimaryPad());
336 }
337 else
338 {
339 UINT uiIDA[1];
340 uiIDA[0]=IDS_CONFIRM_OK;
341 StorageManager.RequestMessageBox( IDS_CONNECTION_FAILED, exitReasonStringId, uiIDA,1,ProfileManager.GetPrimaryPad(),NULL,NULL, app.GetStringTable());
342 exitReasonStringId = -1;
343
344 app.NavigateToHomeMenu();
345 }
346 }
347 }
348}
349
350HRESULT CScene_MultiGameInfo::OnTimer( XUIMessageTimer *pTimer, BOOL& bHandled )
351{
352 if ( pTimer->nId == UPDATE_PLAYERS_TIMER_ID)
353 {
354 PlayerUID selectedPlayerXUID = m_selectedSession->data.players[playersList.GetCurSel()];
355
356 bool success = g_NetworkManager.GetGameSessionInfo(m_iPad, m_selectedSession->sessionId,m_selectedSession);
357
358 if( success )
359 {
360 playersList.DeleteItems(0, playersList.GetItemCount());
361 int selectedIndex = 0;
362 for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i)
363 {
364 if( m_selectedSession->data.players[i] != NULL )
365 {
366 if(m_selectedSession->data.players[i] == selectedPlayerXUID) selectedIndex = i;
367 playersList.InsertItems(i,1);
368#ifndef _CONTENT_PACKAGE
369 if(app.DebugSettingsOn() && (app.GetGameSettingsDebugMask()&(1L<<eDebugSetting_DebugLeaderboards)))
370 {
371 playersList.SetText(i, L"WWWWWWWWWWWWWWWW" );
372 }
373 else
374#endif
375 {
376 playersList.SetText(i, convStringToWstring( m_selectedSession->data.szPlayers[i] ).c_str() );
377 }
378 }
379 else
380 {
381 // Leave the loop when we hit the first NULL player
382 break;
383 }
384 }
385 playersList.SetCurSel(selectedIndex);
386 }
387 }
388
389 return S_OK;
390}
391
392