From 45d310550868c103cbe123a23875c398f18c67a6 Mon Sep 17 00:00:00 2001 From: tmatale Date: Fri, 2 Aug 2024 16:41:40 -0400 Subject: [PATCH] Fix #22292: Progress bars displayed incorrectly if multiple windows are open --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/Guest.cpp | 56 +++++++++++++++---------------- src/openrct2-ui/windows/Ride.cpp | 16 +++++---- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 2533f1d72e..0e7d5f0836 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -31,6 +31,7 @@ - Fix: [#22222] Staff list may remain invalid when changing tabs. - Fix: [#22265] Button for switching covered tracks on slides doesn’t stay pressed. - Fix: [#22284] Unrated rides cause high amount of nausea. +- Fix: [#22292] Progress bar widgets in guest and ride windows are not updating correctly. - Fix: [#22304] Graphs don’t draw lines on the left edge of the screen. - Fix: [#22318] Water sparkles are missing if transparent water is enabled without RCT1 linked. - Fix: [#22333] Tile inspector closes other tool windows. diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 20fc64e9a7..16ac4ab758 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1064,6 +1064,34 @@ static_assert(_guestWindowPageWidgets.size() == WINDOW_GUEST_PAGE_COUNT); void OnDrawStats(DrawPixelInfo& dpi) { + // ebx + const auto peep = GetGuest(); + if (peep == nullptr) + { + return; + } + + int32_t happinessPercentage = NormalizeGuestStatValue(peep->Happiness, kPeepMaxHappiness, 10); + WidgetProgressBarSetNewPercentage(widgets[WIDX_HAPPINESS_BAR], happinessPercentage); + + int32_t energyPercentage = NormalizeGuestStatValue( + peep->Energy - kPeepMinEnergy, kPeepMaxEnergy - kPeepMinEnergy, 10); + WidgetProgressBarSetNewPercentage(widgets[WIDX_ENERGY_BAR], energyPercentage); + + int32_t hungerPercentage = NormalizeGuestStatValue(peep->Hunger - 32, 158, 0); + hungerPercentage = 100 - hungerPercentage; // the bar should be longer when peep->Hunger is low + WidgetProgressBarSetNewPercentage(widgets[WIDX_HUNGER_BAR], hungerPercentage); + + int32_t thirstPercentage = NormalizeGuestStatValue(peep->Thirst - 32, 158, 0); + thirstPercentage = 100 - thirstPercentage; // the bar should be longer when peep->Thirst is low + WidgetProgressBarSetNewPercentage(widgets[WIDX_THIRST_BAR], thirstPercentage); + + int32_t nauseaPercentage = NormalizeGuestStatValue(peep->Nausea - 32, 223, 0); + WidgetProgressBarSetNewPercentage(widgets[WIDX_NAUSEA_BAR], nauseaPercentage); + + int32_t toiletPercentage = NormalizeGuestStatValue(peep->Toilet - 64, 178, 0); + WidgetProgressBarSetNewPercentage(widgets[WIDX_TOILET_BAR], toiletPercentage); + DrawWidgets(dpi); OverviewTabDraw(dpi); StatsTabDraw(dpi); @@ -1073,13 +1101,6 @@ static_assert(_guestWindowPageWidgets.size() == WINDOW_GUEST_PAGE_COUNT); InventoryTabDraw(dpi); DebugTabDraw(dpi); - // ebx - const auto peep = GetGuest(); - if (peep == nullptr) - { - return; - } - // Not sure why this is not stats widgets // cx dx auto screenCoords = windowPos @@ -1088,47 +1109,26 @@ static_assert(_guestWindowPageWidgets.size() == WINDOW_GUEST_PAGE_COUNT); // Happiness DrawTextBasic(dpi, screenCoords, STR_GUEST_STAT_HAPPINESS_LABEL); - int32_t happinessPercentage = NormalizeGuestStatValue(peep->Happiness, kPeepMaxHappiness, 10); - WidgetProgressBarSetNewPercentage(widgets[WIDX_HAPPINESS_BAR], happinessPercentage); - // Energy screenCoords.y += kListRowHeight; DrawTextBasic(dpi, screenCoords, STR_GUEST_STAT_ENERGY_LABEL); - int32_t energyPercentage = NormalizeGuestStatValue( - peep->Energy - kPeepMinEnergy, kPeepMaxEnergy - kPeepMinEnergy, 10); - WidgetProgressBarSetNewPercentage(widgets[WIDX_ENERGY_BAR], energyPercentage); - // Hunger screenCoords.y += kListRowHeight; DrawTextBasic(dpi, screenCoords, STR_GUEST_STAT_HUNGER_LABEL); - int32_t hungerPercentage = NormalizeGuestStatValue(peep->Hunger - 32, 158, 0); - hungerPercentage = 100 - hungerPercentage; // the bar should be longer when peep->Hunger is low - WidgetProgressBarSetNewPercentage(widgets[WIDX_HUNGER_BAR], hungerPercentage); - // Thirst screenCoords.y += kListRowHeight; DrawTextBasic(dpi, screenCoords, STR_GUEST_STAT_THIRST_LABEL); - int32_t thirstPercentage = NormalizeGuestStatValue(peep->Thirst - 32, 158, 0); - thirstPercentage = 100 - thirstPercentage; // the bar should be longer when peep->Thirst is low - WidgetProgressBarSetNewPercentage(widgets[WIDX_THIRST_BAR], thirstPercentage); - // Nausea screenCoords.y += kListRowHeight; DrawTextBasic(dpi, screenCoords, STR_GUEST_STAT_NAUSEA_LABEL); - int32_t nauseaPercentage = NormalizeGuestStatValue(peep->Nausea - 32, 223, 0); - WidgetProgressBarSetNewPercentage(widgets[WIDX_NAUSEA_BAR], nauseaPercentage); - // Toilet screenCoords.y += kListRowHeight; DrawTextBasic(dpi, screenCoords, STR_GUEST_STAT_TOILET_LABEL); - int32_t toiletPercentage = NormalizeGuestStatValue(peep->Toilet - 64, 178, 0); - WidgetProgressBarSetNewPercentage(widgets[WIDX_TOILET_BAR], toiletPercentage); - // Time in park screenCoords.y += kListRowHeight + 1; int32_t guestEntryTime = peep->GetParkEntryTime(); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index a59a9e4e8f..9ba1fc187d 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -3965,13 +3965,19 @@ static_assert(std::size(RatingNames) == 6); void MaintenanceOnDraw(DrawPixelInfo& dpi) { - DrawWidgets(dpi); - DrawTabImages(dpi); - auto ride = GetRide(rideId); if (ride == nullptr) return; + uint16_t reliability = ride->reliability_percentage; + WidgetProgressBarSetNewPercentage(widgets[WIDX_RELIABILITY_BAR], std::max(10, reliability)); + + uint16_t downTime = ride->downtime; + WidgetProgressBarSetNewPercentage(widgets[WIDX_DOWN_TIME_BAR], downTime); + + DrawWidgets(dpi); + DrawTabImages(dpi); + // Locate mechanic button image Widget* widget = &widgets[WIDX_LOCATE_MECHANIC]; auto screenCoords = windowPos + ScreenCoordsXY{ widget->left, widget->top }; @@ -3987,18 +3993,14 @@ static_assert(std::size(RatingNames) == 6); widget = &widgets[WIDX_PAGE_BACKGROUND]; screenCoords = windowPos + ScreenCoordsXY{ widget->left + 4, widget->top + 4 }; - uint16_t reliability = ride->reliability_percentage; auto ft = Formatter(); ft.Add(reliability); DrawTextBasic(dpi, screenCoords, STR_RELIABILITY_LABEL_1757, ft); - WidgetProgressBarSetNewPercentage(widgets[WIDX_RELIABILITY_BAR], std::max(10, reliability)); screenCoords.y += 11; - uint16_t downTime = ride->downtime; ft = Formatter(); ft.Add(downTime); DrawTextBasic(dpi, screenCoords, STR_DOWN_TIME_LABEL_1889, ft); - WidgetProgressBarSetNewPercentage(widgets[WIDX_DOWN_TIME_BAR], downTime); screenCoords.y += 26; // Last inspection