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
|
/* 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 "common/file.h"
#include "sludge/allfiles.h"
#include "sludge/backdrop.h"
#include "sludge/sprites.h"
#include "sludge/fonttext.h"
#include "sludge/moreio.h"
#include "sludge/stringy.h"
#include "sludge/newfatal.h"
#include "sludge/statusba.h"
namespace Sludge {
spritePalette verbLinePalette;
spritePalette litVerbLinePalette;
statusStuff mainStatus;
statusStuff *nowStatus = & mainStatus;
extern int fontHeight;
extern float cameraZoom;
void setLitStatus(int i) {
nowStatus->litStatus = i;
}
void killLastStatus() {
if (nowStatus->firstStatusBar) {
statusBar *kill = nowStatus->firstStatusBar;
nowStatus->firstStatusBar = kill->next;
delete kill->text;
delete kill;
}
}
void clearStatusBar() {
statusBar *stat = nowStatus->firstStatusBar;
statusBar *kill;
nowStatus->litStatus = -1;
while (stat) {
kill = stat;
stat = stat->next;
delete kill->text;
delete kill;
}
nowStatus->firstStatusBar = NULL;
}
void addStatusBar() {
statusBar *newStat = new statusBar;
if (checkNew(newStat)) {
newStat->next = nowStatus->firstStatusBar;
newStat->text = copyString("");
nowStatus->firstStatusBar = newStat;
}
}
void setStatusBar(char *txt) {
if (nowStatus->firstStatusBar) {
delete[] nowStatus->firstStatusBar->text;
nowStatus->firstStatusBar->text = copyString(txt);
}
}
void positionStatus(int x, int y) {
nowStatus->statusX = x;
nowStatus->statusY = y;
}
void drawStatusBar() {
int y = nowStatus->statusY, n = 0;
statusBar *stat = nowStatus->firstStatusBar;
fixFont(litVerbLinePalette);
fixFont(verbLinePalette);
while (stat) {
switch (nowStatus->alignStatus) {
case IN_THE_CENTRE:
pasteString(stat->text, ((winWidth - stringWidth(stat->text)) >> 1) / cameraZoom, y / cameraZoom, (n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
break;
case 1001:
pasteString(stat->text, (winWidth - stringWidth(stat->text)) - nowStatus->statusX / cameraZoom, y / cameraZoom, (n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
break;
default:
pasteString(stat->text, nowStatus->statusX / cameraZoom, y / cameraZoom, (n ++ == nowStatus->litStatus) ? litVerbLinePalette : verbLinePalette);
}
stat = stat->next;
y -= fontHeight;
}
}
void statusBarColour(byte r, byte g, byte b) {
setFontColour(verbLinePalette, r, g, b);
nowStatus->statusR = r;
nowStatus->statusG = g;
nowStatus->statusB = b;
}
void statusBarLitColour(byte r, byte g, byte b) {
setFontColour(litVerbLinePalette, r, g, b);
nowStatus->statusLR = r;
nowStatus->statusLG = g;
nowStatus->statusLB = b;
}
statusStuff *copyStatusBarStuff(statusStuff *here) {
// Things we want to keep
here->statusLR = nowStatus->statusLR;
here->statusLG = nowStatus->statusLG;
here->statusLB = nowStatus->statusLB;
here->statusR = nowStatus->statusR;
here->statusG = nowStatus->statusG;
here->statusB = nowStatus->statusB;
here->alignStatus = nowStatus->alignStatus;
here->statusX = nowStatus->statusX;
here->statusY = nowStatus->statusY;
// Things we want to clear
here->litStatus = -1;
here->firstStatusBar = NULL;
statusStuff *old = nowStatus;
nowStatus = here;
return old;
}
void restoreBarStuff(statusStuff *here) {
delete nowStatus;
setFontColour(verbLinePalette, here->statusR, here->statusG, here->statusB);
setFontColour(litVerbLinePalette, here->statusLR, here->statusLG, here->statusLB);
nowStatus = here;
}
void initStatusBar() {
mainStatus.firstStatusBar = NULL;
mainStatus.alignStatus = IN_THE_CENTRE;
mainStatus.litStatus = -1;
mainStatus.statusX = 10;
mainStatus.statusY = winHeight - 15;
statusBarColour(255, 255, 255);
statusBarLitColour(255, 255, 128);
}
const char *statusBarText() {
if (nowStatus->firstStatusBar) {
return nowStatus->firstStatusBar->text;
} else {
return "";
}
}
void saveStatusBars(Common::WriteStream *stream) {
statusBar *viewLine = nowStatus->firstStatusBar;
stream->writeUint16BE(nowStatus->alignStatus);
putSigned(nowStatus->litStatus, stream);
stream->writeUint16BE(nowStatus->statusX);
stream->writeUint16BE(nowStatus->statusY);
stream->writeByte(nowStatus->statusR);
stream->writeByte(nowStatus->statusG);
stream->writeByte(nowStatus->statusB);
stream->writeByte(nowStatus->statusLR);
stream->writeByte(nowStatus->statusLG);
stream->writeByte(nowStatus->statusLB);
// Write what's being said
while (viewLine) {
stream->writeByte(1);
writeString(viewLine->text, stream);
viewLine = viewLine->next;
}
stream->writeByte(0);
}
bool loadStatusBars(Common::SeekableReadStream *stream) {
clearStatusBar();
nowStatus->alignStatus = stream->readUint16BE();
nowStatus->litStatus = getSigned(stream);
nowStatus->statusX = stream->readUint16BE();
nowStatus->statusY = stream->readUint16BE();
nowStatus->statusR = stream->readByte();
nowStatus->statusG = stream->readByte();
nowStatus->statusB = stream->readByte();
nowStatus->statusLR = stream->readByte();
nowStatus->statusLG = stream->readByte();
nowStatus->statusLB = stream->readByte();
setFontColour(verbLinePalette, nowStatus->statusR, nowStatus->statusG, nowStatus->statusB);
setFontColour(litVerbLinePalette, nowStatus->statusLR, nowStatus->statusLG, nowStatus->statusLB);
// Read what's being said
statusBar * * viewLine = & (nowStatus->firstStatusBar);
statusBar *newOne;
while (stream->readByte()) {
newOne = new statusBar;
if (! checkNew(newOne)) return false;
newOne->text = readString(stream);
newOne->next = NULL;
(*viewLine) = newOne;
viewLine = &(newOne->next);
}
return true;
}
} // End of namespace Sludge
|