aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/XUI/XUI_DebugSchematicCreator.cpp
blob: 66279d1f5810e9eb5aa5fda4c3a3e74b4040fb25 (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
#include "stdafx.h"
#include "..\..\..\Minecraft.World\StringHelpers.h"
#include "XUI_DebugSchematicCreator.h"
#include "..\..\..\Minecraft.World\ChunkSource.h"
#include "..\..\..\Minecraft.World\net.minecraft.world.level.h"

#ifndef _CONTENT_PACKAGE
HRESULT CScene_DebugSchematicCreator::OnInit( XUIMessageInit *pInitData, BOOL &bHandled )
{
	MapChildControls();

	m_startX	.SetKeyboardType(C_4JInput::EKeyboardMode_Numeric);
	m_startY	.SetKeyboardType(C_4JInput::EKeyboardMode_Numeric);
	m_startZ	.SetKeyboardType(C_4JInput::EKeyboardMode_Numeric);
	m_endX		.SetKeyboardType(C_4JInput::EKeyboardMode_Numeric);
	m_endY		.SetKeyboardType(C_4JInput::EKeyboardMode_Numeric);
	m_endZ		.SetKeyboardType(C_4JInput::EKeyboardMode_Numeric);

	m_data = new ConsoleSchematicFile::XboxSchematicInitParam();

	return S_OK;
}

HRESULT CScene_DebugSchematicCreator::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);

	if ( hObjPressed == m_createButton )
	{
		// We want the start to be even
		if(m_data->startX > 0 && m_data->startX%2 != 0)
			m_data->startX-=1;
		else if(m_data->startX < 0 && m_data->startX%2 !=0)
			m_data->startX-=1;
		if(m_data->startY < 0) m_data->startY = 0;
		else if(m_data->startY > 0 && m_data->startY%2 != 0)
			m_data->startY-=1;
		if(m_data->startZ > 0 && m_data->startZ%2 != 0)
			m_data->startZ-=1;
		else if(m_data->startZ < 0 && m_data->startZ%2 !=0)
			m_data->startZ-=1;
	
		// We want the end to be odd to have a total size that is even
		if(m_data->endX > 0 && m_data->endX%2 == 0)
			m_data->endX+=1;
		else if(m_data->endX < 0 && m_data->endX%2 ==0)
			m_data->endX+=1;
		if(m_data->endY > Level::maxBuildHeight)
			m_data->endY = Level::maxBuildHeight;
		else if(m_data->endY > 0 && m_data->endY%2 == 0)
			m_data->endY+=1;
		else if(m_data->endY < 0 && m_data->endY%2 ==0)
			m_data->endY+=1;
		if(m_data->endZ > 0 && m_data->endZ%2 == 0)
			m_data->endZ+=1;
		else if(m_data->endZ < 0 && m_data->endZ%2 ==0)
			m_data->endZ+=1;

		wstring value = m_name.GetText();
		if(!value.empty())
		{
			swprintf(m_data->name,64,L"%ls", value.c_str());
		}
		else
		{
			swprintf(m_data->name,64,L"schematic");
		}

		m_data->bSaveMobs = m_saveMobs.IsChecked();

#ifdef _XBOX
		if (m_useXboxCompr.IsChecked())
			m_data->compressionType = Compression::eCompressionType_LZXRLE;
		else
#endif
			m_data->compressionType = Compression::eCompressionType_RLE;

		app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), eXuiServerAction_ExportSchematic, (void *)m_data);
		
		NavigateBack();
		rfHandled = TRUE;
	}
	return S_OK;
}

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

	switch(pInputData->dwKeyCode)
	{

	case VK_PAD_B:
	case VK_PAD_START:
	case VK_PAD_BACK:
		NavigateBack();

		rfHandled = TRUE;

		break;

	}

	return S_OK;
}

HRESULT CScene_DebugSchematicCreator::OnNotifyValueChanged( HXUIOBJ hObjSource, XUINotifyValueChanged *pNotifyValueChangedData, BOOL &bHandled)
{
	if(hObjSource == m_startX)
	{
		int iVal = 0;
		wstring value = m_startX.GetText();
		if(!value.empty()) iVal = _fromString<int>( value );

		if( iVal >= (LEVEL_MAX_WIDTH * -16) || iVal < (LEVEL_MAX_WIDTH * 16))
		{
			m_data->startX = iVal;
		}
	}
	else if(hObjSource == m_startY)
	{
		int iVal = 0;
		wstring value = m_startY.GetText();
		if(!value.empty()) iVal = _fromString<int>( value );

		if( iVal >= (LEVEL_MAX_WIDTH * -16) || iVal < (LEVEL_MAX_WIDTH * 16))
		{
			m_data->startY = iVal;
		}
	}
	else if(hObjSource == m_startZ)
	{
		int iVal = 0;
		wstring value = m_startZ.GetText();
		if(!value.empty()) iVal = _fromString<int>( value );

		if( iVal >= (LEVEL_MAX_WIDTH * -16) || iVal < (LEVEL_MAX_WIDTH * 16))
		{
			m_data->startZ = iVal;
		}
	}
	else if(hObjSource == m_endX)
	{
		int iVal = 0;
		wstring value = m_endX.GetText();
		if(!value.empty()) iVal = _fromString<int>( value );

		if( iVal >= (LEVEL_MAX_WIDTH * -16) || iVal < (LEVEL_MAX_WIDTH * 16))
		{
			m_data->endX = iVal;
		}
	}
	else if(hObjSource == m_endY)
	{
		int iVal = 0;
		wstring value = m_endY.GetText();
		if(!value.empty()) iVal = _fromString<int>( value );

		if( iVal >= (LEVEL_MAX_WIDTH * -16) || iVal < (LEVEL_MAX_WIDTH * 16))
		{
			m_data->endY = iVal;
		}
	}
	else if(hObjSource == m_endZ)
	{
		int iVal = 0;
		wstring value = m_endZ.GetText();
		if(!value.empty()) iVal = _fromString<int>( value );

		if( iVal >= (LEVEL_MAX_WIDTH * -16) || iVal < (LEVEL_MAX_WIDTH * 16))
		{
			m_data->endZ = iVal;
		}
	}
	return S_OK;
}
#endif