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#include "..\XUI\XUI_SettingsGraphics.h"
6
7//----------------------------------------------------------------------------------
8// Performs initialization tasks - retrieves controls.
9//----------------------------------------------------------------------------------
10HRESULT CScene_SettingsGraphics::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 bIsPrimaryPad=(ProfileManager.GetPrimaryPad()==m_iPad);
17
18 MapChildControls();
19
20 // Display the tooltips
21
22 m_Clouds.SetCheck( (app.GetGameSettings(m_iPad,eGameSetting_Clouds)!=0)?TRUE:FALSE);
23 m_Clouds.SetText(app.GetString( IDS_CHECKBOX_RENDER_CLOUDS ));
24
25 m_SliderA[SLIDER_SETTINGS_GAMMA].SetValue(app.GetGameSettings(m_iPad,eGameSetting_Gamma));
26 swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_GAMMA ),app.GetGameSettings(m_iPad,eGameSetting_Gamma));
27 m_SliderA[SLIDER_SETTINGS_GAMMA].SetText(TempString);
28
29 m_SliderA[SLIDER_SETTINGS_INTERFACE_OPACITY].SetValue(app.GetGameSettings(m_iPad,eGameSetting_InterfaceOpacity));
30 swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_INTERFACEOPACITY ),app.GetGameSettings(m_iPad,eGameSetting_InterfaceOpacity));
31 m_SliderA[SLIDER_SETTINGS_INTERFACE_OPACITY].SetText(TempString);
32
33 m_BedrockFog.SetCheck( (app.GetGameSettings(m_iPad,eGameSetting_BedrockFog)!=0)?TRUE:FALSE);
34 m_BedrockFog.SetText(app.GetString( IDS_CHECKBOX_RENDER_BEDROCKFOG ));
35
36 m_CustomSkinAnim.SetCheck( (app.GetGameSettings(m_iPad,eGameSetting_CustomSkinAnim)!=0)?TRUE:FALSE);
37 m_CustomSkinAnim.SetText(app.GetString( IDS_CHECKBOX_CUSTOM_SKIN_ANIM ));
38
39 // if we're not in the game, we need to use basescene 0
40 if(bNotInGame)
41 {
42 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
43 CXuiSceneBase::ShowBackground( DEFAULT_XUI_MENU_USER, TRUE );
44 }
45 else
46 {
47 // If the game has started, then you need to be the host to change the in-game gamertags
48 if(bIsPrimaryPad)
49 {
50 // are we the game host? If not, we need to remove the bedrockfog setting
51 if(!g_NetworkManager.IsHost())
52 {
53 // we are the primary player on this machine, but not the game host
54 D3DXVECTOR3 vec;
55 // hide the in-game bedrock fog setting
56 m_BedrockFog.SetShow(FALSE);
57
58 // m_SliderA[SLIDER_SETTINGS_INTERFACE_OPACITY] -> m_SliderA[SLIDER_SETTINGS_GAMMA]
59 // m_SliderA[SLIDER_SETTINGS_GAMMA] -> m_CustomSkinAnim
60 // m_CustomSkinAnim -> m_BedrockFog
61
62 XuiElementGetPosition(m_SliderA[SLIDER_SETTINGS_GAMMA],&vec);
63 m_SliderA[SLIDER_SETTINGS_INTERFACE_OPACITY].SetPosition(&vec);
64
65 XuiElementGetPosition(m_CustomSkinAnim,&vec);
66 m_SliderA[SLIDER_SETTINGS_GAMMA].SetPosition(&vec);
67
68 XuiElementGetPosition(m_BedrockFog,&vec);
69 m_CustomSkinAnim.SetPosition(&vec);
70
71 // reduce the size of the background
72 float fWidth, fHeight, fbgnWidth, fBgnHeight;
73 m_BedrockFog.GetBounds(&fWidth, &fHeight);
74 GetBounds(&fbgnWidth, &fBgnHeight);
75 fBgnHeight-=fHeight;
76 SetBounds(fbgnWidth, fBgnHeight);
77 }
78 }
79 else
80 {
81 // We shouldn't have the bedrock fog option, or the m_CustomSkinAnim option
82 m_BedrockFog.SetShow(FALSE);
83 m_CustomSkinAnim.SetShow(FALSE);
84
85 D3DXVECTOR3 vec,vecGamma,vecOpacity;
86 float fSliderYDiff;
87
88 // m_SliderA[SLIDER_SETTINGS_INTERFACE_OPACITY] -> m_BedrockFog
89 // m_SliderA[SLIDER_SETTINGS_GAMMA] -> m_BedrockFog
90
91 m_SliderA[SLIDER_SETTINGS_GAMMA].GetPosition(&vecGamma);
92 m_SliderA[SLIDER_SETTINGS_INTERFACE_OPACITY].GetPosition(&vecOpacity);
93 fSliderYDiff=vecOpacity.y-vecGamma.y;
94
95 XuiElementGetPosition(m_BedrockFog,&vec);
96 m_SliderA[SLIDER_SETTINGS_GAMMA].SetPosition(&vec);
97 vec.y+=fSliderYDiff;
98 m_SliderA[SLIDER_SETTINGS_INTERFACE_OPACITY].SetPosition(&vec);
99
100 // reduce the size of the background
101 float fWidth, fHeight, fbgnWidth, fBgnHeight;
102 GetBounds(&fbgnWidth, &fBgnHeight);
103 m_BedrockFog.GetBounds(&fWidth, &fHeight);
104 fBgnHeight-=fHeight;
105 m_CustomSkinAnim.GetBounds(&fWidth, &fHeight);
106 fBgnHeight-=fHeight;
107 SetBounds(fbgnWidth, fBgnHeight);
108 }
109
110 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
111 CXuiSceneBase::ShowBackground( m_iPad, FALSE );
112 }
113
114
115 if(app.GetLocalPlayerCount()>1)
116 {
117 app.AdjustSplitscreenScene(m_hObj,&m_OriginalPosition,m_iPad);
118 CXuiSceneBase::ShowLogo( m_iPad, FALSE );
119 }
120 else
121 {
122 if(bNotInGame)
123 {
124 CXuiSceneBase::ShowLogo( DEFAULT_XUI_MENU_USER, TRUE );
125 }
126 else
127 {
128 CXuiSceneBase::ShowLogo( m_iPad, TRUE );
129 }
130 }
131
132 return S_OK;
133}
134
135HRESULT CScene_SettingsGraphics::OnNotifyValueChanged( HXUIOBJ hObjSource, XUINotifyValueChanged* pNotifyValueChanged, BOOL& bHandled )
136{
137 WCHAR TempString[256];
138
139 if(hObjSource==m_SliderA[SLIDER_SETTINGS_GAMMA].GetSlider() )
140 {
141 app.SetGameSettings(m_iPad,eGameSetting_Gamma,pNotifyValueChanged->nValue);
142 swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_GAMMA ),pNotifyValueChanged->nValue);
143 m_SliderA[SLIDER_SETTINGS_GAMMA].SetText(TempString);
144 }
145 else if(hObjSource==m_SliderA[SLIDER_SETTINGS_INTERFACE_OPACITY].GetSlider() )
146 {
147 app.SetGameSettings(m_iPad,eGameSetting_InterfaceOpacity,pNotifyValueChanged->nValue);
148 swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_INTERFACEOPACITY ),pNotifyValueChanged->nValue);
149 m_SliderA[SLIDER_SETTINGS_INTERFACE_OPACITY].SetText(TempString);
150 }
151
152 return S_OK;
153}
154
155
156HRESULT CScene_SettingsGraphics::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled)
157{
158 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode);
159
160 HRESULT hr=S_OK;
161
162 // Explicitly handle B button presses
163 switch(pInputData->dwKeyCode)
164 {
165 case VK_PAD_B:
166 case VK_ESCAPE:
167 // if the profile data has been changed, then force a profile write
168 // It seems we're allowed to break the 5 minute rule if it's the result of a user action
169
170 // not in this scene - app.CheckGameSettingsChanged(true,pInputData->UserIndex);
171
172 // check the checkboxes
173 app.SetGameSettings(m_iPad,eGameSetting_Clouds,m_Clouds.IsChecked()?1:0);
174 app.SetGameSettings(m_iPad,eGameSetting_BedrockFog,m_BedrockFog.IsChecked()?1:0);
175 app.SetGameSettings(m_iPad,eGameSetting_CustomSkinAnim,m_CustomSkinAnim.IsChecked()?1:0);
176
177 app.NavigateBack(pInputData->UserIndex);
178 rfHandled = TRUE;
179 break;
180 }
181
182 return hr;
183}
184
185//----------------------------------------------------------------------------------
186// Handler for the button press message.
187//----------------------------------------------------------------------------------
188HRESULT CScene_SettingsGraphics::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPress* pNotifyPressData, BOOL& rfHandled)
189{
190 // This assumes all buttons can only be pressed with the A button
191 ui.AnimateKeyPress(pNotifyPressData->UserIndex, VK_PAD_A);
192
193 return S_OK;
194}
195
196HRESULT CScene_SettingsGraphics::OnControlNavigate(XUIMessageControlNavigate *pControlNavigateData, BOOL& bHandled)
197{
198 // added so we can skip greyed out items
199 pControlNavigateData->hObjDest=XuiControlGetNavigation(pControlNavigateData->hObjSource,pControlNavigateData->nControlNavigate,TRUE,TRUE);
200
201 if(pControlNavigateData->hObjDest!=NULL)
202 {
203 bHandled=TRUE;
204 }
205
206 return S_OK;
207}
208
209HRESULT CScene_SettingsGraphics::OnTransitionStart( XUIMessageTransition *pTransition, BOOL& bHandled )
210{
211 HRESULT hr;
212 WCHAR TempString[256];
213 if(pTransition->dwTransAction==XUI_TRANSITION_ACTION_DESTROY ) return S_OK;
214
215 if(pTransition->dwTransType == XUI_TRANSITION_TO || pTransition->dwTransType == XUI_TRANSITION_BACKTO)
216 {
217 // 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)
218
219 float fMaxTextLen=0.0f;
220 float fMaxLen=0.0f;
221
222 // sliders first
223 HXUIOBJ hSlider,hVisual,hText,hCheckboxText;
224 XUIRect xuiRect;
225 float fWidth,fHeight,fTemp;
226 D3DXVECTOR3 vec,vecCheckboxText,vSlider,vecCheckbox;
227
228 // don't display values on these - we handle that
229 for(int i=0;i<SLIDER_SETTINGS_GRAPHICS_MAX;i++)
230 {
231 m_SliderA[i].SetValueDisplay(FALSE);
232 }
233
234 hr=XuiControlGetVisual(m_Clouds.m_hObj,&hVisual);
235 hr=XuiElementGetChildById(hVisual,L"text_Button",&hCheckboxText);
236
237 hr=XuiElementGetChildById(m_SliderA[SLIDER_SETTINGS_GAMMA].m_hObj,L"XuiSlider",&hSlider);
238 hr=XuiControlGetVisual(hSlider,&hVisual);
239 hr=XuiElementGetChildById(hVisual,L"text_Label",&hText);
240 hr=XuiElementGetPosition(m_SliderA[SLIDER_SETTINGS_GAMMA].m_hObj,&vSlider);
241
242 for(int i=0;i<SLIDER_SETTINGS_GRAPHICS_MAX;i++)
243 {
244 switch(i)
245 {
246 case SLIDER_SETTINGS_GAMMA: // 3 digits
247 swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_GAMMA ),999);
248 break;
249 case SLIDER_SETTINGS_INTERFACE_OPACITY: // 3 digits
250 swprintf( (WCHAR *)TempString, 256, L"%ls: %d%%", app.GetString( IDS_SLIDER_INTERFACEOPACITY ),999);
251 break;
252 }
253 hr=XuiTextPresenterMeasureText(hText, TempString, &xuiRect);
254 // 4J-PB - the text measuring doesn't seem to be long enough - add a fudge
255 xuiRect.right+=25.0f;
256 m_SliderA[i].GetBounds(&fWidth,&fHeight);
257 if(xuiRect.right>fMaxTextLen) fMaxTextLen=xuiRect.right;
258 if(fWidth>fMaxLen) fMaxLen=fWidth;
259 }
260
261 // now the clouds checkbox - let's just use the visual we already have...
262 hr=XuiTextPresenterMeasureText(hText, m_Clouds.GetText(), &xuiRect);
263 hr=XuiTextPresenterMeasureText(hCheckboxText, m_Clouds.GetText(), &xuiRect);
264 m_Clouds.GetBounds(&fWidth,&fHeight);
265 // need to add the size of the checkbox graphic
266 if((xuiRect.right+vecCheckbox.x+vecCheckboxText.x)>fMaxTextLen) fMaxTextLen=xuiRect.right+vecCheckbox.x+vecCheckboxText.x;
267 if(fWidth>fMaxLen) fMaxLen=fWidth;
268
269 if(fMaxLen<fMaxTextLen)
270 {
271 float fWidth;
272 XuiElementGetPosition(m_hObj,&vec);
273 XuiElementGetBounds(m_hObj,&fWidth,&fHeight);
274
275 // need to centre the scene now the size has changed
276 if((!RenderManager.IsHiDef() && !RenderManager.IsWidescreen()) || app.GetLocalPlayerCount()>1)
277 {
278 // scene width needs to be more that the text width on buttons
279 fWidth=vSlider.x;
280 vec.x=floorf((640.0f-(fMaxTextLen+fWidth))/2.0f);
281 XuiElementSetPosition(m_hObj,&vec);
282 XuiElementSetBounds(m_hObj,fMaxTextLen+(fWidth*2.0f),fHeight);
283 }
284 else
285 {
286 fWidth=vSlider.x;
287 vec.x=floorf((1280.0f-(fMaxTextLen+fWidth))/2.0f);
288 XuiElementSetPosition(m_hObj,&vec);
289 XuiElementSetBounds(m_hObj,fMaxTextLen+(fWidth*2.0f),fHeight);
290 }
291 // Need to refresh the scenes visual since the object size has now changed
292 XuiControlAttachVisual(m_hObj);
293
294 // centre is vec.x+(fWidth/2)
295 for(int i=0;i<SLIDER_SETTINGS_GRAPHICS_MAX;i++)
296 {
297 hr=XuiElementGetChildById(m_SliderA[i].m_hObj,L"XuiSlider",&hSlider);
298 XuiElementGetPosition(hSlider,&vec);
299 XuiElementGetBounds(hSlider,&fTemp,&fHeight);
300 XuiElementSetBounds(hSlider,fMaxTextLen,fHeight);
301 }
302
303 m_Clouds.SetBounds(fMaxTextLen,fHeight);
304
305 }
306 }
307
308 return S_OK;
309}
310
311HRESULT CScene_SettingsGraphics::OnNavReturn(HXUIOBJ hObj,BOOL& rfHandled)
312{
313 bool bNotInGame=(Minecraft::GetInstance()->level==NULL);
314
315 // if we're not in the game, we need to use basescene 0
316 if(bNotInGame)
317 {
318 ui.SetTooltips( DEFAULT_XUI_MENU_USER, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
319 }
320 else
321 {
322 ui.SetTooltips( m_iPad, IDS_TOOLTIPS_SELECT,IDS_TOOLTIPS_BACK);
323 }
324
325 return S_OK;
326}
327
328HRESULT CScene_SettingsGraphics::OnCustomMessage_Splitscreenplayer(bool bJoining, BOOL& bHandled)
329{
330 bHandled=true;
331 return app.AdjustSplitscreenScene_PlayerChanged(m_hObj,&m_OriginalPosition,m_iPad,bJoining);
332}
333