3 Copyright (C) 2010-2013 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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser 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 "guiConfigureWorld.h"
24 #include "guiMessageMenu.h"
25 #include "guiConfirmMenu.h"
27 #include "serialization.h"
29 #include <IGUICheckBox.h>
30 #include <IGUIEditBox.h>
31 #include <IGUIButton.h>
32 #include <IGUIStaticText.h>
34 #include <IGUIListBox.h>
35 #include <IGUITabControl.h>
36 #include <IGUIImage.h>
38 #include "guiPauseMenu.h"
40 #include "tile.h" // getTexturePath
42 #include "util/string.h"
45 struct CreateWorldDestMainMenu : public CreateWorldDest
47 CreateWorldDestMainMenu(GUIMainMenu *menu):
50 void accepted(std::wstring name, std::string gameid)
52 std::string name_narrow = wide_to_narrow(name);
53 if(!string_allowed_blacklist(name_narrow, WORLDNAME_BLACKLISTED_CHARS))
55 m_menu->displayMessageMenu(wgettext("Cannot create world: Name contains invalid characters"));
58 std::vector<WorldSpec> worlds = getAvailableWorlds();
59 for(std::vector<WorldSpec>::iterator i = worlds.begin();
60 i != worlds.end(); i++)
62 if((*i).name == name_narrow)
64 m_menu->displayMessageMenu(wgettext("Cannot create world: A world by this name already exists"));
68 m_menu->createNewWorld(name, gameid);
73 struct ConfirmDestDeleteWorld : public ConfirmDest
75 ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu,
76 const std::vector<std::string> &paths):
81 void answer(bool answer)
85 m_menu->deleteWorld(m_paths);
89 std::vector<std::string> m_paths;
94 GUI_ID_QUIT_BUTTON = 101,
99 GUI_ID_SMOOTH_LIGHTING_CB,
101 GUI_ID_OPAQUE_WATER_CB,
103 GUI_ID_ANISOTROPIC_CB,
107 GUI_ID_PRELOAD_ITEM_VISUALS_CB,
108 GUI_ID_ENABLE_PARTICLES_CB,
112 GUI_ID_JOIN_GAME_BUTTON,
113 GUI_ID_CHANGE_KEYS_BUTTON,
114 GUI_ID_DELETE_WORLD_BUTTON,
115 GUI_ID_CREATE_WORLD_BUTTON,
116 GUI_ID_CONFIGURE_WORLD_BUTTON,
117 GUI_ID_WORLD_LISTBOX,
120 GUI_ID_SERVERLIST_TOGGLE,
121 GUI_ID_SERVERLIST_DELETE,
133 GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
134 gui::IGUIElement* parent, s32 id,
135 IMenuManager *menumgr,
137 IGameCallback *gamecallback
139 GUIModalMenu(env, parent, id, menumgr),
142 m_gamecallback(gamecallback),
143 m_is_regenerating(false)
147 this->parent = parent;
149 this->menumgr = menumgr;
152 GUIMainMenu::~GUIMainMenu()
157 void GUIMainMenu::removeChildren()
159 const core::list<gui::IGUIElement*> &children = getChildren();
160 core::list<gui::IGUIElement*> children_copy;
161 for(core::list<gui::IGUIElement*>::ConstIterator
162 i = children.begin(); i != children.end(); i++)
164 children_copy.push_back(*i);
166 for(core::list<gui::IGUIElement*>::Iterator
167 i = children_copy.begin();
168 i != children_copy.end(); i++)
174 void GUIMainMenu::regenerateGui(v2u32 screensize)
176 m_is_regenerating = true;
178 Read stuff from elements into m_data
188 Calculate new sizes and positions
191 v2s32 size(screensize.X, screensize.Y);
193 core::rect<s32> rect(
194 screensize.X/2 - size.X/2,
195 screensize.Y/2 - size.Y/2,
196 screensize.X/2 + size.X/2,
197 screensize.Y/2 + size.Y/2
201 recalculateAbsolutePosition(false);
203 //v2s32 size = rect.getSize();
212 //if(m_data->selected_tab != TAB_CREDITS)
214 core::rect<s32> rect(0, 0, size.X, 40);
216 Environment->addStaticText(narrow_to_wide(
217 "Minetest " VERSION_STRING).c_str(),
218 rect, false, true, this, -1);
221 //v2s32 center(size.X/2, size.Y/2);
222 v2s32 c800(size.X/2-400, size.Y/2-300);
224 m_topleft_client = c800 + v2s32(90, 70+50+30);
225 m_size_client = v2s32(620, 270);
227 m_size_server = v2s32(620, 140);
229 if(m_data->selected_tab == TAB_ADVANCED)
231 m_topleft_client = c800 + v2s32(90, 70+50+30);
232 m_size_client = v2s32(620, 200);
234 m_size_server = v2s32(620, 140);
237 m_topleft_server = m_topleft_client + v2s32(0, m_size_client.Y+20);
242 core::rect<s32> rect(0, 0, m_size_client.X, 30);
243 rect += m_topleft_client + v2s32(0, -30);
244 gui::IGUITabControl *e = Environment->addTabControl(
245 rect, this, true, true, GUI_ID_TAB_CONTROL);
246 e->addTab(wgettext("Singleplayer"));
247 e->addTab(wgettext("Multiplayer"));
248 e->addTab(wgettext("Advanced"));
249 e->addTab(wgettext("Settings"));
250 e->addTab(wgettext("Credits"));
251 e->setActiveTab(m_data->selected_tab);
255 if(m_data->selected_tab == TAB_SINGLEPLAYER)
259 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
260 rect += m_topleft_client + v2s32(15, 0);
261 //const wchar_t *text = L"H\nY\nB\nR\nI\nD";
262 const wchar_t *text = L"T\nA\nP\nE\n\nA\nN\nD\n\nG\nL\nU\nE";
263 gui::IGUIStaticText *t =
264 Environment->addStaticText(text, rect, false, true, this, -1);
265 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
268 // World selection listbox
269 u32 world_sel_h = 160;
270 u32 world_sel_w = 365;
271 //s32 world_sel_x = 50;
272 s32 world_sel_x = m_size_client.X-world_sel_w-30;
273 s32 world_sel_y = 30;
274 u32 world_button_count = 3;
275 u32 world_button_w = (world_sel_w)/world_button_count - bs
276 + bs/(world_button_count-1);
278 core::rect<s32> rect(0, 0, world_sel_w-4, 20);
279 rect += m_topleft_client + v2s32(world_sel_x+4, world_sel_y-20);
280 /*gui::IGUIStaticText *e =*/ Environment->addStaticText(
281 wgettext("Select World:"),
282 rect, false, true, this, -1);
283 /*e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);*/
286 core::rect<s32> rect(0, 0, world_sel_w, world_sel_h);
287 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y);
288 gui::IGUIListBox *e = Environment->addListBox(rect, this,
289 GUI_ID_WORLD_LISTBOX);
290 e->setDrawBackground(true);
291 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
292 i != m_data->worlds.end(); i++){
293 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
295 e->setSelected(m_data->selected_world);
296 Environment->setFocus(e);
298 // Delete world button
300 core::rect<s32> rect(0, 0, world_button_w, 30);
301 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y+world_sel_h+0);
302 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
305 // Create world button
307 core::rect<s32> rect(0, 0, world_button_w, 30);
308 rect += m_topleft_client + v2s32(world_sel_x+world_button_w+bs, world_sel_y+world_sel_h+0);
309 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
312 // Configure world button
314 core::rect<s32> rect(0, 0, world_button_w, 30);
315 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*2,
316 world_sel_y+world_sel_h+0);
317 Environment->addButton(rect, this, GUI_ID_CONFIGURE_WORLD_BUTTON,
318 wgettext("Configure"));
322 /*core::rect<s32> rect(0, 0, world_button_w, 30);
323 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*3,
324 world_sel_y+world_sel_h+0);*/
326 /*core::rect<s32> rect(0, 0, bw, 30);
327 rect += m_topleft_client + v2s32(m_size_client.X-bw-30,
328 m_size_client.Y-30-15);*/
329 core::rect<s32> rect(0, 0, bw, 30);
330 rect += m_topleft_client + v2s32(world_sel_x+world_sel_w-bw,
331 world_sel_y+world_sel_h+30+bs);
332 Environment->addButton(rect, this,
333 GUI_ID_JOIN_GAME_BUTTON, wgettext("Play"));
337 //s32 option_x = 50+world_sel_w+20;
341 core::rect<s32> rect(0, 0, option_w, 30);
342 rect += m_topleft_client + v2s32(option_x, option_y+20*0);
343 Environment->addCheckBox(m_data->creative_mode, rect, this,
344 GUI_ID_CREATIVE_CB, wgettext("Creative Mode"));
347 core::rect<s32> rect(0, 0, option_w, 30);
348 rect += m_topleft_client + v2s32(option_x, option_y+20*1);
349 Environment->addCheckBox(m_data->enable_damage, rect, this,
350 GUI_ID_DAMAGE_CB, wgettext("Enable Damage"));
354 else if(m_data->selected_tab == TAB_MULTIPLAYER)
359 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
360 rect += m_topleft_client + v2s32(15, 0);
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_CENTER);
366 // Nickname + password
368 core::rect<s32> rect(0, 0, 110, 20);
369 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 10+6);
370 Environment->addStaticText(wgettext("Name/Password"),
371 rect, false, true, this, -1);
375 core::rect<s32> rect(0, 0, 120, 30);
376 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 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, 90);
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, 390, 160);
396 rect += m_topleft_client + v2s32(50, 10);
397 gui::IGUIListBox *e = Environment->addListBox(rect, this,
399 e->setDrawBackground(true);
400 if (m_data->serverlist_show_available == false)
401 m_data->servers = ServerList::getLocal();
402 updateGuiServerList();
407 core::rect<s32> rect(0, 0, 110, 20);
408 rect += m_topleft_client + v2s32(50, m_size_client.Y-50-15+6);
409 Environment->addStaticText(wgettext("Address/Port"),
410 rect, false, true, this, -1);
414 core::rect<s32> rect(0, 0, 260, 30);
415 rect += m_topleft_client + v2s32(50, m_size_client.Y-25-15);
416 gui::IGUIElement *e =
417 Environment->addEditBox(m_data->address.c_str(), rect, true,
418 this, GUI_ID_ADDRESS_INPUT);
419 if(m_data->name != L"" && m_data->address == L"")
420 Environment->setFocus(e);
423 core::rect<s32> rect(0, 0, 120, 30);
424 rect += m_topleft_client + v2s32(50+260+10, m_size_client.Y-25-15);
425 Environment->addEditBox(m_data->port.c_str(), rect, true,
426 this, GUI_ID_PORT_INPUT);
430 // Toggle Serverlist (Favorites/Online)
432 core::rect<s32> rect(0, 0, 260, 30);
433 rect += m_topleft_client + v2s32(50,
435 gui::IGUIButton *e = Environment->addButton(rect, this, GUI_ID_SERVERLIST_TOGGLE,
436 wgettext("Show Public"));
437 e->setIsPushButton(true);
438 if (m_data->serverlist_show_available)
440 e->setText(wgettext("Show Favorites"));
445 // Delete Local Favorite
447 core::rect<s32> rect(0, 0, 120, 30);
448 rect += m_topleft_client + v2s32(50+260+10, 180);
449 gui::IGUIButton *e = Environment->addButton(rect, this, GUI_ID_SERVERLIST_DELETE,
451 if (m_data->serverlist_show_available) // Hidden on Show-Online mode
452 e->setVisible(false);
456 core::rect<s32> rect(0, 0, 120, 30);
457 rect += m_topleft_client + v2s32(m_size_client.X-130-30,
458 m_size_client.Y-25-15);
459 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
460 wgettext("Connect"));
464 else if(m_data->selected_tab == TAB_ADVANCED)
469 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
470 rect += m_topleft_client + v2s32(15, 0);
471 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
472 gui::IGUIStaticText *t =
473 Environment->addStaticText(text, rect, false, true, this, -1);
474 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
476 // Nickname + password
478 core::rect<s32> rect(0, 0, 110, 20);
479 rect += m_topleft_client + v2s32(35+30, 35+6);
480 Environment->addStaticText(wgettext("Name/Password"),
481 rect, false, true, this, -1);
485 core::rect<s32> rect(0, 0, 230, 30);
486 rect += m_topleft_client + v2s32(160+30, 35);
487 gui::IGUIElement *e =
488 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
489 if(m_data->name == L"")
490 Environment->setFocus(e);
493 core::rect<s32> rect(0, 0, 120, 30);
494 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 35);
495 gui::IGUIEditBox *e =
496 Environment->addEditBox(L"", rect, true, this, 264);
497 e->setPasswordBox(true);
498 if(m_data->name != L"" && m_data->address != L"")
499 Environment->setFocus(e);
505 core::rect<s32> rect(0, 0, 110, 20);
506 rect += m_topleft_client + v2s32(35+30, 75+6);
507 Environment->addStaticText(wgettext("Address/Port"),
508 rect, false, true, this, -1);
512 core::rect<s32> rect(0, 0, 230, 30);
513 rect += m_topleft_client + v2s32(160+30, 75);
514 gui::IGUIElement *e =
515 Environment->addEditBox(m_data->address.c_str(), rect, true,
516 this, GUI_ID_ADDRESS_INPUT);
517 if(m_data->name != L"" && m_data->address == L"")
518 Environment->setFocus(e);
521 core::rect<s32> rect(0, 0, 120, 30);
522 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 75);
523 Environment->addEditBox(m_data->port.c_str(), rect, true,
524 this, GUI_ID_PORT_INPUT);
528 core::rect<s32> rect(0, 0, 400, 20);
529 rect += m_topleft_client + v2s32(160+30, 75+35);
530 Environment->addStaticText(wgettext("Leave address blank to start a local server."),
531 rect, false, true, this, -1);
535 core::rect<s32> rect(0, 0, 180, 30);
536 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
537 m_size_client.Y-30-20);
538 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
539 wgettext("Start Game / Connect"));
546 core::rect<s32> rect(0, 0, 10, m_size_server.Y);
547 rect += m_topleft_server + v2s32(15, 0);
548 const wchar_t *text = L"S\nE\nR\nV\nE\nR";
549 gui::IGUIStaticText *t =
550 Environment->addStaticText(text, rect, false, true, this, -1);
551 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
555 core::rect<s32> rect(0, 0, 250, 30);
556 rect += m_topleft_server + v2s32(30+20+250+20, 20);
557 Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB,
558 wgettext("Creative Mode"));
561 core::rect<s32> rect(0, 0, 250, 30);
562 rect += m_topleft_server + v2s32(30+20+250+20, 40);
563 Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
564 wgettext("Enable Damage"));
568 core::rect<s32> rect(0, 0, 250, 30);
569 rect += m_topleft_server + v2s32(30+20+250+20, 60);
570 Environment->addCheckBox(m_data->enable_public, rect, this, GUI_ID_PUBLIC_CB,
574 // Delete world button
576 core::rect<s32> rect(0, 0, 130, 30);
577 rect += m_topleft_server + v2s32(30+20+250+20, 90);
578 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
579 wgettext("Delete world"));
581 // Create world button
583 core::rect<s32> rect(0, 0, 130, 30);
584 rect += m_topleft_server + v2s32(30+20+250+20+140, 90);
585 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
586 wgettext("Create world"));
588 // World selection listbox
590 core::rect<s32> rect(0, 0, 250, 120);
591 rect += m_topleft_server + v2s32(30+20, 10);
592 gui::IGUIListBox *e = Environment->addListBox(rect, this,
593 GUI_ID_WORLD_LISTBOX);
594 e->setDrawBackground(true);
595 for(std::vector<WorldSpec>::const_iterator i = m_data->worlds.begin();
596 i != m_data->worlds.end(); i++){
597 e->addItem(narrow_to_wide(i->name+" ["+i->gameid+"]").c_str());
599 e->setSelected(m_data->selected_world);
603 else if(m_data->selected_tab == TAB_SETTINGS)
606 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
607 rect += m_topleft_client + v2s32(15, 0);
608 const wchar_t *text = L"S\nE\nT\nT\nI\nN\nG\nS";
609 gui::IGUIStaticText *t =
610 Environment->addStaticText(text, rect, false, true, this, -1);
611 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
617 core::rect<s32> rect(0, 0, option_w, 30);
618 rect += m_topleft_client + v2s32(option_x, option_y);
619 Environment->addCheckBox(m_data->fancy_trees, rect, this,
620 GUI_ID_FANCYTREE_CB, wgettext("Fancy trees"));
623 core::rect<s32> rect(0, 0, option_w, 30);
624 rect += m_topleft_client + v2s32(option_x, option_y+20);
625 Environment->addCheckBox(m_data->smooth_lighting, rect, this,
626 GUI_ID_SMOOTH_LIGHTING_CB, wgettext("Smooth Lighting"));
629 core::rect<s32> rect(0, 0, option_w, 30);
630 rect += m_topleft_client + v2s32(option_x, option_y+20*2);
631 Environment->addCheckBox(m_data->clouds_3d, rect, this,
632 GUI_ID_3D_CLOUDS_CB, wgettext("3D Clouds"));
635 core::rect<s32> rect(0, 0, option_w, 30);
636 rect += m_topleft_client + v2s32(option_x, option_y+20*3);
637 Environment->addCheckBox(m_data->opaque_water, rect, this,
638 GUI_ID_OPAQUE_WATER_CB, wgettext("Opaque water"));
642 // Anisotropic/mipmap/bi-/trilinear settings
645 core::rect<s32> rect(0, 0, option_w+20, 30);
646 rect += m_topleft_client + v2s32(option_x+175, option_y);
647 Environment->addCheckBox(m_data->mip_map, rect, this,
648 GUI_ID_MIPMAP_CB, wgettext("Mip-Mapping"));
652 core::rect<s32> rect(0, 0, option_w+20, 30);
653 rect += m_topleft_client + v2s32(option_x+175, option_y+20);
654 Environment->addCheckBox(m_data->anisotropic_filter, rect, this,
655 GUI_ID_ANISOTROPIC_CB, wgettext("Anisotropic Filtering"));
659 core::rect<s32> rect(0, 0, option_w+20, 30);
660 rect += m_topleft_client + v2s32(option_x+175, option_y+20*2);
661 Environment->addCheckBox(m_data->bilinear_filter, rect, this,
662 GUI_ID_BILINEAR_CB, wgettext("Bi-Linear Filtering"));
666 core::rect<s32> rect(0, 0, option_w+20, 30);
667 rect += m_topleft_client + v2s32(option_x+175, option_y+20*3);
668 Environment->addCheckBox(m_data->trilinear_filter, rect, this,
669 GUI_ID_TRILINEAR_CB, wgettext("Tri-Linear Filtering"));
672 // shader/on demand image loading/particles settings
674 core::rect<s32> rect(0, 0, option_w+20, 30);
675 rect += m_topleft_client + v2s32(option_x+175*2, option_y);
676 Environment->addCheckBox(m_data->enable_shaders, rect, this,
677 GUI_ID_SHADERS_CB, wgettext("Shaders"));
681 core::rect<s32> rect(0, 0, option_w+20+20, 30);
682 rect += m_topleft_client + v2s32(option_x+175*2, option_y+20);
683 Environment->addCheckBox(m_data->preload_item_visuals, rect, this,
684 GUI_ID_PRELOAD_ITEM_VISUALS_CB, wgettext("Preload item visuals"));
688 core::rect<s32> rect(0, 0, option_w+20+20, 30);
689 rect += m_topleft_client + v2s32(option_x+175*2, option_y+20*2);
690 Environment->addCheckBox(m_data->enable_particles, rect, this,
691 GUI_ID_ENABLE_PARTICLES_CB, wgettext("Enable Particles"));
696 core::rect<s32> rect(0, 0, 120, 30);
697 /*rect += m_topleft_client + v2s32(m_size_client.X-120-30,
698 m_size_client.Y-30-20);*/
699 rect += m_topleft_client + v2s32(option_x, option_y+120);
700 Environment->addButton(rect, this,
701 GUI_ID_CHANGE_KEYS_BUTTON, wgettext("Change keys"));
705 else if(m_data->selected_tab == TAB_CREDITS)
709 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
710 rect += m_topleft_client + v2s32(15, 0);
711 const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS";
712 gui::IGUIStaticText *t =
713 Environment->addStaticText(text, rect, false, true, this, -1);
714 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
717 core::rect<s32> rect(0, 0, 454, 250);
718 rect += m_topleft_client + v2s32(110, 50+35);
719 Environment->addStaticText(narrow_to_wide(
720 "Minetest " VERSION_STRING "\n"
721 "http://minetest.net/\n"
723 "by Perttu Ahola <celeron55@gmail.com>\n"
724 "and contributors: PilzAdam, Taoki, tango_, kahrl (kaaaaaahrl?), darkrose, matttpt, erlehmann, SpeedProg, JacobF, teddydestodes, marktraceur, Jonathan Neuschäfer, thexyz, VanessaE, sfan5... and tens of more random people."
725 ).c_str(), rect, false, true, this, -1);
729 m_is_regenerating = false;
732 void GUIMainMenu::drawMenu()
734 gui::IGUISkin* skin = Environment->getSkin();
737 video::IVideoDriver* driver = Environment->getVideoDriver();
739 /*video::SColor bgcolor(140,0,0,0);
740 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
742 video::SColor bgcolor(140,0,0,0);
744 if(getTab() == TAB_SINGLEPLAYER)
747 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
748 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
749 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
752 else if(getTab() == TAB_MULTIPLAYER)
755 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
756 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
757 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
760 else if(getTab() == TAB_ADVANCED)
763 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
764 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
765 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
768 core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y);
769 rect += AbsoluteRect.UpperLeftCorner + m_topleft_server;
770 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
773 else if(getTab() == TAB_SETTINGS)
776 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
777 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
778 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
781 else if(getTab() == TAB_CREDITS)
784 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
785 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
786 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
788 video::ITexture *logotexture =
789 driver->getTexture(getTexturePath("menulogo.png").c_str());
792 v2s32 logosize(logotexture->getOriginalSize().Width,
793 logotexture->getOriginalSize().Height);
795 core::rect<s32> rect(0,0,logosize.X,logosize.Y);
796 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
797 rect += v2s32(130, 50);
798 driver->draw2DImage(logotexture, rect,
799 core::rect<s32>(core::position2d<s32>(0,0),
800 core::dimension2di(logotexture->getSize())),
805 gui::IGUIElement::draw();
808 void GUIMainMenu::readInput(MainMenuData *dst)
811 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
812 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
813 dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab();
815 if(dst->selected_tab == TAB_SINGLEPLAYER)
817 dst->simple_singleplayer_mode = true;
821 dst->simple_singleplayer_mode = false;
823 gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
825 dst->name = e->getText();
828 gui::IGUIElement *e = getElementFromId(264);
830 dst->password = e->getText();
833 gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
835 dst->address = e->getText();
838 gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
840 dst->port = e->getText();
844 gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
845 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
846 dst->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
849 gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
850 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
851 dst->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
854 gui::IGUIElement *e = getElementFromId(GUI_ID_PUBLIC_CB);
855 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
856 dst->enable_public = ((gui::IGUICheckBox*)e)->isChecked();
859 gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
860 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
861 dst->fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
864 gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
865 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
866 dst->smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
869 gui::IGUIElement *e = getElementFromId(GUI_ID_3D_CLOUDS_CB);
870 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
871 dst->clouds_3d = ((gui::IGUICheckBox*)e)->isChecked();
874 gui::IGUIElement *e = getElementFromId(GUI_ID_OPAQUE_WATER_CB);
875 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
876 dst->opaque_water = ((gui::IGUICheckBox*)e)->isChecked();
880 gui::IGUIElement *e = getElementFromId(GUI_ID_MIPMAP_CB);
881 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
882 dst->mip_map = ((gui::IGUICheckBox*)e)->isChecked();
886 gui::IGUIElement *e = getElementFromId(GUI_ID_ANISOTROPIC_CB);
887 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
888 dst->anisotropic_filter = ((gui::IGUICheckBox*)e)->isChecked();
892 gui::IGUIElement *e = getElementFromId(GUI_ID_BILINEAR_CB);
893 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
894 dst->bilinear_filter = ((gui::IGUICheckBox*)e)->isChecked();
898 gui::IGUIElement *e = getElementFromId(GUI_ID_TRILINEAR_CB);
899 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
900 dst->trilinear_filter = ((gui::IGUICheckBox*)e)->isChecked();
904 gui::IGUIElement *e = getElementFromId(GUI_ID_SHADERS_CB);
905 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
906 dst->enable_shaders = ((gui::IGUICheckBox*)e)->isChecked() ? 2 : 0;
910 gui::IGUIElement *e = getElementFromId(GUI_ID_PRELOAD_ITEM_VISUALS_CB);
911 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
912 dst->preload_item_visuals = ((gui::IGUICheckBox*)e)->isChecked();
916 gui::IGUIElement *e = getElementFromId(GUI_ID_ENABLE_PARTICLES_CB);
917 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
918 dst->enable_particles = ((gui::IGUICheckBox*)e)->isChecked();
922 gui::IGUIElement *e = getElementFromId(GUI_ID_WORLD_LISTBOX);
923 if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX)
924 dst->selected_world = ((gui::IGUIListBox*)e)->getSelected();
927 ServerListSpec server =
928 getServerListSpec(wide_to_narrow(dst->address), wide_to_narrow(dst->port));
929 dst->servername = server["name"].asString();
930 dst->serverdescription = server["description"].asString();
934 void GUIMainMenu::acceptInput()
940 bool GUIMainMenu::OnEvent(const SEvent& event)
942 if(event.EventType==EET_KEY_INPUT_EVENT)
944 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
946 m_gamecallback->exitToOS();
950 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
957 if(event.EventType==EET_GUI_EVENT)
959 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
962 if(!canTakeFocus(event.GUIEvent.Element))
964 dstream<<"GUIMainMenu: Not allowing focus change."
966 // Returning true disables focus change
970 if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED)
972 if(!m_is_regenerating)
973 regenerateGui(m_screensize_old);
976 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_CHANGED && event.GUIEvent.Caller->getID() == GUI_ID_SERVERLIST)
978 serverListOnSelected();
981 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
983 switch(event.GUIEvent.Caller->getID())
985 case GUI_ID_JOIN_GAME_BUTTON: {
988 if (getTab() == TAB_MULTIPLAYER && cur.address == L"")
990 (new GUIMessageMenu(env, parent, -1, menumgr,
991 wgettext("Address required."))
999 case GUI_ID_CHANGE_KEYS_BUTTON: {
1000 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
1004 case GUI_ID_DELETE_WORLD_BUTTON: {
1007 if(cur.selected_world == -1){
1008 (new GUIMessageMenu(env, parent, -1, menumgr,
1009 wgettext("Cannot delete world: Nothing selected"))
1012 WorldSpec spec = m_data->worlds[cur.selected_world];
1013 // Get files and directories involved
1014 std::vector<std::string> paths;
1015 paths.push_back(spec.path);
1016 fs::GetRecursiveSubPaths(spec.path, paths);
1017 // Launch confirmation dialog
1018 ConfirmDestDeleteWorld *dest = new
1019 ConfirmDestDeleteWorld(spec, this, paths);
1020 std::wstring text = wgettext("Delete world");
1022 text += narrow_to_wide(spec.name);
1024 text += wgettext("Files to be deleted");
1026 for(u32 i=0; i<paths.size(); i++){
1027 if(i == 3){ text += L"..."; break; }
1028 text += narrow_to_wide(paths[i]) + L"\n";
1030 (new GUIConfirmMenu(env, parent, -1, menumgr, dest,
1031 text.c_str()))->drop();
1035 case GUI_ID_CREATE_WORLD_BUTTON: {
1036 std::vector<SubgameSpec> games = getAvailableGames();
1037 if(games.size() == 0){
1038 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
1040 wgettext("Cannot create world: No games found"));
1043 CreateWorldDest *dest = new CreateWorldDestMainMenu(this);
1044 GUICreateWorld *menu = new GUICreateWorld(env, parent, -1,
1045 menumgr, dest, games);
1050 case GUI_ID_CONFIGURE_WORLD_BUTTON: {
1053 if(cur.selected_world == -1)
1055 (new GUIMessageMenu(env, parent, -1, menumgr,
1056 wgettext("Cannot configure world: Nothing selected"))
1061 WorldSpec wspec = m_data->worlds[cur.selected_world];
1062 GUIConfigureWorld *menu = new GUIConfigureWorld(env, parent,
1063 -1, menumgr, wspec);
1068 case GUI_ID_SERVERLIST_DELETE: {
1069 gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST);
1070 s32 selected = ((gui::IGUIListBox*)serverlist)->getSelected();
1071 if (selected == -1) return true;
1072 ServerList::deleteEntry(m_data->servers[selected]);
1073 m_data->servers = ServerList::getLocal();
1074 updateGuiServerList();
1077 serverlist->setSelected(selected);
1078 serverListOnSelected();
1082 case GUI_ID_SERVERLIST_TOGGLE: {
1083 gui::IGUIElement *togglebutton = getElementFromId(GUI_ID_SERVERLIST_TOGGLE);
1084 gui::IGUIElement *deletebutton = getElementFromId(GUI_ID_SERVERLIST_DELETE);
1085 gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST);
1086 if (m_data->serverlist_show_available) // switch to favorite list
1088 m_data->servers = ServerList::getLocal();
1089 togglebutton->setText(wgettext("Show Public"));
1090 deletebutton->setVisible(true);
1091 updateGuiServerList();
1092 serverlist->setSelected(0);
1094 else // switch to online list
1096 m_data->servers = ServerList::getOnline();
1097 togglebutton->setText(wgettext("Show Favorites"));
1098 deletebutton->setVisible(false);
1099 updateGuiServerList();
1100 serverlist->setSelected(0);
1102 serverListOnSelected();
1104 m_data->serverlist_show_available = !m_data->serverlist_show_available;
1109 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
1111 switch(event.GUIEvent.Caller->getID())
1113 case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
1119 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN)
1121 switch(event.GUIEvent.Caller->getID())
1123 case GUI_ID_WORLD_LISTBOX:
1125 if(getTab() != TAB_SINGLEPLAYER)
1126 m_data->address = L""; // Force local game
1129 case GUI_ID_SERVERLIST:
1130 gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST);
1131 if (serverlist->getSelected() > -1)
1141 return Parent ? Parent->OnEvent(event) : false;
1144 void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
1149 m_data->create_world_name = name;
1150 m_data->create_world_gameid = gameid;
1154 void GUIMainMenu::deleteWorld(const std::vector<std::string> &paths)
1157 bool did = fs::DeletePaths(paths);
1159 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
1160 -1, menumgr, wgettext("Failed to delete all world files"));
1163 // Quit menu to refresh it
1165 m_data->only_refresh = true;
1169 int GUIMainMenu::getTab()
1171 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
1172 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
1173 return ((gui::IGUITabControl*)e)->getActiveTab();
1174 return TAB_SINGLEPLAYER; // Default
1177 void GUIMainMenu::displayMessageMenu(std::wstring msg)
1179 (new GUIMessageMenu(env, parent, -1, menumgr, msg))->drop();
1182 void GUIMainMenu::updateGuiServerList()
1184 gui::IGUIListBox *serverlist = (gui::IGUIListBox *)getElementFromId(GUI_ID_SERVERLIST);
1185 serverlist->clear();
1187 for(std::vector<ServerListSpec>::iterator i = m_data->servers.begin();
1188 i != m_data->servers.end(); i++)
1192 if ((*i)["clients"].asString().size())
1193 text += (*i)["clients"].asString();
1194 if ((*i)["clients_max"].asString().size())
1195 text += "/" + (*i)["clients_max"].asString();
1197 if ((*i)["version"].asString().size())
1198 text += (*i)["version"].asString() + " ";
1199 if ((*i)["password"].asString().size())
1201 if ((*i)["creative"].asString().size())
1203 if ((*i)["damage"].asString().size())
1205 if ((*i)["pvp"].asString().size())
1209 if ((*i)["name"] != "" && (*i)["description"] != "")
1210 text += (*i)["name"].asString() + " (" + (*i)["description"].asString() + ")";
1211 else if ((*i)["name"] !="")
1212 text += (*i)["name"].asString();
1214 text += (*i)["address"].asString() + ":" + (*i)["port"].asString();
1216 serverlist->addItem(narrow_to_wide(text).c_str());
1220 void GUIMainMenu::serverListOnSelected()
1222 if (!m_data->servers.empty())
1224 gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST);
1225 u16 id = serverlist->getSelected();
1226 //if (id < 0) return; // u16>0!
1227 ((gui::IGUIEditBox*)getElementFromId(GUI_ID_ADDRESS_INPUT))
1228 ->setText(narrow_to_wide(m_data->servers[id]["address"].asString()).c_str());
1229 ((gui::IGUIEditBox*)getElementFromId(GUI_ID_PORT_INPUT))
1230 ->setText(narrow_to_wide(m_data->servers[id]["port"].asString()).c_str());
1234 ServerListSpec GUIMainMenu::getServerListSpec(std::string address, std::string port)
1236 ServerListSpec server;
1237 server["address"] = address;
1238 server["port"] = port;
1239 for(std::vector<ServerListSpec>::iterator i = m_data->servers.begin();
1240 i != m_data->servers.end(); i++)
1242 if ((*i)["address"] == address && (*i)["port"] == port)
1244 server["description"] = (*i)["description"];
1245 server["name"] = (*i)["name"];