LAB: Move some code from fromCrumbs() into separate functions

This makes this huge function a bit easier to read and understand
This commit is contained in:
Filippos Karapetis 2015-12-14 23:59:24 +02:00 committed by Willem Jan Palenstijn
parent 69294eccb0
commit 521652e436
2 changed files with 410 additions and 369 deletions

View file

@ -603,10 +603,177 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
uint16 lastInv = kItemMap;
CloseDataPtr wrkClosePtr = nullptr;
bool doit;
bool leftButtonClick = false;
bool rightButtonClick = false;
_anim->_doBlack = false;
if ((msgClass == RAWKEY) && (!_graphics->_longWinInFront)) {
if (!processKey(curMsg, msgClass, qualifier, curPos, curInv, forceDraw, code))
return false;
}
leftButtonClick = (msgClass == MOUSEBUTTONS) && (IEQUALIFIER_LEFTBUTTON & qualifier);
rightButtonClick = (msgClass == MOUSEBUTTONS) && (IEQUALIFIER_RIGHTBUTTON & qualifier);
if (_graphics->_longWinInFront) {
if ((msgClass == RAWKEY) || (leftButtonClick || rightButtonClick)) {
_graphics->_longWinInFront = false;
_graphics->_doNotDrawMessage = false;
_graphics->drawPanel();
drawRoomMessage(curInv, _closeDataPtr);
_graphics->screenUpdate();
}
} else if ((msgClass == BUTTONUP) && !_alternate) {
processMainButton(wrkClosePtr, curInv, lastInv, oldDirection, forceDraw, buttonId, actionMode);
} else if ((msgClass == BUTTONUP) && _alternate) {
processAltButton(curInv, lastInv, buttonId, actionMode);
} else if (leftButtonClick && _mainDisplay) {
interfaceOff();
_mainDisplay = true;
doit = false;
if (_closeDataPtr) {
switch (_closeDataPtr->_closeUpType) {
case SPECIALLOCK:
if (_mainDisplay)
_tilePuzzle->mouseCombination(curPos);
break;
case SPECIALBRICK:
if (_mainDisplay)
_tilePuzzle->mouseTile(curPos);
break;
default:
doit = true;
break;
}
} else
doit = true;
if (doit) {
wrkClosePtr = nullptr;
eatMessages();
switch (actionMode) {
case 0:
// Take something.
if (doActionRule(Common::Point(curPos.x, curPos.y), actionMode, _roomNum, &_closeDataPtr))
_curFileName = _newFileName;
else if (takeItem(curPos.x, curPos.y, &_closeDataPtr))
drawStaticMessage(kTextTakeItem);
else if (doActionRule(curPos, TAKEDEF - 1, _roomNum, &_closeDataPtr))
_curFileName = _newFileName;
else if (doActionRule(curPos, TAKE - 1, 0, &_closeDataPtr))
_curFileName = _newFileName;
else if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
break;
case 1:
case 2:
case 3:
// Manipulate an object, Open up a "door" or Close a "door"
if (doActionRule(curPos, actionMode, _roomNum, &_closeDataPtr))
_curFileName = _newFileName;
else if (!doActionRule(curPos, actionMode, 0, &_closeDataPtr)) {
if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
}
break;
case 4: {
// Look at closeups
CloseDataPtr tmpClosePtr = _closeDataPtr;
setCurrentClose(curPos, &tmpClosePtr, true);
if (_closeDataPtr == tmpClosePtr) {
if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
} else if (tmpClosePtr->_graphicName) {
if (*(tmpClosePtr->_graphicName)) {
_anim->_doBlack = true;
_closeDataPtr = tmpClosePtr;
} else if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
} else if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
}
break;
case 5:
if (_conditions->in(curInv)) {
// Use an item on something else
if (doOperateRule(curPos, curInv, &_closeDataPtr)) {
_curFileName = _newFileName;
if (!_conditions->in(curInv))
decIncInv(&curInv, false);
} else if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
}
}
}
mayShowCrumbIndicator();
_graphics->screenUpdate();
} else if (rightButtonClick) {
eatMessages();
_alternate = !_alternate;
_anim->_doBlack = true;
_graphics->_doNotDrawMessage = false;
_mainDisplay = true;
// Sets the correct button list
interfaceOn();
if (_alternate) {
if (lastInv && _conditions->in(lastInv))
curInv = lastInv;
else
decIncInv(&curInv, false);
}
_graphics->drawPanel();
drawRoomMessage(curInv, _closeDataPtr);
mayShowCrumbIndicator();
_graphics->screenUpdate();
} else if (msgClass == DELTAMOVE) {
ViewData *vptr = getViewData(_roomNum, _direction);
CloseDataPtr oldClosePtr = vptr->_closeUps;
if (!wrkClosePtr) {
CloseDataPtr tmpClosePtr = _closeDataPtr;
setCurrentClose(curPos, &tmpClosePtr, true);
if (!tmpClosePtr || (tmpClosePtr == _closeDataPtr)) {
if (!_closeDataPtr)
wrkClosePtr = oldClosePtr;
else
wrkClosePtr = _closeDataPtr->_subCloseUps;
} else
wrkClosePtr = tmpClosePtr->_nextCloseUp;
} else
wrkClosePtr = wrkClosePtr->_nextCloseUp;
if (!wrkClosePtr) {
if (!_closeDataPtr)
wrkClosePtr = oldClosePtr;
else
wrkClosePtr = _closeDataPtr->_subCloseUps;
}
if (wrkClosePtr)
_event->setMousePos(Common::Point(_utils->scaleX((wrkClosePtr->_x1 + wrkClosePtr->_x2) / 2), _utils->scaleY((wrkClosePtr->_y1 + wrkClosePtr->_y2) / 2)));
}
return true;
}
bool LabEngine::processKey(IntuiMessage *curMsg, uint32 &msgClass, uint16 &qualifier, Common::Point &curPos, uint16 &curInv, bool &forceDraw, uint16 code) {
byte codeLower = tolower(code);
if (code == 13) {
@ -614,14 +781,16 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
msgClass = MOUSEBUTTONS;
qualifier = IEQUALIFIER_LEFTBUTTON;
curPos = _event->getMousePos();
} else if (getPlatform() == Common::kPlatformWindows && codeLower == 'b') {
}
else if (getPlatform() == Common::kPlatformWindows && codeLower == 'b') {
// Start bread crumbs
_breadCrumbs[0]._roomNum = 0;
_numCrumbs = 0;
_droppingCrumbs = true;
mayShowCrumbIndicator();
_graphics->screenUpdate();
} else if (codeLower == 'f' || codeLower == 'r') {
}
else if (codeLower == 'f' || codeLower == 'r') {
// Follow bread crumbs
if (_droppingCrumbs) {
if (_numCrumbs > 0) {
@ -644,7 +813,8 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
drawRoomMessage(curInv, _closeDataPtr);
_graphics->screenUpdate();
}
} else {
}
else {
_breadCrumbs[0]._roomNum = 0;
_droppingCrumbs = false;
@ -653,7 +823,8 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
_graphics->screenUpdate();
}
}
} else if (code == 315 || codeLower == 'x' || codeLower == 'q') {
}
else if (code == 315 || codeLower == 'x' || codeLower == 'q') {
// Quit?
_graphics->_doNotDrawMessage = false;
_graphics->drawMessage("Do you want to quit? (Y/N)");
@ -669,16 +840,19 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
// Does music load and next animation frame when you've run out of messages
_music->updateMusic();
_anim->diffNextFrame();
} else {
}
else {
if (curMsg->_msgClass == RAWKEY) {
codeLower = tolower(curMsg->_code);
if (codeLower == 'y' || codeLower == 'q') {
_anim->stopDiff();
return false;
} else if (curMsg->_code < 128) {
}
else if (curMsg->_code < 128) {
break;
}
} else if (curMsg->_msgClass == MOUSEBUTTONS) {
}
else if (curMsg->_msgClass == MOUSEBUTTONS) {
break;
}
}
@ -686,28 +860,22 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
forceDraw = true;
interfaceOn();
} else if (code == 9) {
}
else if (code == 9) {
// TAB key
msgClass = DELTAMOVE;
} else if (code == 27) {
}
else if (code == 27) {
// ESC key
_closeDataPtr = nullptr;
}
eatMessages();
}
if (_graphics->_longWinInFront) {
if ((msgClass == RAWKEY) || ((msgClass == MOUSEBUTTONS) &&
((IEQUALIFIER_LEFTBUTTON & qualifier) ||
(IEQUALIFIER_RIGHTBUTTON & qualifier)))) {
_graphics->_longWinInFront = false;
_graphics->_doNotDrawMessage = false;
_graphics->drawPanel();
drawRoomMessage(curInv, _closeDataPtr);
_graphics->screenUpdate();
}
} else if ((msgClass == BUTTONUP) && !_alternate) {
return true;
}
void LabEngine::processMainButton(CloseDataPtr wrkClosePtr, uint16 &curInv, uint16 &lastInv, uint16 &oldDirection, bool &forceDraw, uint16 buttonId, uint16 &actionMode) {
uint16 newDir;
switch (buttonId) {
@ -723,7 +891,8 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
wrkClosePtr = nullptr;
_closeDataPtr = nullptr;
mayShowCrumbIndicator();
} else {
}
else {
uint16 oldActionMode = actionMode;
actionMode = buttonId;
@ -747,7 +916,8 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
if (lastInv && _conditions->in(lastInv)) {
curInv = lastInv;
_nextFileName = getInvName(curInv);
} else
}
else
decIncInv(&curInv, false);
_graphics->drawPanel();
@ -793,7 +963,8 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
if (doGoForward(&_closeDataPtr)) {
if (oldRoomNum == _roomNum)
_anim->_doBlack = true;
} else {
}
else {
_anim->_doBlack = true;
_direction = processArrow(_direction, buttonId - 6);
@ -803,7 +974,8 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
_roomsFound->inclElement(_roomNum);
_curFileName = " ";
forceDraw = true;
} else {
}
else {
_anim->_doBlack = true;
drawStaticMessage(kTextNoPath);
}
@ -814,19 +986,22 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
if (_direction == oldDirection) {
_followingCrumbs = false;
}
} else {
}
else {
if (_roomNum == oldRoomNum) { // didn't get there?
_followingCrumbs = false;
}
}
} else if (_droppingCrumbs && oldRoomNum != _roomNum) {
}
else if (_droppingCrumbs && oldRoomNum != _roomNum) {
// If in surreal maze, turn off DroppingCrumbs.
if (_roomNum >= 245 && _roomNum <= 280) {
_followingCrumbs = false;
_droppingCrumbs = false;
_numCrumbs = 0;
_breadCrumbs[0]._roomNum = 0;
} else {
}
else {
bool intersect = false;
for (int idx = 0; idx < _numCrumbs; idx++) {
if (_breadCrumbs[idx]._roomNum == _roomNum) {
@ -852,7 +1027,11 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
break;
}
_graphics->screenUpdate();
} else if ((msgClass == BUTTONUP) && _alternate) {
}
void LabEngine::processAltButton(uint16 &curInv, uint16 &lastInv, uint16 buttonId, uint16 &actionMode) {
bool doit;
_anim->_doBlack = true;
switch (buttonId) {
@ -965,7 +1144,8 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
interfaceOn();
_graphics->drawPanel();
drawRoomMessage(curInv, _closeDataPtr);
} else {
}
else {
_breadCrumbs[0]._roomNum = 0;
_droppingCrumbs = false;
@ -976,148 +1156,6 @@ bool LabEngine::fromCrumbs(uint32 tmpClass, uint16 code, uint16 qualifier, Commo
break;
}
_graphics->screenUpdate();
} else if ((msgClass == MOUSEBUTTONS) && (IEQUALIFIER_LEFTBUTTON & qualifier) && _mainDisplay) {
interfaceOff();
_mainDisplay = true;
doit = false;
if (_closeDataPtr) {
switch (_closeDataPtr->_closeUpType) {
case SPECIALLOCK:
if (_mainDisplay)
_tilePuzzle->mouseCombination(curPos);
break;
case SPECIALBRICK:
if (_mainDisplay)
_tilePuzzle->mouseTile(curPos);
break;
default:
doit = true;
break;
}
} else
doit = true;
if (doit) {
wrkClosePtr = nullptr;
eatMessages();
switch (actionMode) {
case 0:
// Take something.
if (doActionRule(Common::Point(curPos.x, curPos.y), actionMode, _roomNum, &_closeDataPtr))
_curFileName = _newFileName;
else if (takeItem(curPos.x, curPos.y, &_closeDataPtr))
drawStaticMessage(kTextTakeItem);
else if (doActionRule(curPos, TAKEDEF - 1, _roomNum, &_closeDataPtr))
_curFileName = _newFileName;
else if (doActionRule(curPos, TAKE - 1, 0, &_closeDataPtr))
_curFileName = _newFileName;
else if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
break;
case 1:
case 2:
case 3:
// Manipulate an object, Open up a "door" or Close a "door"
if (doActionRule(curPos, actionMode, _roomNum, &_closeDataPtr))
_curFileName = _newFileName;
else if (!doActionRule(curPos, actionMode, 0, &_closeDataPtr)) {
if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
}
break;
case 4: {
// Look at closeups
CloseDataPtr tmpClosePtr = _closeDataPtr;
setCurrentClose(curPos, &tmpClosePtr, true);
if (_closeDataPtr == tmpClosePtr) {
if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
} else if (tmpClosePtr->_graphicName) {
if (*(tmpClosePtr->_graphicName)) {
_anim->_doBlack = true;
_closeDataPtr = tmpClosePtr;
} else if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
} else if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
}
break;
case 5:
if (_conditions->in(curInv)) {
// Use an item on something else
if (doOperateRule(curPos, curInv, &_closeDataPtr)) {
_curFileName = _newFileName;
if (!_conditions->in(curInv))
decIncInv(&curInv, false);
} else if (curPos.y < (_utils->vgaScaleY(149) + _utils->svgaCord(2)))
drawStaticMessage(kTextNothing);
}
}
}
mayShowCrumbIndicator();
_graphics->screenUpdate();
} else if (msgClass == DELTAMOVE) {
ViewData *vptr = getViewData(_roomNum, _direction);
CloseDataPtr oldClosePtr = vptr->_closeUps;
if (!wrkClosePtr) {
CloseDataPtr tmpClosePtr = _closeDataPtr;
setCurrentClose(curPos, &tmpClosePtr, true);
if (!tmpClosePtr || (tmpClosePtr == _closeDataPtr)) {
if (!_closeDataPtr)
wrkClosePtr = oldClosePtr;
else
wrkClosePtr = _closeDataPtr->_subCloseUps;
} else
wrkClosePtr = tmpClosePtr->_nextCloseUp;
} else
wrkClosePtr = wrkClosePtr->_nextCloseUp;
if (!wrkClosePtr) {
if (!_closeDataPtr)
wrkClosePtr = oldClosePtr;
else
wrkClosePtr = _closeDataPtr->_subCloseUps;
}
if (wrkClosePtr)
_event->setMousePos(Common::Point(_utils->scaleX((wrkClosePtr->_x1 + wrkClosePtr->_x2) / 2), _utils->scaleY((wrkClosePtr->_y1 + wrkClosePtr->_y2) / 2)));
} else if ((msgClass == MOUSEBUTTONS) && (IEQUALIFIER_RIGHTBUTTON & qualifier)) {
eatMessages();
_alternate = !_alternate;
_anim->_doBlack = true;
_graphics->_doNotDrawMessage = false;
_mainDisplay = true;
// Sets the correct button list
interfaceOn();
if (_alternate) {
if (lastInv && _conditions->in(lastInv))
curInv = lastInv;
else
decIncInv(&curInv, false);
}
_graphics->drawPanel();
drawRoomMessage(curInv, _closeDataPtr);
mayShowCrumbIndicator();
_graphics->screenUpdate();
}
return true;
}
void LabEngine::go() {

View file

@ -251,6 +251,9 @@ private:
void setCurrentClose(Common::Point pos, CloseDataPtr *closePtrList, bool useAbsoluteCoords);
bool takeItem(uint16 x, uint16 y, CloseDataPtr *closePtrList);
void turnPage(bool fromLeft);
bool processKey(IntuiMessage *curMsg, uint32 &msgClass, uint16 &qualifier, Common::Point &curPos, uint16 &curInv, bool &forceDraw, uint16 code);
void processMainButton(CloseDataPtr wrkClosePtr, uint16 &curInv, uint16 &lastInv, uint16 &oldDirection, bool &forceDraw, uint16 buttonId, uint16 &actionMode);
void processAltButton(uint16 &curInv, uint16 &lastInv, uint16 buttonId, uint16 &actionMode);
private:
bool saveGame(int slot, Common::String desc);