1 #include "ConfigMenu.h"
5 #include "../common/GameConfig.h"
6 #include "../common/GameState.h"
7 #include "../graphics/Font.h"
8 #include "../graphics/Frame.h"
11 using common::GameState;
12 using geometry::Vector;
14 using graphics::Frame;
18 ConfigMenu::ConfigMenu(PartyMenu *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);
28 void ConfigMenu::OnEnterState(SDL_Surface *) {
32 void ConfigMenu::OnExitState(SDL_Surface *) {
36 void ConfigMenu::OnResumeState(SDL_Surface *) {
40 void ConfigMenu::OnPauseState(SDL_Surface *) {
45 void ConfigMenu::OnResize(int width, int height) {
50 int ConfigMenu::Width() const {
51 return parent->Width();
54 int ConfigMenu::Height() const {
55 return parent->Height();
59 void ConfigMenu::HandleEvents(const Input &input) {
60 if (input.JustPressed(Input::ACTION_B)) {
63 if (input.JustPressed(Input::PAD_DOWN)) {
66 if (input.JustPressed(Input::PAD_UP)) {
67 configMenu.PreviousRow();
70 GameState &state(*parent->Game().state);
73 switch (configMenu.Selected()) {
75 property = &state.messageSpeed;
79 property = &state.battleCursor;
83 property = &state.statusCursor;
87 property = &state.music;
91 if (input.JustPressed(Input::ACTION_A) || input.JustPressed(Input::PAD_RIGHT)) {
92 *property = (*property + 1) % mod;
94 if (input.JustPressed(Input::PAD_LEFT)) {
95 *property = (*property + mod - 1) % mod;
99 void ConfigMenu::UpdateWorld(float deltaT) {
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);
111 parent->RenderBackground(screen);
112 RenderHeadline(screen, offset + headlineOffset);
113 RenderMenu(screen, offset + menuOffset);
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());
122 frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
123 font.DrawString(parent->Res().mainMenuConfigText, screen, offset + textOffset, 6);
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());
135 frame.Draw(screen, offset, 30 * font.CharWidth(), 14 * font.CharHeight());
136 configMenu.Draw(screen, offset + menuOffset);
138 Vector<int> lineOffset(
139 menuOffset.X() + configMenu.Width() + 2 * font.CharWidth(),
141 Vector<int> colOffset(lineOffset);
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();
147 inactiveFont.DrawString(res.configMessageSpeedFast, screen, offset + colOffset);
148 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedFast) + inactiveFont.CharWidth();
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();
154 inactiveFont.DrawString(res.configMessageSpeedNormal, screen, offset + colOffset);
155 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedNormal) + inactiveFont.CharWidth();
157 if (state.messageSpeed == GameState::MESSAGE_SPEED_SLOW) {
158 font.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
160 inactiveFont.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
163 lineOffset.Y() += configMenu.RowHeight();
164 colOffset = lineOffset;
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();
170 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
171 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
173 if (state.battleCursor == GameState::CURSOR_MEMORY) {
174 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
176 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
179 lineOffset.Y() += configMenu.RowHeight();
180 colOffset = lineOffset;
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();
186 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
187 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
189 if (state.statusCursor == GameState::CURSOR_MEMORY) {
190 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
192 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
195 lineOffset.Y() += configMenu.RowHeight();
196 colOffset = lineOffset;
198 if (state.music == GameState::MUSIC_STEREO) {
199 font.DrawString(res.configMusicStereo, screen, offset + colOffset);
200 colOffset.X() += font.StringWidth(res.configMusicStereo) + font.CharWidth();
202 inactiveFont.DrawString(res.configMusicStereo, screen, offset + colOffset);
203 colOffset.X() += inactiveFont.StringWidth(res.configMusicStereo) + inactiveFont.CharWidth();
205 if (state.music == GameState::MUSIC_MONO) {
206 font.DrawString(res.configMusicMono, screen, offset + colOffset);
208 inactiveFont.DrawString(res.configMusicMono, screen, offset + colOffset);