the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1// Minecraft.cpp : Defines the entry point for the application.
2//
3
4#include "stdafx.h"
5
6#include <assert.h>
7#include "..\..\Minecraft.h"
8#include "..\..\ProgressRenderer.h"
9#include "..\..\..\Minecraft.World\StringHelpers.h"
10#include "..\..\Common\Tutorial\TutorialMode.h"
11
12//----------------------------------------------------------------------------------
13// Performs initialization tasks - retrieves controls.
14//----------------------------------------------------------------------------------
15HRESULT CScene_FullscreenProgress::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
16{
17 MapChildControls();
18
19 m_buttonConfirm.SetText( app.GetString( IDS_CONFIRM_OK ) );
20
21 LoadingInputParams *params = (LoadingInputParams *)pInitData->pvInitData;
22
23 m_CompletionData = params->completionData;
24 m_iPad=params->completionData->iPad;
25 m_cancelFunc = params->cancelFunc;
26 m_cancelFuncParam = params->m_cancelFuncParam;
27 m_completeFunc = params->completeFunc;
28 m_completeFuncParam = params->m_completeFuncParam;
29 m_bWasCancelled=false;
30
31 thread = new C4JThread(params->func, params->lpParam, "FullscreenProgress");
32 thread->SetProcessor(3); // TODO 4J Stu - Make sure this is a good thread/core to use
33
34 m_threadCompleted = false;
35 threadStarted = false;
36 //ResumeThread( thread );
37 if( CXuiSceneBase::GetPlayerBasePosition(m_iPad) != CXuiSceneBase::e_BaseScene_Fullscreen && CXuiSceneBase::GetPlayerBasePosition(m_iPad) != CXuiSceneBase::e_BaseScene_NotSet)
38 {
39 app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad,false);
40 CXuiSceneBase::ShowLogo( m_iPad, FALSE );
41 }
42 else
43 {
44 CXuiSceneBase::ShowLogo( m_iPad, params->completionData->bShowLogo );
45 }
46
47 CXuiSceneBase::ShowBackground( m_iPad, params->completionData->bShowBackground );
48 ui.SetTooltips( m_iPad, -1, params->cancelText, -1, -1 );
49
50 // Clear the progress text
51 Minecraft *pMinecraft=Minecraft::GetInstance();
52 pMinecraft->progressRenderer->progressStart(-1);
53 pMinecraft->progressRenderer->progressStage(-1);
54
55 // set the tip
56 wstring wsText=app.FormatHTMLString(m_iPad,app.GetString(app.GetNextTip()));
57 wchar_t startTags[64];
58 swprintf(startTags,64,L"<font color=\"#%08x\" size=14><DIV ALIGN=CENTER>",app.GetHTMLColour(eHTMLColor_White));
59 wsText= startTags + wsText + L"</DIV>";
60 XuiControlSetText(m_tip, wsText.c_str());
61
62 m_tip.SetShow( m_CompletionData->bShowTips );
63
64 return S_OK;
65}
66
67// The framework calls this handler when the object is to be destroyed.
68HRESULT CScene_FullscreenProgress::OnDestroy()
69{
70 if( thread != NULL && thread != INVALID_HANDLE_VALUE )
71 delete thread;
72
73 if( m_CompletionData != NULL )
74 delete m_CompletionData;
75
76 return S_OK;
77}
78
79HRESULT CScene_FullscreenProgress::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled)
80{
81 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode);
82
83 switch(pInputData->dwKeyCode)
84 {
85
86 case VK_PAD_B:
87 case VK_ESCAPE:
88 // 4J-JEV: Fix for Xbox360 #162749 - TU17: Save Upload: Content: UI: Player is presented with non-functional Tooltips after the Upload Save For Xbox One is completed.
89 if( m_cancelFunc != NULL && !m_threadCompleted )
90 {
91 m_cancelFunc( m_cancelFuncParam );
92 m_bWasCancelled=true;
93 }
94 break;
95 }
96
97 return S_OK;
98}
99
100//----------------------------------------------------------------------------------
101// Updates the UI when the list selection changes.
102//----------------------------------------------------------------------------------
103HRESULT CScene_FullscreenProgress::OnNotifySelChanged( HXUIOBJ hObjSource, XUINotifySelChanged* pNotifySelChangedData, BOOL& bHandled )
104{
105
106 return S_OK;
107}
108
109//----------------------------------------------------------------------------------
110// Handler for the button press message.
111//----------------------------------------------------------------------------------
112HRESULT CScene_FullscreenProgress::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPress* pNotifyPressData, BOOL& rfHandled)
113{
114 // This assumes all buttons can only be pressed with the A button
115 ui.AnimateKeyPress(pNotifyPressData->UserIndex, VK_PAD_A);
116
117 if(m_threadCompleted == true && hObjPressed == m_buttonConfirm)
118 {
119 // if there's a complete function, call it
120 if(m_completeFunc)
121 {
122 m_completeFunc(m_completeFuncParam);
123 }
124 switch(m_CompletionData->type)
125 {
126 case e_ProgressCompletion_NavigateBack:
127 CXuiSceneBase::ShowBackground( m_CompletionData->iPad, FALSE );
128 CXuiSceneBase::ShowBackground( m_CompletionData->iPad, TRUE );
129 app.NavigateBack(m_CompletionData->iPad);
130 // Show the other players scenes
131 CXuiSceneBase::ShowOtherPlayersBaseScene(m_CompletionData->iPad, true);
132 ui.UpdatePlayerBasePositions();
133 break;
134 case e_ProgressCompletion_NavigateBackToScene:
135 CXuiSceneBase::ShowBackground( m_CompletionData->iPad, FALSE );
136 CXuiSceneBase::ShowBackground( m_CompletionData->iPad, TRUE );
137 CXuiSceneBase::ShowOtherPlayersBaseScene(m_CompletionData->iPad, true);
138 // If the pause menu is still active, then navigate back
139 // Otherwise close everything then navigate forwads to the pause menu
140 if(app.IsSceneInStack(m_CompletionData->iPad, m_CompletionData->scene))
141 {
142 app.NavigateBack(m_CompletionData->iPad,false, m_CompletionData->scene);
143 }
144 else
145 {
146 app.CloseXuiScenesAndNavigateToScene(m_CompletionData->iPad,m_CompletionData->scene);
147 }
148 ui.UpdatePlayerBasePositions();
149 break;
150 case e_ProgressCompletion_CloseUIScenes:
151 app.CloseXuiScenes(m_CompletionData->iPad);
152 ui.UpdatePlayerBasePositions();
153 break;
154 case e_ProgressCompletion_CloseAllPlayersUIScenes:
155 app.CloseAllPlayersXuiScenes();
156 ui.UpdatePlayerBasePositions();
157 break;
158 case e_ProgressCompletion_NavigateToHomeMenu:
159 app.NavigateToHomeMenu();
160 ui.UpdatePlayerBasePositions();
161 break;
162 }
163 }
164
165 return S_OK;
166}
167
168HRESULT CScene_FullscreenProgress::OnGetSourceDataText(XUIMessageGetSourceText *pGetSourceTextData, BOOL& bHandled)
169{
170 // This gets called every frame, so use it to update our two text boxes
171
172 Minecraft *pMinecraft=Minecraft::GetInstance();
173
174 int title = pMinecraft->progressRenderer->getCurrentTitle();
175 if(title >= 0)
176 m_title.SetText( app.GetString( title ) );
177 else
178 m_title.SetText( L"" );
179
180 int status = pMinecraft->progressRenderer->getCurrentStatus();
181 if(status >= 0)
182 m_status.SetText( app.GetString( status ) );
183 else
184 m_status.SetText( L"" );
185
186 return S_OK;
187}
188
189HRESULT CScene_FullscreenProgress::OnTransitionStart( XUIMessageTransition *pTransition, BOOL& bHandled )
190{
191 if(!threadStarted)
192 {
193 thread->Run();
194 threadStarted = true;
195 XuiSetTimer(m_hObj,TIMER_FULLSCREEN_PROGRESS,TIMER_FULLSCREEN_PROGRESS_TIME);
196 XuiSetTimer(m_hObj,TIMER_FULLSCREEN_TIPS,TIMER_FULLSCREEN_TIPS_TIME);
197 }
198 return S_OK;
199}
200
201HRESULT CScene_FullscreenProgress::OnTimer( XUIMessageTimer *pTimer, BOOL& bHandled )
202{
203 int code = thread->GetExitCode();
204 DWORD exitcode = *((DWORD *)&code);
205
206 //app.DebugPrintf("CScene_FullscreenProgress Timer %d\n",pTimer->nId);
207
208 if( exitcode != STILL_ACTIVE )
209 {
210 // 4J-PB - need to kill the timers whatever happens
211 XuiKillTimer(m_hObj,TIMER_FULLSCREEN_PROGRESS);
212 XuiKillTimer(m_hObj,TIMER_FULLSCREEN_TIPS);
213 XuiControlSetText(m_tip,L"");
214
215 // hide the tips bar in cause we're waiting for the user to press ok
216 m_tip.SetShow( FALSE );
217
218 // If we failed (currently used by network connection thread), navigate back
219 if( exitcode != S_OK )
220 {
221 if( exitcode == ERROR_CANCELLED )
222 {
223 // Current thread cancelled for whatever reason
224 // Currently used only for the CConsoleMinecraftApp::RemoteSaveThreadProc thread
225 // Assume to just ignore this thread as something else is now running that will
226 // cause another action
227 }
228 else
229 {
230 /*m_threadCompleted = true;
231 m_buttonConfirm.SetShow( TRUE );
232 m_buttonConfirm.SetFocus( m_CompletionData->iPad );
233 m_CompletionData->type = e_ProgressCompletion_NavigateToHomeMenu;
234
235 int exitReasonStringId;
236 switch( app.GetDisconnectReason() )
237 {
238 default:
239 exitReasonStringId = IDS_CONNECTION_FAILED;
240 }
241 Minecraft *pMinecraft=Minecraft::GetInstance();
242 pMinecraft->progressRenderer->progressStartNoAbort( exitReasonStringId );*/
243 //app.NavigateBack(m_CompletionData->iPad);
244
245 UINT uiIDA[1];
246 uiIDA[0]=IDS_CONFIRM_OK;
247 StorageManager.RequestMessageBox( IDS_CONNECTION_FAILED, IDS_CONNECTION_LOST_SERVER, uiIDA,1,ProfileManager.GetPrimaryPad(),NULL,NULL, app.GetStringTable());
248
249 app.NavigateToHomeMenu();
250 ui.UpdatePlayerBasePositions();
251 }
252 }
253 else
254 {
255 if(( m_CompletionData->bRequiresUserAction == TRUE ) && (!m_bWasCancelled))
256 {
257 m_threadCompleted = true;
258 m_buttonConfirm.SetShow( TRUE );
259 m_buttonConfirm.SetFocus( ProfileManager.GetPrimaryPad() );
260 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT, -1, -1, -1 );
261 }
262 else
263 {
264 if(m_bWasCancelled)
265 {
266 m_threadCompleted = true;
267 }
268 app.DebugPrintf("FullScreenProgress complete with action: ");
269 switch(m_CompletionData->type)
270 {
271 case e_ProgressCompletion_AutosaveNavigateBack:
272 app.DebugPrintf("e_ProgressCompletion_AutosaveNavigateBack\n");
273 {
274 // store these - they get wiped by the destroy caused by navigateback
275 int iPad=m_CompletionData->iPad;
276 //bool bAutosaveWasMenuDisplayed=m_CompletionData->bAutosaveWasMenuDisplayed;
277 CXuiSceneBase::ShowBackground( iPad, FALSE );
278 CXuiSceneBase::ShowLogo(iPad, FALSE );
279 app.NavigateBack(iPad);
280
281 // 4J Stu - Fix for #65437 - Customer Encountered: Code: Settings: Autosave option doesn't work when the Host goes into idle state during gameplay.
282 // Autosave obviously cannot occur if an ignore autosave menu is displayed, so even if we navigate back to a scene and not empty
283 // then we still want to reset this flag which was set true by the navigate to the fullscreen progress
284 app.SetIgnoreAutosaveMenuDisplayed(iPad, false);
285
286 // the navigate back leaves SetMenuDisplayed as true, but there may not have been a menu up when autosave was kicked off
287// if(bAutosaveWasMenuDisplayed==false)
288// {
289// app.SetMenuDisplayed(iPad,false);
290// }
291 // Show the other players scenes
292 CXuiSceneBase::ShowOtherPlayersBaseScene(iPad, true);
293 // This just allows it to be shown
294 Minecraft *pMinecraft = Minecraft::GetInstance();
295 if(pMinecraft->localgameModes[ProfileManager.GetPrimaryPad()] != NULL) pMinecraft->localgameModes[ProfileManager.GetPrimaryPad()]->getTutorial()->showTutorialPopup(true);
296 ui.UpdatePlayerBasePositions();
297 }
298 break;
299
300 case e_ProgressCompletion_NavigateBack:
301 app.DebugPrintf("e_ProgressCompletion_NavigateBack\n");
302 {
303 // store these - they get wiped by the destroy caused by navigateback
304 int iPad=m_CompletionData->iPad;
305
306 CXuiSceneBase::ShowBackground( iPad, FALSE );
307 CXuiSceneBase::ShowBackground( iPad, TRUE );
308 app.NavigateBack(iPad);
309 // Show the other players scenes
310 CXuiSceneBase::ShowOtherPlayersBaseScene(iPad, true);
311 ui.UpdatePlayerBasePositions();
312 }
313 break;
314 case e_ProgressCompletion_NavigateBackToScene:
315 app.DebugPrintf("e_ProgressCompletion_NavigateBackToScene\n");
316 CXuiSceneBase::ShowBackground( m_CompletionData->iPad, FALSE );
317 CXuiSceneBase::ShowBackground( m_CompletionData->iPad, TRUE );
318 CXuiSceneBase::ShowOtherPlayersBaseScene(m_CompletionData->iPad, true);
319 // If the pause menu is still active, then navigate back
320 // Otherwise close everything then navigate forwads to the pause menu
321 if(app.IsSceneInStack(m_CompletionData->iPad, m_CompletionData->scene))
322 {
323 app.NavigateBack(m_CompletionData->iPad,false, m_CompletionData->scene);
324 }
325 else
326 {
327 app.CloseXuiScenesAndNavigateToScene(m_CompletionData->iPad,m_CompletionData->scene);
328 }
329 ui.UpdatePlayerBasePositions();
330 break;
331 case e_ProgressCompletion_CloseUIScenes:
332 app.DebugPrintf("e_ProgressCompletion_CloseUIScenes\n");
333 app.CloseXuiScenes(m_CompletionData->iPad);
334 ui.UpdatePlayerBasePositions();
335 break;
336 case e_ProgressCompletion_CloseAllPlayersUIScenes:
337 app.DebugPrintf("e_ProgressCompletion_CloseAllPlayersUIScenes\n");
338 app.CloseAllPlayersXuiScenes();
339 ui.UpdatePlayerBasePositions();
340 break;
341 case e_ProgressCompletion_NavigateToHomeMenu:
342 app.DebugPrintf("e_ProgressCompletion_NavigateToHomeMenu\n");
343 app.NavigateToHomeMenu();
344 //ui.UpdatePlayerBasePositions();
345 break;
346 default:
347 app.DebugPrintf("Default\n");
348 break;
349 }
350 }
351 }
352 }
353 else
354 {
355 switch(pTimer->nId)
356 {
357 case TIMER_FULLSCREEN_PROGRESS:
358 break;
359 case TIMER_FULLSCREEN_TIPS:
360 {
361 // display the next tip
362 wstring wsText=app.FormatHTMLString(m_iPad,app.GetString(app.GetNextTip()));
363 wchar_t startTags[64];
364 swprintf(startTags,64,L"<font color=\"#%08x\" size=14><DIV ALIGN=CENTER>",app.GetHTMLColour(eHTMLColor_White));
365 wsText= startTags + wsText + L"</DIV>";
366 XuiControlSetText(m_tip,wsText.c_str());
367 }
368 break;
369 }
370 }
371
372 bHandled = TRUE;
373
374 return( S_OK );
375}