Compare commits

...

2 Commits

Author SHA1 Message Date
Misa 775ac4c40c Fix bringing up map menu during gamemode(teleporter)
When gamemode(teleporter) gets run in a script, it brings up a read-only
version of the teleporter screen, intended only for displaying rooms on
the minimap.

However, ever since 2.3 allowed bringing up the map screen during
cutscenes (in order to prevent softlocks), bringing up the map screen
during this mode would (1) do an unnecessary animation of suddenly
switching back to the game and bringing up the menu screen again (even
though the menu screen has already been brought up), and (2) would let
you close the menu entirely and go back to GAMEMODE, thus
unintentionally closing the teleporter screen and kind of ruining the
cutscene.

To fix this, when you bring up the map screen, it will instead instantly
transition to the map screen. And when you bring it down, it will also
instantly transition back to the teleporter screen.

But that's not all. The previous behavior was actually kind of a nice
failsafe, in that if you somehow got stuck in a state where a script ran
gamemode(teleporter), but stopped running before it could take you out
of that mode by running gamemode(game), then you could return to
GAMEMODE yourself by bringing up the map screen and then bringing it
back down. So I've made sure to keep that failsafe behavior, only as
long as there isn't a script running.
2020-12-28 21:12:51 -05:00
Misa 0eddd2d015 De-duplicate menu animation code when bringing up map screen
When bringing up the map screen, the game does a small menu animation
where the menu comes in from the bottom. The code to calculate the menu
offset is copy-pasted everywhere, so I thought I'd de-duplicate it to
make my life easier when working with it. I also included the
game.gamestate assignment in the de-duplicated function, so it would be
easier for a future bugfix.

At the same time, I'm also removing all the BlitSurfaceStandard()s that
copied menubuffer to backBuffer. The red flag is that this blit happened
for every single entry point to MAPMODE and TELEPORTERMODE, except for
the script command gamemode(teleporter). Pressing Enter to bring up the
map screen, pressing Enter to quit the Super Gravitron, pressing Esc to
bring up the pause screen, and pressing Enter to bring up the teleporter
screen all do this blit, so if this blit was there to fix a bug, then
there's a bug with using the script command gamemode(teleporter)... but,
as far as I can tell, there isn't.

That's because the blit basically does nothing. All the blit does is
copy menubuffer onto backBuffer. Then the next thing that happens is
that either maprender() or teleporterrender() will be called, and the
first thing that those functions will always do is fill backBuffer with
solid black, completely overriding the previous blit. So that's why
removing this blit won't have any effect, and it can be safely removed
for code clarity.
2020-12-28 19:55:23 -05:00
5 changed files with 64 additions and 62 deletions

View File

@ -117,6 +117,8 @@ void Game::init(void)
musicmutebutton = 0;
glitchrunkludge = false;
gamestate = TITLEMODE;
prevgamestate = TITLEMODE;
hascontrol = true;
jumpheld = false;
advancetext = false;
@ -7146,3 +7148,25 @@ void Game::unlockAchievement(const char *name) {
if (!map.custommode) NETWORK_unlockAchievement(name);
#endif
}
void Game::mapmenuchange(const int newgamestate)
{
prevgamestate = gamestate;
gamestate = newgamestate;
graphics.resumegamemode = false;
mapheld = true;
if (prevgamestate == GAMEMODE)
{
graphics.menuoffset = 240;
if (map.extrarow)
{
graphics.menuoffset -= 10;
}
}
else
{
graphics.menuoffset = 0;
}
graphics.oldmenuoffset = graphics.menuoffset;
}

View File

@ -206,6 +206,7 @@ public:
bool glitchrunkludge;
int gamestate;
int prevgamestate; //only used sometimes
bool hascontrol, jumpheld;
int jumppressed;
int gravitycontrol;
@ -218,6 +219,7 @@ public:
int tapleft, tapright;
//Menu interaction stuff
void mapmenuchange(const int newgamestate);
bool mapheld;
int menupage;
int lastsaved;

View File

