aboutsummaryrefslogtreecommitdiff
path: root/engines/sherlock/tattoo/widget_options.cpp
blob: 5dc6fc55b912e913aeda967445fce438ab3e22f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "sherlock/tattoo/widget_options.h"
#include "sherlock/tattoo/tattoo.h"
#include "sherlock/tattoo/tattoo_fixed_text.h"
#include "sherlock/tattoo/tattoo_scene.h"
#include "sherlock/tattoo/tattoo_user_interface.h"

namespace Sherlock {

namespace Tattoo {

WidgetOptions::WidgetOptions(SherlockEngine *vm) : WidgetBase(vm) {
	_midiSliderX = _digiSliderX = 0;
	_selector = _oldSelector = -1;
}

void WidgetOptions::load() {
	Events &events = *_vm->_events;
	TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
	_centerPos = events.mousePos();

	render();

	summonWindow();
	ui._menuMode = OPTION_MODE;
}

void WidgetOptions::handleEvents() {
	TattooEngine &vm = *(TattooEngine *)_vm;
	Events &events = *_vm->_events;
	Music &music = *_vm->_music;
	Screen &screen = *_vm->_screen;
	Sound &sound = *_vm->_sound;
	Talk &talk = *_vm->_talk;
	TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
	Common::Point mousePos = events.mousePos();

	if (talk._talkToAbort) {
		sound.stopSound();
		return;
	}

	// Flag if they started pressing outside the window
	if (events._firstPress && !_bounds.contains(mousePos))
		_outsideMenu = true;

	if (events.kbHit()) {
		ui._keyState = events.getKey();

		// Emulate a mouse release if Enter or Space Bar is pressed
		if (ui._keyState.keycode == Common::KEYCODE_RETURN || ui._keyState.keycode == Common::KEYCODE_SPACE) {
			events._pressed  = events._oldButtons = false;
			events._released = true;
		} else if (ui._keyState.keycode == Common::KEYCODE_ESCAPE) {
			close();
			return;
		} else {
			checkTabbingKeys(11);
		}
	}

	// Check highlighting the various controls
	if (_bounds.contains(mousePos)) {
		_selector = (mousePos.y - _bounds.top) / (_surface.fontHeight() + 7);

		// If one of the sliders has been selected, & the mouse is not pressed, reset the selector to -1
		if ((_selector == 3 || _selector == 6) && !events._pressed)
			_selector = -1;
	} else {
		_selector = -1;
		if (_outsideMenu && (events._released || events._rightReleased)) {
			events.clearEvents();
			close();
			return;
		}
	}

	// If the selected control has changed, redraw the dialog contents
	if (_selector != _oldSelector)
		render(OP_CONTENTS);
	_oldSelector = _selector;

	// Adjust the Volume Sliders (if neccessary) here
	switch (_selector) {
	case 3: {
		// Set Music Volume
		_midiSliderX = mousePos.x - _bounds.left;
		if (_midiSliderX < _surface.widestChar())
			_midiSliderX = _surface.widestChar();
		else
			if (_midiSliderX > _bounds.width() - _surface.widestChar())
				_midiSliderX = _bounds.width() - _surface.widestChar();

		int newVolume = (_midiSliderX - _surface.widestChar()) * 255 / (_bounds.width() - _surface.widestChar() * 2);
		if (newVolume != music._musicVolume) {
			music.setMusicVolume(newVolume);
			vm.saveConfig();
		}

		render(OP_NAMES);
		break;
	}

	case 6: {
		// Set Digitized Volume
		_digiSliderX = mousePos.x - _bounds.left;
		if (_digiSliderX < _surface.widestChar())
			_digiSliderX = _surface.widestChar();
		else if (_digiSliderX > _bounds.width() - _surface.widestChar())
			_digiSliderX = _bounds.width() - _surface.widestChar();

		int temp = sound._soundVolume;
		sound._soundVolume = (_digiSliderX - _surface.widestChar()) * 255 / (_bounds.width() - _surface.widestChar() * 2);
		if (sound._soundVolume != temp) {
			sound.setVolume(sound._soundVolume);
			vm.saveConfig();
		}

		render(OP_NAMES);
		break;
	}

	default:
		break;
	}

	// Option selected
	if (events._released || events._rightReleased) {
		events.clearEvents();
		_outsideMenu = false;
		int temp = _selector;
		_selector = -1;

		switch (temp) {
		case 0:
			// Load Game
			close();
			ui.loadGame();
			break;

		case 1:
			// Save Game
			close();
			ui.saveGame();
			break;

		case 2:
			// Toggle Music
			music._musicOn = !music._musicOn;
			if (!music._musicOn)
				music.stopMusic();
			else
				music.startSong();

			render(OP_NAMES);
			vm.saveConfig();
			break;

		case 4:
			// Toggle Sound Effects
			sound.stopSound();
			sound._digitized = !sound._digitized;

			render(OP_NAMES);
			vm.saveConfig();
			break;

		case 5:
			// Toggle Voices
			sound._voices = !sound._voices;

			render(OP_NAMES);
			vm.saveConfig();
			break;
			
		case 7:
			// Toggle Text Windows
			vm._textWindowsOn = !vm._textWindowsOn;

			render(OP_NAMES);
			vm.saveConfig();
			break;

		case 8: {
			// New Font Style
			int fontNumber = screen.fontNumber() + 1;
			if (fontNumber == 7)
				fontNumber = 0;
			screen.setFont(fontNumber);

			render(OP_ALL);
			vm.saveConfig();
			break;
		}

		case 9:
			// Toggle Transparent Menus
			vm._transparentMenus = !vm._transparentMenus;

			render(OP_NAMES);
			vm.saveConfig();
			break;

		case 10:
			// Quit
			banishWindow();
			ui.doQuitMenu();
			break;

		default:
			break;
		}
		
		_oldSelector = -1;
	}
}

void WidgetOptions::render(OptionRenderMode mode) {
	TattooEngine &vm = *(TattooEngine *)_vm;
	Music &music = *_vm->_music;
	Sound &sound = *_vm->_sound;
	TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
	ImageFile &images = *ui._interfaceImages;
	const char *const OFF_ON[2] = { FIXED(Off), FIXED(On) };

	// Draw the border if necessary
	if (mode == OP_ALL) {
		// Set bounds for the dialog
		Common::String widestString = Common::String::format("%s %s", FIXED(TransparentMenus), FIXED(Off));
		_bounds = Common::Rect(_surface.stringWidth(widestString) + _surface.widestChar() * 2 + 6,
			(_surface.fontHeight() + 7) * 11 + 3);
		_bounds.moveTo(_centerPos.x - _bounds.width() / 2, _centerPos.y - _bounds.height() / 2);

		// Get slider positions
		_midiSliderX = music._musicVolume * (_bounds.width() - _surface.widestChar() * 2) / 255 + _surface.widestChar();
		_digiSliderX = sound._soundVolume * (_bounds.width() - _surface.widestChar() * 2) / 255 + _surface.widestChar();

		// Setup the dialog
		_surface.create(_bounds.width(), _bounds.height());
		_surface.fill(TRANSPARENCY);
		makeInfoArea();

		// Draw the lines separating options in the dialog
		int yp = _surface.fontHeight() + 7;
		for (int idx = 0; idx < 7; ++idx) {
			_surface.transBlitFrom(images[4], Common::Point(0, yp - 1));
			_surface.transBlitFrom(images[5], Common::Point(_surface.w() - images[5]._width, yp - 1));
			_surface.hLine(3, yp, _surface.w() - 4, INFO_TOP);
			_surface.hLine(3, yp + 1, _surface.w() - 4, INFO_MIDDLE);
			_surface.hLine(3, yp + 2, _surface.w() - 4, INFO_BOTTOM);

			yp += _surface.fontHeight() + 7;
			if (idx == 1)
				yp += _surface.fontHeight() + 7;
			else if (idx == 2)
				yp += (_surface.fontHeight() + 7) * 2;
		}
	}

	// Now go through and display all the items that can be highlighted
	for (int idx = 0, yp = 5; idx < 11; ++idx, yp += _surface.fontHeight() + 7) {
		if (mode == OP_ALL || idx == _selector || idx == _oldSelector) {
			if (mode == OP_NAMES)
				_surface.fillRect(Common::Rect(4, yp, _surface.w() - 5, yp + _surface.fontHeight() - 1), TRANSPARENCY);
			byte color = (idx == _selector) ? COMMAND_HIGHLIGHTED : INFO_TOP;
			Common::String str;

			switch (idx) {
			case 0:
				str = FIXED(LoadGame);
				break;

			case 1:
				str = FIXED(SaveGame);
				break;

			case 2:
				str = Common::String::format("%s %s", FIXED(Music), OFF_ON[music._musicOn]);
				break;

			case 3: {
				int num = (_surface.fontHeight() + 4) & 0xfe;
				int sliderY = yp + num / 2 - 8;

				_surface.fillRect(Common::Rect(4, sliderY - (num - 6) / 2, _surface.w() - 5, 
					sliderY - (num - 6) / 2 + num - 1), TRANSPARENCY);
				_surface.fillRect(Common::Rect(_surface.widestChar(), sliderY + 2, 
					_surface.w() - _surface.widestChar() - 1, sliderY + 3), INFO_MIDDLE);
				drawDialogRect(Common::Rect(_surface.widestChar(), sliderY, _surface.w() - _surface.widestChar(), sliderY + 6));
				
				_surface.fillRect(Common::Rect(_midiSliderX - 1, sliderY - (num - 6) / 2 + 2, 
					_midiSliderX + 1, sliderY - (num - 6) / 2 + num - 3), INFO_MIDDLE);
				drawDialogRect(Common::Rect(_midiSliderX - 3, sliderY - (num - 6) / 2, 
					_midiSliderX + 4, sliderY - (num - 6) / 2 + num));
	
				if (_midiSliderX - 4 > _surface.widestChar())
					_surface.fillRect(Common::Rect(_midiSliderX - 4, sliderY, _midiSliderX - 4, sliderY + 4), INFO_BOTTOM);
				if (_midiSliderX + 4 < _surface.w() - _surface.widestChar())
					_surface.fillRect(Common::Rect(_midiSliderX + 4, sliderY, _midiSliderX + 4, sliderY + 4), INFO_BOTTOM);
				break;
			}

			case 4:
				str = Common::String::format("%s %s", FIXED(SoundEffects), OFF_ON[sound._digitized]);
				break;

			case 5:
				str = Common::String::format("%s %s", FIXED(Voices), OFF_ON[sound._voices]);
				break;

			case 6: {
				int num = (_surface.fontHeight() + 4) & 0xfe;
				int sliderY = yp + num / 2 - 8;

				_surface.fillRect(Common::Rect(4, sliderY - (num - 6) / 2, _surface.w() - 5, 
					sliderY - (num - 6) / 2 + num - 1), TRANSPARENCY);
				_surface.fillRect(Common::Rect(_surface.widestChar(), sliderY + 2, _surface.w() - _surface.widestChar() - 1, 
					sliderY + 3), INFO_MIDDLE);
				drawDialogRect(Common::Rect(_surface.widestChar(), sliderY, _surface.w() - _surface.widestChar(), sliderY + 6));
				_surface.fillRect(Common::Rect(_digiSliderX - 1, sliderY - (num - 6) / 2 + 2, _digiSliderX + 1, 
					sliderY - (num - 6) / 2 + num - 3), INFO_MIDDLE);
				drawDialogRect(Common::Rect(_digiSliderX - 3, sliderY - (num - 6) / 2, _digiSliderX + 4, 
					sliderY - (num - 6) / 2 + num));
				if (_digiSliderX - 4 > _surface.widestChar())
					_surface.fillRect(Common::Rect(_digiSliderX - 4, sliderY, _digiSliderX - 4, sliderY + 4), INFO_BOTTOM);
				if (_digiSliderX + 4 < _surface.w() - _surface.widestChar())
					_surface.fillRect(Common::Rect(_digiSliderX + 4, sliderY, _digiSliderX + 4, sliderY + 4), INFO_BOTTOM);
				break;
			}

			case 7:
				if (!sound._voices) {
					color = INFO_BOTTOM;
					str = Common::String::format("%s %s", FIXED(TextWindows), FIXED(On));
				} else {
					str = Common::String::format("%s %s", FIXED(TextWindows), OFF_ON[vm._textWindowsOn]);
				}
				break;

			case 8:
				str = FIXED(ChangeFont);
				break;

			case 9:
				str = Common::String::format("%s %s", FIXED(TransparentMenus), OFF_ON[vm._transparentMenus]);
				break;

			case 10:
				str = FIXED(Quit);
				break;

			default:
				break;
			}

			// Unless we're doing one of the Slider Controls, print the text for the line
			if (idx != 3 && idx != 6) {
				int xp = (_surface.w() - _surface.stringWidth(str)) / 2;
				_surface.writeString(str, Common::Point(xp, yp), color);
			}
		}
	}
}

} // End of namespace Tattoo

} // End of namespace Sherlock