the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 376 lines 14 kB view raw
1// Minecraft.cpp : Defines the entry point for the application. 2// 3 4#include "stdafx.h" 5#include "..\XUI\XUI_SettingsUI.h" 6 7//---------------------------------------------------------------------------------- 8// Performs initialization tasks - retrieves controls. 9//---------------------------------------------------------------------------------- 10HRESULT CScene_SettingsUI::OnInit( XUIMessageInit* pInitData, BOOL& bHandled ) 11{ 12 WCHAR TempString[256]; 13 m_iPad=*(int *)pInitData->pvInitData; 14 // if we're not in the game, we need to use basescene 0 15 bool bNotInGame=(Minecraft::GetInstance()->level==NULL); 16 bool bPrimaryPlayer = ProfileManager.GetPrimaryPad()==m_iPad; 17 18 MapChildControls(); 19 20 m_SplitScreen.SetCheck( (app.GetGameSettings(m_iPad,eGameSetting_SplitScreenVertical)!=0)?TRUE:FALSE); 21 m_SplitScreen.SetText(app.GetString( IDS_CHECKBOX_VERTICAL_SPLIT_SCREEN ) ); 22 23 m_SplitScreenGamertags.SetCheck( (app.GetGameSettings(m_iPad,eGameSetting_DisplaySplitscreenGamertags)!=0)?TRUE:FALSE); 24 m_SplitScreenGamertags.SetText(app.GetString( IDS_CHECKBOX_DISPLAY_SPLITSCREENGAMERTAGS )); 25 26 m_SliderA[SLIDER_SETTINGS_UISIZE].SetValue(app.GetGameSettings(m_iPad,eGameSetting_UISize)+1); 27 swprintf( (WCHAR *)TempString, 256, L"%ls: %d", app.GetString( IDS_SLIDER_UISIZE ),app.GetGameSettings(m_iPad,eGameSetting_UISize)+1); 28 m_SliderA[SLIDER_SETTINGS_UISIZE].SetText(TempString); 29 30 m_SliderA[SLIDER_SETTINGS_UISIZESPLITSCREEN].SetValue(app.GetGameSettings(m_iPad,eGameSetting_UISizeSplitscreen)+1); 31 swprintf( (WCHAR *)TempString, 256, L"%ls: %d", app.GetString( IDS_SLIDER_UISIZESPLITSCREEN ),app.GetGameSettings(m_iPad,eGameSetting_UISizeSplitscreen)+1); 32 m_SliderA[SLIDER_SETTINGS_UISIZESPLITSCREEN].SetText(TempString); 33 34 m_DisplayHUD.SetCheck( (app.GetGameSettings(m_iPad,eGameSetting_DisplayHUD)!=0)?TRUE:FALSE); 35 m_DisplayHUD.SetText(app.GetString( IDS_CHECKBOX_DISPLAY_HUD )); 36 37 m_DisplayHand.SetCheck( (app.GetGameSettings(m_iPad,eGameSetting_DisplayHand)!=0)?TRUE:FALSE); 38 m_DisplayHand.SetText(app.GetString( IDS_CHECKBOX_DISPLAY_HAND )); 39 40 m_DeathMessages.SetCheck( (app.GetGameSettings(m_iPad,eGameSetting_DeathMessages)!=0)?TRUE:FALSE); 41 m_DeathMessages.SetText(app.GetString( IDS_CHECKBOX_DEATH_MESSAGES )); 42 43 m_AnimatedCharacter.SetCheck( (app.GetGameSettings(m_iPad,eGameSetting_AnimatedCharacter)!=0)?TRUE:FALSE); 44 m_AnimatedCharacter.SetText(app.GetString( IDS_CHECKBOX_ANIMATED_CHARACTER )); 45 46 // if we're not in the game, we need to use basescene 0 47 if(bNotInGame) 48 { 49 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); 50 CXuiSceneBase::ShowBackground( DEFAULT_XUI_MENU_USER, TRUE ); 51 } 52 else 53 { 54 // If the game has started, then you need to be the host to change the in-game gamertags 55 if(!bPrimaryPlayer) 56 { 57 // hide things we don't want the splitscreen player changing 58 m_SplitScreen.SetShow(FALSE); 59 m_SplitScreen.SetEnable(FALSE); 60 m_SplitScreenGamertags.SetShow(FALSE); 61 m_SplitScreenGamertags.SetEnable(FALSE); 62 63 // move the sliders up, and resize the scene 64 float fRemoveHeight=0.0f, fHeight, fWidth; 65 D3DXVECTOR3 vec; 66 67 m_SplitScreen.GetBounds(&fWidth, &fHeight); 68 fRemoveHeight+=fHeight+4.0f; // add padding 69 m_SplitScreenGamertags.GetBounds(&fWidth, &fHeight); 70 fRemoveHeight+=fHeight+4.0f; // add padding 71 72 m_SliderA[SLIDER_SETTINGS_UISIZE].GetPosition(&vec); 73 vec.y-=fRemoveHeight; 74 m_SliderA[SLIDER_SETTINGS_UISIZE].SetPosition(&vec); 75 m_SliderA[SLIDER_SETTINGS_UISIZESPLITSCREEN].GetPosition(&vec); 76 vec.y-=fRemoveHeight; 77 m_SliderA[SLIDER_SETTINGS_UISIZESPLITSCREEN].SetPosition(&vec); 78 79 GetBounds(&fWidth, &fHeight); 80 fHeight-=fRemoveHeight; 81 SetBounds(fWidth, fHeight); 82 } 83 84 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); 85 CXuiSceneBase::ShowBackground( m_iPad, FALSE ); 86 } 87 88 89 if(app.GetLocalPlayerCount()>1) 90 { 91 app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad); 92 CXuiSceneBase::ShowLogo( m_iPad, FALSE ); 93 } 94 else 95 { 96 if(bNotInGame) 97 { 98 CXuiSceneBase::ShowLogo( DEFAULT_XUI_MENU_USER, TRUE ); 99 } 100 else 101 { 102 CXuiSceneBase::ShowLogo( m_iPad, TRUE ); 103 } 104 } 105 106 return S_OK; 107} 108 109HRESULT CScene_SettingsUI::OnNotifyValueChanged( HXUIOBJ hObjSource, XUINotifyValueChanged* pNotifyValueChanged, BOOL& bHandled ) 110{ 111 WCHAR TempString[256]; 112 113 if(hObjSource==m_SliderA[SLIDER_SETTINGS_UISIZE].GetSlider() ) 114 { 115 // slider is 1 to 3 116 117 // is this different from the current value? 118 swprintf( (WCHAR *)TempString, 256, L"%ls: %d", app.GetString( IDS_SLIDER_UISIZE ),pNotifyValueChanged->nValue); 119 m_SliderA[SLIDER_SETTINGS_UISIZE].SetText(TempString); 120 if(pNotifyValueChanged->nValue != app.GetGameSettings(m_iPad,eGameSetting_UISize)+1) 121 { 122 app.SetGameSettings(m_iPad,eGameSetting_UISize,pNotifyValueChanged->nValue-1); 123 // Apply the changes to the selected text position 124 CXuiSceneBase::UpdateSelectedItemPos(m_iPad); 125 } 126 } 127 else if(hObjSource==m_SliderA[SLIDER_SETTINGS_UISIZESPLITSCREEN].GetSlider() ) 128 { 129 swprintf( (WCHAR *)TempString, 256, L"%ls: %d", app.GetString( IDS_SLIDER_UISIZESPLITSCREEN ),pNotifyValueChanged->nValue); 130 m_SliderA[SLIDER_SETTINGS_UISIZESPLITSCREEN].SetText(TempString); 131 132 if(pNotifyValueChanged->nValue != app.GetGameSettings(m_iPad,eGameSetting_UISizeSplitscreen)+1) 133 { 134 // slider is 1 to 3 135 app.SetGameSettings(m_iPad,eGameSetting_UISizeSplitscreen,pNotifyValueChanged->nValue-1); 136 // Apply the changes to the selected text position 137 CXuiSceneBase::UpdateSelectedItemPos(m_iPad); 138 } 139 } 140 141 return S_OK; 142} 143 144 145HRESULT CScene_SettingsUI::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled) 146{ 147 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode); 148 149 HRESULT hr=S_OK; 150 151 // Explicitly handle B button presses 152 switch(pInputData->dwKeyCode) 153 { 154 case VK_PAD_B: 155 case VK_ESCAPE: 156 // if the profile data has been changed, then force a profile write 157 // It seems we're allowed to break the 5 minute rule if it's the result of a user action 158 159 // not in this scene - app.CheckGameSettingsChanged(true,pInputData->UserIndex); 160 161 // check the checkboxes 162 app.SetGameSettings(m_iPad,eGameSetting_DisplayHUD,m_DisplayHUD.IsChecked()?1:0); 163 app.SetGameSettings(m_iPad,eGameSetting_DisplayHand,m_DisplayHand.IsChecked()?1:0); 164 app.SetGameSettings(m_iPad,eGameSetting_DisplaySplitscreenGamertags,m_SplitScreenGamertags.IsChecked()?1:0); 165 app.SetGameSettings(m_iPad,eGameSetting_DeathMessages,m_DeathMessages.IsChecked()?1:0); 166 app.SetGameSettings(m_iPad,eGameSetting_AnimatedCharacter,m_AnimatedCharacter.IsChecked()?1:0); 167 168 // if the splitscreen vertical/horizontal has changed, need to update the scenes 169 if(app.GetGameSettings(m_iPad,eGameSetting_SplitScreenVertical)!=(m_SplitScreen.IsChecked()?1:0)) 170 { 171 // changed 172 app.SetGameSettings(m_iPad,eGameSetting_SplitScreenVertical,m_SplitScreen.IsChecked()?1:0); 173 174 // close the xui scenes, so we don't have the navigate backed to menu at the wrong place 175 if(app.GetLocalPlayerCount()==2) 176 { 177 app.CloseAllPlayersXuiScenes(); 178 } 179 else 180 { 181 app.NavigateBack(pInputData->UserIndex); 182 } 183 } 184 else 185 { 186 app.NavigateBack(pInputData->UserIndex); 187 } 188 189 190 rfHandled = TRUE; 191 break; 192 } 193 194 return hr; 195} 196 197//---------------------------------------------------------------------------------- 198// Handler for the button press message. 199//---------------------------------------------------------------------------------- 200HRESULT CScene_SettingsUI::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPress* pNotifyPressData, BOOL& rfHandled) 201{ 202 // This assumes all buttons can only be pressed with the A button 203 ui.AnimateKeyPress(pNotifyPressData->UserIndex, VK_PAD_A); 204 205 return S_OK; 206} 207 208HRESULT CScene_SettingsUI::OnControlNavigate(XUIMessageControlNavigate *pControlNavigateData, BOOL& bHandled) 209{ 210 // added so we can skip greyed out items 211 pControlNavigateData->hObjDest=XuiControlGetNavigation(pControlNavigateData->hObjSource,pControlNavigateData->nControlNavigate,TRUE,TRUE); 212 213 if(pControlNavigateData->hObjDest!=NULL) 214 { 215 bHandled=TRUE; 216 } 217 218 return S_OK; 219} 220 221HRESULT CScene_SettingsUI::OnTransitionStart( XUIMessageTransition *pTransition, BOOL& bHandled ) 222{ 223 HRESULT hr; 224 WCHAR TempString[256]; 225 if(pTransition->dwTransAction==XUI_TRANSITION_ACTION_DESTROY ) return S_OK; 226 227 if(pTransition->dwTransType == XUI_TRANSITION_TO || pTransition->dwTransType == XUI_TRANSITION_BACKTO) 228 { 229 // 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) 230 231 float fMaxTextLen=0.0f; 232 float fMaxLen=0.0f; 233 234 // sliders first 235 HXUIOBJ hSlider,hVisual,hText,hCheckboxText; 236 XUIRect xuiRect; 237 float fWidth,fHeight;//,fTemp; 238 D3DXVECTOR3 vec,vecCheckboxText,vSlider,vecCheckbox; 239 240 hr=XuiControlGetVisual(m_SplitScreen.m_hObj,&hVisual); 241 hr=XuiElementGetChildById(hVisual,L"text_Button",&hCheckboxText); 242 hr=XuiElementGetPosition(hCheckboxText,&vecCheckboxText); 243 hr=XuiElementGetPosition(m_SplitScreen.m_hObj,&vecCheckbox); 244 hr=XuiElementGetChildById(m_SliderA[SLIDER_SETTINGS_UISIZESPLITSCREEN].m_hObj,L"XuiSlider",&hSlider); 245 hr=XuiControlGetVisual(hSlider,&hVisual); 246 hr=XuiElementGetChildById(hVisual,L"text_Label",&hText); 247 hr=XuiElementGetPosition(m_SliderA[SLIDER_SETTINGS_UISIZE].m_hObj,&vSlider); 248 249 250 // don't display values on these - we handle that 251 for(int i=0;i<SLIDER_SETTINGS_UI_MAX;i++) 252 { 253 m_SliderA[i].SetValueDisplay(FALSE); 254 } 255 256 for(int i=0;i<SLIDER_SETTINGS_UI_MAX;i++) 257 { 258 switch(i) 259 { 260 case SLIDER_SETTINGS_UISIZE: // 3 digits 261 swprintf( (WCHAR *)TempString, 256, L"%ls: %d", app.GetString( IDS_SLIDER_UISIZE ),3); 262 break; 263 case SLIDER_SETTINGS_UISIZESPLITSCREEN: // 3 digits 264 swprintf( (WCHAR *)TempString, 256, L"%ls: %d", app.GetString( IDS_SLIDER_UISIZESPLITSCREEN ),3); 265 break; 266 } 267 268 //LPCWSTR temp=m_SliderA[i].GetText(); 269 hr=XuiTextPresenterMeasureText(hText, TempString, &xuiRect); 270 // 4J-PB - the text measuring doesn't seem to be long enough - add a fudge 271 xuiRect.right+=25.0f; 272 m_SliderA[i].GetBounds(&fWidth,&fHeight); 273 if(xuiRect.right>fMaxTextLen) fMaxTextLen=xuiRect.right; 274 if(fWidth>fMaxLen) fMaxLen=fWidth; 275 } 276 277 // now the m_SplitScreen checkbox - let's just use the visual we already have... 278 279 hr=XuiTextPresenterMeasureText(hCheckboxText, m_SplitScreen.GetText(), &xuiRect); 280 m_SplitScreen.GetBounds(&fWidth,&fHeight); 281 // need to add the size of the checkbox graphic 282 if((xuiRect.right+vecCheckbox.x+vecCheckboxText.x)>fMaxTextLen) fMaxTextLen=xuiRect.right+vecCheckbox.x+vecCheckboxText.x; 283 if(fWidth>fMaxLen) fMaxLen=fWidth; 284 285 // now the m_SplitScreenGamertags checkbox - let's just use the visual we already have... 286 287 hr=XuiTextPresenterMeasureText(hCheckboxText, m_SplitScreenGamertags.GetText(), &xuiRect); 288 m_SplitScreenGamertags.GetBounds(&fWidth,&fHeight); 289 // need to add the size of the checkbox graphic 290 if((xuiRect.right+vecCheckbox.x+vecCheckboxText.x)>fMaxTextLen) fMaxTextLen=xuiRect.right+vecCheckbox.x+vecCheckboxText.x; 291 if(fWidth>fMaxLen) fMaxLen=fWidth; 292 293 // now the m_DisplayHUD checkbox - let's just use the visual we already have... 294 295 hr=XuiTextPresenterMeasureText(hCheckboxText, m_DisplayHUD.GetText(), &xuiRect); 296 m_DisplayHUD.GetBounds(&fWidth,&fHeight); 297 // need to add the size of the checkbox graphic 298 if((xuiRect.right+vecCheckbox.x+vecCheckboxText.x)>fMaxTextLen) fMaxTextLen=xuiRect.right+vecCheckbox.x+vecCheckboxText.x; 299 if(fWidth>fMaxLen) fMaxLen=fWidth; 300 301 302 // now the m_DisplayHand checkbox - let's just use the visual we already have... 303 hr=XuiTextPresenterMeasureText(hCheckboxText, m_DisplayHand.GetText(), &xuiRect); 304 m_DisplayHand.GetBounds(&fWidth,&fHeight); 305 // need to add the size of the checkbox graphic 306 if((xuiRect.right+vecCheckbox.x+vecCheckboxText.x)>fMaxTextLen) fMaxTextLen=xuiRect.right+vecCheckbox.x+vecCheckboxText.x; 307 if(fWidth>fMaxLen) fMaxLen=fWidth; 308 309 310 // now the m_DeathMessages checkbox - let's just use the visual we already have... 311 hr=XuiTextPresenterMeasureText(hCheckboxText, m_DeathMessages.GetText(), &xuiRect); 312 m_DeathMessages.GetBounds(&fWidth,&fHeight); 313 // need to add the size of the checkbox graphic 314 if((xuiRect.right+vecCheckbox.x+vecCheckboxText.x)>fMaxTextLen) fMaxTextLen=xuiRect.right+vecCheckbox.x+vecCheckboxText.x; 315 if(fWidth>fMaxLen) fMaxLen=fWidth; 316 317 if(fMaxLen<fMaxTextLen) 318 { 319 float fWidth; 320 XuiElementGetPosition(m_hObj,&vec); 321 XuiElementGetBounds(m_hObj,&fWidth,&fHeight); 322 323 // need to centre the scene now the size has changed 324 if((!RenderManager.IsHiDef() && !RenderManager.IsWidescreen()) || app.GetLocalPlayerCount()>1) 325 { 326 // scene width needs to be more that the text width on buttons 327 fWidth=vSlider.x; 328 vec.x=floorf((640.0f-(fMaxTextLen+fWidth))/2.0f); 329 XuiElementSetPosition(m_hObj,&vec); 330 XuiElementSetBounds(m_hObj,fMaxTextLen+(fWidth*2.0f),fHeight); 331 } 332 else 333 { 334 fWidth=vSlider.x; 335 vec.x=floorf((1280.0f-(fMaxTextLen+fWidth))/2.0f); 336 XuiElementSetPosition(m_hObj,&vec); 337 XuiElementSetBounds(m_hObj,fMaxTextLen+(fWidth*2.0f),fHeight); 338 } 339 340 m_SplitScreen.SetBounds(fMaxTextLen,fHeight); 341 m_SplitScreenGamertags.SetBounds(fMaxTextLen,fHeight); 342 m_DisplayHUD.SetBounds(fMaxTextLen,fHeight); 343 m_DisplayHand.SetBounds(fMaxTextLen,fHeight); 344 m_DeathMessages.SetBounds(fMaxTextLen,fHeight); 345 346 // Need to refresh the scenes visual since the object size has now changed 347 XuiControlAttachVisual(m_hObj); 348 } 349 } 350 351 return S_OK; 352} 353 354HRESULT CScene_SettingsUI::OnNavReturn(HXUIOBJ hObj,BOOL& rfHandled) 355{ 356 bool bNotInGame=(Minecraft::GetInstance()->level==NULL); 357 358 // if we're not in the game, we need to use basescene 0 359 if(bNotInGame) 360 { 361 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); 362 } 363 else 364 { 365 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK); 366 } 367 368 return S_OK; 369} 370 371HRESULT CScene_SettingsUI::OnCustomMessage_Splitscreenplayer(bool bJoining, BOOL& bHandled) 372{ 373 bHandled=true; 374 return app.AdjustSplitscreenScene_PlayerChanged(m_hObj,&m_OriginalPosition,m_iPad,bJoining); 375} 376