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