aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/helper.cpp
blob: 622244e1337778670e7d8b4c72e8c031247451cb (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
/* 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.
 *
 */

/*
 * This code is based on the original source code of Lord Avalot d'Argent version 1.3.
 * Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
 */

/*
  ��� ��� ����  ��� ���  �� ���      �����  ��� ��  � ����  ��� ��� ��� �
  ��  ��  �  � � �  ��� ��   �      �  �  �  �  � ���  ����  �  ��  ��� �
  �   � �  ��   ��  ���   �  �      �  �  � ��� �  ��  ���   �  � � ��� ���

                 HELPER           The help system unit. */

#define __helper_implementation__


#include "helper.h"


/*#include "Crt.h"*/
/*#include "Lucerna.h"*/
/*#include "Pingo.h"*/

namespace Avalanche {

struct buttontype {
	char trigger;
	byte whither;
};

const integer buttonsize = 930;

const integer toolbar = 0;
const integer nim = 1;
const integer kbd = 2;
const integer credits = 3;
const integer joystick = 4;
const integer troubleshooting = 5;
const integer story = 6;
const integer mainscreen = 7;
const integer registering = 8;
const integer sound = 9;
const integer mouse = 10;
const integer filer = 11;
const integer back2game = 12;
const integer helponhelp = 13;
const integer pgdn = 14;
const integer pgup = 15;

array<1, 10, buttontype> buttons;
byte highlight_was;

void plot_button(integer y, byte which) {
	untyped_file f;
	pointer p;

	if (y > 200) {
		background(2);    /* Silly buttons. */
		delay(10);
		background(0);
		return;
	}
	getmem(p, buttonsize);
	assign(f, "buttons.avd");
	reset(f, 1);
	seek(f, which * buttonsize);
	blockread(f, p, buttonsize);

	if (y == -177)
		putimage(229, 5, p, 0);
	else
		putimage(470, y, p, 0);
	close(f);
	freemem(p, buttonsize);
}

void getme(byte which);

static untyped_file f;


static void chalk(byte y, string z) {
	outtextxy(16, 41 + y * 10, z);
}



static void getline(string &x) {
	byte fz;

	blockread(f, x[0], 1);
	blockread(f, x[1], (byte)(x[0]));
	for (fz = 1; fz <= length(x); fz ++)
		x[fz] = chr(ord(x[fz]) ^ 177);
}

void getme(byte which) {     /* Help icons are 80x20 */
	string x;
	byte y, fv;
	word offset;


	off;
	assign(f, "help.avd");
	y = 0;
	highlight_was = 177; /* Forget where the highlight was. */
	reset(f, 1);
	seek(f, which * 2);
	blockread(f, offset, 2);
	seek(f, offset);

	getline(x);
	setfillstyle(1, 1);
	bar(0, 0, 640, 200);
	setfillstyle(1, 15);
	bar(8, 40, 450, 200);
	settextjustify(2, 2);
	blockread(f, fv, 1);
	plot_button(-177, fv);

	setcolor(0);
	outtextxy(629, 26, x); /* Plot the title. */
	setcolor(3);
	outtextxy(630, 25, x);

	settextjustify(0, 2);
	settextstyle(0, 0, 2);
	setcolor(0);
	outtextxy(549, 1, "help!");
	setcolor(3);
	outtextxy(550, 0, "help!");
	/***/ settextstyle(0, 0, 1);

	do {
		getline(x);
		if (x == '!')  flush(); /* End of the help text is signalled with a !. */
		if (x[1] == '\\') {
			setcolor(4);
			chalk(y, copy(x, 2, 255));
		} else {
			setcolor(0);
			chalk(y, x);
		}
		y += 1;
	} while (!false);

	/* We are now at the end of the text. Next we must read the icons. */

	y = 0;
	settextjustify(1, 1);
	settextstyle(0, 0, 2);
	while (! eof(f)) {
		y += 1;
		blockread(f, buttons[y].trigger, 1);
		if (buttons[y].trigger == '\261')  flush();
		blockread(f, fv, 1);
		if (buttons[y].trigger != '\0')  plot_button(13 + y * 27, fv);
		blockread(f, buttons[y].whither, 1); /* this is the position to jump to */


		switch (buttons[y].trigger) {
		case '�' :
			x = "Esc";
			break;
		case '�' :
			x = '\30';
			break;
		case '�' :
			x = '\31';
			break;
		default:
			x = buttons[y].trigger;
		}
		setcolor(0);
		outtextxy(589, 26 + y * 27, x);
		setcolor(3);
		outtextxy(590, 25 + y * 27, x);

	}

	settextjustify(0, 2);
	settextstyle(0, 0, 1);
	close(f);
	on;
}


byte check_mouse();
/* Returns clicked-on button, or 0 if none. */
static void light(byte which, byte colour) {
	if (which == 177)  return; /* Dummy value for "no button at all". */
	setcolor(colour);
	which = which & 31;
	rectangle(466, 11 + which * 27, 555, 35 + which * 27);
}

byte check_mouse() {
	byte h_is;

	byte check_mouse_result;
	check;

	if (mrelease != 0) {
		/* Clicked *somewhere*... */
		if ((mx < 470) || (mx > 550) || (((my - 13) % 27) > 20))
			check_mouse_result = 0;
		else
			/* Clicked on a button. */
			check_mouse_result = ((my - 13) / 27);
	} else {
		if ((mx > 470) && (mx <= 550) && (((my - 13) % 27) <= 20)) {
			/* No click, so highlight. */
			h_is = (my - 13) / 27;
			if ((h_is < 1) || (h_is > 6))  h_is = 177; /* In case of silly values. */
		} else h_is = 177;

		if ((h_is != 177) && ((keystatus & 1) > 0))  h_is += 32;

		if (h_is != highlight_was) {
			off;
			light(highlight_was, 1);
			highlight_was = h_is;
			if (buttons[h_is & 31].trigger != '\0') {
				if (h_is > 31)  light(h_is, 11);
				else light(h_is, 9);
			}
			on;
		}

		check_mouse_result = 0;
	}
	return check_mouse_result;
}

void continue_help() {
	char r;
	byte fv;

	do {
		while (! keypressed()) {
			fv = check_mouse();

			if (fv > 0)
				switch (buttons[fv].trigger) {
				case '\0':/*null*/
					break;
				case '\376':
					return;
					break;
				default: {
					dusk;
					getme(buttons[fv].whither);
					dawn;
					continue_;
				}
				}

		}
		r = upcase(readkey());
		switch (r) {
		case '\33' :
			return;
			break;
		case '\0'  :
			switch (readkey()) {
			case '\110':
			case '\111':
				r = '�';
				break;
			case '\120':
			case '\121':
				r = '�';
				break;
			case '\73':
				r = 'H';
				break; /* Help on help */
			default:
				continue_;
			}
			break;
		}

		for (fv = 1; fv <= 10; fv ++) {
			buttontype &with = buttons[fv];
			if (with.trigger == r) {
				dusk;
				getme(with.whither);
				dawn;
				flush();
			}
		}

	} while (!false);
}

void boot_help() {
	byte groi;

	dusk;
	off;
	oncandopageswap = false;
	highlight_was = 177;
	copypage(3, 1 - cp); /* Store old screen. */ groi = getpixel(0, 0);

	/* Set up mouse. */
	off_virtual;
	newpointer(2);
	setactivepage(3);
	setvisualpage(3);

	getme(0);
	dawn;

	newpointer(9);
	on;
	mousepage(3);

	continue_help();

	mousepage(cp);
	dusk;
	off;
	oncandopageswap = true;
	copypage(1 - cp, 3); /* Restore old screen. */ groi = getpixel(0, 0);
	on_virtual;
	dawn;
	fix_flashers;

	setvisualpage(cp);
	setactivepage(1 - cp);
}

} // End of namespace Avalanche.