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,
99 GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
100 gui::IGUIElement* parent, s32 id,
101 IMenuManager *menumgr,
103 IGameCallback *gamecallback
105 GUIModalMenu(env, parent, id, menumgr),
108 m_gamecallback(gamecallback),
109 m_is_regenerating(false)
113 this->parent = parent;
115 this->menumgr = menumgr;
118 GUIMainMenu::~GUIMainMenu()
123 void GUIMainMenu::removeChildren()
125 const core::list<gui::IGUIElement*> &children = getChildren();
126 core::list<gui::IGUIElement*> children_copy;
127 for(core::list<gui::IGUIElement*>::ConstIterator
128 i = children.begin(); i != children.end(); i++)
130 children_copy.push_back(*i);
132 for(core::list<gui::IGUIElement*>::Iterator
133 i = children_copy.begin();
134 i != children_copy.end(); i++)
140 void GUIMainMenu::regenerateGui(v2u32 screensize)
142 m_is_regenerating = true;
144 Read stuff from elements into m_data
148 int active_tab = getTab();
156 Calculate new sizes and positions
159 v2s32 size(screensize.X, screensize.Y);
161 core::rect<s32> rect(
162 screensize.X/2 - size.X/2,
163 screensize.Y/2 - size.Y/2,
164 screensize.X/2 + size.X/2,
165 screensize.Y/2 + size.Y/2
169 recalculateAbsolutePosition(false);
171 //v2s32 size = rect.getSize();
180 if(active_tab != TAB_CREDITS)
182 core::rect<s32> rect(0, 0, size.X, 40);
184 Environment->addStaticText(narrow_to_wide(
185 "Minetest-c55 " VERSION_STRING).c_str(),
186 rect, false, true, this, -1);
189 //v2s32 center(size.X/2, size.Y/2);
190 v2s32 c800(size.X/2-400, size.Y/2-300);
192 m_topleft_client = c800 + v2s32(90, 70+50+30);
193 m_size_client = v2s32(620, 270);
195 m_topleft_server = c800 + v2s32(90, 70+30+50+290);
196 m_size_server = v2s32(620, 140);
198 if(active_tab == TAB_ADVANCED)
200 m_topleft_client = c800 + v2s32(90, 20+50+30);
201 m_size_client = v2s32(620, 270);
203 m_topleft_server = c800 + v2s32(90, 20+30+50+290);
204 m_size_server = v2s32(620, 140);
210 core::rect<s32> rect(0, 0, m_size_client.X, 30);
211 rect += m_topleft_client + v2s32(0, -30);
212 gui::IGUITabControl *e = Environment->addTabControl(
213 rect, this, true, true, GUI_ID_TAB_CONTROL);
214 e->addTab(L"Singleplayer");
215 e->addTab(L"Multiplayer");
216 e->addTab(L"Advanced");
217 e->addTab(L"Credits");
218 e->setActiveTab(active_tab);
222 if(active_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);
266 // Delete world button
268 core::rect<s32> rect(0, 0, world_button_w, 30);
269 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y+world_sel_h+0);
270 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
273 // Create world button
275 core::rect<s32> rect(0, 0, world_button_w, 30);
276 rect += m_topleft_client + v2s32(world_sel_x+world_button_w+bs, world_sel_y+world_sel_h+0);
277 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
280 // Configure world button
282 core::rect<s32> rect(0, 0, world_button_w, 30);
283 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*2,
284 world_sel_y+world_sel_h+0);
285 Environment->addButton(rect, this, GUI_ID_CONFIGURE_WORLD_BUTTON,
286 wgettext("Configure"));
290 /*core::rect<s32> rect(0, 0, 120, 30);
291 rect += m_topleft_client + v2s32(m_size_client.X-120-30,
292 m_size_client.Y-30-20-30-5);*/
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(world_sel_x+world_sel_w-bw,
299 world_sel_y+world_sel_h+30+bs);
300 Environment->addButton(rect, this,
301 GUI_ID_JOIN_GAME_BUTTON, wgettext("Play"));
304 //s32 option_x = 450;
308 core::rect<s32> rect(0, 0, 250, 30);
309 rect += m_topleft_client + v2s32(option_x, option_y);
310 Environment->addCheckBox(m_data->fancy_trees, rect, this,
311 GUI_ID_FANCYTREE_CB, wgettext("Fancy trees"));
314 core::rect<s32> rect(0, 0, 250, 30);
315 rect += m_topleft_client + v2s32(option_x, option_y+20);
316 Environment->addCheckBox(m_data->smooth_lighting, rect, this,
317 GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting"));
320 core::rect<s32> rect(0, 0, 250, 30);
321 rect += m_topleft_client + v2s32(option_x, option_y+20*2);
322 Environment->addCheckBox(m_data->clouds_3d, rect, this,
323 GUI_ID_3D_CLOUDS_CB, wgettext("3D Clouds"));
326 core::rect<s32> rect(0, 0, 250, 30);
327 rect += m_topleft_client + v2s32(option_x, option_y+20*3);
328 Environment->addCheckBox(m_data->opaque_water, rect, this,
329 GUI_ID_OPAQUE_WATER_CB, wgettext("Opaque water"));
332 core::rect<s32> rect(0, 0, 250, 30);
333 rect += m_topleft_client + v2s32(option_x, option_y+20*4);
334 Environment->addCheckBox(m_data->creative_mode, rect, this,
335 GUI_ID_CREATIVE_CB, wgettext("Creative Mode"));
338 core::rect<s32> rect(0, 0, 250, 30);
339 rect += m_topleft_client + v2s32(option_x, option_y+20*5);
340 Environment->addCheckBox(m_data->enable_damage, rect, this,
341 GUI_ID_DAMAGE_CB, wgettext("Enable Damage"));
345 core::rect<s32> rect(0, 0, 120, 30);
346 /*rect += m_topleft_client + v2s32(m_size_client.X-120-30,
347 m_size_client.Y-30-20);*/
348 rect += m_topleft_client + v2s32(option_x, option_y+20*6+20);
349 Environment->addButton(rect, this,
350 GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys"));
354 else if(active_tab == TAB_MULTIPLAYER)
359 core::rect<s32> rect(0, 0, 20, 125);
360 rect += m_topleft_client + v2s32(15, 80);
361 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
362 //gui::IGUIStaticText *t =
363 Environment->addStaticText(text, rect, false, true, this, -1);
364 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
366 // Nickname + password
368 core::rect<s32> rect(0, 0, 110, 20);
369 rect += m_topleft_client + v2s32(35+30, 50+6);
370 Environment->addStaticText(wgettext("Name/Password"),
371 rect, false, true, this, -1);
375 core::rect<s32> rect(0, 0, 230, 30);
376 rect += m_topleft_client + v2s32(160+30, 50);
377 gui::IGUIElement *e =
378 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
379 if(m_data->name == L"")
380 Environment->setFocus(e);
383 core::rect<s32> rect(0, 0, 120, 30);
384 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50);
385 gui::IGUIEditBox *e =
386 Environment->addEditBox(L"", rect, true, this, 264);
387 e->setPasswordBox(true);
388 if(m_data->name != L"" && m_data->address != L"")
389 Environment->setFocus(e);
395 core::rect<s32> rect(0, 0, 110, 20);
396 rect += m_topleft_client + v2s32(35+30, 100+6);
397 Environment->addStaticText(wgettext("Address/Port"),
398 rect, false, true, this, -1);
402 core::rect<s32> rect(0, 0, 230, 30);
403 rect += m_topleft_client + v2s32(160+30, 100);
404 gui::IGUIElement *e =
405 Environment->addEditBox(m_data->address.c_str(), rect, true,
406 this, GUI_ID_ADDRESS_INPUT);
407 if(m_data->name != L"" && m_data->address == L"")
408 Environment->setFocus(e);
411 core::rect<s32> rect(0, 0, 120, 30);
412 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100);
413 Environment->addEditBox(m_data->port.c_str(), rect, true,
414 this, GUI_ID_PORT_INPUT);
418 core::rect<s32> rect(0, 0, 250, 30);
419 rect += m_topleft_client + v2s32(35+30, 150);
420 Environment->addCheckBox(m_data->fancy_trees, rect, this, GUI_ID_FANCYTREE_CB,
421 wgettext("Fancy trees"));
424 core::rect<s32> rect(0, 0, 250, 30);
425 rect += m_topleft_client + v2s32(35+30, 150+20);
426 Environment->addCheckBox(m_data->smooth_lighting, rect, this, GUI_ID_SMOOTH_LIGHTING_CB,
427 wgettext("Smooth Lighting"));
430 core::rect<s32> rect(0, 0, 250, 30);
431 rect += m_topleft_client + v2s32(35+30, 150+40);
432 Environment->addCheckBox(m_data->clouds_3d, rect, this, GUI_ID_3D_CLOUDS_CB,
433 wgettext("3D Clouds"));
436 core::rect<s32> rect(0, 0, 250, 30);
437 rect += m_topleft_client + v2s32(35+30, 150+60);
438 Environment->addCheckBox(m_data->opaque_water, rect, this, GUI_ID_OPAQUE_WATER_CB,
439 wgettext("Opaque water"));
443 core::rect<s32> rect(0, 0, 120, 30);
444 rect += m_topleft_client + v2s32(m_size_client.X-180-30-120-20,
445 m_size_client.Y-30-20);
446 Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON,
447 wgettext("Change keys"));
451 core::rect<s32> rect(0, 0, 180, 30);
452 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
453 m_size_client.Y-30-20);
454 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
455 wgettext("Start Game / Connect"));
459 else if(active_tab == TAB_ADVANCED)
464 core::rect<s32> rect(0, 0, 20, 125);
465 rect += m_topleft_client + v2s32(15, 80);
466 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
467 //gui::IGUIStaticText *t =
468 Environment->addStaticText(text, rect, false, true, this, -1);
469 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
471 // Nickname + password
473 core::rect<s32> rect(0, 0, 110, 20);
474 rect += m_topleft_client + v2s32(35+30, 50+6);
475 Environment->addStaticText(wgettext("Name/Password"),
476 rect, false, true, this, -1);
480 core::rect<s32> rect(0, 0, 230, 30);
481 rect += m_topleft_client + v2s32(160+30, 50);
482 gui::IGUIElement *e =
483 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
484 if(m_data->name == L"")
485 Environment->setFocus(e);
488 core::rect<s32> rect(0, 0, 120, 30);
489 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50);
490 gui::IGUIEditBox *e =
491 Environment->addEditBox(L"", rect, true, this, 264);
492 e->setPasswordBox(true);
493 if(m_data->name != L"" && m_data->address != L"")
494 Environment->setFocus(e);
500 core::rect<s32> rect(0, 0, 110, 20);
501 rect += m_topleft_client + v2s32(35+30, 100+6);
502 Environment->addStaticText(wgettext("Address/Port"),
503 rect, false, true, this, -1);
507 core::rect<s32> rect(0, 0, 230, 30);
508 rect += m_topleft_client + v2s32(160+30, 100);
509 gui::IGUIElement *e =
510 Environment->addEditBox(m_data->address.c_str(), rect, true,
511 this, GUI_ID_ADDRESS_INPUT);
512 if(m_data->name != L"" && m_data->address == L"")
513 Environment->setFocus(e);
516 core::rect<s32> rect(0, 0, 120, 30);
517 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100);
518 Environment->addEditBox(m_data->port.c_str(), rect, true,
519 this, GUI_ID_PORT_INPUT);
523 core::rect<s32> rect(0, 0, 400, 20);
524 rect += m_topleft_client + v2s32(160+30, 100+35);
525 Environment->addStaticText(wgettext("Leave address blank to start a local server."),
526 rect, false, true, this, -1);
529 core::rect<s32> rect(0, 0, 250, 30);
530 rect += m_topleft_client + v2s32(35+30, 150);
531 Environment->addCheckBox(m_data->fancy_trees, rect, this, GUI_ID_FANCYTREE_CB,
532 wgettext("Fancy trees"));
535 core::rect<s32> rect(0, 0, 250, 30);
536 rect += m_topleft_client + v2s32(35+30, 150+20);
537 Environment->addCheckBox(m_data->smooth_lighting, rect, this, GUI_ID_SMOOTH_LIGHTING_CB,
538 wgettext("Smooth Lighting"));
541 core::rect<s32> rect(0, 0, 250, 30);
542 rect += m_topleft_client + v2s32(35+30, 150+40);
543 Environment->addCheckBox(m_data->clouds_3d, rect, this, GUI_ID_3D_CLOUDS_CB,
544 wgettext("3D Clouds"));
547 core::rect<s32> rect(0, 0, 250, 30);
548 rect += m_topleft_client + v2s32(35+30, 150+60);
549 Environment->addCheckBox(m_data->opaque_water, rect, this, GUI_ID_OPAQUE_WATER_CB,
550 wgettext("Opaque water"));
554 core::rect<s32> rect(0, 0, 120, 30);
555 rect += m_topleft_client + v2s32(m_size_client.X-180-30-120-20,
556 m_size_client.Y-30-20);
557 Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON,
558 wgettext("Change keys"));
562 core::rect<s32> rect(0, 0, 180, 30);
563 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
564 m_size_client.Y-30-20);
565 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
566 wgettext("Start Game / Connect"));
573 core::rect<s32> rect(0, 0, 20, 125);
574 rect += m_topleft_server + v2s32(15, 15);
575 const wchar_t *text = L"S\nE\nR\nV\nE\nR";
576 //gui::IGUIStaticText *t =
577 Environment->addStaticText(text, rect, false, true, this, -1);
578 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
582 core::rect<s32> rect(0, 0, 250, 30);
583 rect += m_topleft_server + v2s32(30+20+250+20, 20);
584 Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB,
585 wgettext("Creative Mode"));
588 core::rect<s32> rect(0, 0, 250, 30);
589 rect += m_topleft_server + v2s32(30+20+250+20, 40);
590 Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
591 wgettext("Enable Damage"));
593 // Delete world button
595 core::rect<s32> rect(0, 0, 130, 30);
596 rect += m_topleft_server + v2s32(30+20+250+20, 90);
597 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
598 wgettext("Delete world"));
600 // Create world button
602 core::rect<s32> rect(0, 0, 130, 30);
603 rect += m_topleft_server + v2s32(30+20+250+20+140, 90);
604 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
605 wgettext("Create world"));
607 // World selection listbox
609 core::rect<s32> rect(0, 0, 250, 120);
610 rect += m_topleft_server + v2s32(30+20, 10);
611 gui::IGUIListBox *e = Environment->addListBox(rect, this,
612 GUI_ID_WORLD_LISTBOX);
613 e->setDrawBackground(true);
614 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
615 i != m_data->worlds.end(); i++){
616 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
618 e->setSelected(m_data->selected_world);
622 else if(active_tab == TAB_CREDITS)
626 core::rect<s32> rect(0, 0, 20, 200);
627 rect += m_topleft_client + v2s32(15, 60);
628 const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS";
629 //gui::IGUIStaticText *t =
630 Environment->addStaticText(text, rect, false, true, this, -1);
631 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
634 core::rect<s32> rect(0, 0, 620, 250);
635 rect += m_topleft_client + v2s32(150+14, 50+35);
636 Environment->addStaticText(narrow_to_wide(
637 "Minetest-c55 " VERSION_STRING "\n"
638 "http://c55.me/minetest/\n"
640 "by Perttu Ahola <celeron55@gmail.com>\n"
642 ).c_str(), rect, false, true, this, -1);
646 m_is_regenerating = false;
649 void GUIMainMenu::drawMenu()
651 gui::IGUISkin* skin = Environment->getSkin();
654 video::IVideoDriver* driver = Environment->getVideoDriver();
656 /*video::SColor bgcolor(140,0,0,0);
657 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
659 video::SColor bgcolor(140,0,0,0);
661 if(getTab() == TAB_SINGLEPLAYER)
664 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
665 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
666 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
669 else if(getTab() == TAB_MULTIPLAYER)
672 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
673 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
674 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
677 else if(getTab() == TAB_ADVANCED)
680 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
681 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
682 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
685 core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y);
686 rect += AbsoluteRect.UpperLeftCorner + m_topleft_server;
687 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
690 else if(getTab() == TAB_CREDITS)
693 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
694 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
695 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
697 video::ITexture *logotexture =
698 driver->getTexture(getTexturePath("menulogo.png").c_str());
701 v2s32 logosize(logotexture->getOriginalSize().Width,
702 logotexture->getOriginalSize().Height);
704 core::rect<s32> rect(0,0,logosize.X,logosize.Y);
705 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
706 rect += v2s32(150, 50);
707 driver->draw2DImage(logotexture, rect,
708 core::rect<s32>(core::position2d<s32>(0,0),
709 core::dimension2di(logotexture->getSize())),
714 gui::IGUIElement::draw();
717 void GUIMainMenu::readInput(MainMenuData *dst)
719 if(getTab() == TAB_SINGLEPLAYER)
721 dst->name = L"singleplayer";
729 gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
731 dst->name = e->getText();
734 gui::IGUIElement *e = getElementFromId(264);
736 dst->password = e->getText();
739 gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
741 dst->address = e->getText();
744 gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
746 dst->port = e->getText();
750 gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
751 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
752 dst->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
755 gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
756 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
757 dst->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
760 gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
761 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
762 dst->fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
765 gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
766 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
767 dst->smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
770 gui::IGUIElement *e = getElementFromId(GUI_ID_3D_CLOUDS_CB);
771 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
772 dst->clouds_3d = ((gui::IGUICheckBox*)e)->isChecked();
775 gui::IGUIElement *e = getElementFromId(GUI_ID_OPAQUE_WATER_CB);
776 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
777 dst->opaque_water = ((gui::IGUICheckBox*)e)->isChecked();
781 gui::IGUIElement *e = getElementFromId(GUI_ID_WORLD_LISTBOX);
782 if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX)
783 dst->selected_world = ((gui::IGUIListBox*)e)->getSelected();
787 void GUIMainMenu::acceptInput()
793 bool GUIMainMenu::OnEvent(const SEvent& event)
795 if(event.EventType==EET_KEY_INPUT_EVENT)
797 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
799 m_gamecallback->exitToOS();
803 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
810 if(event.EventType==EET_GUI_EVENT)
812 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
815 if(!canTakeFocus(event.GUIEvent.Element))
817 dstream<<"GUIMainMenu: Not allowing focus change."
819 // Returning true disables focus change
823 if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED)
825 if(!m_is_regenerating)
826 regenerateGui(m_screensize_old);
829 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
831 switch(event.GUIEvent.Caller->getID())
833 case GUI_ID_JOIN_GAME_BUTTON: {
836 if(cur.address == L"" && getTab() == TAB_MULTIPLAYER){
837 (new GUIMessageMenu(env, parent, -1, menumgr,
838 wgettext("Address required."))
846 case GUI_ID_CHANGE_KEYS_BUTTON: {
847 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
851 case GUI_ID_DELETE_WORLD_BUTTON: {
854 if(cur.selected_world == -1){
855 (new GUIMessageMenu(env, parent, -1, menumgr,
856 wgettext("Cannot delete world: Nothing selected"))
859 WorldSpec spec = m_data->worlds[cur.selected_world];
860 ConfirmDestDeleteWorld *dest = new
861 ConfirmDestDeleteWorld(spec, this);
862 (new GUIConfirmMenu(env, parent, -1, menumgr, dest,
863 (std::wstring(wgettext("Delete world "))
864 +L"\""+narrow_to_wide(spec.name)+L"\"?").c_str()
869 case GUI_ID_CREATE_WORLD_BUTTON: {
870 std::vector<SubgameSpec> games = getAvailableGames();
871 if(games.size() == 0){
872 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
874 wgettext("Cannot create world: No games found"));
877 CreateWorldDest *dest = new CreateWorldDestMainMenu(this);
878 GUICreateWorld *menu = new GUICreateWorld(env, parent, -1,
879 menumgr, dest, games);
884 case GUI_ID_CONFIGURE_WORLD_BUTTON: {
885 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
887 wgettext("Nothing here"));
893 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
895 switch(event.GUIEvent.Caller->getID())
897 case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
903 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN)
905 switch(event.GUIEvent.Caller->getID())
907 case GUI_ID_WORLD_LISTBOX:
909 m_data->address = L""; // Force local game
916 return Parent ? Parent->OnEvent(event) : false;
919 void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
924 m_data->create_world_name = name;
925 m_data->create_world_gameid = gameid;
929 void GUIMainMenu::deleteWorld(WorldSpec spec)
934 m_data->delete_world_spec = spec;
938 int GUIMainMenu::getTab()
940 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
941 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
942 return ((gui::IGUITabControl*)e)->getActiveTab();
943 //return TAB_ADVANCED; // Default
944 return TAB_SINGLEPLAYER; // Default