1 /*
2  * Zaz
3  * Copyright (C) Remigiusz Dybka 2009 <remigiusz.dybka@gmail.com>
4  *
5  Zaz is free software: you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the
7  Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Zaz is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  See the GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __MAINMENU_H__
20 #define __MAINMENU_H__
21 
22 #include <vector>
23 
24 #include "common.h"
25 #include "menu.h"
26 #include "scene.h"
27 #include "level.h"
28 #include "ballpath.h"
29 #include "game.h"
30 #include "lineeditor.h"
31 #include "levelset.h"
32 #include "hiscores.h"
33 
34 struct LevelDesc
35 {
36     Level lev;
37     GLuint tex;
38     bool locked;
39 
LevelDescLevelDesc40     LevelDesc(const char *philename)
41             : lev(philename, true), tex(0), locked(true) {};
42 
LevelDescLevelDesc43     LevelDesc()
44             : tex(0), locked(true) {};
45 
~LevelDescLevelDesc46     ~LevelDesc()
47     {
48         if (tex)
49         {
50             glDeleteTextures(1, &tex);
51         }
52     }
53 };
54 
55 struct CreditsLine
56 {
57     bool fat;
58     string txt;
59 
60     CreditsLine(string txt, bool fat = false)
fatCreditsLine61             : fat(fat), txt(txt) {};
62 };
63 
64 class MainMenu : public Scenes::Scene
65 {
66     friend void menuBackHandler(void *ptr);
67     friend void optionsMenuCancelHandler(void *ptr);
68     friend void optionsMenuApplyHandler(void *ptr);
69     friend void startMenuOptionsHandler(void *ptr);
70     friend void startMenuExitHandler(void *ptr);
71     friend void startMenuStartHandler(void *ptr);
72     friend void startMenuCreditsHandler(void *ptr);
73     friend void browserMenuLeftHandler(void *ptr);
74     friend void browserMenuRightHandler(void *ptr);
75     friend void startMenuShowProfilesHandler(void *ptr);
76     friend void profileActionsMenuNewHandler(void *ptr);
77     friend void profileActionsMenuDeleteHandler(void *ptr);
78     friend void profileActionsMenuUseHandler(void *ptr);
79 
80     const static int browserNLevelsPerPage = 3;
81     const static uint browserThumbSpacing = 5;
82     const static uint hiScoreWaitPageSec = 10;
83     const static int linesPerHiScorePage = 10;
84 
85     double lmx;
86     double lmy;
87 
88     Menu startMenu;
89     Menu optionsMenu;
90     Menu creditsMenu;
91     Menu browserMenu;
92     Menu profileActionsMenu;
93     Menu profileListMenu;
94     LineEditor *newProfileEditor;
95     Menu *currentMenu;
96 
97     GLuint logoTex;
98 
99     Level menuLev;
100 
101     GLuint ballText[NBALLCOLORS + BONUS_BOMB + 2];
102     std::vector<BallPath> bp;
103     vector<LevelSet> sets;
104     vector<string> setNames;
105     vector<GLuint> setTex;
106 
107     int nBallPaths;
108 
109     Scenes::Sample *music;
110     bool renderHiscores;
111     bool showCredits;
112     bool showBrowser;
113     bool showProfiles;
114     bool showNewProfile;
115     bool showSets;
116 
117     void StartMusic();
118     void StopMusic();
119 
120     bool oldFullscreen;
121     string oldRes;
122     bool oldColourHints;
123     string oldLanguage;
124     int oldMusicVol;
125     void CenterMsg(string msg, double y, FTFont *font, double size = 0.2);
126     void LoadTextures();
127     void LoadLevelSets();
128     void FixLevelLocks();
129     void CreateOptionsMenu();
130     void CreateCredits();
131 
132     GLuint logoGpl;
133     LevelDesc *levels;
134     int nleveldesc;
135     vector<string> profileNames;
136     vector<CreditsLine> credits;
137 
138     bool startup;
139     float startupProgress;
140     float startupProgressSteps;
141     void RenderStartupProgress();
142 
143     double browserScrollOffset;
144     int browserScrollOffsetDest;
145     int browserSelectedLevel;
146     int browserMouseOverLevel;
147     bool browserUsedKeyboard;
148 
149     uint selectedSet;
150     void FillLevelDesc();
151 
152     std::vector<ReportPage> hiScoreRep;
153     uint hiScorePage;
154     uint hiScoreTimeout;
155     int creditsScroll;
156     const static int creditsScrollClearance = 900;
157 
158 public:
159     MainMenu(SDL_Surface *surf, uint fps = Scenes::DEFAULT_FPS);
160     ~MainMenu();
161     void GLSetup();
162     void Render(ulong frame);
163 
164 
165     void Logic(ulong frame);
166 };
167 
168 void menuBackHandler(void *ptr);
169 void optionsMenuCancelHandler(void *ptr);
170 void optionsMenuApplyHandler(void *ptr);
171 void startMenuOptionsHandler(void *ptr);
172 void startMenuExitHandler(void *ptr);
173 void startMenuStartHandler(void *ptr);
174 void startMenuCreditsHandler(void *ptr);
175 void startMenuShowProfilesHandler(void *ptr);
176 void profileActionsMenuNewHandler(void *ptr);
177 void profileActionsMenuDeleteHandler(void *ptr);
178 void profileActionsMenuUseHandler(void *ptr);
179 
180 void browserMenuLeftHandler(void *ptr);
181 void browserMenuRightHandler(void *ptr);
182 
183 #endif //__MAINMENU_H__
184