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_InGameInfoMenu.h"
4#include "..\..\MultiPlayerLocalPlayer.h"
5#include "..\..\..\Minecraft.World\net.minecraft.network.packet.h"
6#include "..\..\MultiPlayerLocalPlayer.h"
7#include "..\..\ClientConnection.h"
8
9UIScene_InGameInfoMenu::UIScene_InGameInfoMenu(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer)
10{
11 // Setup all the Iggy references we need for this scene
12 initialiseMovie();
13
14 m_buttonGameOptions.init(app.GetString(IDS_HOST_OPTIONS),eControl_GameOptions);
15 m_labelTitle.init(app.GetString(IDS_PLAYERS_INVITE));
16 m_playerList.init(eControl_GamePlayers);
17
18 m_players = vector<PlayerInfo *>();
19
20 DWORD playerCount = g_NetworkManager.GetPlayerCount();
21
22 for(DWORD i = 0; i < playerCount; ++i)
23 {
24 INetworkPlayer *player = g_NetworkManager.GetPlayerByIndex( i );
25
26 if( player != NULL )
27 {
28 PlayerInfo *info = BuildPlayerInfo(player);
29
30 m_players.push_back(info);
31 m_playerList.addItem(info->m_name, info->m_colorState, info->m_voiceStatus);
32 }
33 }
34
35 g_NetworkManager.RegisterPlayerChangedCallback(m_iPad, &UIScene_InGameInfoMenu::OnPlayerChanged, this);
36
37 INetworkPlayer *thisPlayer = g_NetworkManager.GetLocalPlayerByUserIndex( m_iPad );
38 m_isHostPlayer = false;
39 if(thisPlayer != NULL) m_isHostPlayer = thisPlayer->IsHost() == TRUE;
40
41 Minecraft *pMinecraft = Minecraft::GetInstance();
42 shared_ptr<MultiplayerLocalPlayer> localPlayer = pMinecraft->localplayers[m_iPad];
43 if(!m_isHostPlayer && !localPlayer->isModerator() )
44 {
45 removeControl( &m_buttonGameOptions, false );
46 }
47
48 updateTooltips();
49
50#if TO_BE_IMPLEMENTED
51 SetTimer( TOOLTIP_TIMERID , INGAME_INFO_TOOLTIP_TIMER );
52#endif
53
54 // get rid of the quadrant display if it's on
55 ui.HidePressStart();
56
57#if TO_BE_IMPLEMENTED
58 SetTimer(IGNORE_KEYPRESS_TIMERID,IGNORE_KEYPRESS_TIME);
59#endif
60}
61
62UIScene_InGameInfoMenu::~UIScene_InGameInfoMenu()
63{
64 // Delete player infos
65 for (int i = 0; i < m_players.size(); i++) { delete m_players[i]; }
66}
67
68wstring UIScene_InGameInfoMenu::getMoviePath()
69{
70 if(app.GetLocalPlayerCount() > 1)
71 {
72 return L"InGameInfoMenuSplit";
73 }
74 else
75 {
76 return L"InGameInfoMenu";
77 }
78}
79
80void UIScene_InGameInfoMenu::updateTooltips()
81{
82 int keyX = IDS_TOOLTIPS_INVITE_FRIENDS;
83 int ikeyY = -1;
84
85 XPARTY_USER_LIST partyList;
86 if((XPartyGetUserList( &partyList ) != XPARTY_E_NOT_IN_PARTY ) && (partyList.dwUserCount>1))
87 {
88 keyX = IDS_TOOLTIPS_INVITE_PARTY;
89 }
90
91 if(g_NetworkManager.IsLocalGame()) keyX = -1;
92#ifdef __PSVITA__
93 if(CGameNetworkManager::usingAdhocMode()) keyX = -1;
94#endif
95
96 INetworkPlayer *selectedPlayer = g_NetworkManager.GetPlayerBySmallId(m_players[m_playerList.getCurrentSelection()]->m_smallId);
97
98 int keyA = -1;
99 Minecraft *pMinecraft = Minecraft::GetInstance();
100 shared_ptr<MultiplayerLocalPlayer> localPlayer = pMinecraft->localplayers[m_iPad];
101
102 bool isOp = m_isHostPlayer || localPlayer->isModerator();
103 bool cheats = app.GetGameHostOption(eGameHostOption_CheatsEnabled) != 0;
104 bool trust = app.GetGameHostOption(eGameHostOption_TrustPlayers) != 0;
105
106 if( isOp )
107 {
108 if(m_buttonGameOptions.hasFocus())
109 {
110 keyA = IDS_TOOLTIPS_SELECT;
111 }
112 else if( selectedPlayer != NULL)
113 {
114 bool editingHost = selectedPlayer->IsHost();
115 if( (cheats && (m_isHostPlayer || !editingHost ) ) || (!trust && (m_isHostPlayer || !editingHost))
116#if (!defined(_CONTENT_PACKAGE) && !defined(_FINAL_BUILD) && defined(_DEBUG_MENUS_ENABLED))
117 || (m_isHostPlayer && editingHost)
118#endif
119 )
120 {
121 keyA = IDS_TOOLTIPS_PRIVILEGES;
122 }
123 else if(selectedPlayer->IsLocal() != TRUE && selectedPlayer->IsSameSystem(g_NetworkManager.GetHostPlayer()) != TRUE)
124 {
125 // Only ops will hit this, can kick anyone not local and not local to the host
126 keyA = IDS_TOOLTIPS_KICK;
127 }
128 }
129 }
130
131#if defined(__PS3__) || defined(__ORBIS__)
132 if(m_iPad == ProfileManager.GetPrimaryPad() ) ikeyY = IDS_TOOLTIPS_GAME_INVITES;
133#else
134 if(!m_buttonGameOptions.hasFocus())
135 {
136 // if the player is me, then view gamer profile
137 if(selectedPlayer != NULL && selectedPlayer->IsLocal() && selectedPlayer->GetUserIndex()==m_iPad)
138 {
139 ikeyY = IDS_TOOLTIPS_VIEW_GAMERPROFILE;
140 }
141 else
142 {
143 ikeyY = IDS_TOOLTIPS_VIEW_GAMERCARD;
144 }
145 }
146#endif
147 ui.SetTooltips( m_iPad, keyA,IDS_TOOLTIPS_BACK,keyX,ikeyY);
148}
149
150void UIScene_InGameInfoMenu::handleDestroy()
151{
152 g_NetworkManager.UnRegisterPlayerChangedCallback(m_iPad, &UIScene_InGameInfoMenu::OnPlayerChanged, this);
153
154 m_parentLayer->removeComponent(eUIComponent_MenuBackground);
155}
156
157void UIScene_InGameInfoMenu::handleGainFocus(bool navBack)
158{
159 UIScene::handleGainFocus(navBack);
160 if( navBack ) g_NetworkManager.RegisterPlayerChangedCallback(m_iPad, &UIScene_InGameInfoMenu::OnPlayerChanged, this);
161}
162
163void UIScene_InGameInfoMenu::handleReload()
164{
165 DWORD playerCount = g_NetworkManager.GetPlayerCount();
166
167 // Remove all player info
168 for (int i = 0; i < m_players.size(); i++) { delete m_players[i]; }
169 m_players.clear();
170
171 for(DWORD i = 0; i < playerCount; ++i)
172 {
173 INetworkPlayer *player = g_NetworkManager.GetPlayerByIndex( i );
174
175 if( player != NULL )
176 {
177 PlayerInfo *info = BuildPlayerInfo(player);
178
179 m_players.push_back(info);
180 m_playerList.addItem(info->m_name, info->m_colorState, info->m_voiceStatus);
181 }
182 }
183
184 INetworkPlayer *thisPlayer = g_NetworkManager.GetLocalPlayerByUserIndex( m_iPad );
185 m_isHostPlayer = false;
186 if(thisPlayer != NULL) m_isHostPlayer = thisPlayer->IsHost() == TRUE;
187
188 Minecraft *pMinecraft = Minecraft::GetInstance();
189 shared_ptr<MultiplayerLocalPlayer> localPlayer = pMinecraft->localplayers[m_iPad];
190 if(!m_isHostPlayer && !localPlayer->isModerator() )
191 {
192 removeControl( &m_buttonGameOptions, false );
193 }
194
195 updateTooltips();
196
197 if(controlHasFocus(eControl_GamePlayers))
198 {
199 m_playerList.setCurrentSelection(getControlChildFocus());
200 }
201}
202
203void UIScene_InGameInfoMenu::tick()
204{
205 UIScene::tick();
206
207 // Update players by index
208 for(DWORD i = 0; i < m_players.size(); ++i)
209 {
210 INetworkPlayer *player = g_NetworkManager.GetPlayerByIndex( i );
211
212 if(player != NULL)
213 {
214 PlayerInfo *info = BuildPlayerInfo(player);
215
216 m_players[i]->m_smallId = info->m_smallId;
217
218 if(info->m_voiceStatus != m_players[i]->m_voiceStatus)
219 {
220 m_players[i]->m_voiceStatus = info->m_voiceStatus;
221 m_playerList.setVOIPIcon(i, info->m_voiceStatus);
222 }
223
224 if(info->m_colorState != m_players[i]->m_colorState)
225 {
226 m_players[i]->m_colorState = info->m_colorState;
227 m_playerList.setPlayerIcon(i, info->m_colorState);
228 }
229
230 if(info->m_name.compare( m_players[i]->m_name ) != 0 )
231 {
232 m_playerList.setButtonLabel(i, info->m_name);
233 m_players[i]->m_name = info->m_name;
234 }
235
236 delete info;
237 }
238 }
239}
240
241void UIScene_InGameInfoMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
242{
243 //app.DebugPrintf("UIScene_DebugOverlay handling input for pad %d, key %d, down- %s, pressed- %s, released- %s\n", iPad, key, down?"TRUE":"FALSE", pressed?"TRUE":"FALSE", released?"TRUE":"FALSE");
244 ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released);
245
246 switch(key)
247 {
248 case ACTION_MENU_CANCEL:
249 if(pressed && !repeat)
250 {
251 ui.PlayUISFX(eSFX_Back);
252 navigateBack();
253 }
254 break;
255 case ACTION_MENU_Y:
256#if defined(__PS3__) || defined(__ORBIS__)
257 if(pressed && iPad == ProfileManager.GetPrimaryPad())
258 {
259#ifdef __PS3__
260 // are we offline?
261 if(!ProfileManager.IsSignedInLive(iPad))
262 {
263 // get them to sign in to online
264 UINT uiIDA[2];
265 uiIDA[0]=IDS_PRO_NOTONLINE_ACCEPT;
266 uiIDA[1]=IDS_PRO_NOTONLINE_DECLINE;
267 ui.RequestErrorMessage(IDS_PRO_NOTONLINE_TITLE, IDS_PRO_NOTONLINE_TEXT, uiIDA, 2, ProfileManager.GetPrimaryPad(),&UIScene_InGameInfoMenu::MustSignInReturnedPSN,this);
268 }
269 else
270#endif
271 {
272#ifdef __ORBIS__
273 SQRNetworkManager_Orbis::RecvInviteGUI();
274#else // __PS3__
275 int ret = sceNpBasicRecvMessageCustom(SCE_NP_BASIC_MESSAGE_MAIN_TYPE_INVITE, SCE_NP_BASIC_RECV_MESSAGE_OPTIONS_INCLUDE_BOOTABLE, SYS_MEMORY_CONTAINER_ID_INVALID);
276 app.DebugPrintf("sceNpBasicRecvMessageCustom return %d ( %08x )\n", ret, ret);
277#endif
278 }
279 }
280#else
281
282
283 if(pressed && m_playerList.hasFocus() && (m_playerList.getItemCount() > 0) && (m_playerList.getCurrentSelection() < m_players.size()) )
284 {
285 INetworkPlayer *player = g_NetworkManager.GetPlayerBySmallId(m_players[m_playerList.getCurrentSelection()]->m_smallId);
286 if( player != NULL )
287 {
288 PlayerUID uid = player->GetUID();
289 if( uid != INVALID_XUID )
290 {
291#ifdef __PSVITA__
292 PSVITA_STUBBED;
293#else
294 ProfileManager.ShowProfileCard(iPad,uid);
295#endif
296 }
297 }
298 }
299
300#endif
301 break;
302 case ACTION_MENU_X:
303
304 if(pressed && !repeat && !g_NetworkManager.IsLocalGame() )
305 {
306#ifdef __PSVITA__
307 if(CGameNetworkManager::usingAdhocMode() == false)
308 g_NetworkManager.SendInviteGUI(iPad);
309#else
310 g_NetworkManager.SendInviteGUI(iPad);
311#endif
312 }
313
314 break;
315 case ACTION_MENU_OK:
316#ifdef __ORBIS__
317 case ACTION_MENU_TOUCHPAD_PRESS:
318#endif
319 case ACTION_MENU_UP:
320 case ACTION_MENU_DOWN:
321 case ACTION_MENU_PAGEUP:
322 case ACTION_MENU_PAGEDOWN:
323 sendInputToMovie(key, repeat, pressed, released);
324 break;
325 }
326}
327
328void UIScene_InGameInfoMenu::handlePress(F64 controlId, F64 childId)
329{
330 app.DebugPrintf("Pressed = %d, %d\n", (int)controlId, (int)childId);
331 switch((int)controlId)
332 {
333 case eControl_GameOptions:
334 ui.NavigateToScene(m_iPad,eUIScene_InGameHostOptionsMenu);
335 break;
336 case eControl_GamePlayers:
337 int currentSelection = (int)childId;
338 INetworkPlayer *selectedPlayer = g_NetworkManager.GetPlayerBySmallId(m_players[currentSelection]->m_smallId);
339
340 Minecraft *pMinecraft = Minecraft::GetInstance();
341 shared_ptr<MultiplayerLocalPlayer> localPlayer = pMinecraft->localplayers[m_iPad];
342
343 bool isOp = m_isHostPlayer || localPlayer->isModerator();
344 bool cheats = app.GetGameHostOption(eGameHostOption_CheatsEnabled) != 0;
345 bool trust = app.GetGameHostOption(eGameHostOption_TrustPlayers) != 0;
346
347 if( isOp && selectedPlayer != NULL)
348 {
349 bool editingHost = selectedPlayer->IsHost();
350 if( (cheats && (m_isHostPlayer || !editingHost ) ) || (!trust && (m_isHostPlayer || !editingHost))
351#if (!defined(_CONTENT_PACKAGE) && !defined(_FINAL_BUILD) && defined(_DEBUG_MENUS_ENABLED))
352 || (m_isHostPlayer && editingHost)
353#endif
354 )
355 {
356 InGamePlayerOptionsInitData *pInitData = new InGamePlayerOptionsInitData();
357 pInitData->iPad = m_iPad;
358 pInitData->networkSmallId = m_players[currentSelection]->m_smallId;
359 pInitData->playerPrivileges = app.GetPlayerPrivileges(m_players[currentSelection]->m_smallId);
360 ui.NavigateToScene(m_iPad,eUIScene_InGamePlayerOptionsMenu,pInitData);
361 }
362 else if(selectedPlayer->IsLocal() != TRUE && selectedPlayer->IsSameSystem(g_NetworkManager.GetHostPlayer()) != TRUE)
363 {
364 // Only ops will hit this, can kick anyone not local and not local to the host
365 BYTE *smallId = new BYTE();
366 *smallId = m_players[currentSelection]->m_smallId;
367 UINT uiIDA[2];
368 uiIDA[0]=IDS_CONFIRM_OK;
369 uiIDA[1]=IDS_CONFIRM_CANCEL;
370
371 ui.RequestAlertMessage(IDS_UNLOCK_KICK_PLAYER_TITLE, IDS_UNLOCK_KICK_PLAYER, uiIDA, 2, m_iPad,&UIScene_InGameInfoMenu::KickPlayerReturned,smallId);
372 }
373 }
374 break;
375 }
376}
377
378void UIScene_InGameInfoMenu::handleFocusChange(F64 controlId, F64 childId)
379{
380 switch((int)controlId)
381 {
382 case eControl_GamePlayers:
383 m_playerList.updateChildFocus( (int) childId );
384 };
385 updateTooltips();
386}
387
388void UIScene_InGameInfoMenu::OnPlayerChanged(void *callbackParam, INetworkPlayer *pPlayer, bool leaving)
389{
390 app.DebugPrintf("<UIScene_InGameInfoMenu::OnPlayerChanged> Player \"%ls\" %s (smallId: %d)\n", pPlayer->GetOnlineName(), leaving ? "leaving" : "joining", pPlayer->GetSmallId());
391
392 UIScene_InGameInfoMenu *scene = (UIScene_InGameInfoMenu *)callbackParam;
393 bool playerFound = false;
394 int foundIndex = 0;
395 for(int i = 0; i < scene->m_players.size(); ++i)
396 {
397 if(!playerFound && scene->m_players[i]->m_smallId == pPlayer->GetSmallId() )
398 {
399 if( scene->m_playerList.getCurrentSelection() == scene->m_playerList.getItemCount() - 1 )
400 {
401 scene->m_playerList.setCurrentSelection( scene->m_playerList.getItemCount() - 2 );
402 }
403
404 // Player found
405 playerFound = true;
406 foundIndex = i;
407 }
408 }
409
410 if (leaving && !playerFound) app.DebugPrintf("<UIScene_InGameInfoMenu::OnPlayerChanged> Error: Player \"%ls\" leaving but not found in list\n", pPlayer->GetOnlineName());
411 if (!leaving && playerFound) app.DebugPrintf("<UIScene_InGameInfoMenu::OnPlayerChanged> Error: Player \"%ls\" joining but already in list\n", pPlayer->GetOnlineName());
412
413 // If the player was found remove them (even if they're joining, they'll be added again later)
414 if(playerFound)
415 {
416 app.DebugPrintf("<UIScene_InGameInfoMenu::OnPlayerChanged> Player \"%ls\" found, removing\n", pPlayer->GetOnlineName());
417
418 // Remove player info
419 delete scene->m_players[foundIndex];
420 scene->m_players.erase(scene->m_players.begin() + foundIndex);
421
422 // Remove player from list
423 scene->m_playerList.removeItem(foundIndex);
424 }
425
426 // If the player is joining
427 if(!leaving)
428 {
429 app.DebugPrintf("<UIScene_InGameInfoMenu::OnPlayerChanged> Player \"%ls\" not found, adding\n", pPlayer->GetOnlineName());
430
431 PlayerInfo *info = scene->BuildPlayerInfo(pPlayer);
432 scene->m_players.push_back(info);
433
434 // Note that the tick updates buttons every tick so it's only really important that we
435 // add the button (not the order or content)
436 scene->m_playerList.addItem(info->m_name, info->m_colorState, info->m_voiceStatus);
437 }
438}
439
440int UIScene_InGameInfoMenu::KickPlayerReturned(void *pParam,int iPad,C4JStorage::EMessageResult result)
441{
442 BYTE smallId = *(BYTE *)pParam;
443 delete pParam;
444
445 if(result==C4JStorage::EMessage_ResultAccept)
446 {
447 Minecraft *pMinecraft = Minecraft::GetInstance();
448 shared_ptr<MultiplayerLocalPlayer> localPlayer = pMinecraft->localplayers[iPad];
449 if(localPlayer->connection)
450 {
451 localPlayer->connection->send( shared_ptr<KickPlayerPacket>( new KickPlayerPacket(smallId) ) );
452 }
453 }
454
455 return 0;
456}
457
458UIScene_InGameInfoMenu::PlayerInfo *UIScene_InGameInfoMenu::BuildPlayerInfo(INetworkPlayer *player)
459{
460 PlayerInfo *info = new PlayerInfo();
461 info->m_smallId = player->GetSmallId();
462
463 wstring playerName = L"";
464#ifndef _CONTENT_PACKAGE
465 if(app.DebugSettingsOn() && (app.GetGameSettingsDebugMask()&(1L<<eDebugSetting_DebugLeaderboards)))
466 {
467 playerName = L"WWWWWWWWWWWWWWWW";
468 }
469 else
470#endif
471 {
472 playerName = player->GetDisplayName();
473 }
474
475 int voiceStatus = 0;
476 if(player != NULL && player->HasVoice() )
477 {
478 if( player->IsMutedByLocalUser(m_iPad) )
479 {
480 // Muted image
481 voiceStatus = 3;
482 }
483 else if( player->IsTalking() )
484 {
485 // Talking image
486 voiceStatus = 2;
487 }
488 else
489 {
490 // Not talking image
491 voiceStatus = 1;
492 }
493 }
494
495 info->m_voiceStatus = voiceStatus;
496 info->m_colorState = app.GetPlayerColour(info->m_smallId);
497 info->m_name = playerName;
498
499 return info;
500}
501
502#if defined __PS3__ || defined __PSVITA__
503int UIScene_InGameInfoMenu::MustSignInReturnedPSN(void *pParam,int iPad,C4JStorage::EMessageResult result)
504{
505 UIScene_InGameInfoMenu* pClass = (UIScene_InGameInfoMenu*)pParam;
506
507 if(result==C4JStorage::EMessage_ResultAccept)
508 {
509#ifdef __PS3__
510 SQRNetworkManager_PS3::AttemptPSNSignIn(&UIScene_InGameInfoMenu::ViewInvites_SignInReturned, pClass);
511#else // __PSVITA__
512 SQRNetworkManager_Vita::AttemptPSNSignIn(&UIScene_InGameInfoMenu::ViewInvites_SignInReturned, pClass);
513#endif
514 }
515
516 return 0;
517}
518
519int UIScene_InGameInfoMenu::ViewInvites_SignInReturned(void *pParam,bool bContinue, int iPad)
520{
521 if(bContinue==true)
522 {
523 // Check if we're signed in to LIVE
524 if(ProfileManager.IsSignedInLive(iPad))
525 {
526#ifdef __ORBIS__
527 SQRNetworkManager_Orbis::RecvInviteGUI();
528#elif defined(__PS3__)
529 int ret = sceNpBasicRecvMessageCustom(SCE_NP_BASIC_MESSAGE_MAIN_TYPE_INVITE, SCE_NP_BASIC_RECV_MESSAGE_OPTIONS_INCLUDE_BOOTABLE, SYS_MEMORY_CONTAINER_ID_INVALID);
530 app.DebugPrintf("sceNpBasicRecvMessageCustom return %d ( %08x )\n", ret, ret);
531#else // __PSVITA__
532 SQRNetworkManager_Vita::RecvInviteGUI();
533#endif
534 }
535 }
536 return 0;
537}
538#endif