1 #include "ConfigMenu.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"
14 using common::GameState;
17 using graphics::Frame;
21 ConfigMenu::ConfigMenu(PartyMenu *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);
31 void ConfigMenu::OnEnterState(SDL_Surface *) {
35 void ConfigMenu::OnExitState(SDL_Surface *) {
39 void ConfigMenu::OnResumeState(SDL_Surface *) {
43 void ConfigMenu::OnPauseState(SDL_Surface *) {
48 void ConfigMenu::OnResize(int width, int height) {
53 int ConfigMenu::Width() const {
54 return parent->Width();
57 int ConfigMenu::Height() const {
58 return parent->Height();
62 void ConfigMenu::HandleEvents(const Input &input) {
63 if (input.JustPressed(Input::ACTION_B)) {
66 if (input.JustPressed(Input::PAD_DOWN)) {
69 if (input.JustPressed(Input::PAD_UP)) {
70 configMenu.PreviousRow();
73 GameState &state(*parent->Game().state);
76 switch (configMenu.Selected()) {
78 property = &state.messageSpeed;
82 property = &state.battleCursor;
86 property = &state.statusCursor;
90 property = &state.music;
94 if (input.JustPressed(Input::ACTION_A) || input.JustPressed(Input::PAD_RIGHT)) {
95 *property = (*property + 1) % mod;
97 if (input.JustPressed(Input::PAD_LEFT)) {
98 *property = (*property + mod - 1) % mod;
102 void ConfigMenu::UpdateWorld(Uint32 deltaT) {
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);
114 parent->RenderBackground(screen);
115 RenderHeadline(screen, offset + headlineOffset);
116 RenderMenu(screen, offset + menuOffset);
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());
125 frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
126 font.DrawString(parent->Res().mainMenuConfigText, screen, offset + textOffset, 6);
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());
138 frame.Draw(screen, offset, 30 * font.CharWidth(), 14 * font.CharHeight());
139 configMenu.Draw(screen, offset + menuOffset);
141 Vector<int> lineOffset(
142 menuOffset.X() + configMenu.Width() + 2 * font.CharWidth(),
144 Vector<int> colOffset(lineOffset);
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();
150 inactiveFont.DrawString(res.configMessageSpeedFast, screen, offset + colOffset);
151 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedFast) + inactiveFont.CharWidth();
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();
157 inactiveFont.DrawString(res.configMessageSpeedNormal, screen, offset + colOffset);
158 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedNormal) + inactiveFont.CharWidth();
160 if (state.messageSpeed == GameState::MESSAGE_SPEED_SLOW) {
161 font.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
163 inactiveFont.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
166 lineOffset.Y() += configMenu.RowHeight();
167 colOffset = lineOffset;
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();
173 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
174 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
176 if (state.battleCursor == GameState::CURSOR_MEMORY) {
177 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
179 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
182 lineOffset.Y() += configMenu.RowHeight();
183 colOffset = lineOffset;
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();
189 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
190 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
192 if (state.statusCursor == GameState::CURSOR_MEMORY) {
193 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
195 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
198 lineOffset.Y() += configMenu.RowHeight();
199 colOffset = lineOffset;
201 if (state.music == GameState::MUSIC_STEREO) {
202 font.DrawString(res.configMusicStereo, screen, offset + colOffset);
203 colOffset.X() += font.StringWidth(res.configMusicStereo) + font.CharWidth();
205 inactiveFont.DrawString(res.configMusicStereo, screen, offset + colOffset);
206 colOffset.X() += inactiveFont.StringWidth(res.configMusicStereo) + inactiveFont.CharWidth();
208 if (state.music == GameState::MUSIC_MONO) {
209 font.DrawString(res.configMusicMono, screen, offset + colOffset);
211 inactiveFont.DrawString(res.configMusicMono, screen, offset + colOffset);