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"
13 using common::GameState;
14 using geometry::Vector;
16 using graphics::Frame;
20 ConfigMenu::ConfigMenu(PartyMenu *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);
30 void ConfigMenu::OnEnterState(SDL_Surface *) {
34 void ConfigMenu::OnExitState(SDL_Surface *) {
38 void ConfigMenu::OnResumeState(SDL_Surface *) {
42 void ConfigMenu::OnPauseState(SDL_Surface *) {
47 void ConfigMenu::OnResize(int width, int height) {
52 int ConfigMenu::Width() const {
53 return parent->Width();
56 int ConfigMenu::Height() const {
57 return parent->Height();
61 void ConfigMenu::HandleEvents(const Input &input) {
62 if (input.JustPressed(Input::ACTION_B)) {
65 if (input.JustPressed(Input::PAD_DOWN)) {
68 if (input.JustPressed(Input::PAD_UP)) {
69 configMenu.PreviousRow();
72 GameState &state(*parent->Game().state);
75 switch (configMenu.Selected()) {
77 property = &state.messageSpeed;
81 property = &state.battleCursor;
85 property = &state.statusCursor;
89 property = &state.music;
93 if (input.JustPressed(Input::ACTION_A) || input.JustPressed(Input::PAD_RIGHT)) {
94 *property = (*property + 1) % mod;
96 if (input.JustPressed(Input::PAD_LEFT)) {
97 *property = (*property + mod - 1) % mod;
101 void ConfigMenu::UpdateWorld(float deltaT) {
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);
113 parent->RenderBackground(screen);
114 RenderHeadline(screen, offset + headlineOffset);
115 RenderMenu(screen, offset + menuOffset);
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());
124 frame.Draw(screen, offset, 10 * font.CharWidth(), 3 * font.CharHeight());
125 font.DrawString(parent->Res().mainMenuConfigText, screen, offset + textOffset, 6);
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());
137 frame.Draw(screen, offset, 30 * font.CharWidth(), 14 * font.CharHeight());
138 configMenu.Draw(screen, offset + menuOffset);
140 Vector<int> lineOffset(
141 menuOffset.X() + configMenu.Width() + 2 * font.CharWidth(),
143 Vector<int> colOffset(lineOffset);
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();
149 inactiveFont.DrawString(res.configMessageSpeedFast, screen, offset + colOffset);
150 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedFast) + inactiveFont.CharWidth();
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();
156 inactiveFont.DrawString(res.configMessageSpeedNormal, screen, offset + colOffset);
157 colOffset.X() += inactiveFont.StringWidth(res.configMessageSpeedNormal) + inactiveFont.CharWidth();
159 if (state.messageSpeed == GameState::MESSAGE_SPEED_SLOW) {
160 font.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
162 inactiveFont.DrawString(res.configMessageSpeedSlow, screen, offset + colOffset);
165 lineOffset.Y() += configMenu.RowHeight();
166 colOffset = lineOffset;
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();
172 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
173 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
175 if (state.battleCursor == GameState::CURSOR_MEMORY) {
176 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
178 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
181 lineOffset.Y() += configMenu.RowHeight();
182 colOffset = lineOffset;
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();
188 inactiveFont.DrawString(res.configCursorClear, screen, offset + colOffset);
189 colOffset.X() += inactiveFont.StringWidth(res.configCursorClear) + 2 * inactiveFont.CharWidth();
191 if (state.statusCursor == GameState::CURSOR_MEMORY) {
192 font.DrawString(res.configCursorMemory, screen, offset + colOffset);
194 inactiveFont.DrawString(res.configCursorMemory, screen, offset + colOffset);
197 lineOffset.Y() += configMenu.RowHeight();
198 colOffset = lineOffset;
200 if (state.music == GameState::MUSIC_STEREO) {
201 font.DrawString(res.configMusicStereo, screen, offset + colOffset);
202 colOffset.X() += font.StringWidth(res.configMusicStereo) + font.CharWidth();
204 inactiveFont.DrawString(res.configMusicStereo, screen, offset + colOffset);
205 colOffset.X() += inactiveFont.StringWidth(res.configMusicStereo) + inactiveFont.CharWidth();
207 if (state.music == GameState::MUSIC_MONO) {
208 font.DrawString(res.configMusicMono, screen, offset + colOffset);
210 inactiveFont.DrawString(res.configMusicMono, screen, offset + colOffset);