the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 344 lines 8.8 kB view raw
1#include "stdafx.h" 2#include "UI.h" 3#include "UIScene_TeleportMenu.h" 4#include "..\..\MultiPlayerLocalPlayer.h" 5#include "..\..\..\Minecraft.World\net.minecraft.network.packet.h" 6#include "..\..\MultiPlayerLocalPlayer.h" 7#include "..\..\ClientConnection.h" 8#include "TeleportCommand.h" 9 10UIScene_TeleportMenu::UIScene_TeleportMenu(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) 11{ 12 // Setup all the Iggy references we need for this scene 13 initialiseMovie(); 14 15 TeleportMenuInitData *initParam = (TeleportMenuInitData *)initData; 16 17 m_teleportToPlayer = initParam->teleportToPlayer; 18 19 delete initParam; 20 21 if(m_teleportToPlayer) 22 { 23 m_labelTitle.init(app.GetString(IDS_TELEPORT_TO_PLAYER)); 24 } 25 else 26 { 27 m_labelTitle.init(app.GetString(IDS_TELEPORT_TO_ME)); 28 } 29 30 m_playerList.init(eControl_GamePlayers); 31 32 for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i) 33 { 34 m_playerNames[i] = L""; 35 } 36 37 DWORD playerCount = g_NetworkManager.GetPlayerCount(); 38 39 m_playersCount = 0; 40 for(DWORD i = 0; i < playerCount; ++i) 41 { 42 INetworkPlayer *player = g_NetworkManager.GetPlayerByIndex( i ); 43 44 if( player != NULL && !(player->IsLocal() && player->GetUserIndex() == m_iPad) ) 45 { 46 m_players[m_playersCount] = player->GetSmallId(); 47 ++m_playersCount; 48 49 wstring playerName = L""; 50#ifndef _CONTENT_PACKAGE 51 if(app.DebugSettingsOn() && (app.GetGameSettingsDebugMask()&(1L<<eDebugSetting_DebugLeaderboards))) 52 { 53 playerName = L"WWWWWWWWWWWWWWWW"; 54 } 55 else 56#endif 57 { 58 playerName = player->GetDisplayName(); 59 } 60 61 int voiceStatus = 0; 62 if(player != NULL && player->HasVoice() ) 63 { 64 if( player->IsMutedByLocalUser(m_iPad) ) 65 { 66 // Muted image 67 voiceStatus = 3; 68 } 69 else if( player->IsTalking() ) 70 { 71 // Talking image 72 voiceStatus = 2; 73 } 74 else 75 { 76 // Not talking image 77 voiceStatus = 1; 78 } 79 } 80 81 m_playersVoiceState[m_playersCount] = voiceStatus; 82 m_playersColourState[m_playersCount] = app.GetPlayerColour( m_players[m_playersCount] ); 83 m_playerNames[m_playersCount] = playerName; 84 m_playerList.addItem( playerName, app.GetPlayerColour( m_players[m_playersCount] ), voiceStatus); 85 } 86 } 87 88 g_NetworkManager.RegisterPlayerChangedCallback(m_iPad, &UIScene_TeleportMenu::OnPlayerChanged, this); 89 90 parentLayer->addComponent(iPad,eUIComponent_MenuBackground); 91 92 // get rid of the quadrant display if it's on 93 ui.HidePressStart(); 94} 95 96wstring UIScene_TeleportMenu::getMoviePath() 97{ 98 if(app.GetLocalPlayerCount() > 1) 99 { 100 return L"InGameTeleportMenuSplit"; 101 } 102 else 103 { 104 return L"InGameTeleportMenu"; 105 } 106} 107 108void UIScene_TeleportMenu::updateTooltips() 109{ 110 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); 111} 112 113void UIScene_TeleportMenu::handleDestroy() 114{ 115 g_NetworkManager.UnRegisterPlayerChangedCallback(m_iPad, &UIScene_TeleportMenu::OnPlayerChanged, this); 116 117 m_parentLayer->removeComponent(eUIComponent_MenuBackground); 118} 119 120void UIScene_TeleportMenu::handleGainFocus(bool navBack) 121{ 122 if( navBack ) g_NetworkManager.RegisterPlayerChangedCallback(m_iPad, &UIScene_TeleportMenu::OnPlayerChanged, this); 123} 124 125void UIScene_TeleportMenu::handleReload() 126{ 127 DWORD playerCount = g_NetworkManager.GetPlayerCount(); 128 129 m_playersCount = 0; 130 for(DWORD i = 0; i < playerCount; ++i) 131 { 132 INetworkPlayer *player = g_NetworkManager.GetPlayerByIndex( i ); 133 134 if( player != NULL && !(player->IsLocal() && player->GetUserIndex() == m_iPad) ) 135 { 136 m_players[m_playersCount] = player->GetSmallId(); 137 ++m_playersCount; 138 139 wstring playerName = L""; 140#ifndef _CONTENT_PACKAGE 141 if(app.DebugSettingsOn() && (app.GetGameSettingsDebugMask()&(1L<<eDebugSetting_DebugLeaderboards))) 142 { 143 playerName = L"WWWWWWWWWWWWWWWW"; 144 } 145 else 146#endif 147 { 148 playerName = player->GetDisplayName(); 149 } 150 151 int voiceStatus = 0; 152 if(player != NULL && player->HasVoice() ) 153 { 154 if( player->IsMutedByLocalUser(m_iPad) ) 155 { 156 // Muted image 157 voiceStatus = 3; 158 } 159 else if( player->IsTalking() ) 160 { 161 // Talking image 162 voiceStatus = 2; 163 } 164 else 165 { 166 // Not talking image 167 voiceStatus = 1; 168 } 169 } 170 171 m_playersVoiceState[m_playersCount] = voiceStatus; 172 m_playersColourState[m_playersCount] = app.GetPlayerColour( m_players[m_playersCount] ); 173 m_playerNames[m_playersCount] = playerName; 174 m_playerList.addItem( playerName, app.GetPlayerColour( m_players[m_playersCount] ), voiceStatus); 175 } 176 } 177 178 if(controlHasFocus(eControl_GamePlayers)) 179 { 180 m_playerList.setCurrentSelection(getControlChildFocus()); 181 } 182} 183 184void UIScene_TeleportMenu::tick() 185{ 186 UIScene::tick(); 187 188 for(DWORD i = 0; i < m_playersCount; ++i) 189 { 190 INetworkPlayer *player = g_NetworkManager.GetPlayerBySmallId( m_players[i] ); 191 192 if( player != NULL ) 193 { 194 m_players[i] = player->GetSmallId(); 195 196 short icon = app.GetPlayerColour( m_players[i] ); 197 198 if(icon != m_playersColourState[i]) 199 { 200 m_playersColourState[i] = icon; 201 m_playerList.setPlayerIcon( i, (int)app.GetPlayerColour( m_players[i] ) ); 202 } 203 204 wstring playerName = L""; 205#ifndef _CONTENT_PACKAGE 206 if(app.DebugSettingsOn() && (app.GetGameSettingsDebugMask()&(1L<<eDebugSetting_DebugLeaderboards))) 207 { 208 playerName = L"WWWWWWWWWWWWWWWW"; 209 } 210 else 211#endif 212 { 213 playerName = player->GetDisplayName(); 214 } 215 if(playerName.compare( m_playerNames[i] ) != 0 ) 216 { 217 m_playerList.setButtonLabel(i, playerName); 218 m_playerNames[i] = playerName; 219 } 220 } 221 } 222} 223 224void UIScene_TeleportMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) 225{ 226 //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"); 227 ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released); 228 229 switch(key) 230 { 231 case ACTION_MENU_CANCEL: 232 if(pressed && !repeat) 233 { 234 ui.PlayUISFX(eSFX_Back); 235 navigateBack(); 236 } 237 break; 238 case ACTION_MENU_OK: 239#ifdef __ORBIS__ 240 case ACTION_MENU_TOUCHPAD_PRESS: 241#endif 242 case ACTION_MENU_UP: 243 case ACTION_MENU_DOWN: 244 case ACTION_MENU_PAGEUP: 245 case ACTION_MENU_PAGEDOWN: 246 sendInputToMovie(key, repeat, pressed, released); 247 break; 248 } 249} 250 251void UIScene_TeleportMenu::handlePress(F64 controlId, F64 childId) 252{ 253 app.DebugPrintf("Pressed = %d, %d\n", (int)controlId, (int)childId); 254 switch((int)controlId) 255 { 256 case eControl_GamePlayers: 257 int currentSelection = (int)childId; 258 INetworkPlayer *selectedPlayer = g_NetworkManager.GetPlayerBySmallId( m_players[ currentSelection ] ); 259 INetworkPlayer *thisPlayer = g_NetworkManager.GetLocalPlayerByUserIndex(m_iPad); 260 261 shared_ptr<GameCommandPacket> packet; 262 if(m_teleportToPlayer) 263 { 264 packet = TeleportCommand::preparePacket(thisPlayer->GetUID(),selectedPlayer->GetUID()); 265 } 266 else 267 { 268 packet = TeleportCommand::preparePacket(selectedPlayer->GetUID(),thisPlayer->GetUID()); 269 } 270 ClientConnection *conn = Minecraft::GetInstance()->getConnection(m_iPad); 271 conn->send( packet ); 272 break; 273 } 274} 275 276void UIScene_TeleportMenu::OnPlayerChanged(void *callbackParam, INetworkPlayer *pPlayer, bool leaving) 277{ 278 UIScene_TeleportMenu *scene = (UIScene_TeleportMenu *)callbackParam; 279 bool playerFound = false; 280 int foundIndex = 0; 281 for(int i = 0; i < scene->m_playersCount; ++i) 282 { 283 if(!playerFound && scene->m_players[i] == pPlayer->GetSmallId() ) 284 { 285 if( scene->m_playerList.getCurrentSelection() == scene->m_playerList.getItemCount() - 1 ) 286 { 287 scene->m_playerList.setCurrentSelection( scene->m_playerList.getItemCount() - 2 ); 288 } 289 // Player removed 290 playerFound = true; 291 foundIndex = i; 292 } 293 } 294 295 if( playerFound ) 296 { 297 --scene->m_playersCount; 298 scene->m_playersVoiceState[scene->m_playersCount] = 0; 299 scene->m_playersColourState[scene->m_playersCount] = 0; 300 scene->m_playerNames[scene->m_playersCount] = L""; 301 scene->m_playerList.removeItem(scene->m_playersCount); 302 } 303 304 if( !playerFound ) 305 { 306 // Player added 307 scene->m_players[scene->m_playersCount] = pPlayer->GetSmallId(); 308 ++scene->m_playersCount; 309 310 wstring playerName = L""; 311#ifndef _CONTENT_PACKAGE 312 if(app.DebugSettingsOn() && (app.GetGameSettingsDebugMask()&(1L<<eDebugSetting_DebugLeaderboards))) 313 { 314 playerName = L"WWWWWWWWWWWWWWWW"; 315 } 316 else 317#endif 318 { 319 playerName = pPlayer->GetDisplayName(); 320 } 321 322 int voiceStatus = 0; 323 if(pPlayer != NULL && pPlayer->HasVoice() ) 324 { 325 if( pPlayer->IsMutedByLocalUser(scene->m_iPad) ) 326 { 327 // Muted image 328 voiceStatus = 3; 329 } 330 else if( pPlayer->IsTalking() ) 331 { 332 // Talking image 333 voiceStatus = 2; 334 } 335 else 336 { 337 // Not talking image 338 voiceStatus = 1; 339 } 340 } 341 342 scene->m_playerList.addItem( playerName, app.GetPlayerColour( scene->m_players[scene->m_playersCount - 1] ), voiceStatus); 343 } 344}