00001
00025 #include "dialogues.h"
00026 #include "main.h"
00027 #include "hqrdepack.h"
00028 #include "resources.h"
00029 #include "sdlengine.h"
00030 #include "menu.h"
00031 #include "interface.h"
00032
00033
00034 unsigned char textVar2[256];
00035 unsigned char textVar3;
00036
00038 unsigned char *dialTextPtr;
00040 unsigned char *dialOrderPtr;
00042 short int numDialTextEntries;
00043
00046 void init_dialogue_bank(int bankIdx)
00047 {
00048 int langIdx;
00049 int hqrSize;
00050
00051
00052 if (bankIdx == currentTextBank)
00053 return;
00054
00055 currentTextBank = bankIdx;
00056
00057 textVar2[0] = textVar3;
00058
00059
00060 langIdx = (cfgfile.LanguageId * 14) * 2 + bankIdx * 2;
00061
00062 hqrSize = hqr_entry_size(HQR_TEXT_FILE, langIdx);
00063 if(dialOrderPtr)
00064 free(dialOrderPtr);
00065 dialOrderPtr = (unsigned char *)malloc(hqrSize);
00066 hqr_get_entry(dialOrderPtr, HQR_TEXT_FILE, langIdx);
00067
00068 numDialTextEntries = hqrSize / 2;
00069
00070 hqrSize = hqr_entry_size(HQR_TEXT_FILE, ++langIdx);
00071 if(dialTextPtr)
00072 free(dialTextPtr);
00073 dialTextPtr = (unsigned char *)malloc(hqrSize);
00074 hqr_get_entry(dialTextPtr, HQR_TEXT_FILE, langIdx);
00075
00076
00077
00078 }
00079
00080 void draw_character(int x, int y, unsigned char character)
00081 {
00082 unsigned char sizeX;
00083 unsigned char sizeY;
00084 unsigned char param1;
00085 unsigned char param2;
00086 unsigned char *data;
00087 unsigned char *screen;
00088
00089
00090 int toNextLine;
00091 char index;
00092
00093
00094 char usedColor;
00095 char number;
00096 char jump;
00097
00098 int i;
00099
00100 int tempX;
00101 int tempY;
00102
00103 data = fontPtr + *((short int *) (fontPtr + character * 4));
00104
00105 sizeX = *(data++);
00106 sizeY = *(data++);
00107 param1 = *(data++);
00108 param2 = *(data++);
00109
00110 x += param1;
00111 y += param2;
00112
00113 usedColor = dialTextColor;
00114
00115 screen = frontVideoBuffer + screenLockupTable[y] + x;
00116
00117 tempX = x;
00118 tempY = y;
00119
00120 toNextLine = SCREEN_WIDTH - sizeX;
00121
00122 do
00123 {
00124 index = *(data++);
00125 do
00126 {
00127 jump = *(data++);
00128 screen += jump;
00129 tempX += jump;
00130 if (--index == 0)
00131 {
00132 screen += toNextLine;
00133 tempY++;
00134 tempX = x;
00135 sizeY--;
00136 if (sizeY <= 0)
00137 return;
00138 break;
00139 }
00140 else
00141 {
00142 number = *(data++);
00143 for (i = 0; i < number; i++)
00144 {
00145 if(tempX >= SCREEN_TEXTLIMIT_LEFT && tempX < SCREEN_TEXTLIMIT_RIGHT && tempY >= SCREEN_TEXTLIMIT_TOP && tempY < SCREEN_TEXTLIMIT_BOTTOM)
00146 frontVideoBuffer[SCREEN_WIDTH*tempY + tempX] = usedColor;
00147
00148 screen++;
00149 tempX++;
00150 }
00151
00152 if (--index == 0)
00153 {
00154 screen += toNextLine;
00155 tempY++;
00156 tempX = x;
00157
00158 sizeY--;
00159 if (sizeY <= 0)
00160 return;
00161 break;
00162 }
00163 }
00164 }while (1);
00165 }while (1);
00166 }
00167
00168 void display_dialogue_text(int x, int y, char *dialogue)
00169 {
00170 unsigned char currChar;
00171
00172 if (fontPtr == 0)
00173 return;
00174
00175 do
00176 {
00177 currChar = (unsigned char) *(dialogue++);
00178
00179 if (currChar == 0)
00180 break;
00181
00182 if (currChar == 0x20)
00183 x += dialCharSpace;
00184 else
00185 {
00186 dialTextSize = *(fontPtr + (*((short int *) (fontPtr + currChar * 4))));
00187 draw_character(x, y, currChar);
00188
00189 x += dialSpaceBetween;
00190
00191 x += dialTextSize;
00192 }
00193 }while (1);
00194 }
00195
00196 int dialogue_text_size(char *dialogue)
00197 {
00198 unsigned char currChar;
00199 dialTextSize = 0;
00200
00201 do
00202 {
00203 currChar = (unsigned char) *(dialogue++);
00204
00205 if (currChar == 0)
00206 break;
00207
00208 if (currChar == 0x20)
00209 {
00210 dialTextSize += dialCharSpace;
00211 }
00212 else
00213 {
00214 dialTextSize += dialSpaceBetween;
00215 dialTextSize += *(fontPtr + *((short int *) (fontPtr + currChar * 4)));
00216 }
00217 }
00218 while (1);
00219
00220 return (dialTextSize);
00221 }
00222
00223
00224
00225 void set_font_parameters(int spaceBetween, int charSpace)
00226 {
00227 dialSpaceBetween = spaceBetween;
00228 dialCharSpace = charSpace;
00229 }
00230
00231 void set_font_color(int color)
00232 {
00233 dialTextColor = color;
00234 }
00235
00236 void set_dialogue_cross_color(int stopColor, int startColor, int stepSize)
00237 {
00238 dialTextStartColor = startColor;
00239 dialTextStopColor = stopColor;
00240 dialTextStepSize = stepSize;
00241 dialTextBufferSize = ((startColor-stopColor)+1)/stepSize;
00242 }
00243
00244 int get_text(int index)
00245 {
00246 int currIdx = 0;
00247 int orderIdx = 0;
00248 int numEntries;
00249 int ptrCurrentEntry;
00250 int ptrNextEntry;
00251
00252 short int *localTextBuf = (short int *) dialTextPtr;
00253 short int *localOrderBuf = (short int *) dialOrderPtr;
00254
00255 numEntries = numDialTextEntries;
00256
00257
00258 do
00259 {
00260 orderIdx = *(localOrderBuf++);
00261 if(orderIdx==index)
00262 break;
00263 currIdx++;
00264 }while(currIdx < numDialTextEntries);
00265
00266 if(currIdx >= numEntries)
00267 return 0;
00268
00269 ptrCurrentEntry = localTextBuf[currIdx];
00270 ptrNextEntry = localTextBuf[currIdx + 1];
00271
00272 currDialTextPtr = (dialTextPtr + ptrCurrentEntry);
00273 currDialTextSize = ptrNextEntry - ptrCurrentEntry;
00274 numDialTextEntries = numEntries;
00275
00276 return 1;
00277 }
00278
00279 void copy_dialogues_text(char *a, char *b, int c)
00280 {
00281 int i;
00282 for (i = 0; i < c; i++)
00283 *(b++) = *(a++);
00284 }
00285
00286 void get_menu_text(int index, char *dialogue)
00287 {
00288 if (index == currMenuTextIndex)
00289 {
00290 if (currMenuTextBank == currentTextBank)
00291 {
00292 strcpy(dialogue, currMenuTextBuffer);
00293 return;
00294 }
00295 }
00296 if (!get_text(index))
00297 {
00298
00299 dialogue[0] = 0;
00300 return;
00301 }
00302
00303 if ((currDialTextSize - 1) > 0xFF)
00304 currDialTextSize = 0xFF;
00305
00306 copy_dialogues_text((char *) currDialTextPtr, dialogue, currDialTextSize);
00307 currDialTextSize++;
00308 copy_dialogues_text(dialogue, currMenuTextBuffer, currDialTextSize);
00309
00310 currMenuTextIndex = index;
00311 currMenuTextBank = currentTextBank;
00312 }