forked from diasurgical/devilution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminitext.cpp
More file actions
300 lines (280 loc) · 5.76 KB
/
minitext.cpp
File metadata and controls
300 lines (280 loc) · 5.76 KB
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
/**
* @file minitext.cpp
*
* Implementation of scrolling dialog text.
*/
#include "all.h"
int qtexty;
const char *qtextptr;
int sgLastScroll;
BOOLEAN qtextflag;
int qtextDelay;
int qtextSpd;
BYTE *pMedTextCels;
BYTE *pTextBoxCels;
/** Maps from font index to medtexts.cel frame number. */
const BYTE mfontframe[128] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 37, 49, 38, 0, 39, 40, 47,
42, 43, 41, 45, 52, 44, 53, 55, 36, 27,
28, 29, 30, 31, 32, 33, 34, 35, 51, 50,
48, 46, 49, 54, 0, 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, 42, 0, 43, 0, 0, 0, 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, 48, 0, 49, 0, 0
};
/**
* Maps from medtexts.cel frame number to character width. Note, the
* character width may be distinct from the frame width, which is 22 for every
* medtexts.cel frame.
*/
const BYTE mfontkern[56] = {
5, 15, 10, 13, 14, 10, 9, 13, 11, 5,
5, 11, 10, 16, 13, 16, 10, 15, 12, 10,
14, 17, 17, 22, 17, 16, 11, 5, 11, 11,
11, 10, 11, 11, 11, 11, 15, 5, 10, 18,
15, 8, 6, 6, 7, 10, 9, 6, 10, 10,
5, 5, 5, 5, 11, 12
};
/* data */
/**
* Text scroll speeds. Positive numbers will delay scrolling 1 out of n frames,
* negative numbers will scroll 1+(-n) pixels.
*/
int qscroll_spd_tbl[9] = { 2, 4, 6, 8, 0, -1, -2, -3, -4 };
void FreeQuestText()
{
MemFreeDbg(pMedTextCels);
MemFreeDbg(pTextBoxCels);
}
void InitQuestText()
{
pMedTextCels = LoadFileInMem("Data\\MedTextS.CEL", NULL);
pTextBoxCels = LoadFileInMem("Data\\TextBox.CEL", NULL);
qtextflag = FALSE;
}
void InitQTextMsg(int m)
{
if (alltext[m].scrlltxt) {
questlog = FALSE;
qtextptr = alltext[m].txtstr;
qtextflag = TRUE;
qtexty = 340 + SCREEN_Y;
qtextSpd = qscroll_spd_tbl[alltext[m].txtspd - 1];
qtextDelay = qtextSpd;
sgLastScroll = GetTickCount();
}
PlaySFX(alltext[m].sfxnr);
}
void DrawQTextBack()
{
CelDraw(PANEL_X + 24, SCREEN_Y + 327, pTextBoxCels, 1, 591);
#define TRANS_RECT_X (PANEL_LEFT + 27)
#define TRANS_RECT_Y 28
#define TRANS_RECT_WIDTH 585
#define TRANS_RECT_HEIGHT 297
#include "asm_trans_rect.inc"
}
void PrintQTextChr(int sx, int sy, BYTE *pCelBuff, int nCel)
{
BYTE *dst, *pStart, *pEnd, *end;
/// ASSERT: assert(gpBuffer);
dst = &gpBuffer[sx + PitchTbl[sy]];
pStart = &gpBuffer[PitchTbl[209]];
pEnd = &gpBuffer[PitchTbl[469]];
#ifdef USE_ASM
__asm {
mov ebx, pCelBuff
mov eax, nCel
shl eax, 2
add ebx, eax
mov eax, [ebx+4]
sub eax, [ebx]
mov end, eax
mov esi, pCelBuff
add esi, [ebx]
mov edi, dst
mov ebx, end
add ebx, esi
label1:
mov edx, 22
label2:
xor eax, eax
lodsb
or al, al
js label7
sub edx, eax
cmp edi, pStart
jb label5
cmp edi, pEnd
ja label5
mov ecx, eax
shr ecx, 1
jnb label3
movsb
jecxz label6
label3:
shr ecx, 1
jnb label4
movsw
jecxz label6
label4:
rep movsd
jmp label6
label5:
add esi, eax
add edi, eax
label6:
or edx, edx
jz label8
jmp label2
label7:
neg al
add edi, eax
sub edx, eax
jnz label2
label8:
sub edi, BUFFER_WIDTH + 22
cmp ebx, esi
jnz label1
}
#else
int i;
BYTE width;
BYTE *src;
DWORD *pFrameTable;
pFrameTable = (DWORD *)&pCelBuff[4 * nCel];
src = &pCelBuff[pFrameTable[0]];
end = &src[pFrameTable[1] - pFrameTable[0]];
for (; src != end; dst -= BUFFER_WIDTH + 22) {
for (i = 22; i;) {
width = *src++;
if (!(width & 0x80)) {
i -= width;
if (dst >= pStart && dst <= pEnd) {
if (width & 1) {
dst[0] = src[0];
src++;
dst++;
}
width >>= 1;
if (width & 1) {
dst[0] = src[0];
dst[1] = src[1];
src += 2;
dst += 2;
}
width >>= 1;
for (; width; width--) {
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = src[3];
src += 4;
dst += 4;
}
} else {
src += width;
dst += width;
}
} else {
width = -(char)width;
dst += width;
i -= width;
}
}
}
#endif
}
void DrawQText()
{
int i, l, w, tx, ty;
BYTE c;
const char *p, *pnl, *s;
char tempstr[128];
BOOL doneflag;
DWORD currTime;
DrawQTextBack();
p = qtextptr;
pnl = NULL;
tx = 48 + PANEL_X;
ty = qtexty;
doneflag = FALSE;
while (!doneflag) {
w = 0;
s = p;
l = 0;
while (*s != '\n' && *s != '|' && w < 543) {
c = gbFontTransTbl[(BYTE)*s];
s++;
if (c != '\0') {
tempstr[l] = c;
w += mfontkern[mfontframe[c]] + 2;
} else {
l--;
}
l++;
}
tempstr[l] = '\0';
if (*s == '|') {
tempstr[l] = '\0';
doneflag = TRUE;
} else if (*s != '\n') {
while (tempstr[l] != ' ' && l > 0) {
tempstr[l] = '\0';
l--;
}
}
for (i = 0; tempstr[i]; i++) {
p++;
c = mfontframe[gbFontTransTbl[(BYTE)tempstr[i]]];
if (*p == '\n') {
p++;
}
if (c != 0) {
PrintQTextChr(tx, ty, pMedTextCels, c);
}
tx += mfontkern[c] + 2;
}
if (pnl == NULL) {
pnl = p;
}
tx = 48 + PANEL_X;
ty += 38;
if (ty > 341 + SCREEN_Y) {
doneflag = TRUE;
}
}
currTime = GetTickCount();
while (1) {
if (qtextSpd <= 0) {
qtexty--;
qtexty += qtextSpd;
} else {
qtextDelay--;
if (qtextDelay != 0) {
qtexty--;
}
}
if (qtextDelay == 0) {
qtextDelay = qtextSpd;
}
if (qtexty <= 49 + SCREEN_Y) {
qtexty += 38;
qtextptr = pnl;
if (*pnl == '|') {
qtextflag = FALSE;
}
break;
}
sgLastScroll += 50;
if (currTime - sgLastScroll >= 0x7FFFFFFF) {
break;
}
}
}