3 Copyright (C) 2010-12 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "guiMainMenu.h"
21 #include "guiKeyChangeMenu.h"
22 #include "guiCreateWorld.h"
23 #include "guiMessageMenu.h"
24 #include "guiConfirmMenu.h"
26 #include "serialization.h"
28 #include <IGUICheckBox.h>
29 #include <IGUIEditBox.h>
30 #include <IGUIButton.h>
31 #include <IGUIStaticText.h>
33 #include <IGUIListBox.h>
34 #include <IGUITabControl.h>
35 #include <IGUIImage.h>
37 #include "guiPauseMenu.h"
39 #include "tile.h" // getTexturePath
41 #include "util/string.h"
44 struct CreateWorldDestMainMenu : public CreateWorldDest
46 CreateWorldDestMainMenu(GUIMainMenu *menu):
49 void accepted(std::wstring name, std::string gameid)
51 std::string name_narrow = wide_to_narrow(name);
52 if(!string_allowed_blacklist(name_narrow, WORLDNAME_BLACKLISTED_CHARS))
54 m_menu->displayMessageMenu(wgettext("Cannot create world: Name contains invalid characters"));
57 std::vector<WorldSpec> worlds = getAvailableWorlds();
58 for(std::vector<WorldSpec>::iterator i = worlds.begin();
59 i != worlds.end(); i++)
61 if((*i).name == name_narrow)
63 m_menu->displayMessageMenu(wgettext("Cannot create world: A world by this name already exists"));
67 m_menu->createNewWorld(name, gameid);
72 struct ConfirmDestDeleteWorld : public ConfirmDest
74 ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu,
75 const std::vector<std::string> &paths):
80 void answer(bool answer)
84 m_menu->deleteWorld(m_paths);
88 std::vector<std::string> m_paths;
93 GUI_ID_QUIT_BUTTON = 101,
98 GUI_ID_SMOOTH_LIGHTING_CB,
100 GUI_ID_OPAQUE_WATER_CB,
103 GUI_ID_JOIN_GAME_BUTTON,
104 GUI_ID_CHANGE_KEYS_BUTTON,
105 GUI_ID_DELETE_WORLD_BUTTON,
106 GUI_ID_CREATE_WORLD_BUTTON,
107 GUI_ID_CONFIGURE_WORLD_BUTTON,
108 GUI_ID_WORLD_LISTBOX,
121 GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
122 gui::IGUIElement* parent, s32 id,
123 IMenuManager *menumgr,
125 IGameCallback *gamecallback
127 GUIModalMenu(env, parent, id, menumgr),
130 m_gamecallback(gamecallback),
131 m_is_regenerating(false)
135 this->parent = parent;
137 this->menumgr = menumgr;
140 GUIMainMenu::~GUIMainMenu()
145 void GUIMainMenu::removeChildren()
147 const core::list<gui::IGUIElement*> &children = getChildren();
148 core::list<gui::IGUIElement*> children_copy;
149 for(core::list<gui::IGUIElement*>::ConstIterator
150 i = children.begin(); i != children.end(); i++)
152 children_copy.push_back(*i);
154 for(core::list<gui::IGUIElement*>::Iterator
155 i = children_copy.begin();
156 i != children_copy.end(); i++)
162 void GUIMainMenu::regenerateGui(v2u32 screensize)
164 m_is_regenerating = true;
166 Read stuff from elements into m_data
176 Calculate new sizes and positions
179 v2s32 size(screensize.X, screensize.Y);
181 core::rect<s32> rect(
182 screensize.X/2 - size.X/2,
183 screensize.Y/2 - size.Y/2,
184 screensize.X/2 + size.X/2,
185 screensize.Y/2 + size.Y/2
189 recalculateAbsolutePosition(false);
191 //v2s32 size = rect.getSize();
200 //if(m_data->selected_tab != TAB_CREDITS)
202 core::rect<s32> rect(0, 0, size.X, 40);
204 Environment->addStaticText(narrow_to_wide(
205 "Minetest-c55 " VERSION_STRING).c_str(),
206 rect, false, true, this, -1);
209 //v2s32 center(size.X/2, size.Y/2);
210 v2s32 c800(size.X/2-400, size.Y/2-300);
212 m_topleft_client = c800 + v2s32(90, 70+50+30);
213 m_size_client = v2s32(620, 270);
215 m_size_server = v2s32(620, 140);
217 if(m_data->selected_tab == TAB_ADVANCED)
219 m_topleft_client = c800 + v2s32(90, 70+50+30);
220 m_size_client = v2s32(620, 200);
222 m_size_server = v2s32(620, 140);
225 m_topleft_server = m_topleft_client + v2s32(0, m_size_client.Y+20);
230 core::rect<s32> rect(0, 0, m_size_client.X, 30);
231 rect += m_topleft_client + v2s32(0, -30);
232 gui::IGUITabControl *e = Environment->addTabControl(
233 rect, this, true, true, GUI_ID_TAB_CONTROL);
234 e->addTab(wgettext("Singleplayer"));
235 e->addTab(wgettext("Multiplayer"));
236 e->addTab(wgettext("Advanced"));
237 e->addTab(wgettext("Settings"));
238 e->addTab(wgettext("Credits"));
239 e->setActiveTab(m_data->selected_tab);
243 if(m_data->selected_tab == TAB_SINGLEPLAYER)
247 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
248 rect += m_topleft_client + v2s32(15, 0);
249 //const wchar_t *text = L"H\nY\nB\nR\nI\nD";
250 const wchar_t *text = L"T\nA\nP\nE\n\nA\nN\nD\n\nG\nL\nU\nE";
251 gui::IGUIStaticText *t =
252 Environment->addStaticText(text, rect, false, false, this, -1);
253 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
256 // World selection listbox
257 u32 world_sel_h = 160;
258 u32 world_sel_w = 365;
259 //s32 world_sel_x = 50;
260 s32 world_sel_x = m_size_client.X-world_sel_w-30;
261 s32 world_sel_y = 30;
262 u32 world_button_count = 3;
263 u32 world_button_w = (world_sel_w)/world_button_count - bs
264 + bs/(world_button_count-1);
266 core::rect<s32> rect(0, 0, world_sel_w-4, 20);
267 rect += m_topleft_client + v2s32(world_sel_x+4, world_sel_y-20);
268 /*gui::IGUIStaticText *e =*/ Environment->addStaticText(
269 wgettext("Select World:"),
270 rect, false, true, this, -1);
271 /*e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);*/
274 core::rect<s32> rect(0, 0, world_sel_w, world_sel_h);
275 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y);
276 gui::IGUIListBox *e = Environment->addListBox(rect, this,
277 GUI_ID_WORLD_LISTBOX);
278 e->setDrawBackground(true);
279 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
280 i != m_data->worlds.end(); i++){
281 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
283 e->setSelected(m_data->selected_world);
284 Environment->setFocus(e);
286 // Delete world button
288 core::rect<s32> rect(0, 0, world_button_w, 30);
289 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y+world_sel_h+0);
290 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
293 // Create world button
295 core::rect<s32> rect(0, 0, world_button_w, 30);
296 rect += m_topleft_client + v2s32(world_sel_x+world_button_w+bs, world_sel_y+world_sel_h+0);
297 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
300 // Configure world button
302 core::rect<s32> rect(0, 0, world_button_w, 30);
303 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*2,
304 world_sel_y+world_sel_h+0);
305 Environment->addButton(rect, this, GUI_ID_CONFIGURE_WORLD_BUTTON,
306 wgettext("Configure"));
310 /*core::rect<s32> rect(0, 0, world_button_w, 30);
311 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*3,
312 world_sel_y+world_sel_h+0);*/
314 /*core::rect<s32> rect(0, 0, bw, 30);
315 rect += m_topleft_client + v2s32(m_size_client.X-bw-30,
316 m_size_client.Y-30-15);*/
317 core::rect<s32> rect(0, 0, bw, 30);
318 rect += m_topleft_client + v2s32(world_sel_x+world_sel_w-bw,
319 world_sel_y+world_sel_h+30+bs);
320 Environment->addButton(rect, this,
321 GUI_ID_JOIN_GAME_BUTTON, wgettext("Play"));
325 //s32 option_x = 50+world_sel_w+20;
329 core::rect<s32> rect(0, 0, option_w, 30);
330 rect += m_topleft_client + v2s32(option_x, option_y+20*0);
331 Environment->addCheckBox(m_data->creative_mode, rect, this,
332 GUI_ID_CREATIVE_CB, wgettext("Creative Mode"));
335 core::rect<s32> rect(0, 0, option_w, 30);
336 rect += m_topleft_client + v2s32(option_x, option_y+20*1);
337 Environment->addCheckBox(m_data->enable_damage, rect, this,
338 GUI_ID_DAMAGE_CB, wgettext("Enable Damage"));
342 else if(m_data->selected_tab == TAB_MULTIPLAYER)
347 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
348 rect += m_topleft_client + v2s32(15, 0);
349 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
350 gui::IGUIStaticText *t =
351 Environment->addStaticText(text, rect, false, false, this, -1);
352 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
354 // Nickname + password
356 core::rect<s32> rect(0, 0, 110, 20);
357 rect += m_topleft_client + v2s32(35+30, 50+6);
358 Environment->addStaticText(wgettext("Name/Password"),
359 rect, false, true, this, -1);
363 core::rect<s32> rect(0, 0, 230, 30);
364 rect += m_topleft_client + v2s32(160+30, 50);
365 gui::IGUIElement *e =
366 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
367 if(m_data->name == L"")
368 Environment->setFocus(e);
371 core::rect<s32> rect(0, 0, 120, 30);
372 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50);
373 gui::IGUIEditBox *e =
374 Environment->addEditBox(L"", rect, true, this, 264);
375 e->setPasswordBox(true);
376 if(m_data->name != L"" && m_data->address != L"")
377 Environment->setFocus(e);
383 core::rect<s32> rect(0, 0, 110, 20);
384 rect += m_topleft_client + v2s32(35+30, 100+6);
385 Environment->addStaticText(wgettext("Address/Port"),
386 rect, false, true, this, -1);
390 core::rect<s32> rect(0, 0, 230, 30);
391 rect += m_topleft_client + v2s32(160+30, 100);
392 gui::IGUIElement *e =
393 Environment->addEditBox(m_data->address.c_str(), rect, true,
394 this, GUI_ID_ADDRESS_INPUT);
395 if(m_data->name != L"" && m_data->address == L"")
396 Environment->setFocus(e);
399 core::rect<s32> rect(0, 0, 120, 30);
400 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100);
401 Environment->addEditBox(m_data->port.c_str(), rect, true,
402 this, GUI_ID_PORT_INPUT);
407 core::rect<s32> rect(0, 0, 180, 30);
408 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
409 m_size_client.Y-30-15);
410 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
411 wgettext("Start Game / Connect"));
415 else if(m_data->selected_tab == TAB_ADVANCED)
420 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
421 rect += m_topleft_client + v2s32(15, 0);
422 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
423 gui::IGUIStaticText *t =
424 Environment->addStaticText(text, rect, false, false, this, -1);
425 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
427 // Nickname + password
429 core::rect<s32> rect(0, 0, 110, 20);
430 rect += m_topleft_client + v2s32(35+30, 35+6);
431 Environment->addStaticText(wgettext("Name/Password"),
432 rect, false, true, this, -1);
436 core::rect<s32> rect(0, 0, 230, 30);
437 rect += m_topleft_client + v2s32(160+30, 35);
438 gui::IGUIElement *e =
439 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
440 if(m_data->name == L"")
441 Environment->setFocus(e);
444 core::rect<s32> rect(0, 0, 120, 30);
445 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 35);
446 gui::IGUIEditBox *e =
447 Environment->addEditBox(L"", rect, true, this, 264);
448 e->setPasswordBox(true);
449 if(m_data->name != L"" && m_data->address != L"")
450 Environment->setFocus(e);
456 core::rect<s32> rect(0, 0, 110, 20);
457 rect += m_topleft_client + v2s32(35+30, 75+6);
458 Environment->addStaticText(wgettext("Address/Port"),
459 rect, false, true, this, -1);
463 core::rect<s32> rect(0, 0, 230, 30);
464 rect += m_topleft_client + v2s32(160+30, 75);
465 gui::IGUIElement *e =
466 Environment->addEditBox(m_data->address.c_str(), rect, true,
467 this, GUI_ID_ADDRESS_INPUT);
468 if(m_data->name != L"" && m_data->address == L"")
469 Environment->setFocus(e);
472 core::rect<s32> rect(0, 0, 120, 30);
473 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 75);
474 Environment->addEditBox(m_data->port.c_str(), rect, true,
475 this, GUI_ID_PORT_INPUT);
479 core::rect<s32> rect(0, 0, 400, 20);
480 rect += m_topleft_client + v2s32(160+30, 75+35);
481 Environment->addStaticText(wgettext("Leave address blank to start a local server."),
482 rect, false, true, this, -1);
486 core::rect<s32> rect(0, 0, 180, 30);
487 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
488 m_size_client.Y-30-20);
489 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
490 wgettext("Start Game / Connect"));
497 core::rect<s32> rect(0, 0, 10, m_size_server.Y);
498 rect += m_topleft_server + v2s32(15, 0);
499 const wchar_t *text = L"S\nE\nR\nV\nE\nR";
500 gui::IGUIStaticText *t =
501 Environment->addStaticText(text, rect, false, false, this, -1);
502 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
506 core::rect<s32> rect(0, 0, 250, 30);
507 rect += m_topleft_server + v2s32(30+20+250+20, 20);
508 Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB,
509 wgettext("Creative Mode"));
512 core::rect<s32> rect(0, 0, 250, 30);
513 rect += m_topleft_server + v2s32(30+20+250+20, 40);
514 Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
515 wgettext("Enable Damage"));
517 // Delete world button
519 core::rect<s32> rect(0, 0, 130, 30);
520 rect += m_topleft_server + v2s32(30+20+250+20, 90);
521 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
522 wgettext("Delete world"));
524 // Create world button
526 core::rect<s32> rect(0, 0, 130, 30);
527 rect += m_topleft_server + v2s32(30+20+250+20+140, 90);
528 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
529 wgettext("Create world"));
531 // World selection listbox
533 core::rect<s32> rect(0, 0, 250, 120);
534 rect += m_topleft_server + v2s32(30+20, 10);
535 gui::IGUIListBox *e = Environment->addListBox(rect, this,
536 GUI_ID_WORLD_LISTBOX);
537 e->setDrawBackground(true);
538 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
539 i != m_data->worlds.end(); i++){
540 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
542 e->setSelected(m_data->selected_world);
546 else if(m_data->selected_tab == TAB_SETTINGS)
549 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
550 rect += m_topleft_client + v2s32(15, 0);
551 const wchar_t *text = L"S\nE\nT\nT\nI\nN\nG\nS";
552 gui::IGUIStaticText *t =
553 Environment->addStaticText(text, rect, false, false, this, -1);
554 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
560 core::rect<s32> rect(0, 0, option_w, 30);
561 rect += m_topleft_client + v2s32(option_x, option_y);
562 Environment->addCheckBox(m_data->fancy_trees, rect, this,
563 GUI_ID_FANCYTREE_CB, wgettext("Fancy trees"));
566 core::rect<s32> rect(0, 0, option_w, 30);
567 rect += m_topleft_client + v2s32(option_x, option_y+20);
568 Environment->addCheckBox(m_data->smooth_lighting, rect, this,
569 GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting"));
572 core::rect<s32> rect(0, 0, option_w, 30);
573 rect += m_topleft_client + v2s32(option_x, option_y+20*2);
574 Environment->addCheckBox(m_data->clouds_3d, rect, this,
575 GUI_ID_3D_CLOUDS_CB, wgettext("3D Clouds"));
578 core::rect<s32> rect(0, 0, option_w, 30);
579 rect += m_topleft_client + v2s32(option_x, option_y+20*3);
580 Environment->addCheckBox(m_data->opaque_water, rect, this,
581 GUI_ID_OPAQUE_WATER_CB, wgettext("Opaque water"));
585 core::rect<s32> rect(0, 0, 120, 30);
586 /*rect += m_topleft_client + v2s32(m_size_client.X-120-30,
587 m_size_client.Y-30-20);*/
588 rect += m_topleft_client + v2s32(option_x, option_y+120);
589 Environment->addButton(rect, this,
590 GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys"));
594 else if(m_data->selected_tab == TAB_CREDITS)
598 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
599 rect += m_topleft_client + v2s32(15, 0);
600 const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS";
601 gui::IGUIStaticText *t =
602 Environment->addStaticText(text, rect, false, false, this, -1);
603 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
606 core::rect<s32> rect(0, 0, 454, 250);
607 rect += m_topleft_client + v2s32(110, 50+35);
608 Environment->addStaticText(narrow_to_wide(
609 "Minetest-c55 " VERSION_STRING "\n"
610 "http://minetest.net/\n"
612 "by Perttu Ahola <celeron55@gmail.com>\n"
613 "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."
614 ).c_str(), rect, false, true, this, -1);
618 m_is_regenerating = false;
621 void GUIMainMenu::drawMenu()
623 gui::IGUISkin* skin = Environment->getSkin();
626 video::IVideoDriver* driver = Environment->getVideoDriver();
628 /*video::SColor bgcolor(140,0,0,0);
629 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
631 video::SColor bgcolor(140,0,0,0);
633 if(getTab() == TAB_SINGLEPLAYER)
636 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
637 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
638 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
641 else if(getTab() == TAB_MULTIPLAYER)
644 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
645 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
646 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
649 else if(getTab() == TAB_ADVANCED)
652 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
653 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
654 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
657 core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y);
658 rect += AbsoluteRect.UpperLeftCorner + m_topleft_server;
659 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
662 else if(getTab() == TAB_SETTINGS)
665 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
666 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
667 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
670 else if(getTab() == TAB_CREDITS)
673 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
674 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
675 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
677 video::ITexture *logotexture =
678 driver->getTexture(getTexturePath("menulogo.png").c_str());
681 v2s32 logosize(logotexture->getOriginalSize().Width,
682 logotexture->getOriginalSize().Height);
684 core::rect<s32> rect(0,0,logosize.X,logosize.Y);
685 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
686 rect += v2s32(130, 50);
687 driver->draw2DImage(logotexture, rect,
688 core::rect<s32>(core::position2d<s32>(0,0),
689 core::dimension2di(logotexture->getSize())),
694 gui::IGUIElement::draw();
697 void GUIMainMenu::readInput(MainMenuData *dst)
700 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
701 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
702 dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab();
704 if(dst->selected_tab == TAB_SINGLEPLAYER)
706 dst->simple_singleplayer_mode = true;
710 dst->simple_singleplayer_mode = false;
712 gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
714 dst->name = e->getText();
717 gui::IGUIElement *e = getElementFromId(264);
719 dst->password = e->getText();
722 gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
724 dst->address = e->getText();
727 gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
729 dst->port = e->getText();
733 gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
734 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
735 dst->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
738 gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
739 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
740 dst->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
743 gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
744 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
745 dst->fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
748 gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
749 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
750 dst->smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
753 gui::IGUIElement *e = getElementFromId(GUI_ID_3D_CLOUDS_CB);
754 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
755 dst->clouds_3d = ((gui::IGUICheckBox*)e)->isChecked();
758 gui::IGUIElement *e = getElementFromId(GUI_ID_OPAQUE_WATER_CB);
759 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
760 dst->opaque_water = ((gui::IGUICheckBox*)e)->isChecked();
764 gui::IGUIElement *e = getElementFromId(GUI_ID_WORLD_LISTBOX);
765 if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX)
766 dst->selected_world = ((gui::IGUIListBox*)e)->getSelected();
770 void GUIMainMenu::acceptInput()
776 bool GUIMainMenu::OnEvent(const SEvent& event)
778 if(event.EventType==EET_KEY_INPUT_EVENT)
780 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
782 m_gamecallback->exitToOS();
786 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
793 if(event.EventType==EET_GUI_EVENT)
795 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
798 if(!canTakeFocus(event.GUIEvent.Element))
800 dstream<<"GUIMainMenu: Not allowing focus change."
802 // Returning true disables focus change
806 if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED)
808 if(!m_is_regenerating)
809 regenerateGui(m_screensize_old);
812 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
814 switch(event.GUIEvent.Caller->getID())
816 case GUI_ID_JOIN_GAME_BUTTON: {
819 if(cur.address == L"" && getTab() == TAB_MULTIPLAYER){
820 (new GUIMessageMenu(env, parent, -1, menumgr,
821 wgettext("Address required."))
829 case GUI_ID_CHANGE_KEYS_BUTTON: {
830 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
834 case GUI_ID_DELETE_WORLD_BUTTON: {
837 if(cur.selected_world == -1){
838 (new GUIMessageMenu(env, parent, -1, menumgr,
839 wgettext("Cannot delete world: Nothing selected"))
842 WorldSpec spec = m_data->worlds[cur.selected_world];
843 // Get files and directories involved
844 std::vector<std::string> paths;
845 paths.push_back(spec.path);
846 fs::GetRecursiveSubPaths(spec.path, paths);
847 // Launch confirmation dialog
848 ConfirmDestDeleteWorld *dest = new
849 ConfirmDestDeleteWorld(spec, this, paths);
850 std::wstring text = wgettext("Delete world");
852 text += narrow_to_wide(spec.name);
854 text += wgettext("Files to be deleted");
856 for(u32 i=0; i<paths.size(); i++){
857 if(i == 3){ text += L"..."; break; }
858 text += narrow_to_wide(paths[i]) + L"\n";
860 (new GUIConfirmMenu(env, parent, -1, menumgr, dest,
861 text.c_str()))->drop();
865 case GUI_ID_CREATE_WORLD_BUTTON: {
866 std::vector<SubgameSpec> games = getAvailableGames();
867 if(games.size() == 0){
868 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
870 wgettext("Cannot create world: No games found"));
873 CreateWorldDest *dest = new CreateWorldDestMainMenu(this);
874 GUICreateWorld *menu = new GUICreateWorld(env, parent, -1,
875 menumgr, dest, games);
880 case GUI_ID_CONFIGURE_WORLD_BUTTON: {
881 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
883 wgettext("Nothing here"));
889 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
891 switch(event.GUIEvent.Caller->getID())
893 case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
899 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN)
901 switch(event.GUIEvent.Caller->getID())
903 case GUI_ID_WORLD_LISTBOX:
905 if(getTab() != TAB_SINGLEPLAYER)
906 m_data->address = L""; // Force local game
913 return Parent ? Parent->OnEvent(event) : false;
916 void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
921 m_data->create_world_name = name;
922 m_data->create_world_gameid = gameid;
926 void GUIMainMenu::deleteWorld(const std::vector<std::string> &paths)
929 bool did = fs::DeletePaths(paths);
931 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
932 -1, menumgr, wgettext("Failed to delete all world files"));
935 // Quit menu to refresh it
937 m_data->only_refresh = true;
941 int GUIMainMenu::getTab()
943 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
944 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
945 return ((gui::IGUITabControl*)e)->getActiveTab();
946 return TAB_SINGLEPLAYER; // Default
949 void GUIMainMenu::displayMessageMenu(std::wstring msg)
951 (new GUIMessageMenu(env, parent, -1, menumgr, msg))->drop();