1 /**************************************************************************
2 * PipeWalker game (http://pipewalker.sourceforge.net) *
3 * Copyright (C) 2007-2012 by Artem Senichev <artemsen@gmail.com> *
4 * *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19 #include "mode_settings.h"
20 #include "render.h"
21 #include "settings.h"
22 #include "game.h"
23
24
mode_settings()25 mode_settings::mode_settings()
26 : _btn_ok(render::btn_ok, render::btn_ok_s, PW_BUTTON_X1, PW_BUTTON_Y),
27 _btn_cancel(render::btn_cancel, render::btn_cancel_s, PW_BUTTON_X4, PW_BUTTON_Y),
28 _wrap_mode (true, -0.6f, -0.3f, 0.7f),
29 _rnd_mode(false, -0.6f, -1.0f, 0.7f),
30 _sound_mode(true, -0.6f, -2.3f, 0.7f),
31 _prev_theme(render::btn_prev, render::btn_prev_s, -2.3f, -3.5f, 0.7f),
32 _next_theme(render::btn_next, render::btn_next_s, 2.3f, -3.5f, 0.7f),
33 _sett_size(level::sz_normal),
34 _sett_wrap(true),
35 _sett_rnd(false),
36 _sett_sound(true)
37 {
38 _map_size[0].setup(false, -0.6f, 2.9f, 0.7f, level::sz_small);
39 _map_size[1].setup(false, -0.6f, 2.2f, 0.7f, level::sz_normal);
40 _map_size[2].setup(false, -0.6f, 1.5f, 0.7f, level::sz_big);
41 _map_size[3].setup(false, -0.6f, 0.8f, 0.7f, level::sz_extra);
42 }
43
44
draw(const float alpha)45 bool mode_settings::draw(const float alpha)
46 {
47 const char* theme_name = settings::theme();
48 assert(theme_name);
49
50 render& renderer = render::instance();
51 renderer.draw_text(-2.0f, 5.0f, 0.4f, alpha, "Version " PACKAGE_VERSION);
52 renderer.draw_text(-4.6f, 4.5f, 0.9f, alpha, "Game settings");
53
54 renderer.draw_text(-3.6f, 3.2f, 0.7f, alpha, "Map:");
55 renderer.draw_text( 0.0f, 3.2f, 0.7f, alpha, "Small");
56 renderer.draw_text( 0.0f, 2.5f, 0.7f, alpha, "Normal");
57 renderer.draw_text( 0.0f, 1.8f, 0.7f, alpha, "Big");
58 renderer.draw_text( 0.0f, 1.1f, 0.7f, alpha, "Extra");
59
60 renderer.draw_text( 0.0f, 0.0f, 0.7f, alpha, "Wrap mode");
61 renderer.draw_text( 0.0f, -0.7f, 0.7f, alpha, "Random");
62
63 renderer.draw_text(-4.6f, -2.0f, 0.7f, alpha, "Sound:");
64
65 renderer.draw_text(-1.4f, -3.2f, 0.7f, alpha, "Theme");
66 renderer.draw_text(0.0f - ((static_cast<float>(strlen(theme_name)) / 2.0f) * 0.55f), -4.0f, 0.7f, alpha, theme_name);
67
68 renderer.draw_text(-3.65f, -5.2f, 0.35f, alpha, "(C) 2007-2012 Artem Senichev");
69 renderer.draw_text(-1.90f, -5.6f, 0.35f, alpha, "Moscow, Russia");
70
71 bool redisplay = false;
72
73 //Draw buttons
74 redisplay |= _map_size.draw(alpha);
75 redisplay |= _wrap_mode.draw(alpha);
76 redisplay |= _rnd_mode.draw(alpha);
77 redisplay |= _sound_mode.draw(alpha);
78 redisplay |= _prev_theme.draw(alpha);
79 redisplay |= _next_theme.draw(alpha);
80 redisplay |= _btn_ok.draw(alpha);
81 redisplay |= _btn_cancel.draw(alpha);
82
83 return redisplay;
84 }
85
86
on_mouse_move(const float x,const float y)87 bool mode_settings::on_mouse_move(const float x, const float y)
88 {
89 bool redisplay = false;
90
91 redisplay |= _map_size.on_mouse_move(x, y);
92 redisplay |= _wrap_mode.on_mouse_move(x, y);
93 redisplay |= _rnd_mode.on_mouse_move(x, y);
94 redisplay |= _sound_mode.on_mouse_move(x, y);
95 redisplay |= _prev_theme.on_mouse_move(x, y);
96 redisplay |= _next_theme.on_mouse_move(x, y);
97 redisplay |= _btn_ok.on_mouse_move(x, y);
98 redisplay |= _btn_cancel.on_mouse_move(x, y);
99
100 return redisplay;
101
102 }
103
104
on_mouse_click(const float x,const float y,const Uint8 btn)105 bool mode_settings::on_mouse_click(const float x, const float y, const Uint8 btn)
106 {
107 if (!(btn & SDL_BUTTON(SDL_BUTTON_LEFT)))
108 return false;
109
110 if (_btn_cancel.cross(x, y))
111 return true;
112 if (_btn_ok.cross(x, y)) {
113 _sett_size = static_cast<level::size>(_map_size.get_state());
114 _sett_wrap = _wrap_mode.get_state();
115 _sett_rnd = _rnd_mode.get_state();
116 _sett_sound = _sound_mode.get_state();
117 return true;
118 }
119
120 const bool next_theme = _next_theme.cross(x, y);
121 const bool prev_theme = _prev_theme.cross(x, y);
122 if (next_theme || prev_theme)
123 game::load_next_theme(next_theme);
124 else if (_wrap_mode.cross(x, y))
125 _wrap_mode.invert_state();
126 else if (_rnd_mode.cross(x, y))
127 _rnd_mode.invert_state();
128 else if (_sound_mode.cross(x, y))
129 _sound_mode.invert_state();
130 else
131 _map_size.on_mouse_click(x, y);
132
133 return false;
134 }
135
136
initialize(const level::size sz,const bool wrap,const bool rndm,const bool sound)137 void mode_settings::initialize(const level::size sz, const bool wrap, const bool rndm, const bool sound)
138 {
139 _map_size.set_state(sz);
140 _wrap_mode.set_state(wrap);
141 _rnd_mode.set_state(rndm);
142 _sound_mode.set_state(sound);
143 _sett_size = sz;
144 _sett_wrap = wrap;
145 _sett_rnd = rndm;
146 _sett_sound = sound;
147 }
148
149
reset()150 void mode_settings::reset()
151 {
152 initialize(_sett_size, _sett_wrap, _sett_rnd, _sett_sound);
153 }
154