aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/XUI/XUI_debug.cpp
blob: 61b818a07d46526fd89d6621f0b1235e625a21de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
// Minecraft.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

#include <assert.h>
#include "XUI_Debug.h"
#include "..\..\..\Minecraft.Client\StatsCounter.h"

LPCWSTR CScene_Debug::m_DebugCheckboxTextA[eDebugSetting_Max+1]=
{
	L"Load Saves From Local Folder Mode",
	L"Write Saves To Local Folder Mode",
	L"Freeze Players", //L"Not Used",
	L"Display Safe Area",
	L"Mobs don't attack",
	L"Freeze Time",
	L"Disable Weather",
	L"Craft Anything",
	L"Use DPad for debug",
	L"Mobs don't tick",
	L"Instant Mine",
	L"Show UI Console",
	L"Distributable Save",
	L"Debug Leaderboards",
	L"Height-Water-Biome Maps",
	L"Superflat nether",
	//L"Light/Dark background",
	L"More lightning when thundering",
	L"",
};

LPCWSTR CScene_Debug::m_DebugButtonTextA[eDebugButton_Max+1]=
{
	L"Award Theme",
	L"Award Avatar Item 1",
	L"Award Avatar Item 2",
	L"Award Avatar Item 3",
	L"Award Gamerpic 1",
	L"Award Gamerpic 2",
	L"Check Tips",
	L"Wipe Leaderboards",
	L"",
};



//----------------------------------------------------------------------------------
// Performs initialization tasks - retrieves controls.
//----------------------------------------------------------------------------------
HRESULT CScene_Debug::OnInit( XUIMessageInit* pInitData, BOOL& bHandled )
{
	m_iPad=*(int *)pInitData->pvInitData;

	// set text and enable any debug options required
	int iCheckboxIndex=0;
	int iButtonIndex=0;
	float fWidth=500.0f;
	float fX=240.0f;
	float fY=200.0f;
	float fYInc=5.0f;
	float fControlHeight=25.0f;

	if((!RenderManager.IsHiDef() && !RenderManager.IsWidescreen()) || app.GetLocalPlayerCount()>1)
	{
		fWidth=250.0f;
		fX=30.0f;
		fY=30.0f;
		fYInc=5.0f;
		fControlHeight=15.0f;
	}

	CXuiCheckbox *pCheckbox;
	CXuiControl *pButton;
	m_iTotalCheckboxElements=0;
	m_iTotalButtonElements=0;
	m_bOnCheckboxes=true;

	// count the items
	while((*m_DebugCheckboxTextA[m_iTotalCheckboxElements])!=0)
	{
		m_iTotalCheckboxElements++;
	}

	m_DebugCheckboxDataA= new DEBUGDATA [m_iTotalCheckboxElements];

	while((*m_DebugCheckboxTextA[iCheckboxIndex])!=0)
	{
			XuiCreateObject( XUI_CLASS_CHECKBOX, &m_DebugCheckboxDataA[iCheckboxIndex].hXuiObj );
			XuiObjectFromHandle( m_DebugCheckboxDataA[iCheckboxIndex].hXuiObj, &m_DebugCheckboxDataA[iCheckboxIndex].pvData );

			pCheckbox = (CXuiCheckbox *)m_DebugCheckboxDataA[iCheckboxIndex].pvData;
			//m_phXuiObjA[iElementIndex] = pCheckbox->m_hObj;
			pCheckbox->SetText(m_DebugCheckboxTextA[iCheckboxIndex]);
			pCheckbox->SetShow(TRUE);

			D3DXVECTOR3 vPos;
			float tx,ty;
			pCheckbox->GetBounds(&tx,&ty);
			pCheckbox->SetBounds(fWidth,fControlHeight);
			vPos.x=fX;
			vPos.y=fY;
			vPos.z=0.0f;
			pCheckbox->SetPosition(&vPos);
			fY+=fControlHeight+fYInc;

			XuiElementAddChild(m_hObj,m_DebugCheckboxDataA[iCheckboxIndex].hXuiObj);

		iCheckboxIndex++;
	}
	
	// and the buttons
	if((!RenderManager.IsHiDef() && !RenderManager.IsWidescreen())|| app.GetLocalPlayerCount()>1)
	{
		fWidth=260.0f;
		fX=300.0f;
		fY=30.0f;
		fControlHeight=40.0f;
	}
	else
	{
		fWidth=350.0f;
		fX=750.0f;
		fY=200.0f;
		fControlHeight=40.0f;
	}



	while((*m_DebugButtonTextA[m_iTotalButtonElements])!=0)
	{
		m_iTotalButtonElements++;
	}

	m_DebugButtonDataA= new DEBUGDATA [m_iTotalButtonElements];

	while((*m_DebugButtonTextA[iButtonIndex])!=0)
	{
		XuiCreateObject( XUI_CLASS_BUTTON, &m_DebugButtonDataA[iButtonIndex].hXuiObj );
		XuiObjectFromHandle( m_DebugButtonDataA[iButtonIndex].hXuiObj, &m_DebugButtonDataA[iButtonIndex].pvData );

		pButton = (CXuiControl *)m_DebugButtonDataA[iButtonIndex].pvData;
		//m_phXuiObjA[iElementIndex] = pCheckbox->m_hObj;
		pButton->SetText(m_DebugButtonTextA[iButtonIndex]);
		pButton->SetShow(TRUE);

		D3DXVECTOR3 vPos;
		float tx,ty;
		pButton->GetBounds(&tx,&ty);
		pButton->SetBounds(fWidth,fControlHeight);
		vPos.x=fX;
		vPos.y=fY;
		vPos.z=0.0f;
		pButton->SetPosition(&vPos);
		fY+=fControlHeight+fYInc;

		XuiElementAddChild(m_hObj,m_DebugButtonDataA[iButtonIndex].hXuiObj);

		// if you're not the primary player, disable all these - you need a storage device for them

		if(ProfileManager.GetPrimaryPad()!=m_iPad)
		{
			XuiControlSetEnable(m_DebugButtonDataA[iButtonIndex].hXuiObj,FALSE);
		}
		iButtonIndex++;
	}



	unsigned int uiDebugBitmask=app.GetGameSettingsDebugMask(m_iPad);

	for(int i=0;i<iCheckboxIndex;i++)
	{
		CXuiCheckbox *pCheckbox = (CXuiCheckbox *)m_DebugCheckboxDataA[i].pvData;
		pCheckbox->SetCheck( (uiDebugBitmask&(1<<i)) ?TRUE:FALSE);
	}


	if(m_DebugCheckboxDataA[0].hXuiObj)
	{
		XuiElementSetUserFocus(m_DebugCheckboxDataA[0].hXuiObj,m_iPad);
	}

	m_iCurrentCheckboxElement=0;
	m_iCurrentButtonElement=0;

#ifdef _DEBUG
	// testing the upload of the player custom skin
//  	wstring wsTemp;
//  
// 	wsTemp=L"Deadmau5_Skin.png";
// 	app.UploadFileToGlobalStorage(m_iPad,C4JStorage::eGlobalStorage_TitleUser,&wsTemp);
// 	wsTemp=L"Mojang_Cape.png";
// 	app.UploadFileToGlobalStorage(m_iPad,C4JStorage::eGlobalStorage_TitleUser,&wsTemp);
// 	wsTemp=L"4J_Cape.png";
// 	app.UploadFileToGlobalStorage(m_iPad,C4JStorage::eGlobalStorage_TitleUser,&wsTemp);
#endif

	return S_OK;
}