@ -1769,7 +1769,16 @@ void gameinput()
}
}
if (!game.press_map) game.mapheld = false;
if (!game.press_map
//Extra conditionals as a kludge fix so if you open the quit menu during
//the script command gamemode(teleporter) and close it with Esc, it won't
//immediately open again
//We really need a better input system soon...
&& !key.isDown(27)
&& !key.isDown(game.controllerButton_esc))
{
game.mapheld = false;
}
if (game.intimetrial && graphics.fademode == 1 && game.quickrestartkludge)
{
@ -1846,18 +1855,7 @@ void gameinput()
else if (game.companion == 0)
{
//Alright, normal teleporting
game.gamestate = TELEPORTERMODE;
graphics.menuoffset = 240; //actually this should count the roomname
graphics.oldmenuoffset = 240;
if (map.extrarow)
{
graphics.menuoffset -= 10;
graphics.oldmenuoffset -= 10;
}
BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL);
graphics.resumegamemode = false;
game.mapmenuchange(TELEPORTERMODE);
game.useteleporter = true;
game.initteleportermode();
@ -2010,19 +2008,10 @@ void gameinput()
//quitting the super gravitron
game.mapheld = true;
//Quit menu, same conditions as in game menu
game.gamestate = MAPMODE;
game.mapmenuchange(MAPMODE);
game.gamesaved = false;
game.gamesavefailed = false;
graphics.resumegamemode = false;
game.menupage = 20; // The Map Page
BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL);
graphics.menuoffset = 240; //actually this should count the roomname
graphics.oldmenuoffset = 240;
if (map.extrarow)
{
graphics.menuoffset -= 10;
graphics.oldmenuoffset -= 10;
}
}
else if (game.intimetrial && graphics.fademode == 0)
{
@ -2039,12 +2028,11 @@ void gameinput()
else
{
//Normal map screen, do transition later
game.gamestate = MAPMODE;
game.mapmenuchange(MAPMODE);
map.cursordelay = 0;
map.cursorstate = 0;
game.gamesaved = false;
game.gamesavefailed = false;
graphics.resumegamemode = false;
if (script.running)
{
game.menupage = 3; // Only allow saving
@ -2053,34 +2041,18 @@ void gameinput()
{
game.menupage = 0; // The Map Page
}
BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL);
graphics.menuoffset = 240; //actually this should count the roomname
graphics.oldmenuoffset = 240;
if (map.extrarow)
{
graphics.menuoffset -= 10;
graphics.oldmenuoffset -= 10;
}
}
if ((key.isDown(27) || key.isDown(game.controllerButton_esc)) && (!map.custommode || map.custommodeforreal))
if (!game.mapheld
&& (key.isDown(27) || key.isDown(game.controllerButton_esc))
&& (!map.custommode || map.custommodeforreal))
{
game.mapheld = true;
//Quit menu, same conditions as in game menu
game.gamestate = MAPMODE;
game.mapmenuchange(MAPMODE);
game.gamesaved = false;
game.gamesavefailed = false;
graphics.resumegamemode = false;
game.menupage = 30; // Pause screen
BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL);
graphics.menuoffset = 240; //actually this should count the roomname
graphics.oldmenuoffset = 240;
if (map.extrarow)
{
graphics.menuoffset -= 10;
graphics.oldmenuoffset -= 10;
}
}
if (game.deathseq == -1 && (key.isDown(SDLK_r) || key.isDown(game.controllerButton_restart)) && !game.nodeathmode)// && map.custommode) //Have fun glitchrunners!

View File

@ -197,14 +197,27 @@ void maprenderfixed()
graphics.oldmenuoffset = graphics.menuoffset;
if (graphics.resumegamemode)
{
graphics.menuoffset += 25;
int threshold = map.extrarow ? 230 : 240;
if (graphics.menuoffset >= threshold)
if (game.prevgamestate == GAMEMODE
//Failsafe: if the script command gamemode(teleporter) got ran and the
//cutscene stopped without doing gamemode(game), then we need to go
//back to GAMEMODE, not game.prevgamestate (TELEPORTERMODE)
|| !script.running)
{
graphics.menuoffset += 25;
int threshold = map.extrarow ? 230 : 240;
if (graphics.menuoffset >= threshold)
{
graphics.menuoffset = threshold;
//go back to gamemode!
game.mapheld = true;
game.gamestate = GAMEMODE;
}
}
else
{
graphics.menuoffset = threshold;
//go back to gamemode!
game.mapheld = true;
game.gamestate = GAMEMODE;
game.gamestate = game.prevgamestate;
graphics.resumegamemode = false;
}
}
else if (graphics.menuoffset > 0)

View File

@ -1322,23 +1322,14 @@ void scriptclass::run()
{
if (words[1] == "teleporter")
{
//TODO this draw the teleporter screen. This is a problem. :(
game.gamestate = TELEPORTERMODE;
graphics.menuoffset = 240; //actually this should count the roomname
graphics.oldmenuoffset = 240;
if (map.extrarow)
{
graphics.menuoffset -= 10;
graphics.oldmenuoffset -= 10;
}
graphics.resumegamemode = false;
game.mapmenuchange(TELEPORTERMODE);
game.useteleporter = false; //good heavens don't actually use it
}
else if (words[1] == "game")
{
graphics.resumegamemode = true;
game.prevgamestate = GAMEMODE;
}
}
else if (words[0] == "ifexplored")