4 * Created on: Nov 29, 2012
8 #include "ConfigMenu.h"
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"
18 using common::GameState;
19 using geometry::Vector;
21 using graphics::Frame;
25 ConfigMenu::ConfigMenu(PartyMenu *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);
35 void ConfigMenu::OnEnterState(SDL_Surface *) {
39 void ConfigMenu::OnExitState(SDL_Surface *) {
43 void ConfigMenu::OnResumeState(SDL_Surface *) {
47 void ConfigMenu::OnPauseState(SDL_Surface *) {
52 void ConfigMenu::OnResize(int width, int height) {
57 int ConfigMenu::Width() const {
58 return parent->Width();
61 int ConfigMenu::Height() const {
62 return parent->Height();
66 void ConfigMenu::HandleEvents(const Input &input) {
67 if (input.JustPressed(Input::ACTION_B)) {
70 if (input.JustPressed(Input::PAD_DOWN)) {
73 if (input.JustPressed(Input::PAD_UP)) {
74 configMenu.PreviousRow();
77 GameState &state(*parent->Game().state);
80 switch (configMenu.Selected()) {
82 property = &state.messageSpeed;
86 property = &state.battleCursor;
90 property = &state.statusCursor;
94 property = &state.music;
98 if (input.JustPressed(Input::ACTION_A) || input.JustPressed(Input::PAD_RIGHT)) {
99 *property = (*property + 1) % mod;
101 if (input.JustPressed(Input::PAD_LEFT)) {
102 *property = (*property + mod - 1) % mod;
106 void ConfigMenu::UpdateWorld(float deltaT) {
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);
118 parent->RenderBackground(screen);
119 RenderHeadline(screen, offset + headlineOffset);
120 RenderMenu(screen, offset + menuOffset);
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());
129 frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
130 font.DrawString(parent->Res().mainMenuConfigText, screen, offset + textOffset, 6);
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());
142 frame.Draw(screen, offset, 30 * font.CharWidth(), 14 * font.CharHeight());
143 configMenu.Draw(screen, offset + menuOffset);
145 Vector<int> lineOffset(
146 menuOffset.X() + configMenu.Width() + 2 * font.CharWidth(),
148 Vector<int> colOffset(lineOffset);
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();
154 inactiveFont.DrawString(res.configMessageSpeedFast, screen, offset + colOffset);
155 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedFast) + inactiveFont.CharWidth();
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();
161 inactiveFont.DrawString(res.configMessageSpeedNormal, screen, offset + colOffset);
162 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedNormal) + inactiveFont.CharWidth();
164 if (state.messageSpeed == GameState::MESSAGE_SPEED_SLOW) {
165 font.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
167 inactiveFont.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
170 lineOffset.Y() += configMenu.RowHeight();
171 colOffset = lineOffset;
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();
177 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
178 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
180 if (state.battleCursor == GameState::CURSOR_MEMORY) {
181 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
183 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
186 lineOffset.Y() += configMenu.RowHeight();
187 colOffset = lineOffset;
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();
193 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
194 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
196 if (state.statusCursor == GameState::CURSOR_MEMORY) {
197 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
199 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
202 lineOffset.Y() += configMenu.RowHeight();
203 colOffset = lineOffset;
205 if (state.music == GameState::MUSIC_STEREO) {
206 font.DrawString(res.configMusicStereo, screen, offset + colOffset);
207 colOffset.X() += font.StringWidth(res.configMusicStereo) + font.CharWidth();
209 inactiveFont.DrawString(res.configMusicStereo, screen, offset + colOffset);
210 colOffset.X() += inactiveFont.StringWidth(res.configMusicStereo) + inactiveFont.CharWidth();
212 if (state.music == GameState::MUSIC_MONO) {
213 font.DrawString(res.configMusicMono, screen, offset + colOffset);
215 inactiveFont.DrawString(res.configMusicMono, screen, offset + colOffset);