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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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"
40 #include "tile.h" // getTexturePath
43 struct CreateWorldDestMainMenu : public CreateWorldDest
45 CreateWorldDestMainMenu(GUIMainMenu *menu):
48 void accepted(std::wstring name, std::string gameid)
50 m_menu->createNewWorld(name, gameid);
55 struct ConfirmDestDeleteWorld : public ConfirmDest
57 ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu,
58 const std::vector<std::string> &paths):
63 void answer(bool answer)
67 m_menu->deleteWorld(m_paths);
71 std::vector<std::string> m_paths;
76 GUI_ID_QUIT_BUTTON = 101,
81 GUI_ID_SMOOTH_LIGHTING_CB,
83 GUI_ID_OPAQUE_WATER_CB,
86 GUI_ID_JOIN_GAME_BUTTON,
87 GUI_ID_CHANGE_KEYS_BUTTON,
88 GUI_ID_DELETE_WORLD_BUTTON,
89 GUI_ID_CREATE_WORLD_BUTTON,
90 GUI_ID_CONFIGURE_WORLD_BUTTON,
104 GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
105 gui::IGUIElement* parent, s32 id,
106 IMenuManager *menumgr,
108 IGameCallback *gamecallback
110 GUIModalMenu(env, parent, id, menumgr),
113 m_gamecallback(gamecallback),
114 m_is_regenerating(false)
118 this->parent = parent;
120 this->menumgr = menumgr;
123 GUIMainMenu::~GUIMainMenu()
128 void GUIMainMenu::removeChildren()
130 const core::list<gui::IGUIElement*> &children = getChildren();
131 core::list<gui::IGUIElement*> children_copy;
132 for(core::list<gui::IGUIElement*>::ConstIterator
133 i = children.begin(); i != children.end(); i++)
135 children_copy.push_back(*i);
137 for(core::list<gui::IGUIElement*>::Iterator
138 i = children_copy.begin();
139 i != children_copy.end(); i++)
145 void GUIMainMenu::regenerateGui(v2u32 screensize)
147 m_is_regenerating = true;
149 Read stuff from elements into m_data
159 Calculate new sizes and positions
162 v2s32 size(screensize.X, screensize.Y);
164 core::rect<s32> rect(
165 screensize.X/2 - size.X/2,
166 screensize.Y/2 - size.Y/2,
167 screensize.X/2 + size.X/2,
168 screensize.Y/2 + size.Y/2
172 recalculateAbsolutePosition(false);
174 //v2s32 size = rect.getSize();
183 //if(m_data->selected_tab != TAB_CREDITS)
185 core::rect<s32> rect(0, 0, size.X, 40);
187 Environment->addStaticText(narrow_to_wide(
188 "Minetest-c55 " VERSION_STRING).c_str(),
189 rect, false, true, this, -1);
192 //v2s32 center(size.X/2, size.Y/2);
193 v2s32 c800(size.X/2-400, size.Y/2-300);
195 m_topleft_client = c800 + v2s32(90, 70+50+30);
196 m_size_client = v2s32(620, 270);
198 m_size_server = v2s32(620, 140);
200 if(m_data->selected_tab == TAB_ADVANCED)
202 m_topleft_client = c800 + v2s32(90, 70+50+30);
203 m_size_client = v2s32(620, 200);
205 m_size_server = v2s32(620, 140);
208 m_topleft_server = m_topleft_client + v2s32(0, m_size_client.Y+20);
213 core::rect<s32> rect(0, 0, m_size_client.X, 30);
214 rect += m_topleft_client + v2s32(0, -30);
215 gui::IGUITabControl *e = Environment->addTabControl(
216 rect, this, true, true, GUI_ID_TAB_CONTROL);
217 e->addTab(L"Singleplayer");
218 e->addTab(L"Multiplayer");
219 e->addTab(L"Advanced");
220 e->addTab(L"Settings");
221 e->addTab(L"Credits");
222 e->setActiveTab(m_data->selected_tab);
226 if(m_data->selected_tab == TAB_SINGLEPLAYER)
230 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
231 rect += m_topleft_client + v2s32(15, 0);
232 //const wchar_t *text = L"H\nY\nB\nR\nI\nD";
233 const wchar_t *text = L"T\nA\nP\nE\n\nA\nN\nD\n\nG\nL\nU\nE";
234 gui::IGUIStaticText *t =
235 Environment->addStaticText(text, rect, false, false, this, -1);
236 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
239 // World selection listbox
240 u32 world_sel_h = 160;
241 u32 world_sel_w = 365;
242 //s32 world_sel_x = 50;
243 s32 world_sel_x = m_size_client.X-world_sel_w-30;
244 s32 world_sel_y = 30;
245 u32 world_button_count = 3;
246 u32 world_button_w = (world_sel_w)/world_button_count - bs
247 + bs/(world_button_count-1);
249 core::rect<s32> rect(0, 0, world_sel_w-4, 20);
250 rect += m_topleft_client + v2s32(world_sel_x+4, world_sel_y-20);
251 /*gui::IGUIStaticText *e =*/ Environment->addStaticText(
252 wgettext("Select World:"),
253 rect, false, true, this, -1);
254 /*e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);*/
257 core::rect<s32> rect(0, 0, world_sel_w, world_sel_h);
258 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y);
259 gui::IGUIListBox *e = Environment->addListBox(rect, this,
260 GUI_ID_WORLD_LISTBOX);
261 e->setDrawBackground(true);
262 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
263 i != m_data->worlds.end(); i++){
264 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
266 e->setSelected(m_data->selected_world);
267 Environment->setFocus(e);
269 // Delete world button
271 core::rect<s32> rect(0, 0, world_button_w, 30);
272 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y+world_sel_h+0);
273 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
276 // Create world button
278 core::rect<s32> rect(0, 0, world_button_w, 30);
279 rect += m_topleft_client + v2s32(world_sel_x+world_button_w+bs, world_sel_y+world_sel_h+0);
280 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
283 // Configure world button
285 core::rect<s32> rect(0, 0, world_button_w, 30);
286 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*2,
287 world_sel_y+world_sel_h+0);
288 Environment->addButton(rect, this, GUI_ID_CONFIGURE_WORLD_BUTTON,
289 wgettext("Configure"));
293 /*core::rect<s32> rect(0, 0, world_button_w, 30);
294 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*3,
295 world_sel_y+world_sel_h+0);*/
297 /*core::rect<s32> rect(0, 0, bw, 30);
298 rect += m_topleft_client + v2s32(m_size_client.X-bw-30,
299 m_size_client.Y-30-15);*/
300 core::rect<s32> rect(0, 0, bw, 30);
301 rect += m_topleft_client + v2s32(world_sel_x+world_sel_w-bw,
302 world_sel_y+world_sel_h+30+bs);
303 Environment->addButton(rect, this,
304 GUI_ID_JOIN_GAME_BUTTON, wgettext("Play"));
308 //s32 option_x = 50+world_sel_w+20;
312 core::rect<s32> rect(0, 0, option_w, 30);
313 rect += m_topleft_client + v2s32(option_x, option_y+20*0);
314 Environment->addCheckBox(m_data->creative_mode, rect, this,
315 GUI_ID_CREATIVE_CB, wgettext("Creative Mode"));
318 core::rect<s32> rect(0, 0, option_w, 30);
319 rect += m_topleft_client + v2s32(option_x, option_y+20*1);
320 Environment->addCheckBox(m_data->enable_damage, rect, this,
321 GUI_ID_DAMAGE_CB, wgettext("Enable Damage"));
325 else if(m_data->selected_tab == TAB_MULTIPLAYER)
330 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
331 rect += m_topleft_client + v2s32(15, 0);
332 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
333 gui::IGUIStaticText *t =
334 Environment->addStaticText(text, rect, false, false, this, -1);
335 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
337 // Nickname + password
339 core::rect<s32> rect(0, 0, 110, 20);
340 rect += m_topleft_client + v2s32(35+30, 50+6);
341 Environment->addStaticText(wgettext("Name/Password"),
342 rect, false, true, this, -1);
346 core::rect<s32> rect(0, 0, 230, 30);
347 rect += m_topleft_client + v2s32(160+30, 50);
348 gui::IGUIElement *e =
349 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
350 if(m_data->name == L"")
351 Environment->setFocus(e);
354 core::rect<s32> rect(0, 0, 120, 30);
355 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50);
356 gui::IGUIEditBox *e =
357 Environment->addEditBox(L"", rect, true, this, 264);
358 e->setPasswordBox(true);
359 if(m_data->name != L"" && m_data->address != L"")
360 Environment->setFocus(e);
366 core::rect<s32> rect(0, 0, 110, 20);
367 rect += m_topleft_client + v2s32(35+30, 100+6);
368 Environment->addStaticText(wgettext("Address/Port"),
369 rect, false, true, this, -1);
373 core::rect<s32> rect(0, 0, 230, 30);
374 rect += m_topleft_client + v2s32(160+30, 100);
375 gui::IGUIElement *e =
376 Environment->addEditBox(m_data->address.c_str(), rect, true,
377 this, GUI_ID_ADDRESS_INPUT);
378 if(m_data->name != L"" && m_data->address == L"")
379 Environment->setFocus(e);
382 core::rect<s32> rect(0, 0, 120, 30);
383 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100);
384 Environment->addEditBox(m_data->port.c_str(), rect, true,
385 this, GUI_ID_PORT_INPUT);
390 core::rect<s32> rect(0, 0, 180, 30);
391 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
392 m_size_client.Y-30-15);
393 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
394 wgettext("Start Game / Connect"));
398 else if(m_data->selected_tab == TAB_ADVANCED)
403 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
404 rect += m_topleft_client + v2s32(15, 0);
405 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
406 gui::IGUIStaticText *t =
407 Environment->addStaticText(text, rect, false, false, this, -1);
408 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
410 // Nickname + password
412 core::rect<s32> rect(0, 0, 110, 20);
413 rect += m_topleft_client + v2s32(35+30, 35+6);
414 Environment->addStaticText(wgettext("Name/Password"),
415 rect, false, true, this, -1);
419 core::rect<s32> rect(0, 0, 230, 30);
420 rect += m_topleft_client + v2s32(160+30, 35);
421 gui::IGUIElement *e =
422 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
423 if(m_data->name == L"")
424 Environment->setFocus(e);
427 core::rect<s32> rect(0, 0, 120, 30);
428 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 35);
429 gui::IGUIEditBox *e =
430 Environment->addEditBox(L"", rect, true, this, 264);
431 e->setPasswordBox(true);
432 if(m_data->name != L"" && m_data->address != L"")
433 Environment->setFocus(e);
439 core::rect<s32> rect(0, 0, 110, 20);
440 rect += m_topleft_client + v2s32(35+30, 75+6);
441 Environment->addStaticText(wgettext("Address/Port"),
442 rect, false, true, this, -1);
446 core::rect<s32> rect(0, 0, 230, 30);
447 rect += m_topleft_client + v2s32(160+30, 75);
448 gui::IGUIElement *e =
449 Environment->addEditBox(m_data->address.c_str(), rect, true,
450 this, GUI_ID_ADDRESS_INPUT);
451 if(m_data->name != L"" && m_data->address == L"")
452 Environment->setFocus(e);
455 core::rect<s32> rect(0, 0, 120, 30);
456 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 75);
457 Environment->addEditBox(m_data->port.c_str(), rect, true,
458 this, GUI_ID_PORT_INPUT);
462 core::rect<s32> rect(0, 0, 400, 20);
463 rect += m_topleft_client + v2s32(160+30, 75+35);
464 Environment->addStaticText(wgettext("Leave address blank to start a local server."),
465 rect, false, true, this, -1);
469 core::rect<s32> rect(0, 0, 180, 30);
470 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
471 m_size_client.Y-30-20);
472 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
473 wgettext("Start Game / Connect"));
480 core::rect<s32> rect(0, 0, 10, m_size_server.Y);
481 rect += m_topleft_server + v2s32(15, 0);
482 const wchar_t *text = L"S\nE\nR\nV\nE\nR";
483 gui::IGUIStaticText *t =
484 Environment->addStaticText(text, rect, false, false, this, -1);
485 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
489 core::rect<s32> rect(0, 0, 250, 30);
490 rect += m_topleft_server + v2s32(30+20+250+20, 20);
491 Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB,
492 wgettext("Creative Mode"));
495 core::rect<s32> rect(0, 0, 250, 30);
496 rect += m_topleft_server + v2s32(30+20+250+20, 40);
497 Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
498 wgettext("Enable Damage"));
500 // Delete world button
502 core::rect<s32> rect(0, 0, 130, 30);
503 rect += m_topleft_server + v2s32(30+20+250+20, 90);
504 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
505 wgettext("Delete world"));
507 // Create world button
509 core::rect<s32> rect(0, 0, 130, 30);
510 rect += m_topleft_server + v2s32(30+20+250+20+140, 90);
511 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
512 wgettext("Create world"));
514 // World selection listbox
516 core::rect<s32> rect(0, 0, 250, 120);
517 rect += m_topleft_server + v2s32(30+20, 10);
518 gui::IGUIListBox *e = Environment->addListBox(rect, this,
519 GUI_ID_WORLD_LISTBOX);
520 e->setDrawBackground(true);
521 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
522 i != m_data->worlds.end(); i++){
523 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
525 e->setSelected(m_data->selected_world);
529 else if(m_data->selected_tab == TAB_SETTINGS)
532 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
533 rect += m_topleft_client + v2s32(15, 0);
534 const wchar_t *text = L"S\nE\nT\nT\nI\nN\nG\nS";
535 gui::IGUIStaticText *t =
536 Environment->addStaticText(text, rect, false, false, this, -1);
537 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
543 core::rect<s32> rect(0, 0, option_w, 30);
544 rect += m_topleft_client + v2s32(option_x, option_y);
545 Environment->addCheckBox(m_data->fancy_trees, rect, this,
546 GUI_ID_FANCYTREE_CB, wgettext("Fancy trees"));
549 core::rect<s32> rect(0, 0, option_w, 30);
550 rect += m_topleft_client + v2s32(option_x, option_y+20);
551 Environment->addCheckBox(m_data->smooth_lighting, rect, this,
552 GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting"));
555 core::rect<s32> rect(0, 0, option_w, 30);
556 rect += m_topleft_client + v2s32(option_x, option_y+20*2);
557 Environment->addCheckBox(m_data->clouds_3d, rect, this,
558 GUI_ID_3D_CLOUDS_CB, wgettext("3D Clouds"));
561 core::rect<s32> rect(0, 0, option_w, 30);
562 rect += m_topleft_client + v2s32(option_x, option_y+20*3);
563 Environment->addCheckBox(m_data->opaque_water, rect, this,
564 GUI_ID_OPAQUE_WATER_CB, wgettext("Opaque water"));
568 core::rect<s32> rect(0, 0, 120, 30);
569 /*rect += m_topleft_client + v2s32(m_size_client.X-120-30,
570 m_size_client.Y-30-20);*/
571 rect += m_topleft_client + v2s32(option_x, option_y+120);
572 Environment->addButton(rect, this,
573 GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys"));
577 else if(m_data->selected_tab == TAB_CREDITS)
581 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
582 rect += m_topleft_client + v2s32(15, 0);
583 const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS";
584 gui::IGUIStaticText *t =
585 Environment->addStaticText(text, rect, false, false, this, -1);
586 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
589 core::rect<s32> rect(0, 0, 620, 250);
590 rect += m_topleft_client + v2s32(130+14, 50+35);
591 Environment->addStaticText(narrow_to_wide(
592 "Minetest-c55 " VERSION_STRING "\n"
593 "http://c55.me/minetest/\n"
595 "by Perttu Ahola <celeron55@gmail.com>\n"
597 ).c_str(), rect, false, true, this, -1);
601 m_is_regenerating = false;
604 void GUIMainMenu::drawMenu()
606 gui::IGUISkin* skin = Environment->getSkin();
609 video::IVideoDriver* driver = Environment->getVideoDriver();
611 /*video::SColor bgcolor(140,0,0,0);
612 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
614 video::SColor bgcolor(140,0,0,0);
616 if(getTab() == TAB_SINGLEPLAYER)
619 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
620 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
621 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
624 else if(getTab() == TAB_MULTIPLAYER)
627 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
628 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
629 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
632 else if(getTab() == TAB_ADVANCED)
635 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
636 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
637 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
640 core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y);
641 rect += AbsoluteRect.UpperLeftCorner + m_topleft_server;
642 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
645 else if(getTab() == TAB_SETTINGS)
648 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
649 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
650 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
653 else if(getTab() == TAB_CREDITS)
656 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
657 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
658 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
660 video::ITexture *logotexture =
661 driver->getTexture(getTexturePath("menulogo.png").c_str());
664 v2s32 logosize(logotexture->getOriginalSize().Width,
665 logotexture->getOriginalSize().Height);
667 core::rect<s32> rect(0,0,logosize.X,logosize.Y);
668 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
669 rect += v2s32(130, 50);
670 driver->draw2DImage(logotexture, rect,
671 core::rect<s32>(core::position2d<s32>(0,0),
672 core::dimension2di(logotexture->getSize())),
677 gui::IGUIElement::draw();
680 void GUIMainMenu::readInput(MainMenuData *dst)
683 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
684 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
685 dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab();
687 if(dst->selected_tab == TAB_SINGLEPLAYER)
689 dst->simple_singleplayer_mode = true;
693 dst->simple_singleplayer_mode = false;
695 gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
697 dst->name = e->getText();
700 gui::IGUIElement *e = getElementFromId(264);
702 dst->password = e->getText();
705 gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
707 dst->address = e->getText();
710 gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
712 dst->port = e->getText();
716 gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
717 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
718 dst->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
721 gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
722 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
723 dst->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
726 gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
727 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
728 dst->fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
731 gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
732 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
733 dst->smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
736 gui::IGUIElement *e = getElementFromId(GUI_ID_3D_CLOUDS_CB);
737 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
738 dst->clouds_3d = ((gui::IGUICheckBox*)e)->isChecked();
741 gui::IGUIElement *e = getElementFromId(GUI_ID_OPAQUE_WATER_CB);
742 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
743 dst->opaque_water = ((gui::IGUICheckBox*)e)->isChecked();
747 gui::IGUIElement *e = getElementFromId(GUI_ID_WORLD_LISTBOX);
748 if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX)
749 dst->selected_world = ((gui::IGUIListBox*)e)->getSelected();
753 void GUIMainMenu::acceptInput()
759 bool GUIMainMenu::OnEvent(const SEvent& event)
761 if(event.EventType==EET_KEY_INPUT_EVENT)
763 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
765 m_gamecallback->exitToOS();
769 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
776 if(event.EventType==EET_GUI_EVENT)
778 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
781 if(!canTakeFocus(event.GUIEvent.Element))
783 dstream<<"GUIMainMenu: Not allowing focus change."
785 // Returning true disables focus change
789 if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED)
791 if(!m_is_regenerating)
792 regenerateGui(m_screensize_old);
795 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
797 switch(event.GUIEvent.Caller->getID())
799 case GUI_ID_JOIN_GAME_BUTTON: {
802 if(cur.address == L"" && getTab() == TAB_MULTIPLAYER){
803 (new GUIMessageMenu(env, parent, -1, menumgr,
804 wgettext("Address required."))
812 case GUI_ID_CHANGE_KEYS_BUTTON: {
813 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
817 case GUI_ID_DELETE_WORLD_BUTTON: {
820 if(cur.selected_world == -1){
821 (new GUIMessageMenu(env, parent, -1, menumgr,
822 wgettext("Cannot delete world: Nothing selected"))
825 WorldSpec spec = m_data->worlds[cur.selected_world];
826 // Get files and directories involved
827 std::vector<std::string> paths;
828 paths.push_back(spec.path);
829 fs::GetRecursiveSubPaths(spec.path, paths);
830 // Launch confirmation dialog
831 ConfirmDestDeleteWorld *dest = new
832 ConfirmDestDeleteWorld(spec, this, paths);
833 std::wstring text = wgettext("Delete world");
835 text += narrow_to_wide(spec.name);
837 text += wgettext("Files to be deleted");
839 for(u32 i=0; i<paths.size(); i++){
840 if(i == 3){ text += L"..."; break; }
841 text += narrow_to_wide(paths[i]) + L"\n";
843 (new GUIConfirmMenu(env, parent, -1, menumgr, dest,
844 text.c_str()))->drop();
848 case GUI_ID_CREATE_WORLD_BUTTON: {
849 std::vector<SubgameSpec> games = getAvailableGames();
850 if(games.size() == 0){
851 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
853 wgettext("Cannot create world: No games found"));
856 CreateWorldDest *dest = new CreateWorldDestMainMenu(this);
857 GUICreateWorld *menu = new GUICreateWorld(env, parent, -1,
858 menumgr, dest, games);
863 case GUI_ID_CONFIGURE_WORLD_BUTTON: {
864 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
866 wgettext("Nothing here"));
872 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
874 switch(event.GUIEvent.Caller->getID())
876 case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
882 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN)
884 switch(event.GUIEvent.Caller->getID())
886 case GUI_ID_WORLD_LISTBOX:
888 if(getTab() != TAB_SINGLEPLAYER)
889 m_data->address = L""; // Force local game
896 return Parent ? Parent->OnEvent(event) : false;
899 void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
904 m_data->create_world_name = name;
905 m_data->create_world_gameid = gameid;
909 void GUIMainMenu::deleteWorld(const std::vector<std::string> &paths)
912 bool did = fs::DeletePaths(paths);
914 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
915 -1, menumgr, wgettext("Failed to delete all world files"));
918 // Quit menu to refresh it
920 m_data->only_refresh = true;
924 int GUIMainMenu::getTab()
926 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
927 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
928 return ((gui::IGUITabControl*)e)->getActiveTab();
929 return TAB_SINGLEPLAYER; // Default