1604.00
[voxelands.git] / src / guiMultiplayerMenu.h
blob9f64cf5f291e388c72006960d82d95de542c8c56
1 /************************************************************************
2 * guiMultiplayerMenu.h
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2013-2015 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
19 * License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
20 * for Voxelands.
21 ************************************************************************/
23 #ifndef GUIMULTIPLAYERMENU_HEADER
24 #define GUIMULTIPLAYERMENU_HEADER
26 #include "common_irrlicht.h"
27 #include "utility.h"
28 #include "modalMenu.h"
29 #include "client.h"
30 #include "intl.h"
31 #include "keycode.h"
32 #include <string>
33 // For IGameCallback
34 #include "guiPauseMenu.h"
35 #include "guiMainMenu.h"
37 enum
39 GUI_ID_START_BUTTON = 101,
40 GUI_ID_CONNECT_BUTTON,
41 // full list/favourites
42 GUI_ID_SERVER_LIST,
43 GUI_ID_ADDFAV_BUTTON,
44 GUI_ID_REMFAV_BUTTON,
45 GUI_ID_REFRESH_BUTTON,
46 // custom connect
47 GUI_ID_NAME_INPUT,
48 GUI_ID_PW_INPUT,
49 GUI_ID_ADDRESS_INPUT,
50 GUI_ID_PORT_INPUT,
51 // tabs
52 GUI_ID_TAB_MP_MAINMENU,
53 GUI_ID_TAB_MP_LIST,
54 GUI_ID_TAB_MP_FAVOURITES,
55 GUI_ID_TAB_MP_CUSTOM
58 enum {
59 TAB_MP_LIST=0,
60 TAB_MP_FAVOURITES,
61 TAB_MP_CUSTOM,
62 TAB_MP_CONNECT
65 struct ServerInfo {
66 std::wstring name;
67 std::wstring addr;
68 std::wstring mode;
69 bool is_favourite;
72 struct MultiplayerMenuData
74 MultiplayerMenuData():
75 // Generic
76 selected_tab(TAB_MP_LIST),
77 selected_row(-1),
78 mmdata(NULL)
81 // Generic
82 int selected_tab;
83 int selected_row;
84 // Options
85 std::vector<ServerInfo> servers;
86 std::vector<ServerInfo> favourites;
87 // server address/port/etc is stored in here
88 MainMenuData *mmdata;
91 class GUIMultiplayerMenu: public GUIModalMenu
93 public:
94 GUIMultiplayerMenu(
95 gui::IGUIEnvironment* env,
96 gui::IGUIElement* parent,
97 s32 id,
98 MainMenuData *data,
99 IMenuManager *menumgr,
100 IGameCallback *gamecallback
102 ~GUIMultiplayerMenu();
104 void removeChildren();
106 Remove and re-add (or reposition) stuff
108 void regenerateGui(v2u32 screensize);
110 void drawMenu();
112 bool acceptInput();
114 bool OnEvent(const SEvent& event);
116 private:
117 MultiplayerMenuData m_data;
118 bool m_accepted;
119 IGameCallback *m_gamecallback;
120 v2u32 m_screensize;
122 bool fetchServers();
123 bool loadServers();
124 bool saveFavourites();
125 bool parseFile(std::string data, std::vector<ServerInfo> &list);
128 #endif