aboutsummaryrefslogtreecommitdiff
path: root/queen/credits.cpp
blob: 21b9d525990dcf11681ed81ff93c29dc5d9d39e8 (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
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003-2004 The ScummVM project
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#include "stdafx.h"
#include "queen/credits.h"

#include "queen/display.h"
#include "queen/queen.h"
#include "queen/resource.h"

namespace Queen {

Credits::Credits(QueenEngine *vm, const char* filename) : 
	_vm(vm), _running(true), _count(0), _pause(0), _justify(0), _fontSize(0), _color(0), _zone(0) {
	uint32 size;
	char *buf = (char *)_vm->resource()->loadFile(filename, 0, &size);
	_credits = new LineReader(buf, size);
}

Credits::~Credits() {
	delete _credits;
}

void Credits::nextRoom() {
	if (-1 == _pause) {
		_pause = 0;
		_vm->display()->clearTexts(0, 199);
	}
}

void Credits::update() {
	if (!_running)
		return;

	if (_pause > 0) {
		_pause--;
		if (!_pause)
			_vm->display()->clearTexts(0, 199);
		return;
	}

	/* wait until next room */
	if (-1 == _pause)
		return;

	for (;;) {
		char *line = _credits->nextLine();

		if (0 == memcmp(line, "EN", 2)) {
			_running = false;
			return;
		}

		if ('.' == line[0]) {
			int i;

			switch (tolower(line[1])) {	
			case 'l' :
				_justify = 0;
				break;
			case 'c' :
				_justify = 1;
				break;
			case 'r' :
				_justify = 2;
				break;
			case 's' :
				_fontSize = 0;
				break;
			case 'b' :
				_fontSize = 1;
				break;
			case 'p' :
				_pause = atoi(&line[3]);
				_pause *= 10;
				/* wait until next room */
				if (0 == _pause)
					_pause = -1;
				for (i = 0; i < _count; i++)	{
					_vm->display()->textCurrentColor(_list[i].color);
					_vm->display()->setText(_list[i].x, _list[i].y, _list[i].text);
				}
				_count = 0;
				return;					
			case 'i' :
				_color = atoi(&line[3]);
				break;
			case '1' :
			case '2' :
			case '3' :
			case '4' :
			case '5' :
			case '6' :
			case '7' :
			case '8' :
			case '9' :
				_zone = line[1] - '1';
				break;
			}
		} else {
			assert(_count < ARRAYSIZE(_list));
			_list[_count].text = line;
			_list[_count].color = _color;
			_list[_count].fontSize = _fontSize;
			switch (_justify) {
			case 0:
				_list[_count].x = (_zone % 3) * (320 / 3) + 8;
				break;
			case 1:
				_list[_count].x = (_zone % 3) * (320 / 3) + 54 - _vm->display()->textWidth(line) / 2;
				if (_list[_count].x < 8)
					_list[_count].x = 8;
				break;
			case 2:
				_list[_count].x = (_zone % 3) * (320 / 3) + 100 - _vm->display()->textWidth(line);
				break;
			}
			_list[_count].y = (_zone / 3) * (200 / 3) + (_count * 10);
			_count++;
		}
	}
}


} // End of namespace Queen