1 /*
2 * Copyright 2010-2014 OpenXcom Developers.
3 *
4 * This file is part of OpenXcom.
5 *
6 * OpenXcom is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * OpenXcom is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "OptionsBattlescapeState.h"
20 #include <sstream>
21 #include "../Engine/Game.h"
22 #include "../Resource/ResourcePack.h"
23 #include "../Engine/Language.h"
24 #include "../Engine/Palette.h"
25 #include "../Interface/TextButton.h"
26 #include "../Interface/ToggleTextButton.h"
27 #include "../Interface/Window.h"
28 #include "../Interface/Text.h"
29 #include "../Interface/Slider.h"
30 #include "../Interface/ComboBox.h"
31 #include "../Engine/Action.h"
32 #include "../Engine/Options.h"
33
34 namespace OpenXcom
35 {
36
37 /**
38 * Initializes all the elements in the Battlescape Options screen.
39 * @param game Pointer to the core game.
40 * @param origin Game section that originated this state.
41 */
OptionsBattlescapeState(Game * game,OptionsOrigin origin)42 OptionsBattlescapeState::OptionsBattlescapeState(Game *game, OptionsOrigin origin) : OptionsBaseState(game, origin)
43 {
44 setCategory(_btnBattlescape);
45
46 // Create objects
47 _txtEdgeScroll = new Text(114, 9, 94, 8);
48 _cbxEdgeScroll = new ComboBox(this, 104, 16, 94, 18);
49
50 _txtDragScroll = new Text(114, 9, 206, 8);
51 _cbxDragScroll = new ComboBox(this, 104, 16, 206, 18);
52
53 _txtScrollSpeed = new Text(114, 9, 94, 40);
54 _slrScrollSpeed = new Slider(104, 16, 94, 50);
55
56 _txtFireSpeed = new Text(114, 9, 206, 40);
57 _slrFireSpeed = new Slider(104, 16, 206, 50);
58
59 _txtXcomSpeed = new Text(114, 9, 94, 72);
60 _slrXcomSpeed = new Slider(104, 16, 94, 82);
61
62 _txtAlienSpeed = new Text(114, 9, 206, 72);
63 _slrAlienSpeed = new Slider(104, 16, 206, 82);
64
65 _txtPathPreview = new Text(114, 9, 94, 100);
66 _btnArrows = new ToggleTextButton(104, 16, 94, 110);
67 _btnTuCost = new ToggleTextButton(104, 16, 94, 128);
68
69 _txtOptions = new Text(114, 9, 206, 100);
70 _btnTooltips = new ToggleTextButton(104, 16, 206, 110);
71 _btnDeaths = new ToggleTextButton(104, 16, 206, 128);
72
73 add(_txtEdgeScroll);
74 add(_txtDragScroll);
75
76 add(_txtScrollSpeed);
77 add(_slrScrollSpeed);
78
79 add(_txtFireSpeed);
80 add(_slrFireSpeed);
81
82 add(_txtXcomSpeed);
83 add(_slrXcomSpeed);
84
85 add(_txtAlienSpeed);
86 add(_slrAlienSpeed);
87
88 add(_txtPathPreview);
89 add(_btnArrows);
90 add(_btnTuCost);
91
92 add(_txtOptions);
93 add(_btnTooltips);
94 add(_btnDeaths);
95
96 add(_cbxEdgeScroll);
97 add(_cbxDragScroll);
98
99 centerAllSurfaces();
100
101 // Set up objects
102 _txtEdgeScroll->setColor(Palette::blockOffset(8)+10);
103 _txtEdgeScroll->setText(tr("STR_EDGE_SCROLL"));
104
105 std::vector<std::string> edgeScrolls;
106 edgeScrolls.push_back("STR_DISABLED");
107 edgeScrolls.push_back("STR_TRIGGER_SCROLL");
108 edgeScrolls.push_back("STR_AUTO_SCROLL");
109
110 _cbxEdgeScroll->setColor(Palette::blockOffset(15)-1);
111 _cbxEdgeScroll->setOptions(edgeScrolls);
112 _cbxEdgeScroll->setSelected(Options::battleEdgeScroll);
113 _cbxEdgeScroll->onChange((ActionHandler)&OptionsBattlescapeState::cbxEdgeScrollChange);
114 _cbxEdgeScroll->setTooltip("STR_EDGE_SCROLL_DESC");
115 _cbxEdgeScroll->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
116 _cbxEdgeScroll->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
117
118 _txtDragScroll->setColor(Palette::blockOffset(8)+10);
119 _txtDragScroll->setText(tr("STR_DRAG_SCROLL"));
120
121 std::vector<std::string> dragScrolls;
122 dragScrolls.push_back("STR_DISABLED");
123 dragScrolls.push_back("STR_LEFT_MOUSE_BUTTON");
124 dragScrolls.push_back("STR_MIDDLE_MOUSE_BUTTON");
125 dragScrolls.push_back("STR_RIGHT_MOUSE_BUTTON");
126
127 _cbxDragScroll->setColor(Palette::blockOffset(15)-1);
128 _cbxDragScroll->setOptions(dragScrolls);
129 _cbxDragScroll->setSelected(Options::battleDragScrollButton);
130 _cbxDragScroll->onChange((ActionHandler)&OptionsBattlescapeState::cbxDragScrollChange);
131 _cbxDragScroll->setTooltip("STR_DRAG_SCROLL_DESC");
132 _cbxDragScroll->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
133 _cbxDragScroll->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
134
135 _txtScrollSpeed->setColor(Palette::blockOffset(8)+10);
136 _txtScrollSpeed->setText(tr("STR_SCROLL_SPEED"));
137
138 _slrScrollSpeed->setColor(Palette::blockOffset(15)-1);
139 _slrScrollSpeed->setRange(2, 20);
140 _slrScrollSpeed->setValue(Options::battleScrollSpeed);
141 _slrScrollSpeed->onChange((ActionHandler)&OptionsBattlescapeState::slrScrollSpeedChange);
142 _slrScrollSpeed->setTooltip("STR_SCROLL_SPEED_BATTLE_DESC");
143 _slrScrollSpeed->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
144 _slrScrollSpeed->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
145
146 _txtFireSpeed->setColor(Palette::blockOffset(8)+10);
147 _txtFireSpeed->setText(tr("STR_FIRE_SPEED"));
148
149 _slrFireSpeed->setColor(Palette::blockOffset(15)-1);
150 _slrFireSpeed->setRange(1, 20);
151 _slrFireSpeed->setValue(Options::battleFireSpeed);
152 _slrFireSpeed->onChange((ActionHandler)&OptionsBattlescapeState::slrFireSpeedChange);
153 _slrFireSpeed->setTooltip("STR_FIRE_SPEED_DESC");
154 _slrFireSpeed->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
155 _slrFireSpeed->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
156
157 _txtXcomSpeed->setColor(Palette::blockOffset(8)+10);
158 _txtXcomSpeed->setText(tr("STR_PLAYER_MOVEMENT_SPEED"));
159
160 _slrXcomSpeed->setColor(Palette::blockOffset(15)-1);
161 _slrXcomSpeed->setRange(40, 1);
162 _slrXcomSpeed->setValue(Options::battleXcomSpeed);
163 _slrXcomSpeed->onChange((ActionHandler)&OptionsBattlescapeState::slrXcomSpeedChange);
164 _slrXcomSpeed->setTooltip("STR_PLAYER_MOVEMENT_SPEED_DESC");
165 _slrXcomSpeed->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
166 _slrXcomSpeed->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
167
168 _txtAlienSpeed->setColor(Palette::blockOffset(8)+10);
169 _txtAlienSpeed->setText(tr("STR_COMPUTER_MOVEMENT_SPEED"));
170
171 _slrAlienSpeed->setColor(Palette::blockOffset(15)-1);
172 _slrAlienSpeed->setRange(40, 1);
173 _slrAlienSpeed->setValue(Options::battleAlienSpeed);
174 _slrAlienSpeed->onChange((ActionHandler)&OptionsBattlescapeState::slrAlienSpeedChange);
175 _slrAlienSpeed->setTooltip("STR_COMPUTER_MOVEMENT_SPEED_DESC");
176 _slrAlienSpeed->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
177 _slrAlienSpeed->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
178
179 _txtPathPreview->setColor(Palette::blockOffset(8)+10);
180 _txtPathPreview->setText(tr("STR_PATH_PREVIEW"));
181
182 _btnArrows->setColor(Palette::blockOffset(15)-1);
183 _btnArrows->setText(tr("STR_PATH_ARROWS"));
184 _btnArrows->setPressed((Options::battleNewPreviewPath & PATH_ARROWS) != 0);
185 _btnArrows->onMouseClick((ActionHandler)&OptionsBattlescapeState::btnPathPreviewClick);
186 _btnArrows->setTooltip("STR_PATH_ARROWS_DESC");
187 _btnArrows->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
188 _btnArrows->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
189
190 _btnTuCost->setColor(Palette::blockOffset(15)-1);
191 _btnTuCost->setText(tr("STR_PATH_TIME_UNIT_COST"));
192 _btnTuCost->setPressed((Options::battleNewPreviewPath & PATH_TU_COST) != 0);
193 _btnTuCost->onMouseClick((ActionHandler)&OptionsBattlescapeState::btnPathPreviewClick);
194 _btnTuCost->setTooltip("STR_PATH_TIME_UNIT_COST_DESC");
195 _btnTuCost->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
196 _btnTuCost->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
197
198 _txtOptions->setColor(Palette::blockOffset(8)+10);
199 _txtOptions->setText(tr("STR_USER_INTERFACE_OPTIONS"));
200
201 _btnTooltips->setColor(Palette::blockOffset(15)-1);
202 _btnTooltips->setText(tr("STR_TOOLTIPS"));
203 _btnTooltips->setPressed(Options::battleTooltips);
204 _btnTooltips->onMouseClick((ActionHandler)&OptionsBattlescapeState::btnTooltipsClick);
205 _btnTooltips->setTooltip("STR_TOOLTIPS_DESC");
206 _btnTooltips->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
207 _btnTooltips->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
208
209 _btnDeaths->setColor(Palette::blockOffset(15)-1);
210 _btnDeaths->setText(tr("STR_DEATH_NOTIFICATIONS"));
211 _btnDeaths->setPressed(Options::battleNotifyDeath);
212 _btnDeaths->onMouseClick((ActionHandler)&OptionsBattlescapeState::btnDeathsClick);
213 _btnDeaths->setTooltip("STR_DEATH_NOTIFICATIONS_DESC");
214 _btnDeaths->onMouseIn((ActionHandler)&OptionsBattlescapeState::txtTooltipIn);
215 _btnDeaths->onMouseOut((ActionHandler)&OptionsBattlescapeState::txtTooltipOut);
216 }
217
218 /**
219 *
220 */
~OptionsBattlescapeState()221 OptionsBattlescapeState::~OptionsBattlescapeState()
222 {
223
224 }
225
226 /**
227 * Changes the Edge Scroll option.
228 * @param action Pointer to an action.
229 */
cbxEdgeScrollChange(Action *)230 void OptionsBattlescapeState::cbxEdgeScrollChange(Action *)
231 {
232 Options::battleEdgeScroll = (ScrollType)_cbxEdgeScroll->getSelected();
233 }
234
235 /**
236 * Changes the Drag Scroll option.
237 * @param action Pointer to an action.
238 */
cbxDragScrollChange(Action *)239 void OptionsBattlescapeState::cbxDragScrollChange(Action *)
240 {
241 Options::battleDragScrollButton = _cbxDragScroll->getSelected();
242 }
243
244 /**
245 * Updates the scroll speed.
246 * @param action Pointer to an action.
247 */
slrScrollSpeedChange(Action *)248 void OptionsBattlescapeState::slrScrollSpeedChange(Action *)
249 {
250 Options::battleScrollSpeed = _slrScrollSpeed->getValue();
251 }
252
253 /**
254 * Updates the fire speed.
255 * @param action Pointer to an action.
256 */
slrFireSpeedChange(Action *)257 void OptionsBattlescapeState::slrFireSpeedChange(Action *)
258 {
259 Options::battleFireSpeed = _slrFireSpeed->getValue();
260 }
261
262 /**
263 * Updates the X-COM movement speed.
264 * @param action Pointer to an action.
265 */
slrXcomSpeedChange(Action *)266 void OptionsBattlescapeState::slrXcomSpeedChange(Action *)
267 {
268 Options::battleXcomSpeed = _slrXcomSpeed->getValue();
269 }
270
271 /**
272 * Updates the alien movement speed.
273 * @param action Pointer to an action.
274 */
slrAlienSpeedChange(Action *)275 void OptionsBattlescapeState::slrAlienSpeedChange(Action *)
276 {
277 Options::battleAlienSpeed = _slrAlienSpeed->getValue();
278 }
279
280 /**
281 * Updates the path preview options.
282 * @param action Pointer to an action.
283 */
btnPathPreviewClick(Action *)284 void OptionsBattlescapeState::btnPathPreviewClick(Action *)
285 {
286 int mode = PATH_NONE;
287 if (_btnArrows->getPressed())
288 {
289 mode |= PATH_ARROWS;
290 }
291 if (_btnTuCost->getPressed())
292 {
293 mode |= PATH_TU_COST;
294 }
295 Options::battleNewPreviewPath = (PathPreview)mode;
296 }
297
298 /**
299 * Updates the Tooltips option.
300 * @param action Pointer to an action.
301 */
btnTooltipsClick(Action *)302 void OptionsBattlescapeState::btnTooltipsClick(Action *)
303 {
304 Options::battleTooltips = _btnTooltips->getPressed();
305 }
306
307 /**
308 * Updates the Death Notifications option.
309 * @param action Pointer to an action.
310 */
btnDeathsClick(Action *)311 void OptionsBattlescapeState::btnDeathsClick(Action *)
312 {
313 Options::battleNotifyDeath = _btnDeaths->getPressed();
314 }
315
316
317 }
318