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 #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
46 #define LSTRING(x) LSTRING_(x)
47 #define LSTRING_(x) L##x
49 const wchar_t *contrib_core_strs[] = {
50 L"Perttu Ahola (celeron55) <celeron55@gmail.com>",
51 L"Ryan Kwolek (kwolekr) <kwolekr@minetest.net>",
52 L"PilzAdam <pilzadam@minetest.net>",
53 L"Ilya Zhuravlev (thexyz) <xyz@minetest.net>",
54 L"Lisa Milne (darkrose) <lisa@ltmnet.com>",
55 L"Maciej Kasatkin (RealBadAngel) <mk@realbadangel.pl>",
56 L"proller <proler@gmail.com>",
57 L"sfan5 <sfan5@live.de>",
58 L"kahrl <kahrl@gmx.net>"
61 const wchar_t *contrib_active_strs[] = {
62 L"sapier <sapier@gmx.net>",
63 L"Vanessa Ezekowitz (VanessaE) <vanessaezekowitz@gmail.com>",
64 L"Jurgen Doser (doserj) <jurgen.doser@gmail.com>",
65 L"Jeija <jeija@mesecons.net>",
66 L"MirceaKitsune <mirceakitsune@gmail.com>",
68 L"dannydark <the_skeleton_of_a_child@yahoo.co.uk>",
69 L"0gb.us <0gb.us@0gb.us>"
72 const wchar_t *contrib_previous_strs[] = {
73 L"Giuseppe Bilotta (Oblomov) <giuseppe.bilotta@gmail.com>",
74 L"Jonathan Neuschafer <j.neuschaefer@gmx.net>",
75 L"Nils Dagsson Moskopp (erlehmann) <nils@dieweltistgarnichtso.net>",
76 L"Constantin Wenger (SpeedProg) <constantin.wenger@googlemail.com>",
77 L"matttpt <matttpt@gmail.com>",
78 L"JacobF <queatz@gmail.com>"
82 struct CreateWorldDestMainMenu : public CreateWorldDest
84 CreateWorldDestMainMenu(GUIMainMenu *menu):
87 void accepted(std::wstring name, std::string gameid)
89 std::string name_narrow = wide_to_narrow(name);
90 if(!string_allowed_blacklist(name_narrow, WORLDNAME_BLACKLISTED_CHARS))
92 wchar_t* text = wgettext("Cannot create world: Name contains invalid characters");
93 m_menu->displayMessageMenu(text);
97 std::vector<WorldSpec> worlds = getAvailableWorlds();
98 for(std::vector<WorldSpec>::iterator i = worlds.begin();
99 i != worlds.end(); i++)
101 if((*i).name == name_narrow)
103 wchar_t* text = wgettext("Cannot create world: A world by this name already exists");
104 m_menu->displayMessageMenu(text);
109 m_menu->createNewWorld(name, gameid);
114 struct ConfirmDestDeleteWorld : public ConfirmDest
116 ConfirmDestDeleteWorld(WorldSpec spec, GUIMainMenu *menu,
117 const std::vector<std::string> &paths):
122 void answer(bool answer)
126 m_menu->deleteWorld(m_paths);
130 std::vector<std::string> m_paths;
135 GUI_ID_QUIT_BUTTON = 101,
137 GUI_ID_ADDRESS_INPUT,
140 GUI_ID_SMOOTH_LIGHTING_CB,
142 GUI_ID_OPAQUE_WATER_CB,
144 GUI_ID_ANISOTROPIC_CB,
148 GUI_ID_PRELOAD_ITEM_VISUALS_CB,
149 GUI_ID_ENABLE_PARTICLES_CB,
150 GUI_ID_LIQUID_FINITE_CB,
154 GUI_ID_JOIN_GAME_BUTTON,
155 GUI_ID_CHANGE_KEYS_BUTTON,
156 GUI_ID_DELETE_WORLD_BUTTON,
157 GUI_ID_CREATE_WORLD_BUTTON,
158 GUI_ID_CONFIGURE_WORLD_BUTTON,
159 GUI_ID_WORLD_LISTBOX,
162 GUI_ID_SERVERLIST_TOGGLE,
163 GUI_ID_SERVERLIST_DELETE,
164 GUI_ID_SERVERLIST_TITLE,
165 GUI_ID_GAME_BUTTON_FIRST = 130,
166 GUI_ID_GAME_BUTTON_MAX = 150,
169 GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
170 gui::IGUIElement* parent, s32 id,
171 IMenuManager *menumgr,
173 IGameCallback *gamecallback
175 GUIModalMenu(env, parent, id, menumgr),
178 m_gamecallback(gamecallback),
179 m_is_regenerating(false)
183 this->parent = parent;
185 this->menumgr = menumgr;
188 GUIMainMenu::~GUIMainMenu()
193 void GUIMainMenu::removeChildren()
195 const core::list<gui::IGUIElement*> &children = getChildren();
196 core::list<gui::IGUIElement*> children_copy;
197 for(core::list<gui::IGUIElement*>::ConstIterator
198 i = children.begin(); i != children.end(); i++)
200 children_copy.push_back(*i);
202 for(core::list<gui::IGUIElement*>::Iterator
203 i = children_copy.begin();
204 i != children_copy.end(); i++)
210 void GUIMainMenu::regenerateGui(v2u32 screensize)
212 m_is_regenerating = true;
214 Read stuff from elements into m_data
224 Calculate new sizes and positions
227 v2s32 size(screensize.X, screensize.Y);
229 core::rect<s32> rect(
230 screensize.X/2 - size.X/2,
231 screensize.Y/2 - size.Y/2,
232 screensize.X/2 + size.X/2,
233 screensize.Y/2 + size.Y/2
237 recalculateAbsolutePosition(false);
239 //v2s32 size = rect.getSize();
249 core::rect<s32> rect(0, 0, size.X, 40);
251 std::string t = "Minetest " VERSION_STRING;
252 if(m_data->selected_game_name != "" &&
253 m_data->selected_tab == TAB_SINGLEPLAYER){
255 t += m_data->selected_game_name;
257 Environment->addStaticText(narrow_to_wide(t).c_str(),
258 rect, false, true, this, -1);
261 //v2s32 center(size.X/2, size.Y/2);
262 v2s32 c800(size.X/2-400, size.Y/2-270);
264 m_topleft_client = c800 + v2s32(90, 70+50+30);
265 m_size_client = v2s32(620, 270);
267 m_size_server = v2s32(620, 140);
269 if(m_data->selected_tab == TAB_ADVANCED)
271 m_topleft_client = c800 + v2s32(90, 70+50+30);
272 m_size_client = v2s32(620, 200);
274 m_size_server = v2s32(620, 140);
277 m_topleft_server = m_topleft_client + v2s32(0, m_size_client.Y+20);
281 core::rect<s32> rect(0, 0, m_size_client.X, 30);
282 rect += m_topleft_client + v2s32(0, -30);
283 gui::IGUITabControl *e = Environment->addTabControl(
284 rect, this, true, true, GUI_ID_TAB_CONTROL);
285 wchar_t* text = wgettext("Singleplayer");
288 text = wgettext("Multiplayer");
291 text = wgettext("Advanced");
294 text = wgettext("Settings");
297 text = wgettext("Credits");
301 e->setActiveTab(m_data->selected_tab);
305 if(m_data->selected_tab == TAB_SINGLEPLAYER)
309 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
310 rect += m_topleft_client + v2s32(15, 0);
311 //const wchar_t *text = L"H\nY\nB\nR\nI\nD";
312 const wchar_t *text = L"S\nI\nN\nG\nL\nE\n \nP\nL\nA\nY\nE\nR\n";
313 gui::IGUIStaticText *t =
314 Environment->addStaticText(text, rect, false, true, this, -1);
315 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
318 // World selection listbox
319 u32 world_sel_h = 160;
320 u32 world_sel_w = 365;
321 //s32 world_sel_x = 50;
322 s32 world_sel_x = m_size_client.X-world_sel_w-30;
323 s32 world_sel_y = 30;
324 u32 world_button_count = 3;
325 u32 world_button_w = (world_sel_w)/world_button_count - bs
326 + bs/(world_button_count-1);
328 core::rect<s32> rect(0, 0, world_sel_w-4, 20);
329 rect += m_topleft_client + v2s32(world_sel_x+4, world_sel_y-20);
330 wchar_t* text = wgettext("Select World:");
331 /*gui::IGUIStaticText *e =*/ Environment->addStaticText(
333 rect, false, true, this, -1);
335 /*e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);*/
338 core::rect<s32> rect(0, 0, world_sel_w, world_sel_h);
339 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y);
340 gui::IGUIListBox *e = Environment->addListBox(rect, this,
341 GUI_ID_WORLD_LISTBOX);
342 e->setDrawBackground(true);
343 m_world_indices.clear();
344 for(size_t wi = 0; wi < m_data->worlds.size(); wi++){
345 const WorldSpec &spec = m_data->worlds[wi];
346 if(spec.gameid == m_data->selected_game){
347 //e->addItem(narrow_to_wide(spec.name+" ["+spec.gameid+"]").c_str());
348 e->addItem(narrow_to_wide(spec.name).c_str());
349 m_world_indices.push_back(wi);
350 if(m_data->selected_world == (int)wi)
351 e->setSelected(m_world_indices.size()-1);
354 Environment->setFocus(e);
356 // Delete world button
358 core::rect<s32> rect(0, 0, world_button_w, 30);
359 rect += m_topleft_client + v2s32(world_sel_x, world_sel_y+world_sel_h+0);
360 wchar_t* text = wgettext("Delete");
361 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
365 // Create world button
367 core::rect<s32> rect(0, 0, world_button_w, 30);
368 rect += m_topleft_client + v2s32(world_sel_x+world_button_w+bs, world_sel_y+world_sel_h+0);
369 wchar_t* text = wgettext("New");
370 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
374 // Configure world button
376 core::rect<s32> rect(0, 0, world_button_w, 30);
377 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*2,
378 world_sel_y+world_sel_h+0);
379 wchar_t* text = wgettext("Configure");
380 Environment->addButton(rect, this, GUI_ID_CONFIGURE_WORLD_BUTTON,
386 /*core::rect<s32> rect(0, 0, world_button_w, 30);
387 rect += m_topleft_client + v2s32(world_sel_x+(world_button_w+bs)*3,
388 world_sel_y+world_sel_h+0);*/
390 /*core::rect<s32> rect(0, 0, bw, 30);
391 rect += m_topleft_client + v2s32(m_size_client.X-bw-30,
392 m_size_client.Y-30-15);*/
393 core::rect<s32> rect(0, 0, bw, 30);
394 rect += m_topleft_client + v2s32(world_sel_x+world_sel_w-bw,
395 world_sel_y+world_sel_h+30+bs);
396 wchar_t* text = wgettext("Play");
397 Environment->addButton(rect, this,
398 GUI_ID_JOIN_GAME_BUTTON, text);
403 //s32 option_x = 50+world_sel_w+20;
407 core::rect<s32> rect(0, 0, option_w, 30);
408 rect += m_topleft_client + v2s32(option_x, option_y+20*0);
409 wchar_t* text = wgettext("Creative Mode");
410 Environment->addCheckBox(m_data->creative_mode, rect, this,
411 GUI_ID_CREATIVE_CB, text);
415 core::rect<s32> rect(0, 0, option_w, 30);
416 rect += m_topleft_client + v2s32(option_x, option_y+20*1);
417 wchar_t* text = wgettext("Enable Damage");
418 Environment->addCheckBox(m_data->enable_damage, rect, this,
419 GUI_ID_DAMAGE_CB, text);
424 /* Add game selection buttons */
425 video::IVideoDriver* driver = Environment->getVideoDriver();
426 for(size_t i=0; i<m_data->games.size(); i++){
427 const SubgameSpec *spec = &m_data->games[i];
428 v2s32 p(8 + i*(48+8), screensize.Y - (48+8));
429 core::rect<s32> rect(0, 0, 48, 48);
431 video::ITexture *bgtexture = NULL;
432 if(spec->menuicon_path != "")
433 bgtexture = driver->getTexture(spec->menuicon_path.c_str());
434 gui::IGUIButton *b = Environment->addButton(rect, this,
435 GUI_ID_GAME_BUTTON_FIRST+i, narrow_to_wide(wrap_rows(spec->id, 4)).c_str());
437 b->setImage(bgtexture);
439 b->setDrawBorder(false);
440 b->setUseAlphaChannel(true);
444 else if(m_data->selected_tab == TAB_MULTIPLAYER)
449 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
450 rect += m_topleft_client + v2s32(15, 0);
451 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
452 gui::IGUIStaticText *t =
453 Environment->addStaticText(text, rect, false, true, this, -1);
454 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
456 // Nickname + password
458 core::rect<s32> rect(0, 0, 110, 20);
459 wchar_t* text = wgettext("Name/Password");
460 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 10+6);
461 Environment->addStaticText(text,
462 rect, false, true, this, -1);
467 core::rect<s32> rect(0, 0, 120, 30);
468 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 50);
469 gui::IGUIElement *e =
470 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
471 if(m_data->name == L"")
472 Environment->setFocus(e);
475 core::rect<s32> rect(0, 0, 120, 30);
476 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 90);
477 gui::IGUIEditBox *e =
478 Environment->addEditBox(L"", rect, true, this, 264);
479 e->setPasswordBox(true);
480 if(m_data->name != L"" && m_data->address != L"")
481 Environment->setFocus(e);
487 core::rect<s32> rect(0, 0, 390, 140);
488 rect += m_topleft_client + v2s32(50, 30);
489 gui::IGUIListBox *e = Environment->addListBox(rect, this,
491 e->setDrawBackground(true);
493 if(m_data->selected_serverlist == SERVERLIST_FAVORITES) {
494 m_data->servers = ServerList::getLocal();
496 core::rect<s32> rect(0, 0, 390, 20);
497 rect += m_topleft_client + v2s32(50, 10);
498 wchar_t* text = wgettext("Favorites:");
499 Environment->addStaticText(text,
500 rect, false, true, this, GUI_ID_SERVERLIST_TITLE);
504 m_data->servers = ServerList::getOnline();
506 core::rect<s32> rect(0, 0, 390, 20);
507 rect += m_topleft_client + v2s32(50, 10);
508 wchar_t* text = wgettext("Public Server List:");
509 Environment->addStaticText(text,
510 rect, false, true, this, GUI_ID_SERVERLIST_TITLE);
515 m_data->servers = ServerList::getLocal();
517 core::rect<s32> rect(0, 0, 390, 20);
518 rect += m_topleft_client + v2s32(50, 10);
519 wchar_t* text = wgettext("Favorites:");
520 Environment->addStaticText(text,
521 rect, false, true, this, GUI_ID_SERVERLIST_TITLE);
525 updateGuiServerList();
530 core::rect<s32> rect(0, 0, 110, 20);
531 rect += m_topleft_client + v2s32(50, m_size_client.Y-50-15+6);
532 wchar_t* text = wgettext("Address/Port");
533 Environment->addStaticText(text,
534 rect, false, true, this, -1);
539 core::rect<s32> rect(0, 0, 260, 30);
540 rect += m_topleft_client + v2s32(50, m_size_client.Y-25-15);
541 gui::IGUIElement *e =
542 Environment->addEditBox(m_data->address.c_str(), rect, true,
543 this, GUI_ID_ADDRESS_INPUT);
544 if(m_data->name != L"" && m_data->address == L"")
545 Environment->setFocus(e);
548 core::rect<s32> rect(0, 0, 120, 30);
549 rect += m_topleft_client + v2s32(50+260+10, m_size_client.Y-25-15);
550 Environment->addEditBox(m_data->port.c_str(), rect, true,
551 this, GUI_ID_PORT_INPUT);
555 // Toggle Serverlist (Favorites/Online)
557 core::rect<s32> rect(0, 0, 260, 30);
558 rect += m_topleft_client + v2s32(50,
560 wchar_t* text = wgettext("Show Public");
561 gui::IGUIButton *e = Environment->addButton(rect, this, GUI_ID_SERVERLIST_TOGGLE,
564 e->setIsPushButton(true);
565 if (m_data->selected_serverlist == SERVERLIST_PUBLIC)
567 wchar_t* text = wgettext("Show Favorites");
574 // Delete Local Favorite
576 core::rect<s32> rect(0, 0, 120, 30);
577 rect += m_topleft_client + v2s32(50+260+10, 180);
578 wchar_t* text = wgettext("Delete");
579 gui::IGUIButton *e = Environment->addButton(rect, this, GUI_ID_SERVERLIST_DELETE,
581 if (m_data->selected_serverlist == SERVERLIST_PUBLIC) // Hidden when on public list
582 e->setVisible(false);
588 core::rect<s32> rect(0, 0, 120, 30);
589 rect += m_topleft_client + v2s32(m_size_client.X-130-30,
590 m_size_client.Y-25-15);
591 wchar_t* text = wgettext("Connect");
592 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
598 else if(m_data->selected_tab == TAB_ADVANCED)
603 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
604 rect += m_topleft_client + v2s32(15, 0);
605 const wchar_t *text = L"C\nL\nI\nE\nN\nT";
606 gui::IGUIStaticText *t =
607 Environment->addStaticText(text, rect, false, true, this, -1);
608 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
610 // Nickname + password
612 core::rect<s32> rect(0, 0, 110, 20);
613 rect += m_topleft_client + v2s32(35+30, 35+6);
614 wchar_t* text = wgettext("Name/Password");
615 Environment->addStaticText(text,
616 rect, false, true, this, -1);
621 core::rect<s32> rect(0, 0, 230, 30);
622 rect += m_topleft_client + v2s32(160+30, 35);
623 gui::IGUIElement *e =
624 Environment->addEditBox(m_data->name.c_str(), rect, true, this, GUI_ID_NAME_INPUT);
625 if(m_data->name == L"")
626 Environment->setFocus(e);
629 core::rect<s32> rect(0, 0, 120, 30);
630 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 35);
631 gui::IGUIEditBox *e =
632 Environment->addEditBox(L"", rect, true, this, 264);
633 e->setPasswordBox(true);
634 if(m_data->name != L"" && m_data->address != L"")
635 Environment->setFocus(e);
641 core::rect<s32> rect(0, 0, 110, 20);
642 rect += m_topleft_client + v2s32(35+30, 75+6);
643 wchar_t* text = wgettext("Address/Port");
644 Environment->addStaticText(text,
645 rect, false, true, this, -1);
650 core::rect<s32> rect(0, 0, 230, 30);
651 rect += m_topleft_client + v2s32(160+30, 75);
652 gui::IGUIElement *e =
653 Environment->addEditBox(m_data->address.c_str(), rect, true,
654 this, GUI_ID_ADDRESS_INPUT);
655 if(m_data->name != L"" && m_data->address == L"")
656 Environment->setFocus(e);
659 core::rect<s32> rect(0, 0, 120, 30);
660 rect += m_topleft_client + v2s32(m_size_client.X-60-100, 75);
661 Environment->addEditBox(m_data->port.c_str(), rect, true,
662 this, GUI_ID_PORT_INPUT);
666 core::rect<s32> rect(0, 0, 400, 20);
667 rect += m_topleft_client + v2s32(160+30, 75+35);
668 wchar_t* text = wgettext("Leave address blank to start a local server.");
669 Environment->addStaticText(text,
670 rect, false, true, this, -1);
675 core::rect<s32> rect(0, 0, 180, 30);
676 rect += m_topleft_client + v2s32(m_size_client.X-180-30,
677 m_size_client.Y-30-20);
678 wchar_t* text = wgettext("Start Game / Connect");
679 Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON,
688 core::rect<s32> rect(0, 0, 10, m_size_server.Y);
689 rect += m_topleft_server + v2s32(15, 0);
690 const wchar_t *text = L"S\nE\nR\nV\nE\nR";
691 gui::IGUIStaticText *t =
692 Environment->addStaticText(text, rect, false, true, this, -1);
693 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
697 core::rect<s32> rect(0, 0, 250, 30);
698 rect += m_topleft_server + v2s32(30+20+250+20, 20);
699 wchar_t* text = wgettext("Creative Mode");
700 Environment->addCheckBox(m_data->creative_mode, rect, this, GUI_ID_CREATIVE_CB,
705 core::rect<s32> rect(0, 0, 250, 30);
706 rect += m_topleft_server + v2s32(30+20+250+20, 40);
707 wchar_t* text = wgettext("Enable Damage");
708 Environment->addCheckBox(m_data->enable_damage, rect, this, GUI_ID_DAMAGE_CB,
714 core::rect<s32> rect(0, 0, 250, 30);
715 rect += m_topleft_server + v2s32(30+20+250+20, 60);
716 wchar_t* text = wgettext("Public");
717 Environment->addCheckBox(m_data->enable_public, rect, this, GUI_ID_PUBLIC_CB,
722 // Delete world button
724 core::rect<s32> rect(0, 0, 130, 30);
725 rect += m_topleft_server + v2s32(30+20+250+20, 90);
726 wchar_t* text = wgettext("Delete world");
727 Environment->addButton(rect, this, GUI_ID_DELETE_WORLD_BUTTON,
731 // Create world button
733 core::rect<s32> rect(0, 0, 130, 30);
734 rect += m_topleft_server + v2s32(30+20+250+20+140, 90);
735 wchar_t* text = wgettext("Create world");
736 Environment->addButton(rect, this, GUI_ID_CREATE_WORLD_BUTTON,
740 // World selection listbox
742 core::rect<s32> rect(0, 0, 250, 120);
743 rect += m_topleft_server + v2s32(30+20, 10);
744 gui::IGUIListBox *e = Environment->addListBox(rect, this,
745 GUI_ID_WORLD_LISTBOX);
746 e->setDrawBackground(true);
747 m_world_indices.clear();
748 for(size_t wi = 0; wi < m_data->worlds.size(); wi++){
749 const WorldSpec &spec = m_data->worlds[wi];
750 e->addItem(narrow_to_wide(spec.name+" ["+spec.gameid+"]").c_str());
751 m_world_indices.push_back(wi);
753 e->setSelected(m_data->selected_world);
757 else if(m_data->selected_tab == TAB_SETTINGS)
760 core::rect<s32> rect(0, 0, 10, m_size_client.Y);
761 rect += m_topleft_client + v2s32(15, 0);
762 const wchar_t *text = L"S\nE\nT\nT\nI\nN\nG\nS";
763 gui::IGUIStaticText *t =
764 Environment->addStaticText(text, rect, false, true, this, -1);
765 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
771 core::rect<s32> rect(0, 0, option_w, 30);
772 rect += m_topleft_client + v2s32(option_x, option_y);
773 wchar_t* text = wgettext("Fancy trees");
774 Environment->addCheckBox(m_data->fancy_trees, rect, this,
775 GUI_ID_FANCYTREE_CB, text);
779 core::rect<s32> rect(0, 0, option_w, 30);
780 rect += m_topleft_client + v2s32(option_x, option_y+20);
781 wchar_t* text = wgettext("Smooth Lighting");
782 Environment->addCheckBox(m_data->smooth_lighting, rect, this,
783 GUI_ID_SMOOTH_LIGHTING_CB, text);
787 core::rect<s32> rect(0, 0, option_w, 30);
788 rect += m_topleft_client + v2s32(option_x, option_y+20*2);
789 wchar_t* text = wgettext("3D Clouds");
790 Environment->addCheckBox(m_data->clouds_3d, rect, this,
791 GUI_ID_3D_CLOUDS_CB, text);
795 core::rect<s32> rect(0, 0, option_w, 30);
796 rect += m_topleft_client + v2s32(option_x, option_y+20*3);
797 wchar_t* text = wgettext("Opaque water");
798 Environment->addCheckBox(m_data->opaque_water, rect, this,
799 GUI_ID_OPAQUE_WATER_CB, text);
804 // Anisotropic/mipmap/bi-/trilinear settings
807 core::rect<s32> rect(0, 0, option_w+20, 30);
808 rect += m_topleft_client + v2s32(option_x+175, option_y);
809 wchar_t* text = wgettext("Mip-Mapping");
810 Environment->addCheckBox(m_data->mip_map, rect, this,
811 GUI_ID_MIPMAP_CB, text);
816 core::rect<s32> rect(0, 0, option_w+20, 30);
817 rect += m_topleft_client + v2s32(option_x+175, option_y+20);
818 wchar_t* text = wgettext("Anisotropic Filtering");
819 Environment->addCheckBox(m_data->anisotropic_filter, rect, this,
820 GUI_ID_ANISOTROPIC_CB, text);
825 core::rect<s32> rect(0, 0, option_w+20, 30);
826 rect += m_topleft_client + v2s32(option_x+175, option_y+20*2);
827 wchar_t* text = wgettext("Bi-Linear Filtering");
828 Environment->addCheckBox(m_data->bilinear_filter, rect, this,
829 GUI_ID_BILINEAR_CB, text);
834 core::rect<s32> rect(0, 0, option_w+20, 30);
835 rect += m_topleft_client + v2s32(option_x+175, option_y+20*3);
836 wchar_t* text = wgettext("Tri-Linear Filtering");
837 Environment->addCheckBox(m_data->trilinear_filter, rect, this,
838 GUI_ID_TRILINEAR_CB, text);
842 // shader/on demand image loading/particles settings
844 core::rect<s32> rect(0, 0, option_w+20, 30);
845 rect += m_topleft_client + v2s32(option_x+175*2, option_y);
846 wchar_t* text = wgettext("Shaders");
847 Environment->addCheckBox(m_data->enable_shaders, rect, this,
848 GUI_ID_SHADERS_CB, text);
853 core::rect<s32> rect(0, 0, option_w+20+20, 30);
854 rect += m_topleft_client + v2s32(option_x+175*2, option_y+20);
855 wchar_t* text = wgettext("Preload item visuals");
856 Environment->addCheckBox(m_data->preload_item_visuals, rect, this,
857 GUI_ID_PRELOAD_ITEM_VISUALS_CB, text);
862 core::rect<s32> rect(0, 0, option_w+20+20, 30);
863 rect += m_topleft_client + v2s32(option_x+175*2, option_y+20*2);
864 wchar_t* text = wgettext("Enable Particles");
865 Environment->addCheckBox(m_data->enable_particles, rect, this,
866 GUI_ID_ENABLE_PARTICLES_CB, text);
871 core::rect<s32> rect(0, 0, option_w+20+20, 30);
872 rect += m_topleft_client + v2s32(option_x+175*2, option_y+20*3);
873 wchar_t* text = wgettext("Finite liquid");
874 Environment->addCheckBox(m_data->liquid_finite, rect, this,
875 GUI_ID_LIQUID_FINITE_CB, text);
881 core::rect<s32> rect(0, 0, 120, 30);
882 /*rect += m_topleft_client + v2s32(m_size_client.X-120-30,
883 m_size_client.Y-30-20);*/
884 rect += m_topleft_client + v2s32(option_x, option_y+120);
885 wchar_t* text = wgettext("Change keys");
886 Environment->addButton(rect, this,
887 GUI_ID_CHANGE_KEYS_BUTTON, text);
892 else if(m_data->selected_tab == TAB_CREDITS)
896 core::rect<s32> rect(0, 0, 9, m_size_client.Y);
897 rect += m_topleft_client + v2s32(15, 0);
898 const wchar_t *text = L"C\nR\nE\nD\nI\nT\nS";
899 gui::IGUIStaticText *t =
900 Environment->addStaticText(text, rect, false, true, this, -1);
901 t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
904 core::rect<s32> rect(0, 0, 130, 70);
905 rect += m_topleft_client + v2s32(35, 160);
906 Environment->addStaticText(
907 L"Minetest " LSTRING(VERSION_STRING) L"\nhttp://minetest.net/",
908 rect, false, true, this, -1);
911 video::SColor yellow(255, 255, 255, 0);
912 core::rect<s32> rect(0, 0, 450, 260);
913 rect += m_topleft_client + v2s32(168, 5);
915 irr::gui::IGUIListBox *list = Environment->addListBox(rect, this);
917 list->addItem(L"Core Developers");
918 list->setItemOverrideColor(list->getItemCount() - 1, yellow);
919 for (int i = 0; i != ARRAYLEN(contrib_core_strs); i++)
920 list->addItem(contrib_core_strs[i]);
922 list->addItem(L"Active Contributors");
923 list->setItemOverrideColor(list->getItemCount() - 1, yellow);
924 for (int i = 0; i != ARRAYLEN(contrib_active_strs); i++)
925 list->addItem(contrib_active_strs[i]);
927 list->addItem(L"Previous Contributors");
928 list->setItemOverrideColor(list->getItemCount() - 1, yellow);
929 for (int i = 0; i != ARRAYLEN(contrib_previous_strs); i++)
930 list->addItem(contrib_previous_strs[i]);
935 m_is_regenerating = false;
938 void GUIMainMenu::drawMenu()
940 gui::IGUISkin* skin = Environment->getSkin();
943 video::IVideoDriver* driver = Environment->getVideoDriver();
945 /* Draw menu background */
947 /*video::SColor bgcolor(140,0,0,0);
948 driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
950 video::SColor bgcolor(140,0,0,0);
952 if(getTab() == TAB_SINGLEPLAYER)
955 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
956 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
957 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
960 else if(getTab() == TAB_MULTIPLAYER)
963 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
964 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
965 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
968 else if(getTab() == TAB_ADVANCED)
971 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
972 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
973 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
976 core::rect<s32> rect(0, 0, m_size_server.X, m_size_server.Y);
977 rect += AbsoluteRect.UpperLeftCorner + m_topleft_server;
978 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
981 else if(getTab() == TAB_SETTINGS)
984 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
985 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
986 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
989 else if(getTab() == TAB_CREDITS)
992 core::rect<s32> rect(0, 0, m_size_client.X, m_size_client.Y);
993 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
994 driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
996 video::ITexture *logotexture =
997 driver->getTexture(getTexturePath("logo.png").c_str());
1000 v2s32 logosize(logotexture->getOriginalSize().Width,
1001 logotexture->getOriginalSize().Height);
1003 core::rect<s32> rect(0,0,logosize.X,logosize.Y);
1004 rect += AbsoluteRect.UpperLeftCorner + m_topleft_client;
1005 rect += v2s32(50, 60);
1006 driver->draw2DImage(logotexture, rect,
1007 core::rect<s32>(core::position2d<s32>(0,0),
1008 core::dimension2di(logotexture->getSize())),
1013 /* Draw UI elements */
1015 gui::IGUIElement::draw();
1018 void GUIMainMenu::readInput(MainMenuData *dst)
1021 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
1022 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
1023 dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab();
1025 if(dst->selected_tab == TAB_SINGLEPLAYER)
1027 dst->simple_singleplayer_mode = true;
1031 dst->simple_singleplayer_mode = false;
1033 gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
1035 dst->name = e->getText();
1038 gui::IGUIElement *e = getElementFromId(264);
1040 dst->password = e->getText();
1043 gui::IGUIElement *e = getElementFromId(GUI_ID_ADDRESS_INPUT);
1045 dst->address = e->getText();
1048 gui::IGUIElement *e = getElementFromId(GUI_ID_PORT_INPUT);
1050 dst->port = e->getText();
1054 gui::IGUIElement *e = getElementFromId(GUI_ID_CREATIVE_CB);
1055 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1056 dst->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
1059 gui::IGUIElement *e = getElementFromId(GUI_ID_DAMAGE_CB);
1060 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1061 dst->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
1064 gui::IGUIElement *e = getElementFromId(GUI_ID_PUBLIC_CB);
1065 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1066 dst->enable_public = ((gui::IGUICheckBox*)e)->isChecked();
1069 gui::IGUIElement *e = getElementFromId(GUI_ID_FANCYTREE_CB);
1070 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1071 dst->fancy_trees = ((gui::IGUICheckBox*)e)->isChecked();
1074 gui::IGUIElement *e = getElementFromId(GUI_ID_SMOOTH_LIGHTING_CB);
1075 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1076 dst->smooth_lighting = ((gui::IGUICheckBox*)e)->isChecked();
1079 gui::IGUIElement *e = getElementFromId(GUI_ID_3D_CLOUDS_CB);
1080 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1081 dst->clouds_3d = ((gui::IGUICheckBox*)e)->isChecked();
1084 gui::IGUIElement *e = getElementFromId(GUI_ID_OPAQUE_WATER_CB);
1085 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1086 dst->opaque_water = ((gui::IGUICheckBox*)e)->isChecked();
1090 gui::IGUIElement *e = getElementFromId(GUI_ID_MIPMAP_CB);
1091 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1092 dst->mip_map = ((gui::IGUICheckBox*)e)->isChecked();
1096 gui::IGUIElement *e = getElementFromId(GUI_ID_ANISOTROPIC_CB);
1097 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1098 dst->anisotropic_filter = ((gui::IGUICheckBox*)e)->isChecked();
1102 gui::IGUIElement *e = getElementFromId(GUI_ID_BILINEAR_CB);
1103 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1104 dst->bilinear_filter = ((gui::IGUICheckBox*)e)->isChecked();
1108 gui::IGUIElement *e = getElementFromId(GUI_ID_TRILINEAR_CB);
1109 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1110 dst->trilinear_filter = ((gui::IGUICheckBox*)e)->isChecked();
1114 gui::IGUIElement *e = getElementFromId(GUI_ID_SHADERS_CB);
1115 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1116 dst->enable_shaders = ((gui::IGUICheckBox*)e)->isChecked() ? 2 : 0;
1120 gui::IGUIElement *e = getElementFromId(GUI_ID_PRELOAD_ITEM_VISUALS_CB);
1121 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1122 dst->preload_item_visuals = ((gui::IGUICheckBox*)e)->isChecked();
1126 gui::IGUIElement *e = getElementFromId(GUI_ID_ENABLE_PARTICLES_CB);
1127 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1128 dst->enable_particles = ((gui::IGUICheckBox*)e)->isChecked();
1132 gui::IGUIElement *e = getElementFromId(GUI_ID_LIQUID_FINITE_CB);
1133 if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
1134 dst->liquid_finite = ((gui::IGUICheckBox*)e)->isChecked();
1138 gui::IGUIElement *e = getElementFromId(GUI_ID_WORLD_LISTBOX);
1139 if(e != NULL && e->getType() == gui::EGUIET_LIST_BOX){
1140 int list_i = ((gui::IGUIListBox*)e)->getSelected();
1142 dst->selected_world = -1;
1144 dst->selected_world = m_world_indices[list_i];
1148 ServerListSpec server =
1149 getServerListSpec(wide_to_narrow(dst->address), wide_to_narrow(dst->port));
1150 dst->servername = server["name"].asString();
1151 dst->serverdescription = server["description"].asString();
1155 void GUIMainMenu::acceptInput()
1161 bool GUIMainMenu::OnEvent(const SEvent& event)
1163 if(event.EventType==EET_KEY_INPUT_EVENT)
1165 if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
1167 m_gamecallback->exitToOS();
1171 if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
1178 if(event.EventType==EET_GUI_EVENT)
1180 if(event.GUIEvent.EventType==gui::EGET_ELEMENT_FOCUS_LOST
1183 if(!canTakeFocus(event.GUIEvent.Element))
1185 dstream<<"GUIMainMenu: Not allowing focus change."
1187 // Returning true disables focus change
1191 if(event.GUIEvent.EventType==gui::EGET_TAB_CHANGED)
1193 if(!m_is_regenerating)
1194 regenerateGui(m_screensize_old);
1197 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_CHANGED && event.GUIEvent.Caller->getID() == GUI_ID_SERVERLIST)
1199 serverListOnSelected();
1202 if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
1204 switch(event.GUIEvent.Caller->getID())
1206 case GUI_ID_JOIN_GAME_BUTTON: {
1209 if (getTab() == TAB_MULTIPLAYER && cur.address == L"")
1211 wchar_t* text = wgettext("Address required.");
1212 (new GUIMessageMenu(env, parent, -1, menumgr,
1222 case GUI_ID_CHANGE_KEYS_BUTTON: {
1223 GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(env, parent, -1,menumgr);
1227 case GUI_ID_DELETE_WORLD_BUTTON: {
1230 if(cur.selected_world == -1){
1231 wchar_t* text = wgettext("Cannot delete world: Nothing selected");
1232 (new GUIMessageMenu(env, parent, -1, menumgr,
1237 WorldSpec spec = m_data->worlds[cur.selected_world];
1238 // Get files and directories involved
1239 std::vector<std::string> paths;
1240 paths.push_back(spec.path);
1241 fs::GetRecursiveSubPaths(spec.path, paths);
1242 // Launch confirmation dialog
1243 ConfirmDestDeleteWorld *dest = new
1244 ConfirmDestDeleteWorld(spec, this, paths);
1245 wchar_t* text1 = wgettext("Delete world");
1246 wchar_t* text2 = wgettext("Files to be deleted");
1247 std::wstring text = text1;
1249 text += narrow_to_wide(spec.name);
1255 for(u32 i=0; i<paths.size(); i++){
1256 if(i == 3){ text += L"..."; break; }
1257 text += narrow_to_wide(paths[i]) + L"\n";
1259 (new GUIConfirmMenu(env, parent, -1, menumgr, dest,
1260 text.c_str()))->drop();
1264 case GUI_ID_CREATE_WORLD_BUTTON: {
1265 const std::vector<SubgameSpec> &games = m_data->games;
1266 if(games.size() == 0){
1267 wchar_t* text = wgettext("Cannot create world: No games found");
1268 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
1274 CreateWorldDest *dest = new CreateWorldDestMainMenu(this);
1275 GUICreateWorld *menu = new GUICreateWorld(env, parent, -1,
1276 menumgr, dest, games, m_data->selected_game);
1281 case GUI_ID_CONFIGURE_WORLD_BUTTON: {
1284 if(cur.selected_world == -1)
1286 wchar_t* text = wgettext("Cannot configure world: Nothing selected");
1287 (new GUIMessageMenu(env, parent, -1, menumgr,
1294 WorldSpec wspec = m_data->worlds[cur.selected_world];
1295 GUIConfigureWorld *menu = new GUIConfigureWorld(env, parent,
1296 -1, menumgr, wspec);
1301 case GUI_ID_SERVERLIST_DELETE: {
1302 gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST);
1303 s32 selected = ((gui::IGUIListBox*)serverlist)->getSelected();
1304 if (selected == -1) return true;
1305 ServerList::deleteEntry(m_data->servers[selected]);
1306 m_data->servers = ServerList::getLocal();
1307 updateGuiServerList();
1310 serverlist->setSelected(selected);
1311 serverListOnSelected();
1315 case GUI_ID_SERVERLIST_TOGGLE: {
1316 gui::IGUIElement *togglebutton = getElementFromId(GUI_ID_SERVERLIST_TOGGLE);
1317 gui::IGUIElement *deletebutton = getElementFromId(GUI_ID_SERVERLIST_DELETE);
1318 gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST);
1319 gui::IGUIElement *title = getElementFromId(GUI_ID_SERVERLIST_TITLE);
1320 if (m_data->selected_serverlist == SERVERLIST_PUBLIC) // switch to favorite list
1322 m_data->servers = ServerList::getLocal();
1323 wchar_t* text1 = wgettext("Show Public");
1324 wchar_t* text2 = wgettext("Favorites:");
1325 togglebutton->setText(text1);
1326 title->setText(text2);
1329 deletebutton->setVisible(true);
1330 updateGuiServerList();
1331 serverlist->setSelected(0);
1332 m_data->selected_serverlist = SERVERLIST_FAVORITES;
1334 else // switch to online list
1336 m_data->servers = ServerList::getOnline();
1337 wchar_t* text1 = wgettext("Show Favorites");
1338 wchar_t* text2 = wgettext("Public Server List:");
1339 togglebutton->setText(text1);
1340 title->setText(text2);
1343 deletebutton->setVisible(false);
1344 updateGuiServerList();
1345 serverlist->setSelected(0);
1346 m_data->selected_serverlist = SERVERLIST_PUBLIC;
1348 serverListOnSelected();
1353 int eid = event.GUIEvent.Caller->getID();
1354 if(eid >= GUI_ID_GAME_BUTTON_FIRST &&
1355 eid <= GUI_ID_GAME_BUTTON_MAX){
1356 m_data->selected_game =
1357 m_data->games[eid - GUI_ID_GAME_BUTTON_FIRST].id;
1358 m_data->selected_game_name =
1359 m_data->games[eid - GUI_ID_GAME_BUTTON_FIRST].name;
1360 regenerateGui(m_screensize_old);
1363 if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
1365 switch(event.GUIEvent.Caller->getID())
1367 case GUI_ID_ADDRESS_INPUT: case GUI_ID_PORT_INPUT: case GUI_ID_NAME_INPUT: case 264:
1370 if (getTab() == TAB_MULTIPLAYER && cur.address == L"")
1372 wchar_t* text = wgettext("Address required.");
1373 (new GUIMessageMenu(env, parent, -1, menumgr,
1384 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_CHANGED)
1388 if(event.GUIEvent.EventType==gui::EGET_LISTBOX_SELECTED_AGAIN)
1390 switch(event.GUIEvent.Caller->getID())
1392 case GUI_ID_WORLD_LISTBOX:
1394 if(getTab() != TAB_SINGLEPLAYER)
1395 m_data->address = L""; // Force local game
1398 case GUI_ID_SERVERLIST:
1399 gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST);
1400 if (serverlist->getSelected() > -1)
1410 return Parent ? Parent->OnEvent(event) : false;
1413 void GUIMainMenu::createNewWorld(std::wstring name, std::string gameid)
1418 m_data->create_world_name = name;
1419 m_data->create_world_gameid = gameid;
1423 void GUIMainMenu::deleteWorld(const std::vector<std::string> &paths)
1426 bool did = fs::DeletePaths(paths);
1428 wchar_t* text = wgettext("Failed to delete all world files");
1429 GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
1434 // Quit menu to refresh it
1436 m_data->only_refresh = true;
1440 int GUIMainMenu::getTab()
1442 gui::IGUIElement *e = getElementFromId(GUI_ID_TAB_CONTROL);
1443 if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
1444 return ((gui::IGUITabControl*)e)->getActiveTab();
1445 return TAB_SINGLEPLAYER; // Default
1448 void GUIMainMenu::displayMessageMenu(std::wstring msg)
1450 (new GUIMessageMenu(env, parent, -1, menumgr, msg))->drop();
1453 void GUIMainMenu::updateGuiServerList()
1455 gui::IGUIListBox *serverlist = (gui::IGUIListBox *)getElementFromId(GUI_ID_SERVERLIST);
1456 serverlist->clear();
1458 for(std::vector<ServerListSpec>::iterator i = m_data->servers.begin();
1459 i != m_data->servers.end(); i++)
1463 if ((*i)["clients"].asString().size())
1464 text += (*i)["clients"].asString();
1465 if ((*i)["clients_max"].asString().size())
1466 text += "/" + (*i)["clients_max"].asString();
1468 if ((*i)["version"].asString().size())
1469 text += (*i)["version"].asString() + " ";
1470 if ((*i)["password"].asString().size())
1472 if ((*i)["creative"].asString().size())
1474 if ((*i)["damage"].asString().size())
1476 if ((*i)["pvp"].asString().size())
1480 if ((*i)["name"] != "" && (*i)["description"] != "")
1481 text += (*i)["name"].asString() + " (" + (*i)["description"].asString() + ")";
1482 else if ((*i)["name"] !="")
1483 text += (*i)["name"].asString();
1485 text += (*i)["address"].asString() + ":" + (*i)["port"].asString();
1487 serverlist->addItem(narrow_to_wide(text).c_str());
1491 void GUIMainMenu::serverListOnSelected()
1493 if (!m_data->servers.empty())
1495 gui::IGUIListBox *serverlist = (gui::IGUIListBox*)getElementFromId(GUI_ID_SERVERLIST);
1496 u16 id = serverlist->getSelected();
1497 //if (id < 0) return; // u16>0!
1498 ((gui::IGUIEditBox*)getElementFromId(GUI_ID_ADDRESS_INPUT))
1499 ->setText(narrow_to_wide(m_data->servers[id]["address"].asString()).c_str());
1500 ((gui::IGUIEditBox*)getElementFromId(GUI_ID_PORT_INPUT))
1501 ->setText(narrow_to_wide(m_data->servers[id]["port"].asString()).c_str());
1505 ServerListSpec GUIMainMenu::getServerListSpec(std::string address, std::string port)
1507 ServerListSpec server;
1508 server["address"] = address;
1509 server["port"] = port;
1510 for(std::vector<ServerListSpec>::iterator i = m_data->servers.begin();
1511 i != m_data->servers.end(); i++)
1513 if ((*i)["address"] == address && (*i)["port"] == port)
1515 server["description"] = (*i)["description"];
1516 server["name"] = (*i)["name"];