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
154 Calculate new sizes and positions
157 v2s32 size(screensize.X, screensize.Y);
159 core::rect<s32> rect(
160 screensize.X/2 - size.X/2,
161 screensize.Y/2 - size.Y/2,
162 screensize.X/2 + size.X/2,
163 screensize.Y/2 + size.Y/2
167 recalculateAbsolutePosition(false);
169 //v2s32 size = rect.getSize();
178 if(m_data->selected_tab != TAB_CREDITS)
180 core::rect<s32> rect(0, 0, size.X, 40);
182 Environment->addStaticText(narrow_to_wide(
183 "Minetest-c55 " VERSION_STRING).c_str(),
184 rect, false, true, this, -1);
187 //v2s32 center(size.X/2, size.Y/2);
188 v2s32 c800(size.X/2-400, size.Y/2-300);
190 m_topleft_client = c800 + v2s32(90, 70+50+30);
191 m_size_client = v2s32(620, 270);
193 m_topleft_server = c800 + v2s32(90, 70+30+50+290);
194 m_size_server = v2s32(620, 140);
196 if(m_data->selected_tab == TAB_ADVANCED)
198 m_topleft_client = c800 + v2s32(90, 20+50+30);
199 m_size_client = v2s32(620, 270);
201 m_topleft_server = c800 + v2s32(90, 20+30+50+290);
202 m_size_server = v2s32(620, 140);
208 core::rect<s32> rect(0, 0, m_size_client.X, 30);
209 rect += m_topleft_client + v2s32(0, -30);
210 gui::IGUITabControl *e = Environment->addTabControl(
211 rect, this, true, true, GUI_ID_TAB_CONTROL);
212 e->addTab(L"Singleplayer");
213 e->addTab(L"Multiplayer");
214 e->addTab(L"Advanced");
215 e->addTab(L"Credits");
216 e->setActiveTab(m_data->selected_tab);
220 if(m_data->selected_tab == TAB_SINGLEPLAYER)
224 /*core::rect<s32> rect(0, 0, 20, 125);
225 rect += m_topleft_client + v2s32(15, 80);
226 const wchar_t *text = L"H\nY\nB\nR\nI\nD";*/
227 core::rect<s32> rect(0, 0, 20, 300);
228 rect += m_topleft_client + v2s32(15, 15);
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_UPPERLEFT);
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, 120, 30);
290 rect += m_topleft_client + v2s32(m_size_client.X-120-30,
291 m_size_client.Y-30-20-30-5);*/
292 /*core::rect<s32> rect(0, 0, world_button_w, 30);
293 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*3,
294 world_sel_y+world_sel_h+0);*/
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"));
307 core::rect<s32> rect(0, 0, option_w, 30);
308 rect += m_topleft_client + v2s32(option_x, option_y);
309 Environment->addCheckBox(m_data->fancy_trees, rect, this,
310 GUI_ID_FANCYTREE_CB, wgettext("Fancy trees"));
313 core::rect<s32> rect(0, 0, option_w, 30);
314 rect += m_topleft_client + v2s32(option_x, option_y+20);
315 Environment->addCheckBox(m_data->smooth_lighting, rect, this,
316 GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting"));
319 core::rect<s32> rect(0, 0, option_w, 30);
320 rect += m_topleft_client + v2s32(option_x, option_y+20*2);
321 Environment->addCheckBox(m_data->clouds_3d, rect, this,
322 GUI_ID_3D_CLOUDS_CB, wgettext("3D Clouds"));
325 core::rect<s32> rect(0, 0, option_w, 30);
326 rect += m_topleft_client + v2s32(option_x, option_y+20*3);
327 Environment->addCheckBox(m_data->opaque_water, rect, this,
328 GUI_ID_OPAQUE_WATER_CB, wgettext("Opaque water"));
331 core::rect<s32> rect(0, 0, option_w, 30);
332 rect += m_topleft_client + v2s32(option_x, option_y+20*4);
333 Environment->addCheckBox(m_data->creative_mode, rect, this,
334 GUI_ID_CREATIVE_CB, wgettext("Creative Mode"));
337 core::rect<s32> rect(0, 0, option_w, 30);
338 rect += m_topleft_client + v2s32(option_x, option_y+20*5);
339 Environment->addCheckBox(m_data->enable_damage, rect, this,
340 GUI_ID_DAMAGE_CB, wgettext("Enable Damage"));
344 core::rect<s32> rect(0, 0, 120, 30);
345 /*rect += m_topleft_client + v2s32(m_size_client.X-120-30,
346 m_size_client.Y-30-20);*/
347 rect += m_topleft_client + v2s32(option_x, option_y+20*6+20);
348 Environment->addButton(rect, this,
349 GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys"));
353 else if(m_data->selected_tab == TAB_MULTIPLAYER)
358 core::rect<s32> rect(0, 0, 20, 125);
359 rect += m_topleft_client + v2s32(15, 80);
360 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
361 //gui::IGUIStaticText *t =
362 Environment->addStaticText(text, rect, false, true, this, -1);
363 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
365 // Nickname + password
367 core::rect<s32> rect(0, 0, 110, 20);
368 rect += m_topleft_client + v2s32(35+30, 50+6);
369 Environment->addStaticText(wgettext("Name/Password"),
370 rect, false, true, this, -1);
374 core::rect<s32> rect(0, 0, 230, 30);
375 rect += m_topleft_client + v2s32(160+30, 50);
376 gui::IGUIElement *e =
377 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
378 if(m_data->name == 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, 50);
384 gui::IGUIEditBox *e =
385 Environment->addEditBox(L"", rect, true, this, 264);
386 e->setPasswordBox(true);
387 if(m_data->name != L"" && m_data->address != L"")
388 Environment->setFocus(e);
394 core::rect<s32> rect(0, 0, 110, 20);
395 rect += m_topleft_client + v2s32(35+30, 100+6);
396 Environment->addStaticText(wgettext("Address/Port"),
397 rect, false, true, this, -1);
401 core::rect<s32> rect(0, 0, 230, 30);
402 rect += m_topleft_client + v2s32(160+30, 100);
403 gui::IGUIElement *e =
404 Environment->addEditBox(m_data->address.c_str(), rect, true,
405 this, GUI_ID_ADDRESS_INPUT);
406 if(m_data->name != L"" && m_data->address == L"")
407 Environment->setFocus(e);
410 core::rect<s32> rect(0, 0, 120, 30);
411 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100);
412 Environment->addEditBox(m_data->port.c_str(), rect, true,
413 this, GUI_ID_PORT_INPUT);
417 core::rect<s32> rect(0, 0, 250, 30);
418 rect += m_topleft_client + v2s32(35+30, 150);
419 Environment->addCheckBox(m_data->fancy_trees, rect, this, GUI_ID_FANCYTREE_CB,
420 wgettext("Fancy trees"));
423 core::rect<s32> rect(0, 0, 250, 30);
424 rect += m_topleft_client + v2s32(35+30, 150+20);
425 Environment->addCheckBox(m_data->smooth_lighting, rect, this, GUI_ID_SMOOTH_LIGHTING_CB,
426 wgettext("Smooth Lighting"));
429 core::rect<s32> rect(0, 0, 250, 30);
430 rect += m_topleft_client + v2s32(35+30, 150+40);
431 Environment->addCheckBox(m_data->clouds_3d, rect, this, GUI_ID_3D_CLOUDS_CB,
432 wgettext("3D Clouds"));
435 core::rect<s32> rect(0, 0, 250, 30);
436 rect += m_topleft_client + v2s32(35+30, 150+60);
437 Environment->addCheckBox(m_data->opaque_water, rect, this, GUI_ID_OPAQUE_WATER_CB,
438 wgettext("Opaque water"));
442 core::rect<s32> rect(0, 0, 120, 30);
443 rect += m_topleft_client + v2s32(m_size_client.X-180-30-120-20,
444 m_size_client.Y-30-20);
445 Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON,
446 wgettext("Change keys"));
450 core::rect<s32> rect(0, 0, 180, 30);
451 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
452 m_size_client.Y-30-20);
453 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
454 wgettext("Start Game / Connect"));
458 else if(m_data->selected_tab == TAB_ADVANCED)
463 core::rect<s32> rect(0, 0, 20, 125);
464 rect += m_topleft_client + v2s32(15, 80);
465 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
466 //gui::IGUIStaticText *t =
467 Environment->addStaticText(text, rect, false, true, this, -1);
468 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
470 // Nickname + password
472 core::rect<s32> rect(0, 0, 110, 20);
473 rect += m_topleft_client + v2s32(35+30, 50+6);
474 Environment->addStaticText(wgettext("Name/Password"),
475 rect, false, true, this, -1);
479 core::rect<s32> rect(0, 0, 230, 30);
480 rect += m_topleft_client + v2s32(160+30, 50);
481 gui::IGUIElement *e =
482 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
483 if(m_data->name == L"")
484 Environment->setFocus(e);
487 core::rect<s32> rect(0, 0, 120, 30);
488 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50);
489 gui::IGUIEditBox *e =
490 Environment->addEditBox(L"", rect, true, this, 264);
491 e->setPasswordBox(true);
492 if(m_data->name != L"" && m_data->address != L"")
493 Environment->setFocus(e);
499 core::rect<s32> rect(0, 0, 110, 20);
500 rect += m_topleft_client + v2s32(35+30, 100+6);
501 Environment->addStaticText(wgettext("Address/Port"),
502 rect, false, true, this, -1);
506 core::rect<s32> rect(0, 0, 230, 30);
507 rect += m_topleft_client + v2s32(160+30, 100);
508 gui::IGUIElement *e =
509 Environment->addEditBox(m_data->address.c_str(), rect, true,
510 this, GUI_ID_ADDRESS_INPUT);
511 if(m_data->name != L"" && m_data->address == L"")
512 Environment->setFocus(e);
515 core::rect<s32> rect(0, 0, 120, 30);
516 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 100);
517 Environment->addEditBox(m_data->port.c_str(), rect, true,
518 this, GUI_ID_PORT_INPUT);
522 core::rect<s32> rect(0, 0, 400, 20);
523 rect += m_topleft_client + v2s32(160+30, 100+35);
524 Environment->addStaticText(wgettext("Leave address blank to start a local server."),
525 rect, false, true, this, -1);
528 core::rect<s32> rect(0, 0, 250, 30);
529 rect += m_topleft_client + v2s32(35+30, 150);
530 Environment->addCheckBox(m_data->fancy_trees, rect, this, GUI_ID_FANCYTREE_CB,
531 wgettext("Fancy trees"));
534 core::rect<s32> rect(0, 0, 250, 30);
535 rect += m_topleft_client + v2s32(35+30, 150+20);
536 Environment->addCheckBox(m_data->smooth_lighting, rect, this, GUI_ID_SMOOTH_LIGHTING_CB,
537 wgettext("Smooth Lighting"));
540 core::rect<s32> rect(0, 0, 250, 30);
541 rect += m_topleft_client + v2s32(35+30, 150+40);
542 Environment->addCheckBox(m_data->clouds_3d, rect, this, GUI_ID_3D_CLOUDS_CB,
543 wgettext("3D Clouds"));
546 core::rect<s32> rect(0, 0, 250, 30);
547 rect += m_topleft_client + v2s32(35+30, 150+60);
548 Environment->addCheckBox(m_data->opaque_water, rect, this, GUI_ID_OPAQUE_WATER_CB,
549 wgettext("Opaque water"));
553 core::rect<s32> rect(0, 0, 120, 30);
554 rect += m_topleft_client + v2s32(m_size_client.X-180-30-120-20,
555 m_size_client.Y-30-20);
556 Environment->addButton(rect, this, GUI_ID_CHANGE_KEYS_BUTTON,
557 wgettext("Change keys"));
561 core::rect<s32> rect(0, 0, 180, 30);
562 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
563 m_size_client.Y-30-20);
564 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
565 wgettext("Start Game / Connect"));
572 core::rect<s32> rect(0, 0, 20, 125);
573 rect += m_topleft_server + v2s32(15, 15);
574 const wchar_t *text = L"S\nE\nR\nV\nE\nR";
575 //gui::IGUIStaticText *t =
576 Environment->addStaticText(text, rect, false, true, this, -1);
577 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
581 core::rect<s32> rect(0, 0, 250, 30);
582 rect += m_topleft_server + v2s32(30+20+250+20, 20);
583 Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB,
584 wgettext("Creative Mode"));
587 core::rect<s32> rect(0, 0, 250, 30);
588 rect += m_topleft_server + v2s32(30+20+250+20, 40);
589 Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
590 wgettext("Enable Damage"));
592 // Delete world button
594 core::rect<s32> rect(0, 0, 130, 30);
595 rect += m_topleft_server + v2s32(30+20+250+20, 90);
596 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
597 wgettext("Delete world"));
599 // Create world button
601 core::rect<s32> rect(0, 0, 130, 30);
602 rect += m_topleft_server + v2s32(30+20+250+20+140, 90);
603 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
604 wgettext("Create world"));
606 // World selection listbox
608 core::rect<s32> rect(0, 0, 250, 120);
609 rect += m_topleft_server + v2s32(30+20, 10);
610 gui::IGUIListBox *e = Environment->addListBox(rect, this,
611 GUI_ID_WORLD_LISTBOX);
612 e->setDrawBackground(true);
613 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
614 i != m_data->worlds.end(); i++){
615 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
617 e->setSelected(m_data->selected_world);
621 else if(m_data->selected_tab == TAB_CREDITS)
625 core::rect<s32> rect(0, 0, 20, 200);
626 rect += m_topleft_client + v2s32(15, 60);
627 const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS";
628 //gui::IGUIStaticText *t =
629 Environment->addStaticText(text, rect, false, true, this, -1);
630 //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
633 core::rect<s32> rect(0, 0, 620, 250);
634 rect += m_topleft_client + v2s32(150+14, 50+35);
635 Environment->addStaticText(narrow_to_wide(
636 "Minetest-c55 " VERSION_STRING "\n"
637 "http://c55.me/minetest/\n"
639 "by Perttu Ahola <celeron55@gmail.com>\n"
641 ).c_str(), rect, false, true, this, -1);
645 m_is_regenerating = false;
648 void GUIMainMenu::drawMenu()
650 gui::IGUISkin* skin = Environment->getSkin();
653 video::IVideoDriver* driver = Environment->getVideoDriver();
655 /*video::SColor bgcolor(140,0,0,0);
656 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
658 video::SColor bgcolor(140,0,0,0);
660 if(getTab() == TAB_SINGLEPLAYER)
663 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
664 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
665 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
668 else if(getTab() == TAB_MULTIPLAYER)
671 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
672 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
673 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
676 else if(getTab() == TAB_ADVANCED)
679 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
680 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
681 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
684 core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y);
685 rect += AbsoluteRect.UpperLeftCorner + m_topleft_server;
686 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
689 else if(getTab() == TAB_CREDITS)
692 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
693 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
694 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
696 video::ITexture *logotexture =
697 driver->getTexture(getTexturePath("menulogo.png").c_str());
700 v2s32 logosize(logotexture->getOriginalSize().Width,
701 logotexture->getOriginalSize().Height);
703 core::rect<s32> rect(0,0,logosize.X,logosize.Y);
704 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
705 rect += v2s32(150, 50);
706 driver->draw2DImage(logotexture, rect,
707 core::rect<s32>(core::position2d<s32>(0,0),
708 core::dimension2di(logotexture->getSize())),
713 gui::IGUIElement::draw();
716 void GUIMainMenu::readInput(MainMenuData *dst)
719 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
720 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
721 dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab();
723 if(dst->selected_tab == TAB_SINGLEPLAYER)
725 dst->simple_singleplayer_mode = true;
729 dst->simple_singleplayer_mode = false;
731 gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
733 dst->name = e->getText();
736 gui::IGUIElement *e = getElementFromId(264);
738 dst->password = e->getText();
741 gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
743 dst->address = e->getText();
746 gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
748 dst->port = e->getText();
752 gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
753 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
754 dst->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
757 gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
758 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
759 dst->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
762 gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
763 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
764 dst->fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
767 gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
768 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
769 dst->smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
772 gui::IGUIElement *e = getElementFromId(GUI_ID_3D_CLOUDS_CB);
773 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
774 dst->clouds_3d = ((gui::IGUICheckBox*)e)->isChecked();
777 gui::IGUIElement *e = getElementFromId(GUI_ID_OPAQUE_WATER_CB);
778 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
779 dst->opaque_water = ((gui::IGUICheckBox*)e)->isChecked();
783 gui::IGUIElement *e = getElementFromId(GUI_ID_WORLD_LISTBOX);
784 if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX)
785 dst->selected_world = ((gui::IGUIListBox*)e)->getSelected();
789 void GUIMainMenu::acceptInput()
795 bool GUIMainMenu::OnEvent(const SEvent& event)
797 if(event.EventType==EET_KEY_INPUT_EVENT)
799 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
801 m_gamecallback->exitToOS();
805 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
812 if(event.EventType==EET_GUI_EVENT)
814 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
817 if(!canTakeFocus(event.GUIEvent.Element))
819 dstream<<"GUIMainMenu: Not allowing focus change."
821 // Returning true disables focus change
825 if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED)
827 if(!m_is_regenerating)
828 regenerateGui(m_screensize_old);
831 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
833 switch(event.GUIEvent.Caller->getID())
835 case GUI_ID_JOIN_GAME_BUTTON: {
838 if(cur.address == L"" && getTab() == TAB_MULTIPLAYER){
839 (new GUIMessageMenu(env, parent, -1, menumgr,
840 wgettext("Address required."))
848 case GUI_ID_CHANGE_KEYS_BUTTON: {
849 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
853 case GUI_ID_DELETE_WORLD_BUTTON: {
856 if(cur.selected_world == -1){
857 (new GUIMessageMenu(env, parent, -1, menumgr,
858 wgettext("Cannot delete world: Nothing selected"))
861 WorldSpec spec = m_data->worlds[cur.selected_world];
862 ConfirmDestDeleteWorld *dest = new
863 ConfirmDestDeleteWorld(spec, this);
864 (new GUIConfirmMenu(env, parent, -1, menumgr, dest,
865 (std::wstring(wgettext("Delete world "))
866 +L"\""+narrow_to_wide(spec.name)+L"\"?").c_str()
871 case GUI_ID_CREATE_WORLD_BUTTON: {
872 std::vector<SubgameSpec> games = getAvailableGames();
873 if(games.size() == 0){
874 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
876 wgettext("Cannot create world: No games found"));
879 CreateWorldDest *dest = new CreateWorldDestMainMenu(this);
880 GUICreateWorld *menu = new GUICreateWorld(env, parent, -1,
881 menumgr, dest, games);
886 case GUI_ID_CONFIGURE_WORLD_BUTTON: {
887 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
889 wgettext("Nothing here"));
895 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
897 switch(event.GUIEvent.Caller->getID())
899 case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
905 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN)
907 switch(event.GUIEvent.Caller->getID())
909 case GUI_ID_WORLD_LISTBOX:
911 m_data->address = L""; // Force local game
918 return Parent ? Parent->OnEvent(event) : false;
921 void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
926 m_data->create_world_name = name;
927 m_data->create_world_gameid = gameid;
931 void GUIMainMenu::deleteWorld(WorldSpec spec)
936 m_data->delete_world_spec = spec;
940 int GUIMainMenu::getTab()
942 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
943 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
944 return ((gui::IGUITabControl*)e)->getActiveTab();
945 return TAB_SINGLEPLAYER; // Default