diff options
author | Filippos Karapetis | 2019-05-27 19:11:10 +0300 |
---|---|---|
committer | Filippos Karapetis | 2019-05-27 19:11:10 +0300 |
commit | 88855082373113a4fad3745006a9efc261051a26 (patch) | |
tree | 3afc21dc54f2f6fe1483e9b3ec3986dafb17601d | |
parent | b0699f703eeaa02d0df172380bcdad2f207e330a (diff) | |
download | scummvm-rg350-88855082373113a4fad3745006a9efc261051a26.tar.gz scummvm-rg350-88855082373113a4fad3745006a9efc261051a26.tar.bz2 scummvm-rg350-88855082373113a4fad3745006a9efc261051a26.zip |
STARTREK: Refactor code to remove more gotos
-rw-r--r-- | engines/startrek/menu.cpp | 5 | ||||
-rw-r--r-- | engines/startrek/textbox.cpp | 77 |
2 files changed, 38 insertions, 44 deletions
diff --git a/engines/startrek/menu.cpp b/engines/startrek/menu.cpp index a4a37394bf..72b72d94b5 100644 --- a/engines/startrek/menu.cpp +++ b/engines/startrek/menu.cpp @@ -337,7 +337,6 @@ int StarTrekEngine::showActionMenu() { break; case TREKEVENT_LBUTTONDOWN: -selectAndExit: displayMenu = false; addEventBack = true; break; @@ -404,7 +403,9 @@ exitMenu: case Common::KEYCODE_RETURN: case Common::KEYCODE_KP_ENTER: case Common::KEYCODE_F1: // Exit menu with whatever is selected - goto selectAndExit; + displayMenu = false; + addEventBack = true; + break; case Common::KEYCODE_PAGEUP: case Common::KEYCODE_KP9: diff --git a/engines/startrek/textbox.cpp b/engines/startrek/textbox.cpp index 15be61f7fb..a6fc0d0ee2 100644 --- a/engines/startrek/textbox.cpp +++ b/engines/startrek/textbox.cpp @@ -358,38 +358,24 @@ int StarTrekEngine::showText(TextGetterFunc textGetter, uintptr var, int xoffset break; case TEXTBUTTON_SCROLLUP: - scrollOffset -= numTextboxLines; - goto readjustScrollUp; - - case TEXTBUTTON_SCROLLDOWN: - scrollOffset += numTextboxLines; - goto readjustScrollDown; - case TEXTBUTTON_SCROLLUP_ONELINE: - scrollOffset--; - goto readjustScrollUp; - - case TEXTBUTTON_SCROLLDOWN_ONELINE: - scrollOffset++; - goto readjustScrollDown; - - case TEXTBUTTON_GOTO_TOP: - scrollOffset = 0; - goto readjustScrollUp; - - case TEXTBUTTON_GOTO_BOTTOM: - scrollOffset = numTextLines - numTextboxLines; - goto readjustScrollDown; - -readjustScrollUp: - enableMenuButtons(1 << TEXTBUTTON_SCROLLDOWN); + scrollOffset -= (textboxReturnCode == TEXTBUTTON_SCROLLUP ? numTextboxLines : 1); if (scrollOffset < 0) scrollOffset = 0; if (scrollOffset == 0) disableMenuButtons(1 << TEXTBUTTON_SCROLLUP); + enableMenuButtons(1 << TEXTBUTTON_SCROLLDOWN); + goto readjustScroll; + + case TEXTBUTTON_GOTO_TOP: + scrollOffset = 0; + disableMenuButtons(1 << TEXTBUTTON_SCROLLUP); + enableMenuButtons(1 << TEXTBUTTON_SCROLLDOWN); goto readjustScroll; -readjustScrollDown: + case TEXTBUTTON_SCROLLDOWN: + case TEXTBUTTON_SCROLLDOWN_ONELINE: + scrollOffset += (textboxReturnCode == TEXTBUTTON_SCROLLDOWN ? numTextboxLines : 1); enableMenuButtons(1 << TEXTBUTTON_SCROLLUP); if (scrollOffset >= numTextLines) scrollOffset -= numTextboxLines; @@ -399,6 +385,12 @@ readjustScrollDown: disableMenuButtons(1 << TEXTBUTTON_SCROLLDOWN); goto readjustScroll; + case TEXTBUTTON_GOTO_BOTTOM: + scrollOffset = numTextLines - numTextboxLines; + enableMenuButtons(1 << TEXTBUTTON_SCROLLUP); + disableMenuButtons(1 << TEXTBUTTON_SCROLLDOWN); + goto readjustScroll; + readjustScroll: textboxSprite.bitmapChanged = true; drawMainText( @@ -410,27 +402,28 @@ readjustScroll: break; case TEXTBUTTON_PREVCHOICE: - choiceIndex--; - if (!loopChoices && choiceIndex == 0) { - disableMenuButtons(1 << TEXTBUTTON_PREVCHOICE); - } else { - if (choiceIndex < 0) - choiceIndex = numChoices - 1; - } - enableMenuButtons(1 << TEXTBUTTON_NEXTCHOICE); - goto reloadText; - case TEXTBUTTON_NEXTCHOICE: - enableMenuButtons(1 << TEXTBUTTON_PREVCHOICE); - choiceIndex++; - if (!loopChoices && choiceIndex == numChoices - 1) { - disableMenuButtons(1 << TEXTBUTTON_NEXTCHOICE); + if (textboxReturnCode == TEXTBUTTON_PREVCHOICE) { + choiceIndex--; + if (!loopChoices && choiceIndex == 0) { + disableMenuButtons(1 << TEXTBUTTON_PREVCHOICE); + } + else { + if (choiceIndex < 0) + choiceIndex = numChoices - 1; + } + enableMenuButtons(1 << TEXTBUTTON_NEXTCHOICE); } else { - choiceIndex %= numChoices; + enableMenuButtons(1 << TEXTBUTTON_PREVCHOICE); + choiceIndex++; + if (!loopChoices && choiceIndex == numChoices - 1) { + disableMenuButtons(1 << TEXTBUTTON_NEXTCHOICE); + } + else { + choiceIndex %= numChoices; + } } - goto reloadText; -reloadText: scrollOffset = 0; lineFormattedText = readLineFormattedText(textGetter, var, choiceIndex, textBitmap, numTextboxLines, &numTextLines); if (numTextLines <= numTextboxLines) { |