LAB: Move getText to the Resource class

Also, make getFont() error out when it can't find a font, and get rid
of BigMsgFont
This commit is contained in:
Filippos Karapetis 2015-12-01 02:05:29 +02:00 committed by Willem Jan Palenstijn
parent 51d04a8187
commit 24684fe321
6 changed files with 80 additions and 141 deletions

View file

@ -176,8 +176,8 @@ public:
void drawJournal(uint16 wipenum, bool needFade); void drawJournal(uint16 wipenum, bool needFade);
void processJournal(); void processJournal();
void doJournal(); void doJournal();
void drawMonText(char *text, uint16 x1, uint16 y1, uint16 x2, uint16 y2, bool isinteractive); void drawMonText(char *text, TextFont *monitorFont, uint16 x1, uint16 y1, uint16 x2, uint16 y2, bool isinteractive);
void processMonitor(char *ntext, bool isinteractive, uint16 x1, uint16 y1, uint16 x2, uint16 y2); void processMonitor(char *ntext, TextFont *monitorFont, bool isinteractive, uint16 x1, uint16 y1, uint16 x2, uint16 y2);
void doMonitor(char *background, char *textfile, bool isinteractive, uint16 x1, uint16 y1, uint16 x2, uint16 y2); void doMonitor(char *background, char *textfile, bool isinteractive, uint16 x1, uint16 y1, uint16 x2, uint16 y2);
void eatMessages(); void eatMessages();
void drawStaticMessage(byte index); void drawStaticMessage(byte index);

View file

@ -189,7 +189,6 @@ char *translateFileName(const char *filename);
void fade(bool fadein, uint16 res); void fade(bool fadein, uint16 res);
void setAmigaPal(uint16 *pal, uint16 numcolors); void setAmigaPal(uint16 *pal, uint16 numcolors);
char *getText(const char *filename);
void readImage(byte **buffer, Image **im); void readImage(byte **buffer, Image **im);
void doMap(uint16 CurRoom); void doMap(uint16 CurRoom);
void doJournal(); void doJournal();

View file

