1 // SuperTux
2 // Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 #include "supertux/menu/main_menu.hpp"
18
19 #include "audio/sound_manager.hpp"
20 #include "editor/editor.hpp"
21 #include "gui/dialog.hpp"
22 #include "gui/menu_item.hpp"
23 #include "gui/menu_manager.hpp"
24 #include "supertux/fadetoblack.hpp"
25 #include "supertux/globals.hpp"
26 #include "supertux/level.hpp"
27 #include "supertux/level_parser.hpp"
28 #include "supertux/levelset.hpp"
29 #include "supertux/menu/menu_storage.hpp"
30 #include "supertux/screen_manager.hpp"
31 #include "supertux/game_manager.hpp"
32 #include "supertux/textscroller_screen.hpp"
33 #include "supertux/world.hpp"
34 #include "util/log.hpp"
35 #include "util/file_system.hpp"
36 #include "video/video_system.hpp"
37 #include "video/viewport.hpp"
38
39 #if defined(_WIN32)
40 #include <windows.h>
41 #include <shellapi.h>
42 #else
43 #include <cstdlib>
44 #endif
45
46 #ifdef __EMSCRIPTEN__
47 #include <emscripten.h>
48 #include <emscripten/html5.h>
49 #endif
50
MainMenu()51 MainMenu::MainMenu()
52 {
53 set_center_pos(static_cast<float>(SCREEN_WIDTH) / 2.0f,
54 static_cast<float>(SCREEN_HEIGHT) / 2.0f + 35.0f);
55
56 add_entry(MNID_STARTGAME, _("Start Game"));
57 // TODO: Manage to build OpenSSL for Emscripten so we can build CURL so we can
58 // build the add-ons so we can re-enable them.
59 // Also see src/addon/downloader.*pp
60 add_entry(MNID_ADDONS, _("Add-ons"));
61 #ifdef __EMSCRIPTEN__
62 add_entry(MNID_MANAGEASSETS, _("Manage Assets"));
63 #endif
64 add_submenu(_("Options"), MenuStorage::OPTIONS_MENU);
65 add_entry(MNID_LEVELEDITOR, _("Level Editor"));
66 add_entry(MNID_CREDITS, _("Credits"));
67 add_entry(MNID_DONATE, _("Donate"));
68 #ifndef REMOVE_QUIT_BUTTON
69 add_entry(MNID_QUITMAINMENU, _("Quit"));
70 #endif
71 }
72
73 void
on_window_resize()74 MainMenu::on_window_resize()
75 {
76 set_center_pos(static_cast<float>(SCREEN_WIDTH) / 2.0f,
77 static_cast<float>(SCREEN_HEIGHT) / 2.0f + 35.0f);
78 }
79
80 void
menu_action(MenuItem & item)81 MainMenu::menu_action(MenuItem& item)
82 {
83 switch (item.get_id())
84 {
85
86 case MNID_STARTGAME:
87 // World selection menu
88 MenuManager::instance().push_menu(MenuStorage::WORLDSET_MENU);
89 break;
90
91 case MNID_ADDONS:
92 // Add-ons Menu
93 MenuManager::instance().push_menu(MenuStorage::ADDON_MENU);
94 break;
95
96 case MNID_MANAGEASSETS:
97 MenuManager::instance().push_menu(MenuStorage::ASSET_MENU);
98 break;
99
100 case MNID_CREDITS:
101 {
102 // Credits Level
103 SoundManager::current()->stop_music(0.2f);
104 std::unique_ptr<World> world = World::from_directory("levels/misc");
105 GameManager::current()->start_level(*world, "credits.stl");
106 }
107 break;
108
109 case MNID_LEVELEDITOR:
110 {
111 MenuManager::instance().clear_menu_stack();
112 std::unique_ptr<Screen> screen(new Editor());
113 auto fade = std::make_unique<FadeToBlack>(FadeToBlack::FADEOUT, 0.5f);
114 SoundManager::current()->stop_music(0.5);
115 ScreenManager::current()->push_screen(move(screen),move(fade));
116 //Editor::current()->setup();
117 }
118 break;
119
120 case MNID_DONATE:
121 #ifdef __EMSCRIPTEN__
122 EM_ASM({
123 window.open("https://www.supertux.org/donate.html");
124 }, 0); // EM_ASM is a variadic macro and Clang requires at least 1 value for the variadic argument
125 #else
126 FileSystem::open_path("https://www.supertux.org/donate.html");
127 #endif
128 break;
129
130 case MNID_QUITMAINMENU:
131 MenuManager::instance().clear_menu_stack();
132 ScreenManager::current()->quit(std::unique_ptr<ScreenFade>(new FadeToBlack(FadeToBlack::FADEOUT, 0.25f)));
133 SoundManager::current()->stop_music(0.25);
134 break;
135 }
136 }
137
138 /* EOF */
139