]> git.localhorst.tv Git - l2e.git/blob - src/menu/ConfigMenu.cpp
removed stupid file headers that eclipse put in
[l2e.git] / src / menu / ConfigMenu.cpp
1 #include "ConfigMenu.h"
2
3 #include "PartyMenu.h"
4 #include "Resources.h"
5 #include "../common/GameConfig.h"
6 #include "../common/GameState.h"
7 #include "../graphics/Font.h"
8 #include "../graphics/Frame.h"
9
10 using app::Input;
11 using common::GameState;
12 using geometry::Vector;
13 using graphics::Font;
14 using graphics::Frame;
15
16 namespace menu {
17
18 ConfigMenu::ConfigMenu(PartyMenu *parent)
19 : parent(parent)
20 , configMenu(*parent->Res().configMenuProperties) {
21         configMenu.Add(parent->Res().configMessageSpeedLabel, 0);
22         configMenu.Add(parent->Res().configBattleCursorLabel, 1);
23         configMenu.Add(parent->Res().configStatusCursorLabel, 2);
24         configMenu.Add(parent->Res().configMusicLabel, 3);
25 }
26
27
28 void ConfigMenu::OnEnterState(SDL_Surface *) {
29
30 }
31
32 void ConfigMenu::OnExitState(SDL_Surface *) {
33
34 }
35
36 void ConfigMenu::OnResumeState(SDL_Surface *) {
37
38 }
39
40 void ConfigMenu::OnPauseState(SDL_Surface *) {
41
42 }
43
44
45 void ConfigMenu::OnResize(int width, int height) {
46
47 }
48
49
50 int ConfigMenu::Width() const {
51         return parent->Width();
52 }
53
54 int ConfigMenu::Height() const {
55         return parent->Height();
56 }
57
58
59 void ConfigMenu::HandleEvents(const Input &input) {
60         if (input.JustPressed(Input::ACTION_B)) {
61                 Ctrl().PopState();
62         }
63         if (input.JustPressed(Input::PAD_DOWN)) {
64                 configMenu.NextRow();
65         }
66         if (input.JustPressed(Input::PAD_UP)) {
67                 configMenu.PreviousRow();
68         }
69
70         GameState &state(*parent->Game().state);
71         int *property(0);
72         int mod(0);
73         switch (configMenu.Selected()) {
74                 case 0:
75                         property = &state.messageSpeed;
76                         mod = 3;
77                         break;
78                 case 1:
79                         property = &state.battleCursor;
80                         mod = 2;
81                         break;
82                 case 2:
83                         property = &state.statusCursor;
84                         mod = 2;
85                         break;
86                 case 3:
87                         property = &state.music;
88                         mod = 2;
89                         break;
90         }
91         if (input.JustPressed(Input::ACTION_A) || input.JustPressed(Input::PAD_RIGHT)) {
92                 *property = (*property + 1) % mod;
93         }
94         if (input.JustPressed(Input::PAD_LEFT)) {
95                 *property = (*property + mod - 1) % mod;
96         }
97 }
98
99 void ConfigMenu::UpdateWorld(float deltaT) {
100
101 }
102
103 void ConfigMenu::Render(SDL_Surface *screen) {
104         const Font &font(*parent->Res().normalFont);
105         const Vector<int> offset((screen->w - Width()) / 2, (screen->h - Height()) / 2);
106         const Vector<int> headlineOffset(
107                         font.CharWidth(), 2 * font.CharHeight() - font.CharHeight() / 8);
108         const Vector<int> menuOffset(
109                         font.CharWidth(), 5 * font.CharHeight() - font.CharHeight() / 8);
110
111         parent->RenderBackground(screen);
112         RenderHeadline(screen, offset + headlineOffset);
113         RenderMenu(screen, offset + menuOffset);
114 }
115
116 void ConfigMenu::RenderHeadline(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
117         const Font &font(*parent->Res().normalFont);
118         const Frame &frame(*parent->Res().statusFrame);
119         const Vector<int> textOffset(
120                         2 * font.CharWidth(), font.CharHeight());
121
122         frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
123         font.DrawString(parent->Res().mainMenuConfigText, screen, offset + textOffset, 6);
124 }
125
126 void ConfigMenu::RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
127         const Resources &res(parent->Res());
128         const Font &font(*res.normalFont);
129         const Font &inactiveFont(*res.inactiveFont);
130         const Frame &frame(*res.statusFrame);
131         const GameState &state(*parent->Game().state);
132         const Vector<int> menuOffset(
133                         3 * font.CharWidth(), 2 * font.CharHeight());
134
135         frame.Draw(screen, offset, 30 * font.CharWidth(), 14 * font.CharHeight());
136         configMenu.Draw(screen, offset + menuOffset);
137
138         Vector<int> lineOffset(
139                         menuOffset.X() + configMenu.Width() + 2 * font.CharWidth(),
140                         menuOffset.Y());
141         Vector<int> colOffset(lineOffset);
142
143         if (state.messageSpeed == GameState::MESSAGE_SPEED_FAST) {
144                 font.DrawString(res.configMessageSpeedFast, screen, offset + colOffset);
145                 colOffset.X() += font.StringWidth(res.configMessageSpeedFast) + font.CharWidth();
146         } else {
147                 inactiveFont.DrawString(res.configMessageSpeedFast, screen, offset + colOffset);
148                 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedFast) + inactiveFont.CharWidth();
149         }
150         if (state.messageSpeed == GameState::MESSAGE_SPEED_NORMAL) {
151                 font.DrawString(res.configMessageSpeedNormal, screen, offset + colOffset);
152                 colOffset.X() += font.StringWidth(res.configMessageSpeedNormal) + font.CharWidth();
153         } else {
154                 inactiveFont.DrawString(res.configMessageSpeedNormal, screen, offset + colOffset);
155                 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedNormal) + inactiveFont.CharWidth();
156         }
157         if (state.messageSpeed == GameState::MESSAGE_SPEED_SLOW) {
158                 font.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
159         } else {
160                 inactiveFont.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
161         }
162
163         lineOffset.Y() += configMenu.RowHeight();
164         colOffset = lineOffset;
165
166         if (state.battleCursor == GameState::CURSOR_CLEAR) {
167                 font.DrawString(res.configCursorClear, screen, offset + colOffset);
168                 colOffset.X() += font.StringWidth(res.configCursorClear) + 2 * font.CharWidth();
169         } else {
170                 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
171                 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
172         }
173         if (state.battleCursor == GameState::CURSOR_MEMORY) {
174                 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
175         } else {
176                 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
177         }
178
179         lineOffset.Y() += configMenu.RowHeight();
180         colOffset = lineOffset;
181
182         if (state.statusCursor == GameState::CURSOR_CLEAR) {
183                 font.DrawString(res.configCursorClear, screen, offset + colOffset);
184                 colOffset.X() += font.StringWidth(res.configCursorClear) + 2 * font.CharWidth();
185         } else {
186                 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
187                 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
188         }
189         if (state.statusCursor == GameState::CURSOR_MEMORY) {
190                 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
191         } else {
192                 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
193         }
194
195         lineOffset.Y() += configMenu.RowHeight();
196         colOffset = lineOffset;
197
198         if (state.music == GameState::MUSIC_STEREO) {
199                 font.DrawString(res.configMusicStereo, screen, offset + colOffset);
200                 colOffset.X() += font.StringWidth(res.configMusicStereo) + font.CharWidth();
201         } else {
202                 inactiveFont.DrawString(res.configMusicStereo, screen, offset + colOffset);
203                 colOffset.X() += inactiveFont.StringWidth(res.configMusicStereo) + inactiveFont.CharWidth();
204         }
205         if (state.music == GameState::MUSIC_MONO) {
206                 font.DrawString(res.configMusicMono, screen, offset + colOffset);
207         } else {
208                 inactiveFont.DrawString(res.configMusicMono, screen, offset + colOffset);
209         }
210 }
211
212 }