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_topleft_server = c800 + v2s32(90, 70+30+50+290);
195 m_size_server = v2s32(620, 140);
197 if(m_data->selected_tab == TAB_ADVANCED)
199 m_topleft_client = c800 + v2s32(90, 20+50+30);
200 m_size_client = v2s32(620, 270);
202 m_topleft_server = c800 + v2s32(90, 20+30+50+290);
203 m_size_server = v2s32(620, 140);
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, 20, 125);
227 rect += m_topleft_client + v2s32(15, 80);
228 const wchar_t *text = L"H\nY\nB\nR\nI\nD";*/
229 core::rect<s32> rect(0, 0, 20, 300);
230 rect += m_topleft_client + v2s32(15, 15);
231 const wchar_t *text = L"T\nA\nP\nE\n\nA\nN\nD\n\nG\nL\nU\nE";
232 //gui::IGUIStaticText *t =
233 Environment->addStaticText(text, rect, false, true, this, -1);
234 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
237 // World selection listbox
238 u32 world_sel_h = 160;
239 u32 world_sel_w = 365;
240 //s32 world_sel_x = 50;
241 s32 world_sel_x = m_size_client.X-world_sel_w-30;
242 s32 world_sel_y = 30;
243 u32 world_button_count = 3;
244 u32 world_button_w = (world_sel_w)/world_button_count - bs
245 + bs/(world_button_count-1);
247 core::rect<s32> rect(0, 0, world_sel_w-4, 20);
248 rect += m_topleft_client + v2s32(world_sel_x+4, world_sel_y-20);
249 /*gui::IGUIStaticText *e =*/ Environment->addStaticText(
250 wgettext("Select World:"),
251 rect, false, true, this, -1);
252 /*e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);*/
255 core::rect<s32> rect(0, 0, world_sel_w, world_sel_h);
256 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y);
257 gui::IGUIListBox *e = Environment->addListBox(rect, this,
258 GUI_ID_WORLD_LISTBOX);
259 e->setDrawBackground(true);
260 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
261 i != m_data->worlds.end(); i++){
262 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
264 e->setSelected(m_data->selected_world);
265 Environment->setFocus(e);
267 // Delete world button
269 core::rect<s32> rect(0, 0, world_button_w, 30);
270 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y+world_sel_h+0);
271 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
274 // Create world button
276 core::rect<s32> rect(0, 0, world_button_w, 30);
277 rect += m_topleft_client + v2s32(world_sel_x+world_button_w+bs, world_sel_y+world_sel_h+0);
278 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
281 // Configure world button
283 core::rect<s32> rect(0, 0, world_button_w, 30);
284 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*2,
285 world_sel_y+world_sel_h+0);
286 Environment->addButton(rect, this, GUI_ID_CONFIGURE_WORLD_BUTTON,
287 wgettext("Configure"));
291 /*core::rect<s32> rect(0, 0, 120, 30);
292 rect += m_topleft_client + v2s32(m_size_client.X-120-30,
293 m_size_client.Y-30-20-30-5);*/
294 /*core::rect<s32> rect(0, 0, world_button_w, 30);
295 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*3,
296 world_sel_y+world_sel_h+0);*/
298 core::rect<s32> rect(0, 0, bw, 30);
299 rect += m_topleft_client + v2s32(world_sel_x+world_sel_w-bw,
300 world_sel_y+world_sel_h+30+bs);
301 Environment->addButton(rect, this,
302 GUI_ID_JOIN_GAME_BUTTON, wgettext("Play"));
309 core::rect<s32> rect(0, 0, option_w, 30);
310 rect += m_topleft_client + v2s32(option_x, option_y+20*0);
311 Environment->addCheckBox(m_data->creative_mode, rect, this,
312 GUI_ID_CREATIVE_CB, wgettext("Creative Mode"));
315 core::rect<s32> rect(0, 0, option_w, 30);
316 rect += m_topleft_client + v2s32(option_x, option_y+20*1);
317 Environment->addCheckBox(m_data->enable_damage, rect, this,
318 GUI_ID_DAMAGE_CB, wgettext("Enable Damage"));
322 else if(m_data->selected_tab == TAB_MULTIPLAYER)
327 core::rect<s32> rect(0, 0, 20, 125);
328 rect += m_topleft_client + v2s32(15, 80);
329 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
330 //gui::IGUIStaticText *t =
331 Environment->addStaticText(text, rect, false, true, this, -1);
332 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
334 // Nickname + password
336 core::rect<s32> rect(0, 0, 110, 20);
337 rect += m_topleft_client + v2s32(35+30, 50+6);
338 Environment->addStaticText(wgettext("Name/Password"),
339 rect, false, true, this, -1);
343 core::rect<s32> rect(0, 0, 230, 30);
344 rect += m_topleft_client + v2s32(160+30, 50);
345 gui::IGUIElement *e =
346 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
347 if(m_data->name == L"")
348 Environment->setFocus(e);
351 core::rect<s32> rect(0, 0, 120, 30);
352 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50);
353 gui::IGUIEditBox *e =
354 Environment->addEditBox(L"", rect, true, this, 264);
355 e->setPasswordBox(true);
356 if(m_data->name != L"" && m_data->address != L"")
357 Environment->setFocus(e);
363 core::rect<s32> rect(0, 0, 110, 20);
364 rect += m_topleft_client + v2s32(35+30, 100+6);
365 Environment->addStaticText(wgettext("Address/Port"),
366 rect, false, true, this, -1);
370 core::rect<s32> rect(0, 0, 230, 30);
371 rect += m_topleft_client + v2s32(160+30, 100);
372 gui::IGUIElement *e =
373 Environment->addEditBox(m_data->address.c_str(), rect, true,
374 this, GUI_ID_ADDRESS_INPUT);
375 if(m_data->name != L"" && m_data->address == L"")
376 Environment->setFocus(e);
379 core::rect<s32> rect(0, 0, 120, 30);
380 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100);
381 Environment->addEditBox(m_data->port.c_str(), rect, true,
382 this, GUI_ID_PORT_INPUT);
387 core::rect<s32> rect(0, 0, 180, 30);
388 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
389 m_size_client.Y-30-20);
390 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
391 wgettext("Start Game / Connect"));
395 else if(m_data->selected_tab == TAB_ADVANCED)
400 core::rect<s32> rect(0, 0, 20, 125);
401 rect += m_topleft_client + v2s32(15, 80);
402 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
403 //gui::IGUIStaticText *t =
404 Environment->addStaticText(text, rect, false, true, this, -1);
405 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
407 // Nickname + password
409 core::rect<s32> rect(0, 0, 110, 20);
410 rect += m_topleft_client + v2s32(35+30, 50+6);
411 Environment->addStaticText(wgettext("Name/Password"),
412 rect, false, true, this, -1);
416 core::rect<s32> rect(0, 0, 230, 30);
417 rect += m_topleft_client + v2s32(160+30, 50);
418 gui::IGUIElement *e =
419 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
420 if(m_data->name == L"")
421 Environment->setFocus(e);
424 core::rect<s32> rect(0, 0, 120, 30);
425 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50);
426 gui::IGUIEditBox *e =
427 Environment->addEditBox(L"", rect, true, this, 264);
428 e->setPasswordBox(true);
429 if(m_data->name != L"" && m_data->address != L"")
430 Environment->setFocus(e);
436 core::rect<s32> rect(0, 0, 110, 20);
437 rect += m_topleft_client + v2s32(35+30, 100+6);
438 Environment->addStaticText(wgettext("Address/Port"),
439 rect, false, true, this, -1);
443 core::rect<s32> rect(0, 0, 230, 30);
444 rect += m_topleft_client + v2s32(160+30, 100);
445 gui::IGUIElement *e =
446 Environment->addEditBox(m_data->address.c_str(), rect, true,
447 this, GUI_ID_ADDRESS_INPUT);
448 if(m_data->name != L"" && m_data->address == L"")
449 Environment->setFocus(e);
452 core::rect<s32> rect(0, 0, 120, 30);
453 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100);
454 Environment->addEditBox(m_data->port.c_str(), rect, true,
455 this, GUI_ID_PORT_INPUT);
459 core::rect<s32> rect(0, 0, 400, 20);
460 rect += m_topleft_client + v2s32(160+30, 100+35);
461 Environment->addStaticText(wgettext("Leave address blank to start a local server."),
462 rect, false, true, this, -1);
466 core::rect<s32> rect(0, 0, 180, 30);
467 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
468 m_size_client.Y-30-20);
469 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
470 wgettext("Start Game / Connect"));
477 core::rect<s32> rect(0, 0, 20, 125);
478 rect += m_topleft_server + v2s32(15, 15);
479 const wchar_t *text = L"S\nE\nR\nV\nE\nR";
480 //gui::IGUIStaticText *t =
481 Environment->addStaticText(text, rect, false, true, this, -1);
482 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
486 core::rect<s32> rect(0, 0, 250, 30);
487 rect += m_topleft_server + v2s32(30+20+250+20, 20);
488 Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB,
489 wgettext("Creative Mode"));
492 core::rect<s32> rect(0, 0, 250, 30);
493 rect += m_topleft_server + v2s32(30+20+250+20, 40);
494 Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
495 wgettext("Enable Damage"));
497 // Delete world button
499 core::rect<s32> rect(0, 0, 130, 30);
500 rect += m_topleft_server + v2s32(30+20+250+20, 90);
501 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
502 wgettext("Delete world"));
504 // Create world button
506 core::rect<s32> rect(0, 0, 130, 30);
507 rect += m_topleft_server + v2s32(30+20+250+20+140, 90);
508 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
509 wgettext("Create world"));
511 // World selection listbox
513 core::rect<s32> rect(0, 0, 250, 120);
514 rect += m_topleft_server + v2s32(30+20, 10);
515 gui::IGUIListBox *e = Environment->addListBox(rect, this,
516 GUI_ID_WORLD_LISTBOX);
517 e->setDrawBackground(true);
518 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
519 i != m_data->worlds.end(); i++){
520 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
522 e->setSelected(m_data->selected_world);
526 else if(m_data->selected_tab == TAB_SETTINGS)
529 core::rect<s32> rect(0, 0, 20, 300);
530 rect += m_topleft_client + v2s32(15, 50);
531 const wchar_t *text = L"S\nE\nT\nT\nI\nN\nG\nS";
532 //gui::IGUIStaticText *t =
533 Environment->addStaticText(text, rect, false, true, this, -1);
534 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
540 core::rect<s32> rect(0, 0, option_w, 30);
541 rect += m_topleft_client + v2s32(option_x, option_y);
542 Environment->addCheckBox(m_data->fancy_trees, rect, this,
543 GUI_ID_FANCYTREE_CB, wgettext("Fancy trees"));
546 core::rect<s32> rect(0, 0, option_w, 30);
547 rect += m_topleft_client + v2s32(option_x, option_y+20);
548 Environment->addCheckBox(m_data->smooth_lighting, rect, this,
549 GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting"));
552 core::rect<s32> rect(0, 0, option_w, 30);
553 rect += m_topleft_client + v2s32(option_x, option_y+20*2);
554 Environment->addCheckBox(m_data->clouds_3d, rect, this,
555 GUI_ID_3D_CLOUDS_CB, wgettext("3D Clouds"));
558 core::rect<s32> rect(0, 0, option_w, 30);
559 rect += m_topleft_client + v2s32(option_x, option_y+20*3);
560 Environment->addCheckBox(m_data->opaque_water, rect, this,
561 GUI_ID_OPAQUE_WATER_CB, wgettext("Opaque water"));
565 core::rect<s32> rect(0, 0, 120, 30);
566 /*rect += m_topleft_client + v2s32(m_size_client.X-120-30,
567 m_size_client.Y-30-20);*/
568 rect += m_topleft_client + v2s32(option_x, option_y+120);
569 Environment->addButton(rect, this,
570 GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys"));
574 else if(m_data->selected_tab == TAB_CREDITS)
578 core::rect<s32> rect(0, 0, 20, 200);
579 rect += m_topleft_client + v2s32(15, 60);
580 const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS";
581 //gui::IGUIStaticText *t =
582 Environment->addStaticText(text, rect, false, true, this, -1);
583 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
586 core::rect<s32> rect(0, 0, 620, 250);
587 rect += m_topleft_client + v2s32(150+14, 50+35);
588 Environment->addStaticText(narrow_to_wide(
589 "Minetest-c55 " VERSION_STRING "\n"
590 "http://c55.me/minetest/\n"
592 "by Perttu Ahola <celeron55@gmail.com>\n"
594 ).c_str(), rect, false, true, this, -1);
598 m_is_regenerating = false;
601 void GUIMainMenu::drawMenu()
603 gui::IGUISkin* skin = Environment->getSkin();
606 video::IVideoDriver* driver = Environment->getVideoDriver();
608 /*video::SColor bgcolor(140,0,0,0);
609 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
611 video::SColor bgcolor(140,0,0,0);
613 if(getTab() == TAB_SINGLEPLAYER)
616 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
617 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
618 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
621 else if(getTab() == TAB_MULTIPLAYER)
624 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
625 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
626 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
629 else if(getTab() == TAB_ADVANCED)
632 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
633 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
634 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
637 core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y);
638 rect += AbsoluteRect.UpperLeftCorner + m_topleft_server;
639 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
642 else if(getTab() == TAB_SETTINGS)
645 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
646 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
647 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
650 else if(getTab() == TAB_CREDITS)
653 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
654 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
655 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
657 video::ITexture *logotexture =
658 driver->getTexture(getTexturePath("menulogo.png").c_str());
661 v2s32 logosize(logotexture->getOriginalSize().Width,
662 logotexture->getOriginalSize().Height);
664 core::rect<s32> rect(0,0,logosize.X,logosize.Y);
665 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
666 rect += v2s32(150, 50);
667 driver->draw2DImage(logotexture, rect,
668 core::rect<s32>(core::position2d<s32>(0,0),
669 core::dimension2di(logotexture->getSize())),
674 gui::IGUIElement::draw();
677 void GUIMainMenu::readInput(MainMenuData *dst)
680 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
681 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
682 dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab();
684 if(dst->selected_tab == TAB_SINGLEPLAYER)
686 dst->simple_singleplayer_mode = true;
690 dst->simple_singleplayer_mode = false;
692 gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
694 dst->name = e->getText();
697 gui::IGUIElement *e = getElementFromId(264);
699 dst->password = e->getText();
702 gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
704 dst->address = e->getText();
707 gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
709 dst->port = e->getText();
713 gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
714 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
715 dst->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
718 gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
719 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
720 dst->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
723 gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
724 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
725 dst->fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
728 gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
729 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
730 dst->smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
733 gui::IGUIElement *e = getElementFromId(GUI_ID_3D_CLOUDS_CB);
734 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
735 dst->clouds_3d = ((gui::IGUICheckBox*)e)->isChecked();
738 gui::IGUIElement *e = getElementFromId(GUI_ID_OPAQUE_WATER_CB);
739 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
740 dst->opaque_water = ((gui::IGUICheckBox*)e)->isChecked();
744 gui::IGUIElement *e = getElementFromId(GUI_ID_WORLD_LISTBOX);
745 if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX)
746 dst->selected_world = ((gui::IGUIListBox*)e)->getSelected();
750 void GUIMainMenu::acceptInput()
756 bool GUIMainMenu::OnEvent(const SEvent& event)
758 if(event.EventType==EET_KEY_INPUT_EVENT)
760 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
762 m_gamecallback->exitToOS();
766 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
773 if(event.EventType==EET_GUI_EVENT)
775 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
778 if(!canTakeFocus(event.GUIEvent.Element))
780 dstream<<"GUIMainMenu: Not allowing focus change."
782 // Returning true disables focus change
786 if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED)
788 if(!m_is_regenerating)
789 regenerateGui(m_screensize_old);
792 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
794 switch(event.GUIEvent.Caller->getID())
796 case GUI_ID_JOIN_GAME_BUTTON: {
799 if(cur.address == L"" && getTab() == TAB_MULTIPLAYER){
800 (new GUIMessageMenu(env, parent, -1, menumgr,
801 wgettext("Address required."))
809 case GUI_ID_CHANGE_KEYS_BUTTON: {
810 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
814 case GUI_ID_DELETE_WORLD_BUTTON: {
817 if(cur.selected_world == -1){
818 (new GUIMessageMenu(env, parent, -1, menumgr,
819 wgettext("Cannot delete world: Nothing selected"))
822 WorldSpec spec = m_data->worlds[cur.selected_world];
823 ConfirmDestDeleteWorld *dest = new
824 ConfirmDestDeleteWorld(spec, this);
825 (new GUIConfirmMenu(env, parent, -1, menumgr, dest,
826 (std::wstring(wgettext("Delete world "))
827 +L"\""+narrow_to_wide(spec.name)+L"\"?").c_str()
832 case GUI_ID_CREATE_WORLD_BUTTON: {
833 std::vector<SubgameSpec> games = getAvailableGames();
834 if(games.size() == 0){
835 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
837 wgettext("Cannot create world: No games found"));
840 CreateWorldDest *dest = new CreateWorldDestMainMenu(this);
841 GUICreateWorld *menu = new GUICreateWorld(env, parent, -1,
842 menumgr, dest, games);
847 case GUI_ID_CONFIGURE_WORLD_BUTTON: {
848 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
850 wgettext("Nothing here"));
856 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
858 switch(event.GUIEvent.Caller->getID())
860 case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
866 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN)
868 switch(event.GUIEvent.Caller->getID())
870 case GUI_ID_WORLD_LISTBOX:
872 m_data->address = L""; // Force local game
879 return Parent ? Parent->OnEvent(event) : false;
882 void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
887 m_data->create_world_name = name;
888 m_data->create_world_gameid = gameid;
892 void GUIMainMenu::deleteWorld(WorldSpec spec)
897 m_data->delete_world_spec = spec;
901 int GUIMainMenu::getTab()
903 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
904 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
905 return ((gui::IGUITabControl*)e)->getActiveTab();
906 return TAB_SINGLEPLAYER; // Default