From 45dd7c39b711f73478779f44cd1118ebc418b315 Mon Sep 17 00:00:00 2001 From: Misa Date: Thu, 5 Aug 2021 16:38:06 -0700 Subject: [PATCH] Fix cycling title BG more than once per frame This can happen if you select an option in a menu that (A) returns to the previous menu and (B) saves settings. If the settings save fails, this will create another menu on the same frame that cycles the tower BG after it's already been cycled for that frame. Examples are the slowdown and glitchrunner menus. I could fix this by creating a new function that copy-pastes all of Game::savestatsandsettings_menu() except for the map.nexttowercolour() at the end. But that's copy-pasting code. Instead what I've done is added a variable to signal if the color has already been cycled this frame, so we don't cycle it again. This also covers cases of possible double-cycling in the future as well. --- desktop_version/src/Map.cpp | 9 +++++++++ desktop_version/src/Map.h | 1 + desktop_version/src/main.cpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 406bee9b..bcac820f 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -82,6 +82,8 @@ mapclass::mapclass(void) cameraseek = 0; minitowermode = false; roomtexton = false; + + nexttowercolour_set = false; } //Areamap starts at 100,100 and extends 20x20 @@ -631,6 +633,13 @@ void mapclass::updatetowerglow(TowerBG& bg_obj) void mapclass::nexttowercolour(void) { + /* Prevent cycling title BG more than once per frame. */ + if (nexttowercolour_set) + { + return; + } + nexttowercolour_set = true; + graphics.titlebg.colstate+=5; if (graphics.titlebg.colstate >= 30) graphics.titlebg.colstate = 0; diff --git a/desktop_version/src/Map.h b/desktop_version/src/Map.h index 796c3833..cf7814d5 100644 --- a/desktop_version/src/Map.h +++ b/desktop_version/src/Map.h @@ -55,6 +55,7 @@ public: void updatetowerglow(TowerBG& bg_obj); void nexttowercolour(void); + bool nexttowercolour_set; void settowercolour(int t); diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index bbf4806c..af7af8c6 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -724,7 +724,7 @@ static void unfocused_run(void) static void focused_begin(void) { - /* no-op. */ + map.nexttowercolour_set = false; } static void focused_end(void)