aboutsummaryrefslogtreecommitdiff
path: root/src/serialization.cpp
blob: c0fbe10e23335fb9cc8f2031dd8637e0cec548a3 (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
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "serialization.h"

#include "util/serialize.h"
#ifdef _WIN32
	#define ZLIB_WINAPI
#endif
#include "zlib.h"

/* report a zlib or i/o error */
void zerr(int ret)
{   
    dstream<<"zerr: ";
    switch (ret) {
    case Z_ERRNO:
        if (ferror(stdin))
            dstream<<"error reading stdin"<<std::endl;
        if (ferror(stdout))
            dstream<<"error writing stdout"<<std::endl;
        break;
    case Z_STREAM_ERROR:
        dstream<<"invalid compression level"<<std::endl;
        break;
    case Z_DATA_ERROR:
        dstream<<"invalid or incomplete deflate data"<<std::endl;
        break;
    case Z_MEM_ERROR:
        dstream<<"out of memory"<<std::endl;
        break;
    case Z_VERSION_ERROR:
        dstream<<"zlib version mismatch!"<<std::endl;
		break;
	default:
		dstream<<"return value = "<<ret<<std::endl;
    }
}

void compressZlib(SharedBuffer<u8> data, std::ostream &os, int level)
{
	z_stream z;
	const s32 bufsize = 16384;
	char output_buffer[bufsize];
	int status = 0;
	int ret;

	z.zalloc = Z_NULL;
	z.zfree = Z_NULL;
	z.opaque = Z_NULL;

	ret = deflateInit(&z, level);
	if(ret != Z_OK)
		throw SerializationError("compressZlib: deflateInit failed");
	
	// Point zlib to our input buffer
	z.next_in = (Bytef*)&data[0];
	z.avail_in = data.getSize();
	// And get all output
	for(;;)
	{
		z.next_out = (Bytef*)output_buffer;
		z.avail_out = bufsize;
		
		status = deflate(&z, Z_FINISH);
		if(status == Z_NEED_DICT || status == Z_DATA_ERROR
				|| status == Z_MEM_ERROR)
		{
			zerr(status);
			throw SerializationError("compressZlib: deflate failed");
		}
		int count = bufsize - z.avail_out;
		if(count)
			os.write(output_buffer, count);
		// This determines zlib has given all output
		if(status == Z_STREAM_END)
			break;
	}

	deflateEnd(&z);
}

void compressZlib(const std::string &data, std::ostream &os, int level)
{
	SharedBuffer<u8> databuf((u8*)data.c_str(), data.size());
	compressZlib(databuf, os, level);
}

void decompressZlib(std::istream &is, std::ostream &os)
{
	z_stream z;
	const s32 bufsize = 16384;
	char input_buffer[bufsize];
	char output_buffer[bufsize];
	int status = 0;
	int ret;
	int bytes_read = 0;
	int input_buffer_len = 0;

	z.zalloc = Z_NULL;
	z.zfree = Z_NULL;
	z.opaque = Z_NULL;

	ret = inflateInit(&z);
	if(ret != Z_OK)
		throw SerializationError("dcompressZlib: inflateInit failed");
	
	z.avail_in = 0;
	
	//dstream<<"initial fail="<<is.fail()<<" bad="<<is.bad()<<std::endl;

	for(;;)
	{
		z.next_out = (Bytef*)output_buffer;
		z.avail_out = bufsize;

		if(z.avail_in == 0)
		{
			z.next_in = (Bytef*)input_buffer;
			input_buffer_len = is.readsome(input_buffer, bufsize);
			z.avail_in = input_buffer_len;
			//dstream<<"read fail="<<is.fail()<<" bad="<<is.bad()<<std::endl;
		}
		if(z.avail_in == 0)
		{
			//dstream<<"z.avail_in == 0"<<std::endl;
			break;
		}
			
		//dstream<<"1 z.avail_in="<<z.avail_in<<std::endl;
		status = inflate(&z, Z_NO_FLUSH);
		//dstream<<"2 z.avail_in="<<z.avail_in<<std::endl;
		bytes_read += is.gcount() - z.avail_in;
		//dstream<<"bytes_read="<<bytes_read<<std::endl;

		if(status == Z_NEED_DICT || status == Z_DATA_ERROR
				|| status == Z_MEM_ERROR)
		{
			zerr(status);
			throw SerializationError("decompressZlib: inflate failed");
		}
		int count = bufsize - z.avail_out;
		//dstream<<"count="<<count<<std::endl;
		if(count)
			os.write(output_buffer, count);
		if(status == Z_STREAM_END)
		{
			//dstream<<"Z_STREAM_END"<<std::endl;
			
			//dstream<<"z.avail_in="<<z.avail_in<<std::endl;
			//dstream<<"fail="<<is.fail()<<" bad="<<is.bad()<<std::endl;
			// Unget all the data that inflate didn't take
			for(u32 i=0; i < z.avail_in; i++)
			{
				is.unget();
				if(is.fail() || is.bad())
				{
					dstream<<"unget #"<<i<<" failed"<<std::endl;
					dstream<<"fail="<<is.fail()<<" bad="<<is.bad()<<std::endl;
					throw SerializationError("decompressZlib: unget failed");
				}
			}
			
			break;
		}
	}

	inflateEnd(&z);
}

void compress(SharedBuffer<u8> data, std::ostream &os, u8 version)
{
	if(version >= 11)
	{
		compressZlib(data, os);
		return;
	}

	if(data.getSize() == 0)
		return;
	
	// Write length (u32)

	u8 tmp[4];
	writeU32(tmp, data.getSize());
	os.write((char*)tmp, 4);
	
	// We will be writing 8-bit pairs of more_count and byte
	u8 more_count = 0;
	u8 current_byte = data[0];
	for(u32 i=1; i<data.getSize(); i++)
	{
		if(
			data[i] != current_byte
			|| more_count == 255
		)
		{
			// write count and byte
			os.write((char*)&more_count, 1);
			os.write((char*)&current_byte, 1);
			more_count = 0;
			current_byte = data[i];
		}
		else
		{
			more_count++;
		}
	}
	// write count and byte
	os.write((char*)&more_count, 1);
	os.write((char*)&current_byte, 1);
}

void decompress(std::istream &is, std::ostream &os, u8 version)
{
	if(version >= 11)
	{
		decompressZlib(is, os);
		return;
	}

	// Read length (u32)

	u8 tmp[4];
	is.read((char*)tmp, 4);
	u32 len = readU32(tmp);
	
	// We will be reading 8-bit pairs of more_count and byte
	u32 count = 0;
	for(;;)
	{
		u8 more_count=0;
		u8 byte=0;

		is.read((char*)&more_count, 1);
		
		is.read((char*)&byte, 1);

		if(is.eof())
			throw SerializationError("decompress: stream ended halfway");

		for(s32 i=0; i<(u16)more_count+1; i++)
			os.write((char*)&byte, 1);

		count += (u16)more_count+1;

		if(count == len)
			break;
	}
}


an class="hl opt">(menu), m_paths(paths) {} void answer(bool answer) { if(answer == false) return; m_menu->deleteWorld(m_paths); } WorldSpec m_spec; GUIMainMenu *m_menu; std::vector<std::string> m_paths; }; enum { GUI_ID_QUIT_BUTTON = 101, GUI_ID_NAME_INPUT, GUI_ID_ADDRESS_INPUT, GUI_ID_PORT_INPUT, GUI_ID_FANCYTREE_CB, GUI_ID_SMOOTH_LIGHTING_CB, GUI_ID_3D_CLOUDS_CB, GUI_ID_OPAQUE_WATER_CB, GUI_ID_DAMAGE_CB, GUI_ID_CREATIVE_CB, GUI_ID_JOIN_GAME_BUTTON, GUI_ID_CHANGE_KEYS_BUTTON, GUI_ID_DELETE_WORLD_BUTTON, GUI_ID_CREATE_WORLD_BUTTON, GUI_ID_CONFIGURE_WORLD_BUTTON, GUI_ID_WORLD_LISTBOX, GUI_ID_TAB_CONTROL, }; enum { TAB_SINGLEPLAYER=0, TAB_MULTIPLAYER, TAB_ADVANCED, TAB_SETTINGS, TAB_CREDITS }; GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, MainMenuData *data, IGameCallback *gamecallback ): GUIModalMenu(env, parent, id, menumgr), m_data(data), m_accepted(false), m_gamecallback(gamecallback), m_is_regenerating(false) { assert(m_data); this->env = env; this->parent = parent; this->id = id; this->menumgr = menumgr; } GUIMainMenu::~GUIMainMenu() { removeChildren(); } void GUIMainMenu::removeChildren() { const core::list<gui::IGUIElement*> &children = getChildren(); core::list<gui::IGUIElement*> children_copy; for(core::list<gui::IGUIElement*>::ConstIterator i = children.begin(); i != children.end(); i++) { children_copy.push_back(*i); } for(core::list<gui::IGUIElement*>::Iterator i = children_copy.begin(); i != children_copy.end(); i++) { (*i)->remove(); } } void GUIMainMenu::regenerateGui(v2u32 screensize) { m_is_regenerating = true; /* Read stuff from elements into m_data */ readInput(m_data); /* Remove stuff */ removeChildren(); /* Calculate new sizes and positions */ v2s32 size(screensize.X, screensize.Y); core::rect<s32> rect( screensize.X/2 - size.X/2, screensize.Y/2 - size.Y/2, screensize.X/2 + size.X/2, screensize.Y/2 + size.Y/2 ); DesiredRect = rect; recalculateAbsolutePosition(false); //v2s32 size = rect.getSize(); /* Add stuff */ changeCtype(""); // Version //if(m_data->selected_tab != TAB_CREDITS) { core::rect<s32> rect(0, 0, size.X, 40); rect += v2s32(4, 0); Environment->addStaticText(narrow_to_wide( "Minetest-c55 " VERSION_STRING).c_str(), rect, false, true, this, -1); } //v2s32 center(size.X/2, size.Y/2); v2s32 c800(size.X/2-400, size.Y/2-300); m_topleft_client = c800 + v2s32(90, 70+50+30); m_size_client = v2s32(620, 270); m_size_server = v2s32(620, 140); if(m_data->selected_tab == TAB_ADVANCED) { m_topleft_client = c800 + v2s32(90, 70+50+30); m_size_client = v2s32(620, 200); m_size_server = v2s32(620, 140); } m_topleft_server = m_topleft_client + v2s32(0, m_size_client.Y+20); // Tabs #if 1 { core::rect<s32> rect(0, 0, m_size_client.X, 30); rect += m_topleft_client + v2s32(0, -30); gui::IGUITabControl *e = Environment->addTabControl( rect, this, true, true, GUI_ID_TAB_CONTROL); e->addTab(wgettext("Singleplayer")); e->addTab(wgettext("Multiplayer")); e->addTab(wgettext("Advanced")); e->addTab(wgettext("Settings")); e->addTab(wgettext("Credits")); e->setActiveTab(m_data->selected_tab); } #endif if(m_data->selected_tab == TAB_SINGLEPLAYER) { // HYBRID { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); //const wchar_t *text = L"H\nY\nB\nR\nI\nD"; const wchar_t *text = L"T\nA\nP\nE\n\nA\nN\nD\n\nG\nL\nU\nE"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } u32 bs = 5; // World selection listbox u32 world_sel_h = 160; u32 world_sel_w = 365; //s32 world_sel_x = 50; s32 world_sel_x = m_size_client.X-world_sel_w-30; s32 world_sel_y = 30; u32 world_button_count = 3; u32 world_button_w = (world_sel_w)/world_button_count - bs + bs/(world_button_count-1); { core::rect<s32> rect(0, 0, world_sel_w-4, 20); rect += m_topleft_client + v2s32(world_sel_x+4, world_sel_y-20); /*gui::IGUIStaticText *e =*/ Environment->addStaticText( wgettext("Select World:"), rect, false, true, this, -1); /*e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);*/ } { core::rect<s32> rect(0, 0, world_sel_w, world_sel_h); rect += m_topleft_client + v2s32(world_sel_x, world_sel_y); gui::IGUIListBox *e = Environment->addListBox(rect, this, GUI_ID_WORLD_LISTBOX); e->setDrawBackground(true); for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin(); i != m_data->worlds.end(); i++){ e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str()); } e->setSelected(m_data->selected_world); Environment->setFocus(e); } // Delete world button { core::rect<s32> rect(0, 0, world_button_w, 30); rect += m_topleft_client + v2s32(world_sel_x, world_sel_y+world_sel_h+0); Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON, wgettext("Delete")); } // Create world button { core::rect<s32> rect(0, 0, world_button_w, 30); rect += m_topleft_client + v2s32(world_sel_x+world_button_w+bs, world_sel_y+world_sel_h+0); Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON, wgettext("New")); } // Configure world button { core::rect<s32> rect(0, 0, world_button_w, 30); rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*2, world_sel_y+world_sel_h+0); Environment->addButton(rect, this, GUI_ID_CONFIGURE_WORLD_BUTTON, wgettext("Configure")); } // Start game button { /*core::rect<s32> rect(0, 0, world_button_w, 30); rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*3, world_sel_y+world_sel_h+0);*/ u32 bw = 160; /*core::rect<s32> rect(0, 0, bw, 30); rect += m_topleft_client + v2s32(m_size_client.X-bw-30, m_size_client.Y-30-15);*/ core::rect<s32> rect(0, 0, bw, 30); rect += m_topleft_client + v2s32(world_sel_x+world_sel_w-bw, world_sel_y+world_sel_h+30+bs); Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, wgettext("Play")); } // Options s32 option_x = 50; //s32 option_x = 50+world_sel_w+20; s32 option_y = 30; u32 option_w = 150; { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20*0); Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB, wgettext("Creative Mode")); } { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20*1); Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB, wgettext("Enable Damage")); } changeCtype("C"); } else if(m_data->selected_tab == TAB_MULTIPLAYER) { changeCtype(""); // CLIENT { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); const wchar_t *text = L"C\nL\nI\nE\nN\nT"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } // Nickname + password { core::rect<s32> rect(0, 0, 110, 20); rect += m_topleft_client + v2s32(35+30, 50+6); Environment->addStaticText(wgettext("Name/Password"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += m_topleft_client + v2s32(160+30, 50); gui::IGUIElement *e = Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT); if(m_data->name == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50); gui::IGUIEditBox *e = Environment->addEditBox(L"", rect, true, this, 264); e->setPasswordBox(true); if(m_data->name != L"" && m_data->address != L"") Environment->setFocus(e); } changeCtype(""); // Address + port { core::rect<s32> rect(0, 0, 110, 20); rect += m_topleft_client + v2s32(35+30, 100+6); Environment->addStaticText(wgettext("Address/Port"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += m_topleft_client + v2s32(160+30, 100); gui::IGUIElement *e = Environment->addEditBox(m_data->address.c_str(), rect, true, this, GUI_ID_ADDRESS_INPUT); if(m_data->name != L"" && m_data->address == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100); Environment->addEditBox(m_data->port.c_str(), rect, true, this, GUI_ID_PORT_INPUT); } changeCtype(""); // Start game button { core::rect<s32> rect(0, 0, 180, 30); rect += m_topleft_client + v2s32(m_size_client.X-180-30, m_size_client.Y-30-15); Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, wgettext("Start Game / Connect")); } changeCtype("C"); } else if(m_data->selected_tab == TAB_ADVANCED) { changeCtype(""); // CLIENT { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); const wchar_t *text = L"C\nL\nI\nE\nN\nT"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } // Nickname + password { core::rect<s32> rect(0, 0, 110, 20); rect += m_topleft_client + v2s32(35+30, 35+6); Environment->addStaticText(wgettext("Name/Password"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += m_topleft_client + v2s32(160+30, 35); gui::IGUIElement *e = Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT); if(m_data->name == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); rect += m_topleft_client + v2s32(m_size_client.X-60-100, 35); gui::IGUIEditBox *e = Environment->addEditBox(L"", rect, true, this, 264); e->setPasswordBox(true); if(m_data->name != L"" && m_data->address != L"") Environment->setFocus(e); } changeCtype(""); // Address + port { core::rect<s32> rect(0, 0, 110, 20); rect += m_topleft_client + v2s32(35+30, 75+6); Environment->addStaticText(wgettext("Address/Port"), rect, false, true, this, -1); } changeCtype("C"); { core::rect<s32> rect(0, 0, 230, 30); rect += m_topleft_client + v2s32(160+30, 75); gui::IGUIElement *e = Environment->addEditBox(m_data->address.c_str(), rect, true, this, GUI_ID_ADDRESS_INPUT); if(m_data->name != L"" && m_data->address == L"") Environment->setFocus(e); } { core::rect<s32> rect(0, 0, 120, 30); rect += m_topleft_client + v2s32(m_size_client.X-60-100, 75); Environment->addEditBox(m_data->port.c_str(), rect, true, this, GUI_ID_PORT_INPUT); } changeCtype(""); { core::rect<s32> rect(0, 0, 400, 20); rect += m_topleft_client + v2s32(160+30, 75+35); Environment->addStaticText(wgettext("Leave address blank to start a local server."), rect, false, true, this, -1); } // Start game button { core::rect<s32> rect(0, 0, 180, 30); rect += m_topleft_client + v2s32(m_size_client.X-180-30, m_size_client.Y-30-20); Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, wgettext("Start Game / Connect")); } /* Server section */ // SERVER { core::rect<s32> rect(0, 0, 10, m_size_server.Y); rect += m_topleft_server + v2s32(15, 0); const wchar_t *text = L"S\nE\nR\nV\nE\nR"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } // Server parameters { core::rect<s32> rect(0, 0, 250, 30); rect += m_topleft_server + v2s32(30+20+250+20, 20); Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB, wgettext("Creative Mode")); } { core::rect<s32> rect(0, 0, 250, 30); rect += m_topleft_server + v2s32(30+20+250+20, 40); Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB, wgettext("Enable Damage")); } // Delete world button { core::rect<s32> rect(0, 0, 130, 30); rect += m_topleft_server + v2s32(30+20+250+20, 90); Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON, wgettext("Delete world")); } // Create world button { core::rect<s32> rect(0, 0, 130, 30); rect += m_topleft_server + v2s32(30+20+250+20+140, 90); Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON, wgettext("Create world")); } // World selection listbox { core::rect<s32> rect(0, 0, 250, 120); rect += m_topleft_server + v2s32(30+20, 10); gui::IGUIListBox *e = Environment->addListBox(rect, this, GUI_ID_WORLD_LISTBOX); e->setDrawBackground(true); for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin(); i != m_data->worlds.end(); i++){ e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str()); } e->setSelected(m_data->selected_world); } changeCtype("C"); } else if(m_data->selected_tab == TAB_SETTINGS) { { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); const wchar_t *text = L"S\nE\nT\nT\nI\nN\nG\nS"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } s32 option_x = 70; s32 option_y = 50; u32 option_w = 150; { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y); Environment->addCheckBox(m_data->fancy_trees, rect, this, GUI_ID_FANCYTREE_CB, wgettext("Fancy trees")); } { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20); Environment->addCheckBox(m_data->smooth_lighting, rect, this, GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting")); } { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20*2); Environment->addCheckBox(m_data->clouds_3d, rect, this, GUI_ID_3D_CLOUDS_CB, wgettext("3D Clouds")); } { core::rect<s32> rect(0, 0, option_w, 30); rect += m_topleft_client + v2s32(option_x, option_y+20*3); Environment->addCheckBox(m_data->opaque_water, rect, this, GUI_ID_OPAQUE_WATER_CB, wgettext("Opaque water")); } // Key change button { core::rect<s32> rect(0, 0, 120, 30); /*rect += m_topleft_client + v2s32(m_size_client.X-120-30, m_size_client.Y-30-20);*/ rect += m_topleft_client + v2s32(option_x, option_y+120); Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys")); } changeCtype("C"); } else if(m_data->selected_tab == TAB_CREDITS) { // CREDITS { core::rect<s32> rect(0, 0, 10, m_size_client.Y); rect += m_topleft_client + v2s32(15, 0); const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS"; gui::IGUIStaticText *t = Environment->addStaticText(text, rect, false, false, this, -1); t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER); } { core::rect<s32> rect(0, 0, 454, 250); rect += m_topleft_client + v2s32(110, 50+35); Environment->addStaticText(narrow_to_wide( "Minetest-c55 " VERSION_STRING "\n" "http://minetest.net/\n" "\n" "by Perttu Ahola <celeron55@gmail.com>\n" "and contributors: tango_, kahrl (kaaaaaahrl?), erlehmann (the hippie), SpeedProg, JacobF (sqlite worlds), teddydestodes, marktraceur, darkrose, Jonathan Neuschäfer (who the hell?), Felix Krausse (broke liquids, IIRC), sfan5... and >10 more random people." ).c_str(), rect, false, true, this, -1); } } m_is_regenerating = false; } void GUIMainMenu::drawMenu() { gui::IGUISkin* skin = Environment->getSkin(); if (!skin) return; video::IVideoDriver* driver = Environment->getVideoDriver(); /*video::SColor bgcolor(140,0,0,0); driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/ video::SColor bgcolor(140,0,0,0); if(getTab() == TAB_SINGLEPLAYER) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } } else if(getTab() == TAB_MULTIPLAYER) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } } else if(getTab() == TAB_ADVANCED) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } { core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_server; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } } else if(getTab() == TAB_SETTINGS) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } } else if(getTab() == TAB_CREDITS) { { core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect); } video::ITexture *logotexture = driver->getTexture(getTexturePath("menulogo.png").c_str()); if(logotexture) { v2s32 logosize(logotexture->getOriginalSize().Width, logotexture->getOriginalSize().Height); logosize *= 2; core::rect<s32> rect(0,0,logosize.X,logosize.Y); rect += AbsoluteRect.UpperLeftCorner + m_topleft_client; rect += v2s32(130, 50); driver->draw2DImage(logotexture, rect, core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(logotexture->getSize())), NULL, NULL, true); } } gui::IGUIElement::draw(); } void GUIMainMenu::readInput(MainMenuData *dst) { { gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL); if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL) dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab(); } if(dst->selected_tab == TAB_SINGLEPLAYER) { dst->simple_singleplayer_mode = true; } else { dst->simple_singleplayer_mode = false; { gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT); if(e != NULL) dst->name = e->getText(); } { gui::IGUIElement *e = getElementFromId(264); if(e != NULL) dst->password = e->getText(); } { gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT); if(e != NULL) dst->address = e->getText(); }