diff options
| author | David Turner | 2011-12-18 18:29:05 -0800 |
|---|---|---|
| committer | David Turner | 2011-12-18 18:29:05 -0800 |
| commit | 538d83408091e9077f451f45c1ac1127f302b47d (patch) | |
| tree | a8b3ffaf9199665b41e8f990549fc267c6421b46 /engines/agi | |
| parent | f0eee81d327957cddb85c5a1ffe7a308a377f636 (diff) | |
| parent | f722542ceea557e906699c60b10b3ace1f41c238 (diff) | |
| download | scummvm-rg350-538d83408091e9077f451f45c1ac1127f302b47d.tar.gz scummvm-rg350-538d83408091e9077f451f45c1ac1127f302b47d.tar.bz2 scummvm-rg350-538d83408091e9077f451f45c1ac1127f302b47d.zip | |
Merge pull request #131 from digitall/goto_considered_harmful
Goto Considered Harmful...
The following commits should improve the ScummVM code structure by reducing the number of gotos used in various engine code.
They should implement identical functionality, but without using goto and without the result being less readable/maintainable than the version with goto.
Diffstat (limited to 'engines/agi')
| -rw-r--r-- | engines/agi/cycle.cpp | 75 | ||||
| -rw-r--r-- | engines/agi/menu.cpp | 129 | ||||
| -rw-r--r-- | engines/agi/preagi_winnie.cpp | 61 | ||||
| -rw-r--r-- | engines/agi/predictive.cpp | 34 | ||||
| -rw-r--r-- | engines/agi/saveload.cpp | 189 | ||||
| -rw-r--r-- | engines/agi/text.cpp | 22 |
6 files changed, 265 insertions, 245 deletions
diff --git a/engines/agi/cycle.cpp b/engines/agi/cycle.cpp index 99649fb437..5daadbd1df 100644 --- a/engines/agi/cycle.cpp +++ b/engines/agi/cycle.cpp @@ -248,44 +248,47 @@ int AgiEngine::mainCycle() { if (kascii) setvar(vKey, kascii); -process_key: - - switch (_game.inputMode) { - case INPUT_NORMAL: - if (!handleController(key)) { - if (key == 0 || !_game.inputEnabled) - break; - handleKeys(key); - - // if ESC pressed, activate menu before - // accept.input from the interpreter cycle - // sets the input mode to normal again - // (closes: #540856) - if (key == KEY_ESCAPE) { - key = 0; - goto process_key; + bool restartProcessKey; + do { + restartProcessKey = false; + + switch (_game.inputMode) { + case INPUT_NORMAL: + if (!handleController(key)) { + if (key == 0 || !_game.inputEnabled) + break; + handleKeys(key); + + // if ESC pressed, activate menu before + // accept.input from the interpreter cycle + // sets the input mode to normal again + // (closes: #540856) + if (key == KEY_ESCAPE) { + key = 0; + restartProcessKey = true; + } + + // commented out to close Sarien bug #438872 + //if (key) + // _game.keypress = key; } - - // commented out to close Sarien bug #438872 - //if (key) - // _game.keypress = key; + break; + case INPUT_GETSTRING: + handleController(key); + handleGetstring(key); + setvar(vKey, 0); // clear ENTER key + break; + case INPUT_MENU: + _menu->keyhandler(key); + _gfx->doUpdate(); + return false; + case INPUT_NONE: + handleController(key); + if (key) + _game.keypress = key; + break; } - break; - case INPUT_GETSTRING: - handleController(key); - handleGetstring(key); - setvar(vKey, 0); // clear ENTER key - break; - case INPUT_MENU: - _menu->keyhandler(key); - _gfx->doUpdate(); - return false; - case INPUT_NONE: - handleController(key); - if (key) - _game.keypress = key; - break; - } + } while (restartProcessKey); _gfx->doUpdate(); if (_game.msgBoxTicks > 0) diff --git a/engines/agi/menu.cpp b/engines/agi/menu.cpp index b504cd3e30..cac1701596 100644 --- a/engines/agi/menu.cpp +++ b/engines/agi/menu.cpp @@ -279,6 +279,7 @@ bool Menu::keyhandler(int key) { static int clockVal; static int menuActive = false; static int buttonUsed = 0; + bool exitMenu = false; if (!_vm->getflag(fMenusWork) && !(_vm->getFeatures() & GF_MENUS)) return false; @@ -288,9 +289,8 @@ bool Menu::keyhandler(int key) { _vm->_game.clockEnabled = false; drawMenuBar(); } - // + // Mouse handling - // if (_vm->_mouse.button) { int hmenu, vmenu; @@ -372,83 +372,84 @@ bool Menu::keyhandler(int key) { debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); _vm->_game.controllerOccured[d->event] = true; _vm->_menuSelected = true; - - goto exit_menu; + break; } } } - goto exit_menu; + exitMenu = true; } } - if (!menuActive) { - if (_hCurMenu >= 0) { - drawMenuHilite(_hCurMenu); - drawMenuOption(_hCurMenu); - if (!buttonUsed && _vCurMenu >= 0) - drawMenuOptionHilite(_hCurMenu, _vCurMenu); + if (!exitMenu) { + if (!menuActive) { + if (_hCurMenu >= 0) { + drawMenuHilite(_hCurMenu); + drawMenuOption(_hCurMenu); + if (!buttonUsed && _vCurMenu >= 0) + drawMenuOptionHilite(_hCurMenu, _vCurMenu); + } + menuActive = true; } - menuActive = true; - } - switch (key) { - case KEY_ESCAPE: - debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ESCAPE"); - goto exit_menu; - case KEY_ENTER: - { - debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ENTER"); - AgiMenuOption* d = getMenuOption(_hCurMenu, _vCurMenu); - - if (d->enabled) { - debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); - _vm->_game.controllerOccured[d->event] = true; - _vm->_menuSelected = true; - goto exit_menu; + switch (key) { + case KEY_ESCAPE: + debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ESCAPE"); + exitMenu = true; + break; + case KEY_ENTER: + { + debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ENTER"); + AgiMenuOption* d = getMenuOption(_hCurMenu, _vCurMenu); + + if (d->enabled) { + debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); + _vm->_game.controllerOccured[d->event] = true; + _vm->_menuSelected = true; + exitMenu = true; + } + break; } - break; - } - case KEY_DOWN: - case KEY_UP: - _vCurMenu += key == KEY_DOWN ? 1 : -1; + case KEY_DOWN: + case KEY_UP: + _vCurMenu += key == KEY_DOWN ? 1 : -1; - if (_vCurMenu < 0) - _vCurMenu = _vMaxMenu[_hCurMenu]; - if (_vCurMenu > _vMaxMenu[_hCurMenu]) - _vCurMenu = 0; + if (_vCurMenu < 0) + _vCurMenu = _vMaxMenu[_hCurMenu]; + if (_vCurMenu > _vMaxMenu[_hCurMenu]) + _vCurMenu = 0; - drawMenuOption(_hCurMenu); - drawMenuOptionHilite(_hCurMenu, _vCurMenu); - break; - case KEY_RIGHT: - case KEY_LEFT: - _hCurMenu += key == KEY_RIGHT ? 1 : -1; - - if (_hCurMenu < 0) - _hCurMenu = _hMaxMenu; - if (_hCurMenu > _hMaxMenu) - _hCurMenu = 0; - - _vCurMenu = 0; - newMenuSelected(_hCurMenu); - drawMenuOptionHilite(_hCurMenu, _vCurMenu); - break; - } + drawMenuOption(_hCurMenu); + drawMenuOptionHilite(_hCurMenu, _vCurMenu); + break; + case KEY_RIGHT: + case KEY_LEFT: + _hCurMenu += key == KEY_RIGHT ? 1 : -1; - return true; + if (_hCurMenu < 0) + _hCurMenu = _hMaxMenu; + if (_hCurMenu > _hMaxMenu) + _hCurMenu = 0; -exit_menu: - buttonUsed = 0; - _picture->showPic(); - _vm->writeStatus(); + _vCurMenu = 0; + newMenuSelected(_hCurMenu); + drawMenuOptionHilite(_hCurMenu, _vCurMenu); + break; + } + } - _vm->setvar(vKey, 0); - _vm->_game.keypress = 0; - _vm->_game.clockEnabled = clockVal; - _vm->oldInputMode(); + if (exitMenu) { + buttonUsed = 0; + _picture->showPic(); + _vm->writeStatus(); - debugC(3, kDebugLevelMenu, "exit_menu: input mode reset to %d", _vm->_game.inputMode); - menuActive = false; + _vm->setvar(vKey, 0); + _vm->_game.keypress = 0; + _vm->_game.clockEnabled = clockVal; + _vm->oldInputMode(); + + debugC(3, kDebugLevelMenu, "exit_menu: input mode reset to %d", _vm->_game.inputMode); + menuActive = false; + } return true; } diff --git a/engines/agi/preagi_winnie.cpp b/engines/agi/preagi_winnie.cpp index cc5c2470ae..53863a8c7e 100644 --- a/engines/agi/preagi_winnie.cpp +++ b/engines/agi/preagi_winnie.cpp @@ -1006,36 +1006,47 @@ void WinnieEngine::gameLoop() { WTP_ROOM_HDR hdr; uint8 *roomdata = (uint8 *)malloc(4096); int iBlock; + uint8 decodePhase = 0; -phase0: - if (!_gameStateWinnie.nObjMiss && (_room == IDI_WTP_ROOM_PICNIC)) - _room = IDI_WTP_ROOM_PARTY; + while (!shouldQuit()) { + if (decodePhase == 0) { + if (!_gameStateWinnie.nObjMiss && (_room == IDI_WTP_ROOM_PICNIC)) + _room = IDI_WTP_ROOM_PARTY; - readRoom(_room, roomdata, hdr); - drawRoomPic(); - _gfx->doUpdate(); + readRoom(_room, roomdata, hdr); + drawRoomPic(); + _gfx->doUpdate(); + decodePhase = 1; + } -phase1: - if (getObjInRoom(_room)) { - printObjStr(getObjInRoom(_room), IDI_WTP_OBJ_DESC); - getSelection(kSelAnyKey); - } + if (decodePhase == 1) { + if (getObjInRoom(_room)) { + printObjStr(getObjInRoom(_room), IDI_WTP_OBJ_DESC); + getSelection(kSelAnyKey); + } + decodePhase = 2; + } -phase2: - for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { - if (parser(hdr.ofsDesc[iBlock] - _roomOffset, iBlock, roomdata) == IDI_WTP_PAR_BACK) - goto phase1; - } + if (decodePhase == 2) { + for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { + if (parser(hdr.ofsDesc[iBlock] - _roomOffset, iBlock, roomdata) == IDI_WTP_PAR_BACK) { + decodePhase = 1; + break; + } + } + if (decodePhase == 2) + decodePhase = 3; + } - while (!shouldQuit()) { - for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { - switch (parser(hdr.ofsBlock[iBlock] - _roomOffset, iBlock, roomdata)) { - case IDI_WTP_PAR_GOTO: - goto phase0; - break; - case IDI_WTP_PAR_BACK: - goto phase2; - break; + if (decodePhase == 3) { + for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { + if (parser(hdr.ofsBlock[iBlock] - _roomOffset, iBlock, roomdata) == IDI_WTP_PAR_GOTO) { + decodePhase = 0; + break; + } else if (parser(hdr.ofsBlock[iBlock] - _roomOffset, iBlock, roomdata) == IDI_WTP_PAR_BACK) { + decodePhase = 2; + break; + } } } } diff --git a/engines/agi/predictive.cpp b/engines/agi/predictive.cpp index edfe83b1cb..3290068d5a 100644 --- a/engines/agi/predictive.cpp +++ b/engines/agi/predictive.cpp @@ -96,8 +96,6 @@ void bringWordtoTop(char *str, int wordnum) { } bool AgiEngine::predictiveDialog() { - int key = 0, active = -1, lastactive = 0; - bool rc = false; uint8 x; int y; int bx[17], by[17]; @@ -105,7 +103,6 @@ bool AgiEngine::predictiveDialog() { char temp[MAXWORDLEN + 1], repeatcount[MAXWORDLEN]; AgiBlock tmpwindow; bool navigationwithkeys = false; - bool processkey; const char *buttonStr[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }; const char *buttons[] = { @@ -189,8 +186,11 @@ bool AgiEngine::predictiveDialog() { int mode = kModePre; bool needRefresh = true; - - while (!shouldQuit()) { + int active = -1, lastactive = 0; + bool rc = false; + bool closeDialog = false; + bool enterPredictiveResult = false; + while (!closeDialog && !shouldQuit()) { if (needRefresh) { for (int i = 0; buttons[i]; i++) { int color1 = colors[i * 2]; @@ -234,9 +234,10 @@ bool AgiEngine::predictiveDialog() { _gfx->doUpdate(); } + bool processkey = false; + pollTimer(); - key = doPollKeyboard(); - processkey = false; + int key = doPollKeyboard(); switch (key) { case KEY_ENTER: if (navigationwithkeys) { @@ -251,7 +252,8 @@ bool AgiEngine::predictiveDialog() { break; case KEY_ESCAPE: rc = false; - goto getout; + closeDialog = true; + break; case BUTTON_LEFT: navigationwithkeys = false; for (int i = 0; buttons[i]; i++) { @@ -361,7 +363,7 @@ bool AgiEngine::predictiveDialog() { break; } - if (processkey) { + if (processkey && !closeDialog) { if (active >= 0) { needRefresh = true; lastactive = active; @@ -442,7 +444,8 @@ bool AgiEngine::predictiveDialog() { if (mode == kModePre && _predictiveDictActLine && numMatchingWords > 1 && _wordNumber != 0) bringWordtoTop(_predictiveDictActLine, _wordNumber); rc = true; - goto press; + enterPredictiveResult = true; + closeDialog = true; } else if (active == 14) { // Mode mode++; if (mode > kModeAbc) @@ -456,17 +459,18 @@ bool AgiEngine::predictiveDialog() { _currentWord.clear(); memset(repeatcount, 0, sizeof(repeatcount)); } else { - goto press; + enterPredictiveResult = true; + closeDialog = true; } } } } - press: - Common::strlcpy(_predictiveResult, prefix.c_str(), sizeof(_predictiveResult)); - Common::strlcat(_predictiveResult, _currentWord.c_str(), sizeof(_predictiveResult)); + if (enterPredictiveResult) { + Common::strlcpy(_predictiveResult, prefix.c_str(), sizeof(_predictiveResult)); + Common::strlcat(_predictiveResult, _currentWord.c_str(), sizeof(_predictiveResult)); + } - getout: // if another window was shown, bring it up again if (!tmpwindow.active) closeWindow(); diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 1bcabd507f..00d6a1c8dd 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -609,8 +609,8 @@ int AgiEngine::selectSlot() { AllowSyntheticEvents on(this); int oldFirstSlot = _firstSlot + 1; int oldActive = active + 1; - - while (!(shouldQuit() || _restartGame)) { + bool exitSelectSlot = false; + while (!exitSelectSlot && !(shouldQuit() || _restartGame)) { int sbPos = 0; // Use the extreme scrollbar positions only if the extreme @@ -661,119 +661,122 @@ int AgiEngine::selectSlot() { // out of the dead loop if (getflag(fRestoreJustRan)) { rc = -2; - goto getout; + exitSelectSlot = true; } - switch (key) { - case KEY_ENTER: - rc = active; - strncpy(_game.strings[MAX_STRINGS], desc[i], MAX_STRINGLEN); - goto press; - case KEY_ESCAPE: - rc = -1; - goto getout; - case BUTTON_LEFT: - if (_gfx->testButton(buttonX[0], buttonY, buttonText[0])) { + if (!exitSelectSlot) { + switch (key) { + case KEY_ENTER: rc = active; strncpy(_game.strings[MAX_STRINGS], desc[i], MAX_STRINGLEN); - goto press; - } - if (_gfx->testButton(buttonX[1], buttonY, buttonText[1])) { + debugC(8, kDebugLevelMain | kDebugLevelInput, "Button pressed: %d", rc); + exitSelectSlot = true; + break; + case KEY_ESCAPE: rc = -1; - goto getout; - } - slotClicked = ((int)_mouse.y - 1) / CHAR_COLS - (vm + 4); - xmin = (hm + 1) * CHAR_COLS; - xmax = xmin + CHAR_COLS * 34; - if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) { - if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) - active = slotClicked; - } - xmin = (hm + 36) * CHAR_COLS; - xmax = xmin + CHAR_COLS; - if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) { - if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) { - if (slotClicked == 0) - keyEnqueue(KEY_UP); - else if (slotClicked == NUM_VISIBLE_SLOTS - 1) - keyEnqueue(KEY_DOWN); - else if (slotClicked < sbPos) - keyEnqueue(KEY_UP_RIGHT); - else if (slotClicked > sbPos) - keyEnqueue(KEY_DOWN_RIGHT); + exitSelectSlot = true; + break; + case BUTTON_LEFT: + if (_gfx->testButton(buttonX[0], buttonY, buttonText[0])) { + rc = active; + strncpy(_game.strings[MAX_STRINGS], desc[i], MAX_STRINGLEN); + debugC(8, kDebugLevelMain | kDebugLevelInput, "Button pressed: %d", rc); + exitSelectSlot = true; + } else if (_gfx->testButton(buttonX[1], buttonY, buttonText[1])) { + rc = -1; + exitSelectSlot = true; + } else { + slotClicked = ((int)_mouse.y - 1) / CHAR_COLS - (vm + 4); + xmin = (hm + 1) * CHAR_COLS; + xmax = xmin + CHAR_COLS * 34; + if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) { + if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) + active = slotClicked; + } + xmin = (hm + 36) * CHAR_COLS; + xmax = xmin + CHAR_COLS; + if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) { + if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) { + if (slotClicked == 0) + keyEnqueue(KEY_UP); + else if (slotClicked == NUM_VISIBLE_SLOTS - 1) + keyEnqueue(KEY_DOWN); + else if (slotClicked < sbPos) + keyEnqueue(KEY_UP_RIGHT); + else if (slotClicked > sbPos) + keyEnqueue(KEY_DOWN_RIGHT); + } + } } - } - break; - case KEY_DOWN: - active++; - if (active >= NUM_VISIBLE_SLOTS) { - if (_firstSlot + NUM_VISIBLE_SLOTS < NUM_SLOTS) { + break; + + case KEY_DOWN: + active++; + if (active >= NUM_VISIBLE_SLOTS) { + if (_firstSlot + NUM_VISIBLE_SLOTS < NUM_SLOTS) { + _firstSlot++; + for (i = 1; i < NUM_VISIBLE_SLOTS; i++) + memcpy(desc[i - 1], desc[i], sizeof(desc[0])); + getSavegameDescription(_firstSlot + NUM_VISIBLE_SLOTS - 1, desc[NUM_VISIBLE_SLOTS - 1]); + } + active = NUM_VISIBLE_SLOTS - 1; + } + break; + case KEY_UP: + active--; + if (active < 0) { + active = 0; + if (_firstSlot > 0) { + _firstSlot--; + for (i = NUM_VISIBLE_SLOTS - 1; i > 0; i--) + memcpy(desc[i], desc[i - 1], sizeof(desc[0])); + getSavegameDescription(_firstSlot, desc[0]); + } + } + break; + + // Page Up/Down and mouse wheel scrolling all leave 'active' + // unchanged so that a visible slot will remain selected. + + case WHEEL_DOWN: + if (_firstSlot < NUM_SLOTS - NUM_VISIBLE_SLOTS) { _firstSlot++; for (i = 1; i < NUM_VISIBLE_SLOTS; i++) memcpy(desc[i - 1], desc[i], sizeof(desc[0])); getSavegameDescription(_firstSlot + NUM_VISIBLE_SLOTS - 1, desc[NUM_VISIBLE_SLOTS - 1]); } - active = NUM_VISIBLE_SLOTS - 1; - } - break; - case KEY_UP: - active--; - if (active < 0) { - active = 0; + break; + case WHEEL_UP: if (_firstSlot > 0) { _firstSlot--; for (i = NUM_VISIBLE_SLOTS - 1; i > 0; i--) memcpy(desc[i], desc[i - 1], sizeof(desc[0])); getSavegameDescription(_firstSlot, desc[0]); } + break; + case KEY_DOWN_RIGHT: + // This is probably triggered by Page Down. + _firstSlot += NUM_VISIBLE_SLOTS; + if (_firstSlot > NUM_SLOTS - NUM_VISIBLE_SLOTS) { + _firstSlot = NUM_SLOTS - NUM_VISIBLE_SLOTS; + } + for (i = 0; i < NUM_VISIBLE_SLOTS; i++) + getSavegameDescription(_firstSlot + i, desc[i]); + break; + case KEY_UP_RIGHT: + // This is probably triggered by Page Up. + _firstSlot -= NUM_VISIBLE_SLOTS; + if (_firstSlot < 0) { + _firstSlot = 0; + } + for (i = 0; i < NUM_VISIBLE_SLOTS; i++) + getSavegameDescription(_firstSlot + i, desc[i]); + break; } - break; - - // Page Up/Down and mouse wheel scrolling all leave 'active' - // unchanged so that a visible slot will remain selected. - - case WHEEL_DOWN: - if (_firstSlot < NUM_SLOTS - NUM_VISIBLE_SLOTS) { - _firstSlot++; - for (i = 1; i < NUM_VISIBLE_SLOTS; i++) - memcpy(desc[i - 1], desc[i], sizeof(desc[0])); - getSavegameDescription(_firstSlot + NUM_VISIBLE_SLOTS - 1, desc[NUM_VISIBLE_SLOTS - 1]); - } - break; - case WHEEL_UP: - if (_firstSlot > 0) { - _firstSlot--; - for (i = NUM_VISIBLE_SLOTS - 1; i > 0; i--) - memcpy(desc[i], desc[i - 1], sizeof(desc[0])); - getSavegameDescription(_firstSlot, desc[0]); - } - break; - case KEY_DOWN_RIGHT: - // This is probably triggered by Page Down. - _firstSlot += NUM_VISIBLE_SLOTS; - if (_firstSlot > NUM_SLOTS - NUM_VISIBLE_SLOTS) { - _firstSlot = NUM_SLOTS - NUM_VISIBLE_SLOTS; - } - for (i = 0; i < NUM_VISIBLE_SLOTS; i++) - getSavegameDescription(_firstSlot + i, desc[i]); - break; - case KEY_UP_RIGHT: - // This is probably triggered by Page Up. - _firstSlot -= NUM_VISIBLE_SLOTS; - if (_firstSlot < 0) { - _firstSlot = 0; - } - for (i = 0; i < NUM_VISIBLE_SLOTS; i++) - getSavegameDescription(_firstSlot + i, desc[i]); - break; } _gfx->doUpdate(); } -press: - debugC(8, kDebugLevelMain | kDebugLevelInput, "Button pressed: %d", rc); - -getout: closeWindow(); _noSaveLoadAllowed = false; diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp index 3247862e32..1886a74ab1 100644 --- a/engines/agi/text.cpp +++ b/engines/agi/text.cpp @@ -340,8 +340,6 @@ int AgiEngine::messageBox(const char *s) { int AgiEngine::selectionBox(const char *m, const char **b) { int numButtons = 0; int x, y, i, s; - int key, active = 0; - int rc = -1; int bx[5], by[5]; _noSaveLoadAllowed = true; @@ -380,7 +378,9 @@ int AgiEngine::selectionBox(const char *m, const char **b) { AllowSyntheticEvents on(this); debugC(4, kDebugLevelText, "selectionBox(): waiting..."); - while (!(shouldQuit() || _restartGame)) { + int key, active = 0; + int rc = -1; + while (rc == -1 && !(shouldQuit() || _restartGame)) { for (i = 0; b[i]; i++) _gfx->drawCurrentStyleButton(bx[i], by[i], b[i], i == active, false, i == 0); @@ -389,10 +389,8 @@ int AgiEngine::selectionBox(const char *m, const char **b) { switch (key) { case KEY_ENTER: rc = active; - goto press; - case KEY_ESCAPE: - rc = -1; - goto getout; + debugC(4, kDebugLevelText, "selectionBox(): Button pressed: %d", rc); + break; case KEY_RIGHT: active++; if (active >= numButtons) @@ -407,7 +405,8 @@ int AgiEngine::selectionBox(const char *m, const char **b) { for (i = 0; b[i]; i++) { if (_gfx->testButton(bx[i], by[i], b[i])) { rc = active = i; - goto press; + debugC(4, kDebugLevelText, "selectionBox(): Button pressed: %d", rc); + break; } } break; @@ -418,12 +417,11 @@ int AgiEngine::selectionBox(const char *m, const char **b) { break; } _gfx->doUpdate(); - } -press: - debugC(4, kDebugLevelText, "selectionBox(): Button pressed: %d", rc); + if (key == KEY_ESCAPE) + break; + } -getout: closeWindow(); debugC(2, kDebugLevelText, "selectionBox(): Result = %d", rc); |
