1d09c8baad2c802d9f8bb30bdc0b6e3a160348ee
[oweals/minetest.git] / src / guiMainMenu.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef GUIMAINMENU_HEADER
21 #define GUIMAINMENU_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include "modalMenu.h"
25 #include <string>
26 #include <list>
27 #include "subgame.h"
28 #include "serverlist.h"
29
30 class IGameCallback;
31
32 enum {
33         SERVERLIST_FAVORITES,
34         SERVERLIST_PUBLIC,
35 };
36
37 struct MainMenuData
38 {
39         // These are in the native format of the gui elements
40         // Generic
41         int selected_tab;
42         std::string selected_game;
43         std::string selected_game_name;
44         // Client options
45         std::string servername;
46         std::string serverdescription;
47         std::wstring address;
48         std::wstring port;
49         std::wstring name;
50         std::wstring password;
51         bool fancy_trees;
52         bool smooth_lighting;
53         bool clouds_3d;
54         bool opaque_water;
55         bool mip_map;
56         bool anisotropic_filter;
57         bool bilinear_filter;
58         bool trilinear_filter;
59         int enable_shaders;
60         bool preload_item_visuals;
61         bool enable_particles;
62         bool liquid_finite;
63         // Server options
64         bool creative_mode;
65         bool enable_damage;
66         bool enable_public;
67         int selected_world;
68         bool simple_singleplayer_mode;
69         // Actions
70         std::wstring create_world_name;
71         std::string create_world_gameid;
72         bool only_refresh;
73
74         int selected_serverlist;
75
76         std::vector<WorldSpec> worlds;
77         std::vector<SubgameSpec> games;
78         std::vector<ServerListSpec> servers;
79
80         MainMenuData():
81                 // Generic
82                 selected_tab(0),
83                 selected_game("minetest"),
84                 selected_game_name("Minetest"),
85                 // Client opts
86                 fancy_trees(false),
87                 smooth_lighting(false),
88                 // Server opts
89                 creative_mode(false),
90                 enable_damage(false),
91                 enable_public(false),
92                 selected_world(0),
93                 simple_singleplayer_mode(false),
94                 // Actions
95                 only_refresh(false),
96
97                 selected_serverlist(SERVERLIST_FAVORITES)
98         {}
99 };
100
101 class GUIMainMenu : public GUIModalMenu
102 {
103 public:
104         GUIMainMenu(gui::IGUIEnvironment* env,
105                         gui::IGUIElement* parent, s32 id,
106                         IMenuManager *menumgr,
107                         MainMenuData *data,
108                         IGameCallback *gamecallback);
109         ~GUIMainMenu();
110         
111         void removeChildren();
112         // Remove and re-add (or reposition) stuff
113         void regenerateGui(v2u32 screensize);
114         void drawMenu();
115         void readInput(MainMenuData *dst);
116         void acceptInput();
117         bool getStatus()
118         { return m_accepted; }
119         bool OnEvent(const SEvent& event);
120         void createNewWorld(std::wstring name, std::string gameid);
121         void deleteWorld(const std::vector<std::string> &paths);
122         int getTab();
123         void displayMessageMenu(std::wstring msg);
124         
125 private:
126         MainMenuData *m_data;
127         bool m_accepted;
128         IGameCallback *m_gamecallback;
129
130         gui::IGUIEnvironment* env;
131         gui::IGUIElement* parent;
132         s32 id;
133         IMenuManager *menumgr;
134
135         std::vector<int> m_world_indices;
136
137         bool m_is_regenerating;
138         v2s32 m_topleft_client;
139         v2s32 m_size_client;
140         v2s32 m_topleft_server;
141         v2s32 m_size_server;
142         void updateGuiServerList();
143         void serverListOnSelected();
144         ServerListSpec getServerListSpec(std::string address, std::string port);
145 };
146
147 #endif
148