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