LAB: Change the gadget lists to use Common::List

This commit is contained in:
Filippos Karapetis 2015-12-06 22:50:41 +02:00 committed by Willem Jan Palenstijn
parent 803dbcee90
commit 62c4acc6b3
11 changed files with 106 additions and 117 deletions

View File

@ -130,9 +130,8 @@ void LabEngine::freeScreens() {
/* Permanently flips the imagery of a gadget. */
/******************************************************************************/
void LabEngine::perFlipGadget(uint16 gadgetId) {
Gadget *topGadget = _moveGadgetList;
while (topGadget) {
for (GadgetList::iterator gadget = _moveGadgetList.begin(); gadget != _moveGadgetList.end(); ++gadget) {
Gadget *topGadget = *gadget;
if (topGadget->GadgetID == gadgetId) {
Image *tmpImage = topGadget->_image;
topGadget->_image = topGadget->_altImage;
@ -144,9 +143,8 @@ void LabEngine::perFlipGadget(uint16 gadgetId) {
_event->mouseShow();
}
return;
} else
topGadget = topGadget->NextGadget;
break;
}
}
}
@ -274,9 +272,9 @@ void LabEngine::interfaceOn() {
if (_graphics->_longWinInFront)
_event->attachGadgetList(nullptr);
else if (_alternate)
_event->attachGadgetList(_invGadgetList);
_event->attachGadgetList(&_invGadgetList);
else
_event->attachGadgetList(_moveGadgetList);
_event->attachGadgetList(&_moveGadgetList);
}
/******************************************************************************/

View File

@ -57,30 +57,29 @@ static byte MouseData[] = {1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
/* Checks whether or not the cords fall within one of the gadgets in a list */
/* of gadgets. */
/*****************************************************************************/
Gadget *EventManager::checkGadgetHit(Gadget *gadgetList, Common::Point pos) {
while (gadgetList != NULL) {
if ((pos.x >= gadgetList->x) && (pos.y >= gadgetList->y) &&
(pos.x <= (gadgetList->x + gadgetList->_image->_width)) &&
(pos.y <= (gadgetList->y + gadgetList->_image->_height)) &&
!(GADGETOFF & gadgetList->GadgetFlags)) {
Gadget *EventManager::checkGadgetHit(GadgetList *gadgetList, Common::Point pos) {
for (GadgetList::iterator gadgetItr = gadgetList->begin(); gadgetItr != gadgetList->end(); ++gadgetItr) {
Gadget *gadget = *gadgetItr;
if ((pos.x >= gadget->x) && (pos.y >= gadget->y) &&
(pos.x <= (gadget->x + gadget->_image->_width)) &&
(pos.y <= (gadget->y + gadget->_image->_height)) &&
!(GADGETOFF & gadget->GadgetFlags)) {
if (_vm->_isHiRes) {
_hitGadget = gadgetList;
_hitGadget = gadget;
} else {
mouseHide();
gadgetList->_altImage->drawImage(gadgetList->x, gadgetList->y);
gadget->_altImage->drawImage(gadget->x, gadget->y);
mouseShow();
for (uint16 i = 0; i < 3; i++)
_vm->waitTOF();
mouseHide();
gadgetList->_image->drawImage(gadgetList->x, gadgetList->y);
gadget->_image->drawImage(gadget->x, gadget->y);
mouseShow();
}
return gadgetList;
} else {
gadgetList = gadgetList->NextGadget;
return gadget;
}
}
@ -89,7 +88,7 @@ Gadget *EventManager::checkGadgetHit(Gadget *gadgetList, Common::Point pos) {
void EventManager::attachGadgetList(Gadget *gadgetList) {
void EventManager::attachGadgetList(GadgetList *gadgetList) {
if (_screenGadgetList != gadgetList)
_lastGadgetHit = nullptr;

View File

@ -55,10 +55,10 @@ private:
public:
EventManager (LabEngine *vm);
Gadget *_screenGadgetList;
GadgetList *_screenGadgetList;
Gadget *_hitGadget;
Gadget *checkGadgetHit(Gadget *gadgetList, Common::Point pos);
Gadget *checkGadgetHit(GadgetList *gadgetList, Common::Point pos);
void initMouse();
void updateMouse();
void mouseShow();
@ -67,7 +67,7 @@ public:
void setMousePos(Common::Point pos);
bool mouseButton(uint16 *x, uint16 *y, bool leftButton);
Gadget *mouseGadget();
void attachGadgetList(Gadget *gadgetList);
void attachGadgetList(GadgetList *gadgetList);
void mouseHandler(int flag, Common::Point pos);
bool keyPress(uint16 *keyCode);
bool haveNextChar();

View File

@ -806,7 +806,7 @@ void DisplayMan::drawPanel() {
if (!_vm->_alternate) {
setAPen(4);
drawHLine(0, VGAScaleY(170) + 1, VGAScaleX(319)); /* The horizontal lines under the black one */
drawGadgetList(_vm->_moveGadgetList);
drawGadgetList(&_vm->_moveGadgetList);
} else {
if (_vm->getPlatform() != Common::kPlatformWindows) {
drawVLine(VGAScaleX(124), VGAScaleY(170) + 1, VGAScaleY(199)); /* Vertical Black lines */
@ -832,7 +832,7 @@ void DisplayMan::drawPanel() {
drawVLine(VGAScaleX(232), VGAScaleY(170) + 2, VGAScaleY(198));
}
drawGadgetList(_vm->_invGadgetList);
drawGadgetList(&_vm->_invGadgetList);
}
_vm->_event->mouseShow();
@ -856,25 +856,16 @@ bool DisplayMan::setUpScreens() {
// The key mapping was only set for the Windows version.
// It's very convenient to have those shortcut, so I added them
// for all versions. (Strangerke)
_vm->_moveGadgetList = createButton(1, y, 0, 't', _vm->_moveImages[0], _vm->_moveImages[1]);
Gadget *curGadget = _vm->_moveGadgetList;
curGadget->NextGadget = createButton(33, y, 1, 'm', _vm->_moveImages[2], _vm->_moveImages[3]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(65, y, 2, 'o', _vm->_moveImages[4], _vm->_moveImages[5]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(97, y, 3, 'c', _vm->_moveImages[6], _vm->_moveImages[7]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(129, y, 4, 'l', _vm->_moveImages[8], _vm->_moveImages[9]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(161, y, 5, 'i', _vm->_moveImages[12], _vm->_moveImages[13]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(193, y, 6, VKEY_LTARROW, _vm->_moveImages[14], _vm->_moveImages[15]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(225, y, 7, VKEY_UPARROW, _vm->_moveImages[16], _vm->_moveImages[17]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(257, y, 8, VKEY_RTARROW, _vm->_moveImages[18], _vm->_moveImages[19]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(289, y, 9, 'p', _vm->_moveImages[10], _vm->_moveImages[11]);
_vm->_moveGadgetList.push_back(createButton( 1, y, 0, 't', _vm->_moveImages[0], _vm->_moveImages[1]));
_vm->_moveGadgetList.push_back(createButton( 33, y, 1, 'm', _vm->_moveImages[2], _vm->_moveImages[3]));
_vm->_moveGadgetList.push_back(createButton( 65, y, 2, 'o', _vm->_moveImages[4], _vm->_moveImages[5]));
_vm->_moveGadgetList.push_back(createButton( 97, y, 3, 'c', _vm->_moveImages[6], _vm->_moveImages[7]));
_vm->_moveGadgetList.push_back(createButton(129, y, 4, 'l', _vm->_moveImages[8], _vm->_moveImages[9]));
_vm->_moveGadgetList.push_back(createButton(161, y, 5, 'i', _vm->_moveImages[12], _vm->_moveImages[13]));
_vm->_moveGadgetList.push_back(createButton(193, y, 6, VKEY_LTARROW, _vm->_moveImages[14], _vm->_moveImages[15]));
_vm->_moveGadgetList.push_back(createButton(225, y, 7, VKEY_UPARROW, _vm->_moveImages[16], _vm->_moveImages[17]));
_vm->_moveGadgetList.push_back(createButton(257, y, 8, VKEY_RTARROW, _vm->_moveImages[18], _vm->_moveImages[19]));
_vm->_moveGadgetList.push_back(createButton(289, y, 9, 'p', _vm->_moveImages[10], _vm->_moveImages[11]));
Common::File *invFile = _vm->_resource->openDataFile("P:Inv");
if (_vm->getPlatform() == Common::kPlatformWindows) {
@ -884,25 +875,18 @@ bool DisplayMan::setUpScreens() {
for (uint16 imgIdx = 0; imgIdx < 6; imgIdx++)
_vm->_invImages[imgIdx] = new Image(invFile);
}
_vm->_invGadgetList = createButton(24, y, 0, 'm', _vm->_invImages[0], _vm->_invImages[1]);
curGadget = _vm->_invGadgetList;
curGadget->NextGadget = createButton(56, y, 1, 'g', _vm->_invImages[2], _vm->_invImages[3]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(94, y, 2, 'u', _vm->_invImages[4], _vm->_invImages[5]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(126, y, 3, 'l', _vm->_moveImages[8], _vm->_moveImages[9]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(164, y, 4, VKEY_LTARROW, _vm->_moveImages[14], _vm->_moveImages[15]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(196, y, 5, VKEY_RTARROW, _vm->_moveImages[18], _vm->_moveImages[19]);
_vm->_invGadgetList.push_back(createButton( 24, y, 0, 'm', _vm->_invImages[0], _vm->_invImages[1]));
_vm->_invGadgetList.push_back(createButton( 56, y, 1, 'g', _vm->_invImages[2], _vm->_invImages[3]));
_vm->_invGadgetList.push_back(createButton( 94, y, 2, 'u', _vm->_invImages[4], _vm->_invImages[5]));
_vm->_invGadgetList.push_back(createButton(126, y, 3, 'l', _vm->_moveImages[8], _vm->_moveImages[9]));
_vm->_invGadgetList.push_back(createButton(164, y, 4, VKEY_LTARROW, _vm->_moveImages[14], _vm->_moveImages[15]));
_vm->_invGadgetList.push_back(createButton(196, y, 5, VKEY_RTARROW, _vm->_moveImages[18], _vm->_moveImages[19]));
// The windows version has 2 extra gadgets for breadcrumb trail
// TODO: the game is really hard to play without those, maybe we could add something to enable that.
if (_vm->getPlatform() == Common::kPlatformWindows) {
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(234, y, 6, 'b', _vm->_invImages[6], _vm->_invImages[7]);
curGadget = curGadget->NextGadget;
curGadget->NextGadget = createButton(266, y, 7, 'f', _vm->_invImages[8], _vm->_invImages[9]);
_vm->_invGadgetList.push_back(createButton(234, y, 6, 'b', _vm->_invImages[6], _vm->_invImages[7]));
_vm->_invGadgetList.push_back(createButton(266, y, 7, 'f', _vm->_invImages[8], _vm->_invImages[9]));
}
delete invFile;

View File

@ -52,7 +52,6 @@ Gadget *createButton(uint16 x, uint16 y, uint16 id, uint16 key, Image *im, Image
gptr->KeyEquiv = key;
gptr->_image = im;
gptr->_altImage = imalt;
gptr->NextGadget = NULL;
return gptr;
} else
@ -62,15 +61,12 @@ Gadget *createButton(uint16 x, uint16 y, uint16 id, uint16 key, Image *im, Image
void freeButtonList(Gadget *gptrlist) {
Gadget *next = gptrlist;
while (next) {
Gadget *gptr = next;
next = next->NextGadget;
free(gptr);
void freeButtonList(GadgetList *gadgetList) {
for (GadgetList::iterator gadget = gadgetList->begin(); gadget != gadgetList->end(); ++gadget) {
free(*gadget);
}
gadgetList->clear();
}
@ -79,14 +75,12 @@ void freeButtonList(Gadget *gptrlist) {
/*****************************************************************************/
/* Draws a gadget list to the screen. */
/*****************************************************************************/
void drawGadgetList(Gadget *gadlist) {
while (gadlist) {
gadlist->_image->drawImage(gadlist->x, gadlist->y);
void drawGadgetList(GadgetList *gadgetList) {
for (GadgetList::iterator gadget = gadgetList->begin(); gadget != gadgetList->end(); ++gadget) {
(*gadget)->_image->drawImage((*gadget)->x, (*gadget)->y);
if (GADGETOFF & gadlist->GadgetFlags)
disableGadget(gadlist, 1);
gadlist = gadlist->NextGadget;
if (GADGETOFF & (*gadget)->GadgetFlags)
disableGadget((*gadget), 1);
}
}
@ -124,24 +118,26 @@ uint16 makeGadgetKeyEquiv(uint16 key) {
/* Checks whether or not the cords fall within one of the gadgets in a list */
/* of gadgets. */
/*****************************************************************************/
Gadget *LabEngine::checkNumGadgetHit(Gadget *gadlist, uint16 key) {
Gadget *LabEngine::checkNumGadgetHit(GadgetList *gadgetList, uint16 key) {
uint16 gkey = key - '0';
while (gadlist != NULL) {
if ((gkey - 1 == gadlist->GadgetID || (gkey == 0 && gadlist->GadgetID == 9) ||
(gadlist->KeyEquiv != 0 && makeGadgetKeyEquiv(key) == gadlist->KeyEquiv))
&& !(GADGETOFF & gadlist->GadgetFlags)) {
if (!gadgetList)
return NULL;
for (GadgetList::iterator gadgetItr = gadgetList->begin(); gadgetItr != gadgetList->end(); ++gadgetItr) {
Gadget *gadget = *gadgetItr;
if ((gkey - 1 == gadget->GadgetID || (gkey == 0 && gadget->GadgetID == 9) ||
(gadget->KeyEquiv != 0 && makeGadgetKeyEquiv(key) == gadget->KeyEquiv))
&& !(GADGETOFF & gadget->GadgetFlags)) {
_event->mouseHide();
gadlist->_altImage->drawImage(gadlist->x, gadlist->y);
gadget->_altImage->drawImage(gadget->x, gadget->y);
_event->mouseShow();
g_system->delayMillis(80);
_event->mouseHide();
gadlist->_image->drawImage(gadlist->x, gadlist->y);
gadget->_image->drawImage(gadget->x, gadget->y);
_event->mouseShow();
return gadlist;
} else {
gadlist = gadlist->NextGadget;
return gadget;
}
}

View File

@ -48,7 +48,6 @@ struct Gadget {
uint16 KeyEquiv; // if not zero, a key that activates gadget
uint32 GadgetFlags;
Image *_image, *_altImage;
Gadget *NextGadget;
};
extern Common::KeyState _keyPressed;
@ -57,7 +56,7 @@ extern Common::KeyState _keyPressed;
#define GADGETOFF 0x01
typedef Common::List<Gadget *> GadgetList;
/* Defines for the Class variable in IntuiMessage */
#define SIZEVERIFY 0x00000001
@ -112,8 +111,8 @@ extern Common::KeyState _keyPressed;
/*---------------------------------------------------------------------------*/
Gadget *createButton(uint16 x, uint16 y, uint16 id, uint16 key, Image *im, Image *imalt);
void freeButtonList(void *gptrlist);
void drawGadgetList(Gadget *gadlist);
void freeButtonList(GadgetList *gadgetList);
void drawGadgetList(GadgetList *gadgetList);
void disableGadget(Gadget *curgad, uint16 pencolor);
void enableGadget(Gadget *curgad);
IntuiMessage *getMsg();

View File

@ -103,8 +103,6 @@ LabEngine::LabEngine(OSystem *syst, const ADGameDescription *gameDesc)
for (int i = 0; i < 16; i++)
_tiles[i] = nullptr;
_moveGadgetList = nullptr;
_invGadgetList = nullptr;
_curFileName = nullptr;
_nextFileName = nullptr;
_newFileName = nullptr;

View File

@ -61,6 +61,8 @@ enum GameFeatures {
#define UPSCROLL 3
#define DOWNSCROLL 4
typedef Common::List<Gadget *> GadgetList;
class LabEngine : public Engine {
public:
LabEngine(OSystem *syst, const ADGameDescription *gameDesc);
@ -123,8 +125,8 @@ public:
const char *_newFileName; /* When ProcessRoom.c decides to change the filename
of the current picture. */
TextFont *_msgFont;
Gadget *_moveGadgetList;
Gadget *_invGadgetList;
GadgetList _moveGadgetList;
GadgetList _invGadgetList;
Image *_moveImages[20];
Image *_invImages[10];
Image *_numberImages[10];
@ -147,7 +149,7 @@ public:
void interfaceOff();
void interfaceOn();
void decIncInv(uint16 *CurInv, bool dec);
Gadget *checkNumGadgetHit(Gadget *gadlist, uint16 key);
Gadget *checkNumGadgetHit(GadgetList *gadgetList, uint16 key);
IntuiMessage *getMsg();
void drawMap(uint16 CurRoom, uint16 CurMsg, uint16 Floor, bool fadeout, bool fadein);
void processMap(uint16 CurRoom);

View File

@ -56,11 +56,12 @@ extern char *LOWERFLOORS, *MIDDLEFLOORS, *UPPERFLOORS, *MEDMAZEFLOORS, *HEDGEMAZ
static uint16 MapGadX[3] = {101, 55, 8}, MapGadY[3] = {105, 105, 105};
static Gadget downgadget = { 101, 105, 2, VKEY_DNARROW, 0L, NULL, NULL, NULL },
upgadget = { 55, 105, 1, VKEY_UPARROW, 0L, NULL, NULL, &downgadget },
backgadget = { 8, 105, 0, 0, 0L, NULL, NULL, &upgadget };
static Gadget
backgadget = { 8, 105, 0, 0, 0L, NULL, NULL },
upgadget = { 55, 105, 1, VKEY_UPARROW, 0L, NULL, NULL },
downgadget = { 101, 105, 2, VKEY_DNARROW, 0L, NULL, NULL };
static Gadget *MapGadgetList = &backgadget;
static GadgetList *MapGadgetList;
#define LOWERFLOOR 1
#define MIDDLEFLOOR 2
@ -93,9 +94,13 @@ static uint16 mapScaleY(uint16 y) {
/* Loads in the map data. */
/*****************************************************************************/
static bool loadMapData() {
Gadget *gptr;
uint16 counter;
MapGadgetList = new GadgetList();
MapGadgetList->push_back(&backgadget);
MapGadgetList->push_back(&upgadget);
MapGadgetList->push_back(&downgadget);
Common::File *mapImages = g_lab->_resource->openDataFile("P:MapImage");
Map = new Image(mapImages);
@ -126,12 +131,10 @@ static bool loadMapData() {
delete mapImages;
counter = 0;
gptr = MapGadgetList;
while (gptr) {
gptr->x = g_lab->_graphics->VGAScaleX(MapGadX[counter]);
gptr->y = g_lab->_graphics->VGAScaleY(MapGadY[counter]);
gptr = gptr->NextGadget;
for (GadgetList::iterator gadget = MapGadgetList->begin(); gadget != MapGadgetList->end(); ++gadget) {
(*gadget)->x = g_lab->_graphics->VGAScaleX(MapGadX[counter]);
(*gadget)->y = g_lab->_graphics->VGAScaleY(MapGadY[counter]);
counter++;
}
@ -156,6 +159,9 @@ static bool loadMapData() {
}
static void freeMapData() {
MapGadgetList->clear();
delete MapGadgetList;
delete[] Maps;
Maps = NULL;
}

View File

@ -225,7 +225,7 @@ int16 *Resource::readConditions(Common::File *file) {
RuleList *Resource::readRule(Common::File *file) {
char c;
RuleList *rules = new Common::List<Rule *>();
RuleList *rules = new RuleList();
do {
c = file->readByte();

View File

@ -155,7 +155,6 @@ void LabEngine::doWestPaper() {
/*****************************************************************************/
static bool loadJournalData() {
char filename[20];
Gadget *TopGadget = &BackG;
bool bridge, dirty, news, clean;
journalFont = g_lab->_resource->getFont("P:Journal.fon"); // FIXME: memory leak
@ -206,16 +205,21 @@ static bool loadJournalData() {
uint16 counter = 0;
while (TopGadget) {
TopGadget->x = g_lab->_graphics->VGAScaleX(JGadX[counter]);
GadgetList journalGadgetList;
journalGadgetList.push_back(&BackG);
journalGadgetList.push_back(&CancelG);
journalGadgetList.push_back(&ForwardG);
for (GadgetList::iterator gadgetIter = journalGadgetList.begin(); gadgetIter != journalGadgetList.end(); ++gadgetIter) {
Gadget *gadget = *gadgetIter;
gadget->x = g_lab->_graphics->VGAScaleX(JGadX[counter]);
if (counter == 1)
TopGadget->y = g_lab->_graphics->VGAScaleY(JGadY[counter]) + g_lab->_graphics->SVGACord(1);
gadget->y = g_lab->_graphics->VGAScaleY(JGadY[counter]) + g_lab->_graphics->SVGACord(1);
else
TopGadget->y = g_lab->_graphics->VGAScaleY(JGadY[counter]) - g_lab->_graphics->SVGACord(1);
gadget->y = g_lab->_graphics->VGAScaleY(JGadY[counter]) - g_lab->_graphics->SVGACord(1);
TopGadget->GadgetID = counter;
TopGadget = TopGadget->NextGadget;
gadget->GadgetID = counter;
counter++;
}
@ -372,6 +376,11 @@ void LabEngine::processJournal() {
/* Does the journal processing. */
/*****************************************************************************/
void LabEngine::doJournal() {
GadgetList journalGadgetList;
journalGadgetList.push_back(&BackG);
journalGadgetList.push_back(&CancelG);
journalGadgetList.push_back(&ForwardG);
_graphics->blackAllScreen();
lastpage = false;
@ -381,9 +390,6 @@ void LabEngine::doJournal() {
JBackImage._height = _graphics->_screenHeight;
JBackImage._imageData = NULL;
BackG.NextGadget = &CancelG;
CancelG.NextGadget = &ForwardG;
ScreenImage = JBackImage;
ScreenImage._imageData = _graphics->getCurrentDrawingBuffer();
@ -392,12 +398,13 @@ void LabEngine::doJournal() {
drawJournal(0, true);
_event->attachGadgetList(&BackG);
_event->attachGadgetList(&journalGadgetList);
_event->mouseShow();
processJournal();
_event->attachGadgetList(NULL);
_graphics->fade(false, 0);
_event->mouseHide();
journalGadgetList.clear();
ScreenImage._imageData = _graphics->getCurrentDrawingBuffer();