HRESULT CScene_Debug::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled)
{
	ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode);

	HRESULT hr=S_OK;
	int iCurrentBitmaskIndex=0;
	unsigned int uiDebugBitmask=0L;

	// Explicitly handle X button presses
	if (pInputData->dwKeyCode == VK_PAD_B)
	{
		// check all the settings
		for(int i=0;i<m_iTotalCheckboxElements;i++)
		{
			CXuiCheckbox *pCheckbox = (CXuiCheckbox *)m_DebugCheckboxDataA[i].pvData;
			uiDebugBitmask|=pCheckbox->IsChecked()?(1<<iCurrentBitmaskIndex):0;
			iCurrentBitmaskIndex++;
		}

		if(uiDebugBitmask!=app.GetGameSettingsDebugMask(pInputData->UserIndex))
		{
			app.SetGameSettingsDebugMask(pInputData->UserIndex,uiDebugBitmask);
			if(app.DebugSettingsOn())
			{
				app.ActionDebugMask(pInputData->UserIndex);		
			}
			else
			{
				// force debug mask off
				app.ActionDebugMask(pInputData->UserIndex,true);
			}

			app.CheckGameSettingsChanged(true,pInputData->UserIndex);
		}
		app.NavigateBack(pInputData->UserIndex);
		rfHandled = TRUE;
	}


	return hr;
}