@ -42,10 +42,6 @@
namespace Lab { namespace Lab {
static TextFont *BigMsgFont;
static TextFont bmf;
extern uint16 Direction; extern uint16 Direction;
extern CloseDataPtr CPtr; extern CloseDataPtr CPtr;
@ -70,33 +66,6 @@ void setAmigaPal(uint16 *pal, uint16 numcolors) {
g_lab->writeColorRegsSmooth(vgapal, 0, 16); g_lab->writeColorRegsSmooth(vgapal, 0, 16);
} }
void decrypt(byte *text) {
while (text && *text != '\0') {
*text++ -= (byte)95;
}
}
/*****************************************************************************/
/* Gets a chunk of text and puts it into the graphics memory. */
/*****************************************************************************/
char *getText(const char *filename) {
bool dodecrypt;
byte **tfile;
g_lab->_music->updateMusic();
dodecrypt = (isBuffered(filename) == NULL);
tfile = g_lab->_music->newOpen(filename);
if (!tfile)
return NULL;
if (dodecrypt)
decrypt(*tfile);
return (char *)*tfile;
}
/*****************************************************************************/ /*****************************************************************************/
/* Reads in an image from disk. */ /* Reads in an image from disk. */
@ -193,11 +162,6 @@ static bool loadMapData() {
Gadget *gptr; Gadget *gptr;
uint16 counter; uint16 counter;
BigMsgFont = &bmf;
if (!(BigMsgFont = g_lab->_resource->getFont("P:Map.fon")))
BigMsgFont = MsgFont;
resetBuffer(); /* Make images load into start of buffer */ resetBuffer(); /* Make images load into start of buffer */
buffer = g_lab->_music->newOpen("P:MapImage", Size); buffer = g_lab->_music->newOpen("P:MapImage", Size);

View file

@ -58,7 +58,7 @@ void Resource::readStaticText() {
TextFont *Resource::getFont(const char *fileName) { TextFont *Resource::getFont(const char *fileName) {
Common::File *dataFile; Common::File *dataFile;
if (!(dataFile = openDataFile(fileName, MKTAG('V', 'G', 'A', 'F')))) if (!(dataFile = openDataFile(fileName, MKTAG('V', 'G', 'A', 'F'))))
return NULL; error("getFont: couldn't open %s (%s)", translateFileName(fileName), fileName);
uint32 headerSize = 4L + 2L + 256 * 3 + 4L; uint32 headerSize = 4L + 2L + 256 * 3 + 4L;
uint32 fileSize = dataFile->size(); uint32 fileSize = dataFile->size();
@ -80,6 +80,25 @@ TextFont *Resource::getFont(const char *fileName) {
return textfont; return textfont;
} }
char *Resource::getText(const char *fileName) {
Common::File *dataFile = new Common::File();
dataFile->open(translateFileName(fileName));
if (!dataFile->isOpen())
error("getText: couldn't open %s (%s)", translateFileName(fileName), fileName);
g_lab->_music->updateMusic();
byte count = dataFile->size();
byte *buffer = new byte[count];
byte *text = buffer;
dataFile->read(buffer, count);
while (text && *text != '\0')
*text++ -= (byte)95;
return (char *)buffer;
}
bool Resource::readRoomData(const char *fileName) { bool Resource::readRoomData(const char *fileName) {
Common::File *dataFile; Common::File *dataFile;
if (!(dataFile = openDataFile(fileName, MKTAG('D', 'O', 'R', '1')))) if (!(dataFile = openDataFile(fileName, MKTAG('D', 'O', 'R', '1'))))

View file

@ -102,7 +102,8 @@ public:
bool readRoomData(const char *fileName); bool readRoomData(const char *fileName);
bool readInventory(const char *fileName); bool readInventory(const char *fileName);
bool readViews(uint16 roomNum); bool readViews(uint16 roomNum);
TextFont *getFont(const char *filename); TextFont *getFont(const char *fileName);
char *getText(const char *fileName);
Common::String getStaticText(byte index) const { return _staticText[index]; } Common::String getStaticText(byte index) const { return _staticText[index]; }
private: private:

View file

@ -54,8 +54,7 @@ static Image *Images[10];
byte combination[6] = { 0, 0, 0, 0, 0, 0 }, solution[] = { 0, 4, 0, 8, 7, 2 }; byte combination[6] = { 0, 0, 0, 0, 0, 0 }, solution[] = { 0, 4, 0, 8, 7, 2 };
static uint16 combx[] = { 45, 83, 129, 166, 211, 248 }; static uint16 combx[] = { 45, 83, 129, 166, 211, 248 };
static TextFont *BigMsgFont; static TextFont *journalFont;
static TextFont bmfont;
static char *journaltext, *journaltexttitle; static char *journaltext, *journaltexttitle;
static uint16 JPage = 0; static uint16 JPage = 0;
static bool lastpage = false; static bool lastpage = false;
@ -456,23 +455,15 @@ void mouseTile(Common::Point pos) {
/* Does the things to properly set up the detective notes. */ /* Does the things to properly set up the detective notes. */
/*****************************************************************************/ /*****************************************************************************/
void doNotes() { void doNotes() {
char *ntext; TextFont *noteFont = g_lab->_resource->getFont("P:Note.fon");
char *ntext = g_lab->_resource->getText("Lab:Rooms/Notes");
/* Load in the data */
BigMsgFont = &bmfont;
if (!(BigMsgFont = g_lab->_resource->getFont("P:Note.fon"))) {
BigMsgFont = NULL;
return;
}
if ((ntext = getText("Lab:Rooms/Notes")) == NULL)
return;
flowText(BigMsgFont, -2 + SVGACord(1), 0, 0, false, false, true, true, VGAScaleX(25) + SVGACord(15), VGAScaleY(50), VGAScaleX(295) - SVGACord(15), VGAScaleY(148), ntext);
flowText(noteFont, -2 + SVGACord(1), 0, 0, false, false, true, true, VGAScaleX(25) + SVGACord(15), VGAScaleY(50), VGAScaleX(295) - SVGACord(15), VGAScaleY(148), ntext);
g_lab->setPalette(diffcmap, 256); g_lab->setPalette(diffcmap, 256);
freeAllStolenMem();
delete[] noteFont->data;
free(noteFont);
delete[] ntext;
} }
@ -482,56 +473,39 @@ void doNotes() {
/*****************************************************************************/ /*****************************************************************************/
void doWestPaper() { void doWestPaper() {
char *ntext; char *ntext;
TextFont *paperFont;
int32 FileLen, CharsPrinted; int32 FileLen, CharsPrinted;
uint16 y = 268; uint16 y = 268;
BigMsgFont = &bmfont; paperFont = g_lab->_resource->getFont("P:News22.fon");
ntext = g_lab->_resource->getText("Lab:Rooms/Date");
if (!(BigMsgFont = g_lab->_resource->getFont("P:News22.fon"))) { flowText(paperFont, 0, 0, 0, false, true, false, true, VGAScaleX(57), VGAScaleY(77) + SVGACord(2), VGAScaleX(262), VGAScaleY(91), ntext);
BigMsgFont = NULL; delete[] paperFont->data;
return; free(paperFont);
} delete[] ntext;
if ((ntext = getText("Lab:Rooms/Date")) == NULL)
return;
flowText(BigMsgFont, 0, 0, 0, false, true, false, true, VGAScaleX(57), VGAScaleY(77) + SVGACord(2), VGAScaleX(262), VGAScaleY(91), ntext);
BigMsgFont = &bmfont;
if (!(BigMsgFont = g_lab->_resource->getFont("P:News32.fon"))) {
BigMsgFont = NULL;
return;
}
if ((ntext = getText("Lab:Rooms/Headline")) == NULL)
return;
paperFont = g_lab->_resource->getFont("P:News32.fon");
ntext = g_lab->_resource->getText("Lab:Rooms/Headline");
FileLen = strlen(ntext) - 1; FileLen = strlen(ntext) - 1;
CharsPrinted = flowText(BigMsgFont, -8, 0, 0, false, true, false, true, VGAScaleX(57), VGAScaleY(86) - SVGACord(2), VGAScaleX(262), VGAScaleY(118), ntext); CharsPrinted = flowText(paperFont, -8, 0, 0, false, true, false, true, VGAScaleX(57), VGAScaleY(86) - SVGACord(2), VGAScaleX(262), VGAScaleY(118), ntext);
if (CharsPrinted < FileLen) { if (CharsPrinted < FileLen) {
y = 130 - SVGACord(5); y = 130 - SVGACord(5);
flowText(BigMsgFont, -8 - SVGACord(1), 0, 0, false, true, false, true, VGAScaleX(57), VGAScaleY(86) - SVGACord(2), VGAScaleX(262), VGAScaleY(132), ntext); flowText(paperFont, -8 - SVGACord(1), 0, 0, false, true, false, true, VGAScaleX(57), VGAScaleY(86) - SVGACord(2), VGAScaleX(262), VGAScaleY(132), ntext);
} else } else
y = 115 - SVGACord(5); y = 115 - SVGACord(5);
delete[] paperFont->data;
free(paperFont);
delete[] ntext;
BigMsgFont = &bmfont; paperFont = g_lab->_resource->getFont("P:Note.fon");
ntext = g_lab->_resource->getText("Lab:Rooms/Col1");
if (!(BigMsgFont = g_lab->_resource->getFont("P:Note.fon"))) { CharsPrinted = flowText(paperFont, -4, 0, 0, false, false, false, true, VGAScaleX(45), VGAScaleY(y), VGAScaleX(158), VGAScaleY(148), ntext);
BigMsgFont = NULL; delete[] ntext;
return; ntext = g_lab->_resource->getText("Lab:Rooms/Col2");
} CharsPrinted = flowText(paperFont, -4, 0, 0, false, false, false, true, VGAScaleX(162), VGAScaleY(y), VGAScaleX(275), VGAScaleY(148), ntext);
delete[] ntext;
if ((ntext = getText("Lab:Rooms/Col1")) == NULL) delete[] paperFont->data;
return; free(paperFont);
CharsPrinted = flowText(BigMsgFont, -4, 0, 0, false, false, false, true, VGAScaleX(45), VGAScaleY(y), VGAScaleX(158), VGAScaleY(148), ntext);
if ((ntext = getText("Lab:Rooms/Col2")) == NULL)
return;
CharsPrinted = flowText(BigMsgFont, -4, 0, 0, false, false, false, true, VGAScaleX(162), VGAScaleY(y), VGAScaleX(275), VGAScaleY(148), ntext);
g_lab->setPalette(diffcmap, 256); g_lab->setPalette(diffcmap, 256);
freeAllStolenMem(); freeAllStolenMem();
@ -546,12 +520,7 @@ static bool loadJournalData() {
Gadget *TopGadget = &BackG; Gadget *TopGadget = &BackG;
bool bridge, dirty, news, clean; bool bridge, dirty, news, clean;
BigMsgFont = &bmfont; journalFont = g_lab->_resource->getFont("P:Journal.fon");
if (!(BigMsgFont = g_lab->_resource->getFont("P:Journal.fon"))) {
BigMsgFont = NULL;
return false;
}
g_lab->_music->updateMusic(); g_lab->_music->updateMusic();
@ -580,11 +549,8 @@ static bool loadJournalData() {
else if (bridge) else if (bridge)
filename[11] = '1'; filename[11] = '1';
if ((journaltext = getText(filename)) == NULL) journaltext = g_lab->_resource->getText(filename);
return false; journaltexttitle = g_lab->_resource->getText("Lab:Rooms/jt");
if ((journaltexttitle = getText("Lab:Rooms/jt")) == NULL)
return false;
buffer = g_lab->_music->newOpen("P:JImage"); buffer = g_lab->_music->newOpen("P:JImage");
@ -630,7 +596,7 @@ static void drawJournalText() {
while (DrawingToPage < JPage) { while (DrawingToPage < JPage) {
g_lab->_music->updateMusic(); g_lab->_music->updateMusic();
CurText = (char *)(journaltext + CharsDrawn); CurText = (char *)(journaltext + CharsDrawn);
CharsDrawn += flowText(BigMsgFont, -2, 2, 0, false, false, false, false, VGAScaleX(52), VGAScaleY(32), VGAScaleX(152), VGAScaleY(148), CurText); CharsDrawn += flowText(journalFont, -2, 2, 0, false, false, false, false, VGAScaleX(52), VGAScaleY(32), VGAScaleX(152), VGAScaleY(148), CurText);
lastpage = (*CurText == 0); lastpage = (*CurText == 0);
@ -642,16 +608,16 @@ static void drawJournalText() {
if (JPage <= 1) { if (JPage <= 1) {
CurText = journaltexttitle; CurText = journaltexttitle;
flowTextToMem(&JBackImage, BigMsgFont, -2, 2, 0, false, true, true, true, VGAScaleX(52), VGAScaleY(32), VGAScaleX(152), VGAScaleY(148), CurText); flowTextToMem(&JBackImage, journalFont, -2, 2, 0, false, true, true, true, VGAScaleX(52), VGAScaleY(32), VGAScaleX(152), VGAScaleY(148), CurText);
} else { } else {
CurText = (char *)(journaltext + CharsDrawn); CurText = (char *)(journaltext + CharsDrawn);
CharsDrawn += flowTextToMem(&JBackImage, BigMsgFont, -2, 2, 0, false, false, false, true, VGAScaleX(52), VGAScaleY(32), VGAScaleX(152), VGAScaleY(148), CurText); CharsDrawn += flowTextToMem(&JBackImage, journalFont, -2, 2, 0, false, false, false, true, VGAScaleX(52), VGAScaleY(32), VGAScaleX(152), VGAScaleY(148), CurText);
} }
g_lab->_music->updateMusic(); g_lab->_music->updateMusic();
CurText = (char *)(journaltext + CharsDrawn); CurText = (char *)(journaltext + CharsDrawn);
lastpage = (*CurText == 0); lastpage = (*CurText == 0);
flowTextToMem(&JBackImage, BigMsgFont, -2, 2, 0, false, false, false, true, VGAScaleX(171), VGAScaleY(32), VGAScaleX(271), VGAScaleY(148), CurText); flowTextToMem(&JBackImage, journalFont, -2, 2, 0, false, false, false, true, VGAScaleX(171), VGAScaleY(32), VGAScaleX(271), VGAScaleY(148), CurText);
CurText = (char *)(journaltext + CharsDrawn); CurText = (char *)(journaltext + CharsDrawn);
lastpage = lastpage || (*CurText == 0); lastpage = lastpage || (*CurText == 0);
@ -869,7 +835,7 @@ static void getMonImages() {
/*****************************************************************************/ /*****************************************************************************/
/* Draws the text for the monitor. */ /* Draws the text for the monitor. */
/*****************************************************************************/ /*****************************************************************************/
void LabEngine::drawMonText(char *text, uint16 x1, uint16 y1, uint16 x2, uint16 y2, bool isinteractive) { void LabEngine::drawMonText(char *text, TextFont *monitorFont, uint16 x1, uint16 y1, uint16 x2, uint16 y2, bool isinteractive) {
uint16 DrawingToPage = 0, yspacing = 0, numlines, fheight; uint16 DrawingToPage = 0, yspacing = 0, numlines, fheight;
int32 CharsDrawn = 0L; int32 CharsDrawn = 0L;
char *CurText = text; char *CurText = text;
@ -883,7 +849,7 @@ void LabEngine::drawMonText(char *text, uint16 x1, uint16 y1, uint16 x2, uint16
numlines += (*text - '0'); numlines += (*text - '0');
text += 2; text += 2;
fheight = textHeight(BigMsgFont); fheight = textHeight(monitorFont);
x1 = MonButton->Width + VGAScaleX(3); x1 = MonButton->Width + VGAScaleX(3);
MonGadHeight = MonButton->Height + VGAScaleY(3); MonGadHeight = MonButton->Height + VGAScaleY(3);
@ -908,7 +874,7 @@ void LabEngine::drawMonText(char *text, uint16 x1, uint16 y1, uint16 x2, uint16
while (DrawingToPage < monitorPage) { while (DrawingToPage < monitorPage) {
_music->updateMusic(); _music->updateMusic();
CurText = (char *)(text + CharsDrawn); CurText = (char *)(text + CharsDrawn);
CharsDrawn += flowText(BigMsgFont, yspacing, 0, 0, false, false, false, false, x1, y1, x2, y2, CurText); CharsDrawn += flowText(monitorFont, yspacing, 0, 0, false, false, false, false, x1, y1, x2, y2, CurText);
lastpage = (*CurText == 0); lastpage = (*CurText == 0);
if (lastpage) if (lastpage)
@ -919,7 +885,7 @@ void LabEngine::drawMonText(char *text, uint16 x1, uint16 y1, uint16 x2, uint16
CurText = (char *)(text + CharsDrawn); CurText = (char *)(text + CharsDrawn);
lastpage = (*CurText == 0); lastpage = (*CurText == 0);
CharsDrawn = flowText(BigMsgFont, yspacing, 2, 0, false, false, false, true, x1, y1, x2, y2, CurText); CharsDrawn = flowText(monitorFont, yspacing, 2, 0, false, false, false, true, x1, y1, x2, y2, CurText);
CurText += CharsDrawn; CurText += CharsDrawn;
lastpage = lastpage || (*CurText == 0); lastpage = lastpage || (*CurText == 0);
@ -929,7 +895,7 @@ void LabEngine::drawMonText(char *text, uint16 x1, uint16 y1, uint16 x2, uint16
/*****************************************************************************/ /*****************************************************************************/
/* Processes user input. */ /* Processes user input. */
/*****************************************************************************/ /*****************************************************************************/
void LabEngine::processMonitor(char *ntext, bool isinteractive, uint16 x1, uint16 y1, uint16 x2, uint16 y2) { void LabEngine::processMonitor(char *ntext, TextFont *monitorFont, bool isinteractive, uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
IntuiMessage *Msg; IntuiMessage *Msg;
uint32 Class; uint32 Class;
uint16 Qualifier, Code, MouseX, MouseY; uint16 Qualifier, Code, MouseX, MouseY;
@ -953,10 +919,11 @@ void LabEngine::processMonitor(char *ntext, bool isinteractive, uint16 x1, uint1
monitorPage = 0; monitorPage = 0;
TextFileName = Test; TextFileName = Test;
ntext = getText(TextFileName); ntext = g_lab->_resource->getText(TextFileName);
fade(false, 0); fade(false, 0);
drawMonText(ntext, x1, y1, x2, y2, isinteractive); drawMonText(ntext, monitorFont, x1, y1, x2, y2, isinteractive);
fade(true, 0); fade(true, 0);
delete[] ntext;
} }
} }
@ -981,14 +948,14 @@ void LabEngine::processMonitor(char *ntext, bool isinteractive, uint16 x1, uint1
if ((MouseX >= VGAScaleX(259)) && (MouseX <= VGAScaleX(289))) { if ((MouseX >= VGAScaleX(259)) && (MouseX <= VGAScaleX(289))) {
if (!lastpage) { if (!lastpage) {
monitorPage += 1; monitorPage += 1;
drawMonText(ntext, x1, y1, x2, y2, isinteractive); drawMonText(ntext, monitorFont, x1, y1, x2, y2, isinteractive);
} }
} else if ((MouseX >= VGAScaleX(0)) && (MouseX <= VGAScaleX(31))) { } else if ((MouseX >= VGAScaleX(0)) && (MouseX <= VGAScaleX(31))) {
return; return;
} else if ((MouseX >= VGAScaleX(290)) && (MouseX <= VGAScaleX(320))) { } else if ((MouseX >= VGAScaleX(290)) && (MouseX <= VGAScaleX(320))) {
if (monitorPage >= 1) { if (monitorPage >= 1) {
monitorPage -= 1; monitorPage -= 1;
drawMonText(ntext, x1, y1, x2, y2, isinteractive); drawMonText(ntext, monitorFont, x1, y1, x2, y2, isinteractive);
} }
} else if ((MouseX >= VGAScaleX(31)) && (MouseX <= VGAScaleX(59))) { } else if ((MouseX >= VGAScaleX(31)) && (MouseX <= VGAScaleX(59))) {
if (isinteractive) { if (isinteractive) {
@ -1000,7 +967,7 @@ void LabEngine::processMonitor(char *ntext, bool isinteractive, uint16 x1, uint1
} }
} else if (monitorPage > 0) { } else if (monitorPage > 0) {
monitorPage = 0; monitorPage = 0;
drawMonText(ntext, x1, y1, x2, y2, isinteractive); drawMonText(ntext, monitorFont, x1, y1, x2, y2, isinteractive);
} }
} }
} else if (isinteractive) { } else if (isinteractive) {
@ -1045,31 +1012,20 @@ void LabEngine::doMonitor(char *background, char *textfile, bool isinteractive,
lastpage = false; lastpage = false;
FadePalette = hipal; FadePalette = hipal;
BigMsgFont = &bmfont; TextFont *monitorFont = _resource->getFont("P:Map.fon");
if (!(BigMsgFont = _resource->getFont("P:Map.fon"))) {
freeAllStolenMem();
BigMsgFont = NULL;
return;
}
getMonImages(); getMonImages();
if ((ntext = getText(textfile)) == NULL) { ntext = _resource->getText(textfile);
freeAllStolenMem();
return;
}
loadBackPict(background, false); loadBackPict(background, false);
drawMonText(ntext, monitorFont, x1, y1, x2, y2, isinteractive);
drawMonText(ntext, x1, y1, x2, y2, isinteractive);
_event->mouseShow(); _event->mouseShow();
fade(true, 0); fade(true, 0);
processMonitor(ntext, isinteractive, x1, y1, x2, y2); processMonitor(ntext, monitorFont, isinteractive, x1, y1, x2, y2);
fade(false, 0); fade(false, 0);
_event->mouseHide(); _event->mouseHide();
delete[] ntext;
delete[] monitorFont->data;
free(monitorFont);
freeAllStolenMem(); freeAllStolenMem();
setAPen(0); setAPen(0);