the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 339 lines 11 kB view raw
1// Minecraft.cpp : Defines the entry point for the application. 2// 3 4#include "stdafx.h" 5 6#include <assert.h> 7#include "..\XUI\XUI_Reinstall.h" 8#include "..\..\..\Minecraft.World\AABB.h" 9#include "..\..\..\Minecraft.World\Vec3.h" 10#include "..\..\..\Minecraft.World\net.minecraft.stats.h" 11#include "..\..\..\Minecraft.Client\StatsCounter.h" 12#include "..\..\..\Minecraft.World\Entity.h" 13#include "..\..\..\Minecraft.World\Level.h" 14#include "..\..\..\Minecraft.Client\LocalPlayer.h" 15#include "..\..\MinecraftServer.h" 16#include "..\..\ProgressRenderer.h" 17#include "..\..\..\Minecraft.World\DisconnectPacket.h" 18#include "..\..\Minecraft.h" 19#include "..\..\Options.h" 20 21 22 23//---------------------------------------------------------------------------------- 24// Performs initialization tasks - retrieves controls. 25//---------------------------------------------------------------------------------- 26HRESULT CScene_Reinstall::OnInit( XUIMessageInit* pInitData, BOOL& bHandled ) 27{ 28 // We'll only be in this menu from the main menu, not in game 29 m_iPad = *(int *)pInitData->pvInitData; 30 31 m_bIgnoreInput=false; 32 MapChildControls(); 33 34 XuiControlSetText(m_Buttons[BUTTON_REINSTALL_THEME],app.GetString(IDS_REINSTALL_THEME)); 35 XuiControlSetText(m_Buttons[BUTTON_REINSTALL_GAMERPIC1],app.GetString(IDS_REINSTALL_GAMERPIC_1)); 36 XuiControlSetText(m_Buttons[BUTTON_REINSTALL_GAMERPIC2],app.GetString(IDS_REINSTALL_GAMERPIC_2)); 37 XuiControlSetText(m_Buttons[BUTTON_REINSTALL_AVATAR1],app.GetString(IDS_REINSTALL_AVATAR_ITEM_1)); 38 XuiControlSetText(m_Buttons[BUTTON_REINSTALL_AVATAR2],app.GetString(IDS_REINSTALL_AVATAR_ITEM_2)); 39 XuiControlSetText(m_Buttons[BUTTON_REINSTALL_AVATAR3],app.GetString(IDS_REINSTALL_AVATAR_ITEM_3)); 40 41 int iFirstEnabled=-1; 42 43 // we can only come in here if we are the primary player, it's the full version, and we have some content to re-install 44 45 if(ProfileManager.IsAwardsFlagSet(m_iPad,eAward_mine100Blocks) ) 46 { 47 m_Buttons[BUTTON_REINSTALL_GAMERPIC1].SetEnable(TRUE); 48 m_Buttons[BUTTON_REINSTALL_GAMERPIC1].EnableInput(TRUE); 49 if(iFirstEnabled==-1) iFirstEnabled=BUTTON_REINSTALL_GAMERPIC1; 50 } 51 else 52 { 53 m_Buttons[BUTTON_REINSTALL_GAMERPIC1].SetEnable(FALSE); 54 m_Buttons[BUTTON_REINSTALL_GAMERPIC1].EnableInput(FALSE); 55 } 56 57 if(ProfileManager.IsAwardsFlagSet(m_iPad,eAward_kill10Creepers) ) 58 { 59 m_Buttons[BUTTON_REINSTALL_GAMERPIC2].SetEnable(TRUE); 60 m_Buttons[BUTTON_REINSTALL_GAMERPIC2].EnableInput(TRUE); 61 if(iFirstEnabled==-1) iFirstEnabled=BUTTON_REINSTALL_GAMERPIC2; 62 } 63 else 64 { 65 m_Buttons[BUTTON_REINSTALL_GAMERPIC2].SetEnable(FALSE); 66 m_Buttons[BUTTON_REINSTALL_GAMERPIC2].EnableInput(FALSE); 67 } 68 if(ProfileManager.IsAwardsFlagSet(m_iPad,eAward_eatPorkChop) ) 69 { 70 m_Buttons[BUTTON_REINSTALL_AVATAR1].SetEnable(TRUE); 71 m_Buttons[BUTTON_REINSTALL_AVATAR1].EnableInput(TRUE); 72 if(iFirstEnabled==-1) iFirstEnabled=BUTTON_REINSTALL_AVATAR1; 73 } 74 else 75 { 76 m_Buttons[BUTTON_REINSTALL_AVATAR1].SetEnable(FALSE); 77 m_Buttons[BUTTON_REINSTALL_AVATAR1].EnableInput(FALSE); 78 } 79 if(ProfileManager.IsAwardsFlagSet(m_iPad,eAward_play100Days) ) 80 { 81 m_Buttons[BUTTON_REINSTALL_AVATAR2].SetEnable(TRUE); 82 m_Buttons[BUTTON_REINSTALL_AVATAR2].EnableInput(TRUE); 83 if(iFirstEnabled==-1) iFirstEnabled=BUTTON_REINSTALL_AVATAR2; 84 } 85 else 86 { 87 m_Buttons[BUTTON_REINSTALL_AVATAR2].SetEnable(FALSE); 88 m_Buttons[BUTTON_REINSTALL_AVATAR2].EnableInput(FALSE); 89 } 90 if(ProfileManager.IsAwardsFlagSet(m_iPad,eAward_arrowKillCreeper) ) 91 { 92 m_Buttons[BUTTON_REINSTALL_AVATAR3].SetEnable(TRUE); 93 m_Buttons[BUTTON_REINSTALL_AVATAR3].EnableInput(TRUE); 94 if(iFirstEnabled==-1) iFirstEnabled=BUTTON_REINSTALL_AVATAR3; 95 } 96 else 97 { 98 m_Buttons[BUTTON_REINSTALL_AVATAR3].SetEnable(FALSE); 99 m_Buttons[BUTTON_REINSTALL_AVATAR3].EnableInput(FALSE); 100 } 101 if(ProfileManager.IsAwardsFlagSet(m_iPad,eAward_socialPost) ) 102 { 103 m_Buttons[BUTTON_REINSTALL_THEME].SetEnable(TRUE); 104 m_Buttons[BUTTON_REINSTALL_THEME].EnableInput(TRUE); 105 if(iFirstEnabled==-1) iFirstEnabled=BUTTON_REINSTALL_THEME; 106 } 107 else 108 { 109 m_Buttons[BUTTON_REINSTALL_THEME].SetEnable(FALSE); 110 m_Buttons[BUTTON_REINSTALL_THEME].EnableInput(FALSE); 111 } 112 113 // if iFirstEnabled is still -1 then we shouldn't set focus to a button 114 if(iFirstEnabled!=-1) 115 { 116 m_Buttons[iFirstEnabled].InitFocus(m_iPad); 117 } 118 119 // allow the user to change the storage device 120 if(!StorageManager.GetSaveDeviceSelected(m_iPad)) 121 { 122 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK,IDS_TOOLTIPS_SELECTDEVICE); 123 } 124 else 125 { 126 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK,IDS_TOOLTIPS_CHANGEDEVICE); 127 } 128 129 return S_OK; 130} 131 132//---------------------------------------------------------------------------------- 133// Handler for the button press message. 134//---------------------------------------------------------------------------------- 135HRESULT CScene_Reinstall::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPress* pNotifyPressData, BOOL& rfHandled) 136{ 137 if(m_bIgnoreInput) return S_OK; 138 139 // This assumes all buttons can only be pressed with the A button 140 ui.AnimateKeyPress(pNotifyPressData->UserIndex, VK_PAD_A); 141 142 unsigned int uiButtonCounter=0; 143 144 while((uiButtonCounter<BUTTONS_REINSTALL_MAX) && (m_Buttons[uiButtonCounter]!=hObjPressed)) uiButtonCounter++; 145 146 // Determine which button was pressed, 147 // and call the appropriate function. 148 149 // store the last button pressed, so on a nav back we can set the focus properly 150 m_iLastButtonPressed=uiButtonCounter; 151 // you do have a storage device don't you? 152 if(!StorageManager.GetSaveDeviceSelected(m_iPad) || StorageManager.GetSaveDisabled()) 153 { 154 // Fix for #12531 - TCR 001: BAS Game Stability: When a player selects to change a storage 155 // device, and repeatedly backs out of the SD screen, disconnects from LIVE, and then selects a SD, the title crashes. 156 m_bIgnoreInput=true; 157 158 StorageManager.SetSaveDevice(&CScene_Reinstall::DeviceSelectReturned_AndReinstall,this,true); 159 return S_OK; 160 } 161 162 switch(uiButtonCounter) 163 { 164 case BUTTON_REINSTALL_THEME: 165 ProfileManager.Award( pNotifyPressData->UserIndex, eAward_socialPost, true ); 166 break; 167 case BUTTON_REINSTALL_GAMERPIC1: 168 ProfileManager.Award( pNotifyPressData->UserIndex, eAward_mine100Blocks, true); 169 break; 170 case BUTTON_REINSTALL_GAMERPIC2: 171 ProfileManager.Award( pNotifyPressData->UserIndex, eAward_kill10Creepers, true); 172 break; 173 case BUTTON_REINSTALL_AVATAR1: 174 ProfileManager.Award( pNotifyPressData->UserIndex, eAward_eatPorkChop, true ); 175 break; 176 case BUTTON_REINSTALL_AVATAR2: 177 ProfileManager.Award( pNotifyPressData->UserIndex, eAward_play100Days, true ); 178 break; 179 case BUTTON_REINSTALL_AVATAR3: 180 ProfileManager.Award( pNotifyPressData->UserIndex, eAward_arrowKillCreeper, true ); 181 break; 182 } 183 184 return S_OK; 185} 186 187HRESULT CScene_Reinstall::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled) 188{ 189 if(m_bIgnoreInput) return S_OK; 190 191 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode); 192 193 switch(pInputData->dwKeyCode) 194 { 195 case VK_PAD_B: 196 case VK_PAD_START: 197 case VK_ESCAPE: 198 app.NavigateBack(m_iPad); 199 rfHandled = TRUE; 200 201 break; 202 case VK_PAD_X: 203 // Change device 204 // we need a function to deal with the return from this - if it changes, we need to update the tooltips 205 // Fix for #12531 - TCR 001: BAS Game Stability: When a player selects to change a storage 206 // device, and repeatedly backs out of the SD screen, disconnects from LIVE, and then selects a SD, the title crashes. 207 m_bIgnoreInput=true; 208 StorageManager.SetSaveDevice(&CScene_Reinstall::DeviceSelectReturned,this,true); 209 210 rfHandled = TRUE; 211 break; 212 } 213 214 return S_OK; 215} 216 217HRESULT CScene_Reinstall::OnNavReturn(HXUIOBJ hObj,BOOL& rfHandled) 218{ 219 220 return S_OK; 221} 222 223HRESULT CScene_Reinstall::OnControlNavigate(XUIMessageControlNavigate *pControlNavigateData, BOOL& bHandled) 224{ 225 pControlNavigateData->hObjDest=XuiControlGetNavigation(pControlNavigateData->hObjSource,pControlNavigateData->nControlNavigate,TRUE,TRUE); 226 227 if(pControlNavigateData->hObjDest!=NULL) 228 { 229 bHandled=TRUE; 230 } 231 232 return S_OK; 233} 234 235HRESULT CScene_Reinstall::OnTransitionStart( XUIMessageTransition *pTransition, BOOL& bHandled ) 236{ 237 if(pTransition->dwTransAction==XUI_TRANSITION_ACTION_DESTROY ) return S_OK; 238 239 if(pTransition->dwTransType == XUI_TRANSITION_TO || pTransition->dwTransType == XUI_TRANSITION_BACKTO) 240 { 241 242 // 4J-PB - Going to resize buttons if the text is too big to fit on any of them (Br-pt problem with the length of Unlock Full Game) 243 XUIRect xuiRect; 244 HXUIOBJ visual=NULL; 245 HXUIOBJ text; 246 float fMaxTextLen=0.0f; 247 float fTextVisualLen; 248 float fMaxButton; 249 float fWidth,fHeight; 250 251 HRESULT hr=XuiControlGetVisual(m_Buttons[0].m_hObj,&visual); 252 hr=XuiElementGetChildById(visual,L"text_Label",&text); 253 hr=XuiElementGetBounds(text,&fTextVisualLen,&fHeight); 254 m_Buttons[0].GetBounds(&fMaxButton,&fHeight); 255 256 257 for(int i=0;i<BUTTONS_REINSTALL_MAX;i++) 258 { 259 hr=XuiTextPresenterMeasureText(text, m_Buttons[i].GetText(), &xuiRect); 260 if(xuiRect.right>fMaxTextLen) fMaxTextLen=xuiRect.right; 261 } 262 263 if(fTextVisualLen<fMaxTextLen) 264 { 265 D3DXVECTOR3 vec; 266 267 // centre is vec.x+(fWidth/2) 268 for(int i=0;i<BUTTONS_REINSTALL_MAX;i++) 269 { 270 // need to resize and reposition the buttons 271 m_Buttons[i].GetPosition(&vec); 272 m_Buttons[i].GetBounds(&fWidth,&fHeight); 273 vec.x= vec.x+(fWidth/2.0f)-(fMaxTextLen/2.0f); 274 275 m_Buttons[i].SetPosition(&vec); 276 m_Buttons[i].SetBounds(fMaxButton+fMaxTextLen-fTextVisualLen,fHeight); 277 } 278 } 279 } 280 281 return S_OK; 282} 283 284int CScene_Reinstall::DeviceSelectReturned(void *pParam,bool bContinue) 285{ 286 CScene_Reinstall* pClass = (CScene_Reinstall*)pParam; 287 288 if(!StorageManager.GetSaveDeviceSelected(pClass->m_iPad)) 289 { 290 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK,IDS_TOOLTIPS_SELECTDEVICE); 291 } 292 else 293 { 294 ui.SetTooltips(DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK,IDS_TOOLTIPS_CHANGEDEVICE); 295 } 296 297 pClass->m_bIgnoreInput=false; 298 return 0; 299} 300 301int CScene_Reinstall::DeviceSelectReturned_AndReinstall(void *pParam,bool bContinue) 302{ 303 CScene_Reinstall* pClass = (CScene_Reinstall*)pParam; 304 305 if(!StorageManager.GetSaveDeviceSelected(pClass->m_iPad)) 306 { 307 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK,IDS_TOOLTIPS_SELECTDEVICE); 308 } 309 else 310 { 311 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK,IDS_TOOLTIPS_CHANGEDEVICE); 312 // reinstall 313 switch(pClass->m_iLastButtonPressed) 314 { 315 case BUTTON_REINSTALL_THEME: 316 ProfileManager.Award( pClass->m_iPad, eAward_socialPost, true ); 317 break; 318 case BUTTON_REINSTALL_GAMERPIC1: 319 ProfileManager.Award( pClass->m_iPad, eAward_mine100Blocks, true); 320 break; 321 case BUTTON_REINSTALL_GAMERPIC2: 322 ProfileManager.Award( pClass->m_iPad, eAward_kill10Creepers, true); 323 break; 324 case BUTTON_REINSTALL_AVATAR1: 325 ProfileManager.Award( pClass->m_iPad, eAward_eatPorkChop, true ); 326 break; 327 case BUTTON_REINSTALL_AVATAR2: 328 ProfileManager.Award( pClass->m_iPad, eAward_play100Days, true ); 329 break; 330 case BUTTON_REINSTALL_AVATAR3: 331 ProfileManager.Award( pClass->m_iPad, eAward_arrowKillCreeper, true ); 332 break; 333 } 334 } 335 pClass->m_bIgnoreInput=false; 336 return 0; 337} 338 339