HRESULT CScene_Debug::OnControlNavigate(XUIMessageControlNavigate *pControlNavigateData, BOOL& bHandled)
{
	if(m_bOnCheckboxes)
	{
		// If it's not from the current control, ignore it
		if(m_DebugCheckboxDataA[m_iCurrentCheckboxElement].hXuiObj!=pControlNavigateData->hObjSource) return S_OK;

		switch(pControlNavigateData->nControlNavigate)
		{
		case XUI_CONTROL_NAVIGATE_UP:
			if(m_iCurrentCheckboxElement>0)
			{
				m_iCurrentCheckboxElement--;
				XuiElementSetUserFocus(m_DebugCheckboxDataA[m_iCurrentCheckboxElement].hXuiObj, m_iPad);
			}
			break;	
		case XUI_CONTROL_NAVIGATE_DOWN:
			if((m_iCurrentCheckboxElement+1)<m_iTotalCheckboxElements)
			{
				m_iCurrentCheckboxElement++;
				XuiElementSetUserFocus(m_DebugCheckboxDataA[m_iCurrentCheckboxElement].hXuiObj, m_iPad);
			}
			break;
		case XUI_CONTROL_NAVIGATE_RIGHT:
			m_bOnCheckboxes=false;
			if(m_iCurrentCheckboxElement<m_iTotalButtonElements)
			{
				m_iCurrentButtonElement=m_iCurrentCheckboxElement;
			}
			XuiElementSetUserFocus(m_DebugButtonDataA[m_iCurrentButtonElement].hXuiObj, m_iPad);
			break;	
		}
	}
	else
	{
		// If it's not from the current control, ignore it
		if(m_DebugButtonDataA[m_iCurrentButtonElement].hXuiObj!=pControlNavigateData->hObjSource) return S_OK;

		switch(pControlNavigateData->nControlNavigate)
		{
		case XUI_CONTROL_NAVIGATE_UP:
			if(m_iCurrentButtonElement>0)
			{
				m_iCurrentButtonElement--;
				XuiElementSetUserFocus(m_DebugButtonDataA[m_iCurrentButtonElement].hXuiObj, m_iPad);
			}
			break;	
		case XUI_CONTROL_NAVIGATE_DOWN:
			if((m_iCurrentButtonElement+1)<m_iTotalButtonElements)
			{
				m_iCurrentButtonElement++;
				XuiElementSetUserFocus(m_DebugButtonDataA[m_iCurrentButtonElement].hXuiObj, m_iPad);
			}
			break;

		case XUI_CONTROL_NAVIGATE_LEFT:
			m_bOnCheckboxes=true;
			if(m_iCurrentButtonElement<m_iTotalCheckboxElements)
			{
				m_iCurrentCheckboxElement=m_iCurrentButtonElement;
			}
			XuiElementSetUserFocus(m_DebugCheckboxDataA[m_iCurrentCheckboxElement].hXuiObj, m_iPad);
			break;
		}
	}
	


	return S_OK;
}
//----------------------------------------------------------------------------------
// Updates the UI when the list selection changes.
//----------------------------------------------------------------------------------
HRESULT CScene_Debug::OnNotifyValueChanged( HXUIOBJ hObjSource, XUINotifyValueChanged* pNotifyValueChanged, BOOL& bHandled )
{

	return S_OK;
}
//----------------------------------------------------------------------------------
// Updates the UI when the list selection changes.
//----------------------------------------------------------------------------------
HRESULT CScene_Debug::OnNotifySelChanged( HXUIOBJ hObjSource, XUINotifySelChanged* pNotifySelChangedData, BOOL& bHandled )
{


	return S_OK;
}

//----------------------------------------------------------------------------------
// Handler for the button press message.
//----------------------------------------------------------------------------------
HRESULT CScene_Debug::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPress* pNotifyPressData, BOOL& rfHandled)
{
	// This assumes all buttons can only be pressed with the A button
	ui.AnimateKeyPress(pNotifyPressData->UserIndex, VK_PAD_A);

	int iButton=0;

	while((iButton<m_iTotalButtonElements) && m_DebugButtonDataA[iButton].hXuiObj!=hObjPressed)
	{
		iButton++;
	}

	if(iButton==m_iTotalButtonElements)
	{
		// it's not a button then
		return S_OK;
	}

	// you need to be the primary player to be able to earn these, since you need a storage device

	switch(iButton)
	{
	case eDebugButton_Theme:
		ProfileManager.Award( pNotifyPressData->UserIndex, eAward_socialPost );
		break;
	case eDebugButton_Avatar_Item_1:
		ProfileManager.Award( pNotifyPressData->UserIndex, eAward_eatPorkChop );
		break;
	case eDebugButton_Avatar_Item_2:
		ProfileManager.Award( pNotifyPressData->UserIndex, eAward_play100Days );
		break;
	case eDebugButton_Avatar_Item_3:
		ProfileManager.Award( pNotifyPressData->UserIndex, eAward_arrowKillCreeper );
		break;
	case eDebugButton_Gamerpic_1:
		ProfileManager.Award( pNotifyPressData->UserIndex, eAward_mine100Blocks );
		break;
	case eDebugButton_Gamerpic_2:
		ProfileManager.Award( pNotifyPressData->UserIndex, eAward_kill10Creepers );
		break;
	case eDebugButton_CheckTips:
		app.NavigateToScene(pNotifyPressData->UserIndex,eUIScene_DebugTips);
		break;

	case eDebugButton_WipeLeaderboards:
#ifdef _DEBUG
// commenting out so it doesn't get done by mistake
//		Minecraft::GetInstance()->stats[pNotifyPressData->UserIndex]->WipeLeaderboards();
#endif
		break;

	}

	return S_OK;
}