| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2012 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D 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 | // Dust Racing 2D is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #include "mainmenu.hpp" |
| 17 | |
| 18 | #include "credits.hpp" |
| 19 | #include "difficultymenu.hpp" |
| 20 | #include "help.hpp" |
| 21 | #include "lapcountmenu.hpp" |
| 22 | #include "renderer.hpp" |
| 23 | #include "settingsmenu.hpp" |
| 24 | #include "textmenuitemview.hpp" |
| 25 | #include "trackselectionmenu.hpp" |
| 26 | |
| 27 | #include <MenuItem> |
| 28 | #include <MenuItemAction> |
| 29 | #include <MenuItemView> |
| 30 | #include <MenuManager> |
| 31 | |
| 32 | #include <MCSurface> |
| 33 | #include <MCSurfaceManager> |
| 34 | |
| 35 | #include "simple_logger.hpp" |
| 36 | |
| 37 | static const int ITEM_TEXT_SIZE = 40; |
| 38 | |
| 39 | std::string MainMenu::MenuId = "main"; |
| 40 | |
| 41 | MainMenu::MainMenu(MTFH::MenuManager & menuManager, Scene & scene, int width, int height) |
| 42 | : SurfaceMenu("mainMenuBack", MenuId, width, height, Menu::Style::VerticalList, false) |
| 43 | , m_menuManager(menuManager) |
| 44 | , m_scene(scene) |
| 45 | { |
| 46 | createMenuItems(); |
| 47 | createSubMenus(); |
| 48 | } |
| 49 | |
| 50 | void MainMenu::createMenuItems() |
| 51 | { |
| 52 | using MTFH::MenuItem; |
| 53 | |
| 54 | const int itemHeight = height() / 8; |
| 55 | const int textSize = ITEM_TEXT_SIZE; |
| 56 | |
| 57 | const auto play = std::make_shared<MenuItem>(width(), itemHeight, tr("Play").toUpper().toStdWString()); |
| 58 | play->setView(std::make_shared<TextMenuItemView>(textSize, *play)); |
| 59 | play->setMenuOpenAction("difficulty"); |
| 60 | |
| 61 | const auto help = std::make_shared<MenuItem>(width(), itemHeight, tr("Help").toUpper().toStdWString()); |
| 62 | help->setView(std::make_shared<TextMenuItemView>(textSize, *help)); |
| 63 | help->setMenuOpenAction("help"); |
| 64 | |
| 65 | const auto credits = std::make_shared<MenuItem>(width(), itemHeight, tr("Credits").toUpper().toStdWString()); |
| 66 | credits->setView(std::make_shared<TextMenuItemView>(textSize, *credits)); |
| 67 | credits->setMenuOpenAction("credits"); |
| 68 | |
| 69 | const auto quit = std::make_shared<MenuItem>(width(), itemHeight, tr("Quit").toUpper().toStdWString()); |
| 70 | quit->setView(std::make_shared<TextMenuItemView>(textSize, *quit)); |
| 71 | quit->setAction( |
| 72 | [this]() { |
| 73 | juzzlin::L().info() << "Quit selected from the main menu."; |
| 74 | emit exitGameRequested(); |
| 75 | }); |
| 76 | |
| 77 | const auto settings = std::make_shared<MenuItem>(width(), itemHeight, tr("Settings").toUpper().toStdWString()); |
| 78 | settings->setView(std::make_shared<TextMenuItemView>(textSize, *settings)); |
| 79 | settings->setMenuOpenAction("settings"); |
| 80 | |
| 81 | addItem(quit); |
| 82 | addItem(credits); |
| 83 | addItem(settings); |
| 84 | addItem(help); |
| 85 | addItem(play); |
| 86 | } |
| 87 | |
| 88 | void MainMenu::createSubMenus() |
| 89 | { |
| 90 | m_menuManager.addMenu(std::make_shared<Help>("help", width(), height())); |
| 91 | |
| 92 | m_menuManager.addMenu(std::make_shared<Credits>("credits", width(), height())); |
| 93 | |
| 94 | m_menuManager.addMenu(std::make_shared<LapCountMenu>(width(), height())); |
| 95 | |
| 96 | m_menuManager.addMenu(std::make_shared<SettingsMenu>("settings", width(), height())); |
| 97 | |
| 98 | m_menuManager.addMenu(std::make_shared<TrackSelectionMenu>(width(), height(), m_scene)); |
| 99 | |
| 100 | m_menuManager.addMenu(std::make_shared<DifficultyMenu>(width(), height())); |
| 101 | } |