1 /*
2 * This file is part of Dune Legacy.
3 *
4 * Dune Legacy 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 2 of the License, or
7 * (at your option) any later version.
8 *
9 * Dune Legacy 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 Dune Legacy. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <Menu/MainMenu.h>
19
20 #include <globals.h>
21
22 #include <FileClasses/GFXManager.h>
23 #include <FileClasses/TextManager.h>
24 #include <FileClasses/music/MusicPlayer.h>
25
26 #include <MapEditor/MapEditor.h>
27
28 #include <Menu/SinglePlayerMenu.h>
29 #include <Menu/MultiPlayerMenu.h>
30 #include <Menu/OptionsMenu.h>
31 #include <Menu/AboutMenu.h>
32
MainMenu()33 MainMenu::MainMenu() : MenuBase()
34 {
35 // set up window
36 SDL_Texture *pBackground = pGFXManager->getUIGraphic(UI_MenuBackground);
37 setBackground(pBackground, false);
38 resize(getTextureSize(pBackground));
39
40 setWindowWidget(&windowWidget);
41
42 // set up pictures in the background
43 // set up pictures in the background
44 SDL_Texture* pPlanetBackground = pGFXManager->getUIGraphic(UI_PlanetBackground);
45 planetPicture.setTexture(pPlanetBackground, false);
46 SDL_Rect dest1 = calcAlignedDrawingRect(pPlanetBackground);
47 dest1.y = dest1.y - getHeight(pPlanetBackground)/2 + 10;
48 windowWidget.addWidget(&planetPicture, dest1);
49
50 SDL_Texture* pDuneLegacy = pGFXManager->getUIGraphic(UI_DuneLegacy);
51 duneLegacy.setTexture(pDuneLegacy, false);
52 SDL_Rect dest2 = calcAlignedDrawingRect(pDuneLegacy);
53 dest2.y = dest2.y + getHeight(pDuneLegacy)/2 + 28;
54 windowWidget.addWidget(&duneLegacy, dest2);
55
56 SDL_Texture* pMenuButtonBorder = pGFXManager->getUIGraphic(UI_MenuButtonBorder);
57 buttonBorder.setTexture(pMenuButtonBorder, false);
58 SDL_Rect dest3 = calcAlignedDrawingRect(pMenuButtonBorder);
59 dest3.y = dest3.y + getHeight(pMenuButtonBorder)/2 + 59;
60 windowWidget.addWidget(&buttonBorder, dest3);
61
62 // set up menu buttons
63 windowWidget.addWidget(&MenuButtons,Point((getRendererWidth() - 160)/2,getRendererHeight()/2 + 64),Point(160,111));
64
65 singlePlayerButton.setText(_("SINGLE PLAYER"));
66 singlePlayerButton.setOnClick(std::bind(&MainMenu::onSinglePlayer, this));
67 MenuButtons.addWidget(&singlePlayerButton);
68 singlePlayerButton.setActive();
69
70 MenuButtons.addWidget(VSpacer::create(3));
71
72 multiPlayerButton.setText(_("MULTIPLAYER"));
73 multiPlayerButton.setOnClick(std::bind(&MainMenu::onMultiPlayer, this));
74 MenuButtons.addWidget(&multiPlayerButton);
75
76 MenuButtons.addWidget(VSpacer::create(3));
77
78 // MenuButtons.addWidget(VSpacer::create(16));
79 mapEditorButton.setText(_("MAP EDITOR"));
80 mapEditorButton.setOnClick(std::bind(&MainMenu::onMapEditor, this));
81 MenuButtons.addWidget(&mapEditorButton);
82
83 MenuButtons.addWidget(VSpacer::create(3));
84
85 optionsButton.setText(_("OPTIONS"));
86 optionsButton.setOnClick(std::bind(&MainMenu::onOptions, this));
87 MenuButtons.addWidget(&optionsButton);
88
89 MenuButtons.addWidget(VSpacer::create(3));
90
91 aboutButton.setText(_("ABOUT"));
92 aboutButton.setOnClick(std::bind(&MainMenu::onAbout, this));
93 MenuButtons.addWidget(&aboutButton);
94
95 MenuButtons.addWidget(VSpacer::create(3));
96
97 quitButton.setText(_("QUIT"));
98 quitButton.setOnClick(std::bind(&MainMenu::onQuit, this));
99 MenuButtons.addWidget(&quitButton);
100 }
101
~MainMenu()102 MainMenu::~MainMenu() {
103 }
104
showMenu()105 int MainMenu::showMenu()
106 {
107 musicPlayer->changeMusic(MUSIC_MENU);
108
109 return MenuBase::showMenu();
110 }
111
onSinglePlayer()112 void MainMenu::onSinglePlayer() {
113 SinglePlayerMenu* pSinglePlayerMenu = new SinglePlayerMenu();
114 pSinglePlayerMenu->showMenu();
115 delete pSinglePlayerMenu;
116 }
117
onMultiPlayer()118 void MainMenu::onMultiPlayer() {
119 MultiPlayerMenu* pMultiPlayerMenu = new MultiPlayerMenu();
120 pMultiPlayerMenu->showMenu();
121 delete pMultiPlayerMenu;
122 }
123
onMapEditor()124 void MainMenu::onMapEditor() {
125 MapEditor *pMapEditor = new MapEditor();
126 pMapEditor->RunEditor();
127 delete pMapEditor;
128 }
129
130
onOptions()131 void MainMenu::onOptions() {
132 OptionsMenu* pOptionsMenu = new OptionsMenu();
133 int ret = pOptionsMenu->showMenu();
134 delete pOptionsMenu;
135
136 if(ret == MENU_QUIT_REINITIALIZE) {
137 quit(MENU_QUIT_REINITIALIZE);
138 }
139 }
140
onAbout()141 void MainMenu::onAbout() {
142 AboutMenu* myAbout = new AboutMenu();
143 myAbout->showMenu();
144 delete myAbout;
145 }
146
onQuit()147 void MainMenu::onQuit() {
148 quit();
149 }
150