From af1cebf7a1a01d935e685ce6adb0cdc40237b060 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 25 Apr 2022 00:53:13 -0700 Subject: [PATCH] Unify drawing room name on map menus into one function Previously, it was copy-pasted and slightly different, when really, they ought to both be the exact same code. It kind of pains me that the room name, glitch name, and hidden name don't own their own memory, but, that's to be addressed later. What's a bit annoying is that the `temp` variable used in `teleporterrender` also ends up being reused later in the function. In this case, I opted to just redeclare them when they are used anyway, to make it clearer. Apart from `teleporterrender` no longer calling `map.area` or caring about `map.custommode`, it also no longer cares about `graphics.fademode` being 0. I could never actually get this condition to be false in practice, and I have absolutely no idea why it's there. I'm guessing it could be some weird edge case rendering issue if the screen is fully black? But I wouldn't know how to trigger that, and anyway it should probably be fixed elsewhere. So I'm just going to remove that conditional. --- desktop_version/src/Render.cpp | 56 ++++++++++++++++------------------ 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 36558b5b..457dba39 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -2013,6 +2013,26 @@ void gamerender(void) graphics.renderwithscreeneffects(); } +static void draw_roomname_menu(void) +{ + const char* name; + + if (map.hiddenname[0] != '\0') + { + name = map.hiddenname; + } + else if (map.finalmode) + { + name = map.glitchname; + } + else + { + name = map.roomname; + } + + graphics.Print(5, 2, name, 196, 196, 255 - help.glow, true); +} + /* Used to keep some graphics positions on the map screen * the same in Flip Mode. */ #define FLIP(y, h) (graphics.flipmode ? 220 - (y) - (h) : (y)) @@ -2021,20 +2041,7 @@ void maprender(void) { ClearSurface(graphics.backBuffer); - //draw screen alliteration - //Roomname: - if (map.hiddenname[0] != '\0') - { - graphics.Print(5, 2, map.hiddenname, 196, 196, 255 - help.glow, true); - } - else - { - if (map.finalmode){ - graphics.Print(5, 2, map.glitchname, 196, 196, 255 - help.glow, true); - }else{ - graphics.Print(5, 2, map.roomname, 196, 196, 255 - help.glow, true); - } - } + draw_roomname_menu(); //Background color FillRect(graphics.backBuffer,0, 12, 320, 240, 10, 24, 26 ); @@ -2721,17 +2728,8 @@ void teleporterrender(void) ClearSurface(graphics.backBuffer); int tempx; int tempy; - //draw screen alliteration - //Roomname: - int temp = map.area(game.roomx, game.roomy); - if (temp < 2 && !map.custommode && graphics.fademode==0) - { - graphics.Print(5, 2, map.hiddenname, 196, 196, 255 - help.glow, true); - } - else - { - graphics.Print(5, 2, map.roomname, 196, 196, 255 - help.glow, true); - } + + draw_roomname_menu(); //Background color FillRect(graphics.backBuffer, 0, 12, 320, 240, 10, 24, 26); @@ -2778,13 +2776,13 @@ void teleporterrender(void) { if (map.showteleporters && map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) { - temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y); + int temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y); if (graphics.flipmode) temp += 3; graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp); } else if(map.showtargets && !map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) { - temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y); + int temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y); if (graphics.flipmode) temp += 3; graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp); } @@ -2796,7 +2794,7 @@ void teleporterrender(void) { if (!obj.collect[i]) { - temp = 1086; + int temp = 1086; if (graphics.flipmode) temp += 3; graphics.drawtile(40 + 3 + (map.shinytrinkets[i].x * 12), 22 + (map.shinytrinkets[i].y * 9), temp); } @@ -2808,7 +2806,7 @@ void teleporterrender(void) if (game.useteleporter && ((help.slowsine%16)>8)) { //colour in the legend - temp = 1128; + int temp = 1128; if (graphics.flipmode) temp += 3; graphics.drawtile(40 + 3 + (tempx * 12), 22 + (tempy * 9), temp); }