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