Devilution
Diablo devolved - magic behind the 1996 computer game
minitext.cpp
Go to the documentation of this file.
1 
6 #include "all.h"
7 
9 
10 int qtexty;
11 char *qtextptr;
13 BOOLEAN qtextflag;
18 
20 const BYTE mfontframe[127] = {
21  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24  0, 0, 0, 37, 49, 38, 0, 39, 40, 47,
25  42, 43, 41, 45, 52, 44, 53, 55, 36, 27,
26  28, 29, 30, 31, 32, 33, 34, 35, 51, 50,
27  48, 46, 49, 54, 0, 1, 2, 3, 4, 5,
28  6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
29  16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
30  26, 42, 0, 43, 0, 0, 0, 1, 2, 3,
31  4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
32  14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
33  24, 25, 26, 48, 0, 49, 0
34 };
40 const BYTE mfontkern[56] = {
41  5, 15, 10, 13, 14, 10, 9, 13, 11, 5,
42  5, 11, 10, 16, 13, 16, 10, 15, 12, 10,
43  14, 17, 17, 22, 17, 16, 11, 5, 11, 11,
44  11, 10, 11, 11, 11, 11, 15, 5, 10, 18,
45  15, 8, 6, 6, 7, 10, 9, 6, 10, 10,
46  5, 5, 5, 5, 11, 12
47 };
48 
49 /* data */
50 
55 int qscroll_spd_tbl[9] = { 2, 4, 6, 8, 0, -1, -2, -3, -4 };
56 
58 {
61 }
62 
64 {
65  pMedTextCels = LoadFileInMem("Data\\MedTextS.CEL", NULL);
66  pTextBoxCels = LoadFileInMem("Data\\TextBox.CEL", NULL);
67  qtextflag = FALSE;
68 }
69 
70 void InitQTextMsg(int m)
71 {
72  if (alltext[m].scrlltxt) {
73  questlog = FALSE;
74  qtextptr = alltext[m].txtstr;
75  qtextflag = TRUE;
76  qtexty = 500;
78  if (sgLastScroll <= 0)
79  scrolltexty = 50 / -(sgLastScroll - 1);
80  else
81  scrolltexty = ((sgLastScroll + 1) * 50) / sgLastScroll;
82  qtextSpd = SDL_GetTicks();
83  }
84  PlaySFX(alltext[m].sfxnr);
85 }
86 
88 {
89  CelDraw(PANEL_X + 24, 487, pTextBoxCels, 1, 591);
90  trans_rect(PANEL_LEFT + 27, 28, 585, 297);
91 }
92 
93 void PrintQTextChr(int sx, int sy, BYTE *pCelBuff, int nCel)
94 {
95  BYTE *pStart, *pEnd;
96 
98  pStart = gpBufStart;
100  pEnd = gpBufEnd;
101  gpBufEnd = &gpBuffer[BUFFER_WIDTH * (309 + SCREEN_Y)];
102  CelDraw(sx, sy, pCelBuff, nCel, 22);
103 
104  gpBufStart = pStart;
105  gpBufEnd = pEnd;
106 }
107 
108 void DrawQText()
109 {
110  int i, l, w, tx, ty;
111  BYTE c;
112  char *p, *pnl, *s;
113  char tempstr[128];
114  BOOL doneflag;
115  DWORD currTime;
116 
117  DrawQTextBack();
118 
119  p = qtextptr;
120  pnl = NULL;
121  tx = 48 + PANEL_X;
122  ty = qtexty;
123 
124  doneflag = FALSE;
125  while (!doneflag) {
126  w = 0;
127  s = p;
128  l = 0;
129  while (*s != '\n' && *s != '|' && w < 543) {
130  c = gbFontTransTbl[(BYTE)*s];
131  s++;
132  if (c != '\0') {
133  tempstr[l] = c;
134  w += mfontkern[mfontframe[c]] + 2;
135  } else {
136  l--;
137  }
138  l++;
139  }
140  tempstr[l] = '\0';
141  if (*s == '|') {
142  tempstr[l] = '\0';
143  doneflag = TRUE;
144  } else if (*s != '\n') {
145  while (tempstr[l] != ' ' && l > 0) {
146  tempstr[l] = '\0';
147  l--;
148  }
149  }
150  for (i = 0; tempstr[i]; i++) {
151  p++;
152  c = mfontframe[gbFontTransTbl[(BYTE)tempstr[i]]];
153  if (*p == '\n') {
154  p++;
155  }
156  if (c != 0) {
157  PrintQTextChr(tx, ty, pMedTextCels, c);
158  }
159  tx += mfontkern[c] + 2;
160  }
161  if (pnl == NULL) {
162  pnl = p;
163  }
164  tx = 48 + PANEL_X;
165  ty += 38;
166  if (ty > 501) {
167  doneflag = TRUE;
168  }
169  }
170 
171  for (currTime = SDL_GetTicks(); qtextSpd + scrolltexty < currTime; qtextSpd += scrolltexty) {
172  qtexty--;
173  if (qtexty <= 209) {
174  qtexty += 38;
175  qtextptr = pnl;
176  if (*pnl == '|') {
177  qtextflag = FALSE;
178  }
179  break;
180  }
181  }
182 }
183 
trans_rect
void trans_rect(int sx, int sy, int width, int height)
Draws a half-transparent rectangle by blacking out odd pixels on odd lines, even pixels on even lines...
Definition: render.cpp:342
gpBuffer
BYTE * gpBuffer
qtexty
DEVILUTION_BEGIN_NAMESPACE int qtexty
Definition: minitext.cpp:10
PANEL_X
#define PANEL_X
Definition: defs.h:136
SCREEN_Y
#define SCREEN_Y
Definition: defs.h:126
FreeQuestText
void FreeQuestText()
Definition: minitext.cpp:57
qscroll_spd_tbl
int qscroll_spd_tbl[9]
Text scroll speeds.
Definition: minitext.cpp:55
TextDataStruct::txtspd
int txtspd
Definition: structs.h:366
questlog
BOOL questlog
Definition: quests.cpp:6
MemFreeDbg
#define MemFreeDbg(p)
Definition: defs.h:157
mfontframe
const BYTE mfontframe[127]
Maps from font index to medtexts.cel frame number.
Definition: minitext.cpp:20
all.h
sgLastScroll
int sgLastScroll
Definition: minitext.cpp:15
TextDataStruct::txtstr
char * txtstr
Definition: structs.h:364
gpBufStart
BYTE * gpBufStart
Upper bound of back buffer.
Definition: scrollrt.cpp:15
PrintQTextChr
void PrintQTextChr(int sx, int sy, BYTE *pCelBuff, int nCel)
Definition: minitext.cpp:93
DEVILUTION_END_NAMESPACE
#define DEVILUTION_END_NAMESPACE
Definition: types.h:10
mfontkern
const BYTE mfontkern[56]
Maps from medtexts.cel frame number to character width.
Definition: minitext.cpp:40
LoadFileInMem
BYTE * LoadFileInMem(char *pszName, DWORD *pdwFileLen)
Load a file in to a buffer.
Definition: engine.cpp:801
CelDraw
void CelDraw(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth)
Blit CEL sprite to the back buffer at the given coordinates.
Definition: engine.cpp:47
DrawQTextBack
void DrawQTextBack()
Definition: minitext.cpp:87
InitQuestText
void InitQuestText()
Definition: minitext.cpp:63
gpBufEnd
BYTE * gpBufEnd
Lower bound of back buffer.
Definition: scrollrt.cpp:19
PlaySFX
void PlaySFX(int psfx)
Definition: effects.cpp:1043
InitQTextMsg
void InitQTextMsg(int m)
Definition: minitext.cpp:70
tempstr
char tempstr[256]
Definition: control.cpp:41
alltext
const DEVILUTION_BEGIN_NAMESPACE TextDataStruct alltext[]
Contains the data related to each speech ID.
Definition: textdat.cpp:8
pMedTextCels
BYTE * pMedTextCels
Definition: minitext.cpp:16
BUFFER_WIDTH
#define BUFFER_WIDTH
Definition: defs.h:128
pTextBoxCels
BYTE * pTextBoxCels
Definition: minitext.cpp:17
DEVILUTION_BEGIN_NAMESPACE
Definition: sha.cpp:10
qtextptr
char * qtextptr
Definition: minitext.cpp:11
qtextSpd
int qtextSpd
Definition: minitext.cpp:12
PANEL_LEFT
#define PANEL_LEFT
Definition: defs.h:135
gbFontTransTbl
const BYTE gbFontTransTbl[256]
Maps ASCII character code to font index, as used by the small, medium and large sized fonts; which co...
Definition: control.cpp:106
qtextflag
BOOLEAN qtextflag
Definition: minitext.cpp:13
DrawQText
void DrawQText()
Definition: minitext.cpp:108
scrolltexty
int scrolltexty
Definition: minitext.cpp:14