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
42 struct CreateWorldDestMainMenu : public CreateWorldDest
44 CreateWorldDestMainMenu(GUIMainMenu *menu):
47 void accepted(std::wstring name, std::string gameid)
49 m_menu->createNewWorld(name, gameid);
54 struct ConfirmDestDeleteWorld : public ConfirmDest
56 ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu):
60 void answer(bool answer)
64 m_menu->deleteWorld(m_spec);
72 GUI_ID_QUIT_BUTTON = 101,
77 GUI_ID_SMOOTH_LIGHTING_CB,
79 GUI_ID_OPAQUE_WATER_CB,
82 GUI_ID_JOIN_GAME_BUTTON,
83 GUI_ID_CHANGE_KEYS_BUTTON,
84 GUI_ID_DELETE_WORLD_BUTTON,
85 GUI_ID_CREATE_WORLD_BUTTON,
86 GUI_ID_CONFIGURE_WORLD_BUTTON,
100 GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
101 gui::IGUIElement* parent, s32 id,
102 IMenuManager *menumgr,
104 IGameCallback *gamecallback
106 GUIModalMenu(env, parent, id, menumgr),
109 m_gamecallback(gamecallback),
110 m_is_regenerating(false)
114 this->parent = parent;
116 this->menumgr = menumgr;
119 GUIMainMenu::~GUIMainMenu()
124 void GUIMainMenu::removeChildren()
126 const core::list<gui::IGUIElement*> &children = getChildren();
127 core::list<gui::IGUIElement*> children_copy;
128 for(core::list<gui::IGUIElement*>::ConstIterator
129 i = children.begin(); i != children.end(); i++)
131 children_copy.push_back(*i);
133 for(core::list<gui::IGUIElement*>::Iterator
134 i = children_copy.begin();
135 i != children_copy.end(); i++)
141 void GUIMainMenu::regenerateGui(v2u32 screensize)
143 m_is_regenerating = true;
145 Read stuff from elements into m_data
155 Calculate new sizes and positions
158 v2s32 size(screensize.X, screensize.Y);
160 core::rect<s32> rect(
161 screensize.X/2 - size.X/2,
162 screensize.Y/2 - size.Y/2,
163 screensize.X/2 + size.X/2,
164 screensize.Y/2 + size.Y/2
168 recalculateAbsolutePosition(false);
170 //v2s32 size = rect.getSize();
179 //if(m_data->selected_tab != TAB_CREDITS)
181 core::rect<s32> rect(0, 0, size.X, 40);
183 Environment->addStaticText(narrow_to_wide(
184 "Minetest-c55 " VERSION_STRING).c_str(),
185 rect, false, true, this, -1);
188 //v2s32 center(size.X/2, size.Y/2);
189 v2s32 c800(size.X/2-400, size.Y/2-300);
191 m_topleft_client = c800 + v2s32(90, 70+50+30);
192 m_size_client = v2s32(620, 270);
194 m_size_server = v2s32(620, 140);
196 if(m_data->selected_tab == TAB_ADVANCED)
198 m_topleft_client = c800 + v2s32(90, 70+50+30);
199 m_size_client = v2s32(620, 200);
201 m_size_server = v2s32(620, 140);
204 m_topleft_server = m_topleft_client + v2s32(0, m_size_client.Y+20);
209 core::rect<s32> rect(0, 0, m_size_client.X, 30);
210 rect += m_topleft_client + v2s32(0, -30);
211 gui::IGUITabControl *e = Environment->addTabControl(
212 rect, this, true, true, GUI_ID_TAB_CONTROL);
213 e->addTab(L"Singleplayer");
214 e->addTab(L"Multiplayer");
215 e->addTab(L"Advanced");
216 e->addTab(L"Settings");
217 e->addTab(L"Credits");
218 e->setActiveTab(m_data->selected_tab);
222 if(m_data->selected_tab == TAB_SINGLEPLAYER)
226 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
227 rect += m_topleft_client + v2s32(15, 0);
228 //const wchar_t *text = L"H\nY\nB\nR\nI\nD";
229 const wchar_t *text = L"T\nA\nP\nE\n\nA\nN\nD\n\nG\nL\nU\nE";
230 gui::IGUIStaticText *t =
231 Environment->addStaticText(text, rect, false, true, this, -1);
232 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
235 // World selection listbox
236 u32 world_sel_h = 160;
237 u32 world_sel_w = 365;
238 //s32 world_sel_x = 50;
239 s32 world_sel_x = m_size_client.X-world_sel_w-30;
240 s32 world_sel_y = 30;
241 u32 world_button_count = 3;
242 u32 world_button_w = (world_sel_w)/world_button_count - bs
243 + bs/(world_button_count-1);
245 core::rect<s32> rect(0, 0, world_sel_w-4, 20);
246 rect += m_topleft_client + v2s32(world_sel_x+4, world_sel_y-20);
247 /*gui::IGUIStaticText *e =*/ Environment->addStaticText(
248 wgettext("Select World:"),
249 rect, false, true, this, -1);
250 /*e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);*/
253 core::rect<s32> rect(0, 0, world_sel_w, world_sel_h);
254 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y);
255 gui::IGUIListBox *e = Environment->addListBox(rect, this,
256 GUI_ID_WORLD_LISTBOX);
257 e->setDrawBackground(true);
258 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
259 i != m_data->worlds.end(); i++){
260 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
262 e->setSelected(m_data->selected_world);
263 Environment->setFocus(e);
265 // Delete world button
267 core::rect<s32> rect(0, 0, world_button_w, 30);
268 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y+world_sel_h+0);
269 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
272 // Create world button
274 core::rect<s32> rect(0, 0, world_button_w, 30);
275 rect += m_topleft_client + v2s32(world_sel_x+world_button_w+bs, world_sel_y+world_sel_h+0);
276 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
279 // Configure world button
281 core::rect<s32> rect(0, 0, world_button_w, 30);
282 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*2,
283 world_sel_y+world_sel_h+0);
284 Environment->addButton(rect, this, GUI_ID_CONFIGURE_WORLD_BUTTON,
285 wgettext("Configure"));
289 /*core::rect<s32> rect(0, 0, world_button_w, 30);
290 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*3,
291 world_sel_y+world_sel_h+0);*/
293 /*core::rect<s32> rect(0, 0, bw, 30);
294 rect += m_topleft_client + v2s32(m_size_client.X-bw-30,
295 m_size_client.Y-30-15);*/
296 core::rect<s32> rect(0, 0, bw, 30);
297 rect += m_topleft_client + v2s32(world_sel_x+world_sel_w-bw,
298 world_sel_y+world_sel_h+30+bs);
299 Environment->addButton(rect, this,
300 GUI_ID_JOIN_GAME_BUTTON, wgettext("Play"));
304 //s32 option_x = 50+world_sel_w+20;
308 core::rect<s32> rect(0, 0, option_w, 30);
309 rect += m_topleft_client + v2s32(option_x, option_y+20*0);
310 Environment->addCheckBox(m_data->creative_mode, rect, this,
311 GUI_ID_CREATIVE_CB, wgettext("Creative Mode"));
314 core::rect<s32> rect(0, 0, option_w, 30);
315 rect += m_topleft_client + v2s32(option_x, option_y+20*1);
316 Environment->addCheckBox(m_data->enable_damage, rect, this,
317 GUI_ID_DAMAGE_CB, wgettext("Enable Damage"));
321 else if(m_data->selected_tab == TAB_MULTIPLAYER)
326 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
327 rect += m_topleft_client + v2s32(15, 0);
328 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
329 gui::IGUIStaticText *t =
330 Environment->addStaticText(text, rect, false, true, this, -1);
331 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
333 // Nickname + password
335 core::rect<s32> rect(0, 0, 110, 20);
336 rect += m_topleft_client + v2s32(35+30, 50+6);
337 Environment->addStaticText(wgettext("Name/Password"),
338 rect, false, true, this, -1);
342 core::rect<s32> rect(0, 0, 230, 30);
343 rect += m_topleft_client + v2s32(160+30, 50);
344 gui::IGUIElement *e =
345 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
346 if(m_data->name == L"")
347 Environment->setFocus(e);
350 core::rect<s32> rect(0, 0, 120, 30);
351 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50);
352 gui::IGUIEditBox *e =
353 Environment->addEditBox(L"", rect, true, this, 264);
354 e->setPasswordBox(true);
355 if(m_data->name != L"" && m_data->address != L"")
356 Environment->setFocus(e);
362 core::rect<s32> rect(0, 0, 110, 20);
363 rect += m_topleft_client + v2s32(35+30, 100+6);
364 Environment->addStaticText(wgettext("Address/Port"),
365 rect, false, true, this, -1);
369 core::rect<s32> rect(0, 0, 230, 30);
370 rect += m_topleft_client + v2s32(160+30, 100);
371 gui::IGUIElement *e =
372 Environment->addEditBox(m_data->address.c_str(), rect, true,
373 this, GUI_ID_ADDRESS_INPUT);
374 if(m_data->name != L"" && m_data->address == L"")
375 Environment->setFocus(e);
378 core::rect<s32> rect(0, 0, 120, 30);
379 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100);
380 Environment->addEditBox(m_data->port.c_str(), rect, true,
381 this, GUI_ID_PORT_INPUT);
386 core::rect<s32> rect(0, 0, 180, 30);
387 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
388 m_size_client.Y-30-15);
389 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
390 wgettext("Start Game / Connect"));
394 else if(m_data->selected_tab == TAB_ADVANCED)
399 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
400 rect += m_topleft_client + v2s32(15, 0);
401 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
402 gui::IGUIStaticText *t =
403 Environment->addStaticText(text, rect, false, true, this, -1);
404 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
406 // Nickname + password
408 core::rect<s32> rect(0, 0, 110, 20);
409 rect += m_topleft_client + v2s32(35+30, 35+6);
410 Environment->addStaticText(wgettext("Name/Password"),
411 rect, false, true, this, -1);
415 core::rect<s32> rect(0, 0, 230, 30);
416 rect += m_topleft_client + v2s32(160+30, 35);
417 gui::IGUIElement *e =
418 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
419 if(m_data->name == L"")
420 Environment->setFocus(e);
423 core::rect<s32> rect(0, 0, 120, 30);
424 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 35);
425 gui::IGUIEditBox *e =
426 Environment->addEditBox(L"", rect, true, this, 264);
427 e->setPasswordBox(true);
428 if(m_data->name != L"" && m_data->address != L"")
429 Environment->setFocus(e);
435 core::rect<s32> rect(0, 0, 110, 20);
436 rect += m_topleft_client + v2s32(35+30, 75+6);
437 Environment->addStaticText(wgettext("Address/Port"),
438 rect, false, true, this, -1);
442 core::rect<s32> rect(0, 0, 230, 30);
443 rect += m_topleft_client + v2s32(160+30, 75);
444 gui::IGUIElement *e =
445 Environment->addEditBox(m_data->address.c_str(), rect, true,
446 this, GUI_ID_ADDRESS_INPUT);
447 if(m_data->name != L"" && m_data->address == L"")
448 Environment->setFocus(e);
451 core::rect<s32> rect(0, 0, 120, 30);
452 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 75);
453 Environment->addEditBox(m_data->port.c_str(), rect, true,
454 this, GUI_ID_PORT_INPUT);
458 core::rect<s32> rect(0, 0, 400, 20);
459 rect += m_topleft_client + v2s32(160+30, 75+35);
460 Environment->addStaticText(wgettext("Leave address blank to start a local server."),
461 rect, false, true, this, -1);
465 core::rect<s32> rect(0, 0, 180, 30);
466 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
467 m_size_client.Y-30-20);
468 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
469 wgettext("Start Game / Connect"));
476 core::rect<s32> rect(0, 0, 10, m_size_server.Y);
477 rect += m_topleft_server + v2s32(15, 0);
478 const wchar_t *text = L"S\nE\nR\nV\nE\nR";
479 gui::IGUIStaticText *t =
480 Environment->addStaticText(text, rect, false, true, this, -1);
481 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
485 core::rect<s32> rect(0, 0, 250, 30);
486 rect += m_topleft_server + v2s32(30+20+250+20, 20);
487 Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB,
488 wgettext("Creative Mode"));
491 core::rect<s32> rect(0, 0, 250, 30);
492 rect += m_topleft_server + v2s32(30+20+250+20, 40);
493 Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
494 wgettext("Enable Damage"));
496 // Delete world button
498 core::rect<s32> rect(0, 0, 130, 30);
499 rect += m_topleft_server + v2s32(30+20+250+20, 90);
500 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
501 wgettext("Delete world"));
503 // Create world button
505 core::rect<s32> rect(0, 0, 130, 30);
506 rect += m_topleft_server + v2s32(30+20+250+20+140, 90);
507 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
508 wgettext("Create world"));
510 // World selection listbox
512 core::rect<s32> rect(0, 0, 250, 120);
513 rect += m_topleft_server + v2s32(30+20, 10);
514 gui::IGUIListBox *e = Environment->addListBox(rect, this,
515 GUI_ID_WORLD_LISTBOX);
516 e->setDrawBackground(true);
517 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
518 i != m_data->worlds.end(); i++){
519 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
521 e->setSelected(m_data->selected_world);
525 else if(m_data->selected_tab == TAB_SETTINGS)
528 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
529 rect += m_topleft_client + v2s32(15, 0);
530 const wchar_t *text = L"S\nE\nT\nT\nI\nN\nG\nS";
531 gui::IGUIStaticText *t =
532 Environment->addStaticText(text, rect, false, true, this, -1);
533 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
539 core::rect<s32> rect(0, 0, option_w, 30);
540 rect += m_topleft_client + v2s32(option_x, option_y);
541 Environment->addCheckBox(m_data->fancy_trees, rect, this,
542 GUI_ID_FANCYTREE_CB, wgettext("Fancy trees"));
545 core::rect<s32> rect(0, 0, option_w, 30);
546 rect += m_topleft_client + v2s32(option_x, option_y+20);
547 Environment->addCheckBox(m_data->smooth_lighting, rect, this,
548 GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting"));
551 core::rect<s32> rect(0, 0, option_w, 30);
552 rect += m_topleft_client + v2s32(option_x, option_y+20*2);
553 Environment->addCheckBox(m_data->clouds_3d, rect, this,
554 GUI_ID_3D_CLOUDS_CB, wgettext("3D Clouds"));
557 core::rect<s32> rect(0, 0, option_w, 30);
558 rect += m_topleft_client + v2s32(option_x, option_y+20*3);
559 Environment->addCheckBox(m_data->opaque_water, rect, this,
560 GUI_ID_OPAQUE_WATER_CB, wgettext("Opaque water"));
564 core::rect<s32> rect(0, 0, 120, 30);
565 /*rect += m_topleft_client + v2s32(m_size_client.X-120-30,
566 m_size_client.Y-30-20);*/
567 rect += m_topleft_client + v2s32(option_x, option_y+120);
568 Environment->addButton(rect, this,
569 GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys"));
573 else if(m_data->selected_tab == TAB_CREDITS)
577 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
578 rect += m_topleft_client + v2s32(15, 0);
579 const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS";
580 gui::IGUIStaticText *t =
581 Environment->addStaticText(text, rect, false, true, this, -1);
582 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
585 core::rect<s32> rect(0, 0, 620, 250);
586 rect += m_topleft_client + v2s32(130+14, 50+35);
587 Environment->addStaticText(narrow_to_wide(
588 "Minetest-c55 " VERSION_STRING "\n"
589 "http://c55.me/minetest/\n"
591 "by Perttu Ahola <celeron55@gmail.com>\n"
593 ).c_str(), rect, false, true, this, -1);
597 m_is_regenerating = false;
600 void GUIMainMenu::drawMenu()
602 gui::IGUISkin* skin = Environment->getSkin();
605 video::IVideoDriver* driver = Environment->getVideoDriver();
607 /*video::SColor bgcolor(140,0,0,0);
608 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
610 video::SColor bgcolor(140,0,0,0);
612 if(getTab() == TAB_SINGLEPLAYER)
615 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
616 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
617 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
620 else if(getTab() == TAB_MULTIPLAYER)
623 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
624 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
625 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
628 else if(getTab() == TAB_ADVANCED)
631 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
632 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
633 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
636 core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y);
637 rect += AbsoluteRect.UpperLeftCorner + m_topleft_server;
638 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
641 else if(getTab() == TAB_SETTINGS)
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_CREDITS)
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);
656 video::ITexture *logotexture =
657 driver->getTexture(getTexturePath("menulogo.png").c_str());
660 v2s32 logosize(logotexture->getOriginalSize().Width,
661 logotexture->getOriginalSize().Height);
663 core::rect<s32> rect(0,0,logosize.X,logosize.Y);
664 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
665 rect += v2s32(130, 50);
666 driver->draw2DImage(logotexture, rect,
667 core::rect<s32>(core::position2d<s32>(0,0),
668 core::dimension2di(logotexture->getSize())),
673 gui::IGUIElement::draw();
676 void GUIMainMenu::readInput(MainMenuData *dst)
679 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
680 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
681 dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab();
683 if(dst->selected_tab == TAB_SINGLEPLAYER)
685 dst->simple_singleplayer_mode = true;
689 dst->simple_singleplayer_mode = false;
691 gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
693 dst->name = e->getText();
696 gui::IGUIElement *e = getElementFromId(264);
698 dst->password = e->getText();
701 gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
703 dst->address = e->getText();
706 gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
708 dst->port = e->getText();
712 gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
713 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
714 dst->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
717 gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
718 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
719 dst->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
722 gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
723 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
724 dst->fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
727 gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
728 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
729 dst->smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
732 gui::IGUIElement *e = getElementFromId(GUI_ID_3D_CLOUDS_CB);
733 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
734 dst->clouds_3d = ((gui::IGUICheckBox*)e)->isChecked();
737 gui::IGUIElement *e = getElementFromId(GUI_ID_OPAQUE_WATER_CB);
738 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
739 dst->opaque_water = ((gui::IGUICheckBox*)e)->isChecked();
743 gui::IGUIElement *e = getElementFromId(GUI_ID_WORLD_LISTBOX);
744 if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX)
745 dst->selected_world = ((gui::IGUIListBox*)e)->getSelected();
749 void GUIMainMenu::acceptInput()
755 bool GUIMainMenu::OnEvent(const SEvent& event)
757 if(event.EventType==EET_KEY_INPUT_EVENT)
759 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
761 m_gamecallback->exitToOS();
765 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
772 if(event.EventType==EET_GUI_EVENT)
774 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
777 if(!canTakeFocus(event.GUIEvent.Element))
779 dstream<<"GUIMainMenu: Not allowing focus change."
781 // Returning true disables focus change
785 if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED)
787 if(!m_is_regenerating)
788 regenerateGui(m_screensize_old);
791 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
793 switch(event.GUIEvent.Caller->getID())
795 case GUI_ID_JOIN_GAME_BUTTON: {
798 if(cur.address == L"" && getTab() == TAB_MULTIPLAYER){
799 (new GUIMessageMenu(env, parent, -1, menumgr,
800 wgettext("Address required."))
808 case GUI_ID_CHANGE_KEYS_BUTTON: {
809 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
813 case GUI_ID_DELETE_WORLD_BUTTON: {
816 if(cur.selected_world == -1){
817 (new GUIMessageMenu(env, parent, -1, menumgr,
818 wgettext("Cannot delete world: Nothing selected"))
821 WorldSpec spec = m_data->worlds[cur.selected_world];
822 ConfirmDestDeleteWorld *dest = new
823 ConfirmDestDeleteWorld(spec, this);
824 (new GUIConfirmMenu(env, parent, -1, menumgr, dest,
825 (std::wstring(wgettext("Delete world "))
826 +L"\""+narrow_to_wide(spec.name)+L"\"?").c_str()
831 case GUI_ID_CREATE_WORLD_BUTTON: {
832 std::vector<SubgameSpec> games = getAvailableGames();
833 if(games.size() == 0){
834 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
836 wgettext("Cannot create world: No games found"));
839 CreateWorldDest *dest = new CreateWorldDestMainMenu(this);
840 GUICreateWorld *menu = new GUICreateWorld(env, parent, -1,
841 menumgr, dest, games);
846 case GUI_ID_CONFIGURE_WORLD_BUTTON: {
847 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
849 wgettext("Nothing here"));
855 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
857 switch(event.GUIEvent.Caller->getID())
859 case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
865 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN)
867 switch(event.GUIEvent.Caller->getID())
869 case GUI_ID_WORLD_LISTBOX:
871 m_data->address = L""; // Force local game
878 return Parent ? Parent->OnEvent(event) : false;
881 void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
886 m_data->create_world_name = name;
887 m_data->create_world_gameid = gameid;
891 void GUIMainMenu::deleteWorld(WorldSpec spec)
896 m_data->delete_world_spec = spec;
900 int GUIMainMenu::getTab()
902 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
903 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
904 return ((gui::IGUITabControl*)e)->getActiveTab();
905 return TAB_SINGLEPLAYER; // Default