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_Teleport.h"
5#include "..\..\ServerPlayer.h"
6#include "..\..\PlayerConnection.h"
7#include "..\..\PlayerList.h"
8#include "..\..\MinecraftServer.h"
9#include "..\..\..\Minecraft.World\StringHelpers.h"
10#include "..\..\PlayerRenderer.h"
11#include "XUI_InGamePlayerOptions.h"
12#include "..\..\Minecraft.h"
13#include "..\..\MultiPlayerLocalPlayer.h"
14#include "..\..\ClientConnection.h"
15#include "..\..\..\Minecraft.World\net.minecraft.network.packet.h"
16#include "..\..\Xbox\Network\NetworkPlayerXbox.h"
17#include "TeleportCommand.h"
18
19//----------------------------------------------------------------------------------
20// Performs initialization tasks - retrieves controls.
21//----------------------------------------------------------------------------------
22HRESULT CScene_Teleport::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
23{
24 TeleportMenuInitData *initParam = (TeleportMenuInitData *)pInitData->pvInitData;
25
26 m_iPad = initParam->iPad;
27 m_teleportToPlayer = initParam->teleportToPlayer;
28
29 delete initParam;
30
31 MapChildControls();
32
33 if(m_teleportToPlayer)
34 {
35 m_title.SetText(app.GetString(IDS_TELEPORT_TO_PLAYER));
36 }
37 else
38 {
39 m_title.SetText(app.GetString(IDS_TELEPORT_TO_ME));
40 }
41
42 if(app.GetLocalPlayerCount()>1)
43 {
44 app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad);
45 }
46
47 DWORD playerCount = g_NetworkManager.GetPlayerCount();
48
49 m_playersCount = 0;
50 for(DWORD i = 0; i < playerCount; ++i)
51 {
52 INetworkPlayer *player = g_NetworkManager.GetPlayerByIndex( i );
53
54 if( player != NULL && !(player->IsLocal() && player->GetUserIndex() == m_iPad) )
55 {
56 m_players[m_playersCount] = player->GetSmallId();
57 ++m_playersCount;
58 }
59 }
60
61 g_NetworkManager.RegisterPlayerChangedCallback(m_iPad, &CScene_Teleport::OnPlayerChanged, this);
62
63 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
64
65 CXuiSceneBase::ShowDarkOverlay( m_iPad, TRUE );
66
67 return S_OK;
68}
69
70HRESULT CScene_Teleport::OnDestroy()
71{
72 g_NetworkManager.UnRegisterPlayerChangedCallback(m_iPad, &CScene_Teleport::OnPlayerChanged, this);
73 return S_OK;
74}
75
76HRESULT CScene_Teleport::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled)
77{
78 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode);
79
80 HRESULT hr = S_OK;
81 switch(pInputData->dwKeyCode)
82 {
83
84 case VK_PAD_B:
85 case VK_PAD_BACK:
86 case VK_ESCAPE:
87 CXuiSceneBase::PlayUISFX(eSFX_Back);
88 app.NavigateBack(pInputData->UserIndex);
89 rfHandled = TRUE;
90
91 break;
92 }
93
94
95 return hr;
96}
97
98//----------------------------------------------------------------------------------
99// Handler for the button press message.
100//----------------------------------------------------------------------------------
101HRESULT CScene_Teleport::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPress* pNotifyPressData, BOOL& rfHandled)
102{
103 // This assumes all buttons can only be pressed with the A button
104 ui.AnimateKeyPress(pNotifyPressData->UserIndex, VK_PAD_A);
105
106 if( hObjPressed == playersList )
107 {
108 INetworkPlayer *selectedPlayer = g_NetworkManager.GetPlayerBySmallId( m_players[ playersList.GetCurSel() ] );
109 INetworkPlayer *thisPlayer = g_NetworkManager.GetLocalPlayerByUserIndex(m_iPad);
110
111 shared_ptr<GameCommandPacket> packet;
112 if(m_teleportToPlayer)
113 {
114 packet = TeleportCommand::preparePacket(thisPlayer->GetUID(),selectedPlayer->GetUID());
115 }
116 else
117 {
118 packet = TeleportCommand::preparePacket(selectedPlayer->GetUID(),thisPlayer->GetUID());
119 }
120 ClientConnection *conn = Minecraft::GetInstance()->getConnection(m_iPad);
121 conn->send( packet );
122 }
123 return S_OK;
124}
125
126void CScene_Teleport::OnPlayerChanged(void *callbackParam, INetworkPlayer *pPlayer, bool leaving)
127{
128 CScene_Teleport *scene = (CScene_Teleport *)callbackParam;
129 bool playerFound = false;
130
131 for(int i = 0; i < scene->m_playersCount; ++i)
132 {
133 if(playerFound)
134 {
135 scene->m_players[i-1] = scene->m_players[i];
136 }
137 else if( scene->m_players[i] == pPlayer->GetSmallId() )
138 {
139 if( scene->playersList.GetCurSel() == scene->playersList.GetItemCount() - 1 )
140 {
141 scene->playersList.SetCurSel( scene->playersList.GetItemCount() - 2 );
142 }
143 // Player removed
144 playerFound = true;
145 }
146 }
147
148 if( playerFound )
149 {
150 --scene->m_playersCount;
151 scene->playersList.DeleteItems( scene->playersList.GetItemCount() - 1, 1 );
152 }
153
154 if( !playerFound )
155 {
156 // Player added
157 scene->m_players[scene->m_playersCount] = pPlayer->GetSmallId();
158 ++scene->m_playersCount;
159 scene->playersList.InsertItems( scene->playersList.GetItemCount(), 1 );
160 }
161}
162
163HRESULT CScene_Teleport::OnGetSourceDataText(XUIMessageGetSourceText *pGetSourceTextData, BOOL& bHandled)
164{
165 if( pGetSourceTextData->bItemData )
166 {
167 if( pGetSourceTextData->iItem < m_playersCount )
168 {
169 INetworkPlayer *player = g_NetworkManager.GetPlayerBySmallId( m_players[pGetSourceTextData->iItem] );
170 if( player != NULL )
171 {
172#ifndef _CONTENT_PACKAGE
173 if(app.DebugSettingsOn() && (app.GetGameSettingsDebugMask()&(1L<<eDebugSetting_DebugLeaderboards)))
174 {
175 pGetSourceTextData->szText = L"WWWWWWWWWWWWWWWW";
176 }
177 else
178#endif
179 {
180 pGetSourceTextData->szText = player->GetOnlineName();
181 }
182 }
183 else
184 {
185 pGetSourceTextData->szText = L"";
186 }
187
188 HRESULT hr;
189 HXUIOBJ hButton, hVisual, hPlayerIcon, hVoiceIcon;
190 hButton = playersList.GetItemControl(pGetSourceTextData->iItem);
191 hr=XuiControlGetVisual(hButton,&hVisual);
192
193 // Set the players icon
194 hr=XuiElementGetChildById(hVisual,L"IconGroup",&hPlayerIcon);
195 short colourIndex = app.GetPlayerColour( m_players[pGetSourceTextData->iItem] );
196 int playFrame = 0;
197 switch(colourIndex)
198 {
199 case 1:
200 XuiElementFindNamedFrame(hPlayerIcon, L"P1", &playFrame);
201 break;
202 case 2:
203 XuiElementFindNamedFrame(hPlayerIcon, L"P2", &playFrame);
204 break;
205 case 3:
206 XuiElementFindNamedFrame(hPlayerIcon, L"P3", &playFrame);
207 break;
208 case 4:
209 XuiElementFindNamedFrame(hPlayerIcon, L"P4", &playFrame);
210 break;
211 case 5:
212 XuiElementFindNamedFrame(hPlayerIcon, L"P5", &playFrame);
213 break;
214 case 6:
215 XuiElementFindNamedFrame(hPlayerIcon, L"P6", &playFrame);
216 break;
217 case 7:
218 XuiElementFindNamedFrame(hPlayerIcon, L"P7", &playFrame);
219 break;
220 case 8:
221 XuiElementFindNamedFrame(hPlayerIcon, L"P8", &playFrame);
222 break;
223 case 9:
224 XuiElementFindNamedFrame(hPlayerIcon, L"P9", &playFrame);
225 break;
226 case 10:
227 XuiElementFindNamedFrame(hPlayerIcon, L"P10", &playFrame);
228 break;
229 case 11:
230 XuiElementFindNamedFrame(hPlayerIcon, L"P11", &playFrame);
231 break;
232 case 12:
233 XuiElementFindNamedFrame(hPlayerIcon, L"P12", &playFrame);
234 break;
235 case 13:
236 XuiElementFindNamedFrame(hPlayerIcon, L"P13", &playFrame);
237 break;
238 case 14:
239 XuiElementFindNamedFrame(hPlayerIcon, L"P14", &playFrame);
240 break;
241 case 15:
242 XuiElementFindNamedFrame(hPlayerIcon, L"P15", &playFrame);
243 break;
244 case 0:
245 default:
246 XuiElementFindNamedFrame(hPlayerIcon, L"P0", &playFrame);
247 break;
248 };
249 if(playFrame < 0) playFrame = 0;
250 XuiElementPlayTimeline(hPlayerIcon,playFrame,playFrame,playFrame,FALSE,FALSE);
251
252 // Set the voice icon
253 hr=XuiElementGetChildById(hVisual,L"VoiceGroup",&hVoiceIcon);
254
255 playFrame = -1;
256 if(player != NULL && player->HasVoice() )
257 {
258 if( player->IsMutedByLocalUser(m_iPad) )
259 {
260 // Muted image
261 XuiElementFindNamedFrame(hVoiceIcon, L"Muted", &playFrame);
262 }
263 else if( player->IsTalking() )
264 {
265 // Talking image
266 XuiElementFindNamedFrame(hVoiceIcon, L"Speaking", &playFrame);
267 }
268 else
269 {
270 // Not talking image
271 XuiElementFindNamedFrame(hVoiceIcon, L"NotSpeaking", &playFrame);
272 }
273 }
274
275 if(playFrame < 0)
276 {
277 XuiElementFindNamedFrame(hVoiceIcon, L"Normal", &playFrame);
278 }
279 XuiElementPlayTimeline(hVoiceIcon,playFrame,playFrame,playFrame,FALSE,FALSE);
280
281 pGetSourceTextData->bDisplay = TRUE;
282
283 bHandled = TRUE;
284 }
285 }
286 return S_OK;
287}
288
289HRESULT CScene_Teleport::OnGetSourceDataImage(XUIMessageGetSourceImage *pGetSourceImageData,BOOL& bHandled)
290{
291 if( pGetSourceImageData->bItemData )
292 {
293 if( pGetSourceImageData->iItem < m_playersCount )
294 {
295 bHandled = TRUE;
296 }
297 }
298 return S_OK;
299}
300
301HRESULT CScene_Teleport::OnGetItemCountAll(XUIMessageGetItemCount *pGetItemCountData, BOOL& bHandled)
302{
303 pGetItemCountData->cItems = m_playersCount;
304 bHandled = TRUE;
305 return S_OK;
306}
307
308HRESULT CScene_Teleport::OnCustomMessage_Splitscreenplayer(bool bJoining, BOOL& bHandled)
309{
310 bHandled=true;
311 return app.AdjustSplitscreenScene_PlayerChanged(m_hObj,&m_OriginalPosition,m_iPad,bJoining);
312}